:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #667481;
  --line: #dce2e6;
  --paper: #ffffff;
  --canvas: #f3f5f4;
  --nav: #10293c;
  --nav-soft: #1a3b51;
  --accent: #ed6a38;
  --accent-dark: #ce4d21;
  --green: #16735a;
  --amber: #ae6b05;
  --red: #b73f35;
  --radius: 14px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(360px, 520px);
  background: var(--nav);
}
.login-story { padding: clamp(42px, 8vw, 120px); color: white; align-self: center; }
.login-story .eyebrow { color: #f4a17f; }
.login-story h1 { font-size: clamp(42px, 7vw, 86px); line-height: .96; max-width: 800px; margin: 14px 0 24px; letter-spacing: -.055em; }
.login-story p { max-width: 650px; color: #c9d6de; font-size: 19px; line-height: 1.55; }
.login-panel { background: #f8f8f4; padding: clamp(32px, 6vw, 82px); display: flex; flex-direction: column; justify-content: center; }
.login-panel h2 { font-size: 32px; margin: 0 0 8px; }
.login-panel form { margin-top: 28px; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--nav); color: white; padding: 28px 18px; display: flex; flex-direction: column; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 28px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: var(--accent); display: grid; place-items: center; font-weight: 800; }
.brand strong { display: block; letter-spacing: -.02em; }
.brand small { color: #9fb3c0; }
.nav { display: grid; gap: 6px; }
.nav button { background: transparent; border: 0; color: #c5d2da; text-align: left; padding: 12px 14px; border-radius: 10px; }
.nav button:hover, .nav button.active { background: var(--nav-soft); color: white; }
.user { margin-top: auto; padding: 18px 10px 0; border-top: 1px solid #29475a; color: #c4d1d9; }
.user strong { display: block; color: white; margin-bottom: 4px; }
.link-button { padding: 0; background: transparent; border: 0; color: #8fb3c9; margin-top: 10px; }
.main { min-width: 0; }
.topbar { min-height: 82px; padding: 20px clamp(22px, 4vw, 54px); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.78); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 5; }
.topbar h1 { margin: 0; font-size: 26px; letter-spacing: -.035em; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.content { padding: 30px clamp(22px, 4vw, 54px) 60px; max-width: 1600px; margin: auto; }

.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 800; color: var(--accent-dark); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.button { border: 0; border-radius: 10px; padding: 11px 16px; background: var(--accent); color: white; font-weight: 700; box-shadow: 0 4px 14px rgba(210,80,32,.16); }
.button:hover { background: var(--accent-dark); }
.button.secondary { color: var(--ink); background: white; border: 1px solid var(--line); box-shadow: none; }
.button.small { padding: 7px 10px; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-height: 126px; }
.stat .number { font-size: 37px; font-weight: 780; letter-spacing: -.05em; margin-top: 16px; }
.stat .stat-value { font-size: 22px; font-weight: 760; letter-spacing: -.025em; margin-top: 18px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat.warn { border-top: 4px solid var(--accent); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr); gap: 20px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel + .panel { margin-top: 20px; }
.finance-grid { margin-top: 20px; }
.finance-stats { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
.hierarchy-stats { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
.item-stats { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
.compact-stat { min-height: 100px; }
.compact-stat .number { margin-top: 10px; font-size: 31px; }
.panel-head { padding: 18px 20px; display: flex; gap: 14px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { margin: 0; letter-spacing: -.025em; }
.panel-body { padding: 20px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 34px 20px; text-align: center; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 12px 14px; text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; background: #f7f8f7; white-space: nowrap; }
td { padding: 13px 14px; border-top: 1px solid var(--line); vertical-align: top; }
tbody tr[data-open] { cursor: pointer; }
tbody tr[data-open]:hover { background: #fff8f4; }
.entity-link { padding: 0; border: 0; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.entity-link:hover { color: var(--accent-dark); text-decoration: underline; }
.number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.status { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; background: #eaf2ef; color: var(--green); font-size: 12px; font-weight: 750; white-space: nowrap; }
.status.warn { background: #fff1dc; color: var(--amber); }
.status.done { background: #e8f1ff; color: #2e5f9c; }
.status.cancel { background: #fbe9e7; color: var(--red); }
.progress { width: 95px; height: 7px; border-radius: 99px; background: #e8ecee; overflow: hidden; margin-top: 5px; }
.progress i { display: block; height: 100%; background: var(--green); }

.filters { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filters input, .filters select { max-width: 260px; }
.filter-panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
input, select, textarea { width: 100%; border: 1px solid #cfd7dc; border-radius: 9px; background: white; color: var(--ink); padding: 10px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(237,106,56,.12); }
textarea { resize: vertical; min-height: 82px; }
label { display: grid; gap: 6px; color: #42515d; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.checkbox-label { display: flex; align-items: center; gap: 9px; align-self: end; min-height: 42px; }
.checkbox-label input { width: auto; }
.temporary-password .copy-row { display: flex; gap: 10px; margin-top: 18px; }
.temporary-password input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 16px; }

.detail-header { background: var(--nav); color: white; border-radius: var(--radius); padding: 26px; display: flex; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.detail-header h2 { margin: 7px 0 9px; font-size: 32px; letter-spacing: -.04em; }
.detail-header .muted { color: #b7c8d2; }
.facts { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 18px; }
.fact small { display: block; color: #9eb4c1; margin-bottom: 3px; }
.fact strong { font-size: 15px; }
.attachments { display: grid; gap: 8px; }
.file { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.file small { color: var(--muted); }
.actions-list { display: grid; gap: 10px; }
.action-item { padding: 12px; border-left: 3px solid var(--accent); background: #fff8f4; border-radius: 6px 10px 10px 6px; }
.action-item strong { display: block; margin-bottom: 3px; }
.data-counts { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 14px; }
.data-counts span { border: 1px solid var(--line); border-radius: 10px; padding: 13px; color: var(--muted); }
.data-counts strong { display: block; color: var(--ink); font-size: 22px; margin-bottom: 3px; }
.system-components { table-layout: fixed; }
.system-components td { overflow-wrap: anywhere; }
.system-components td:first-child { width: 56%; }
.system-components td:nth-child(2) { width: 20%; }
.system-components td:last-child { width: 24%; }
.legacy-table { table-layout: fixed; }
.legacy-table th, .legacy-table td { padding-left: 11px; padding-right: 11px; overflow-wrap: anywhere; }
.legacy-table th:nth-child(1) { width: 14%; }
.legacy-table th:nth-child(2) { width: 27%; }
.legacy-table th:nth-child(4) { width: 13%; }
.legacy-table th:nth-child(5) { width: 104px; }
.legacy-preview { line-height: 1.45; }
details { margin-top: 8px; }
details summary { color: var(--accent-dark); cursor: pointer; font-size: 13px; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #f5f7f7; border: 1px solid var(--line); border-radius: 9px; padding: 12px; max-height: 280px; overflow: auto; font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.review-source { border: 1px solid var(--line); background: #f8f9f8; border-radius: 10px; padding: 14px; }

.structure-hint { margin: -8px 0 20px; padding: 14px 17px; border: 1px solid #f0d3c5; border-radius: 12px; background: #fff8f4; color: #5f4c43; }
.hierarchy-list { display: grid; gap: 15px; }
.factory-node { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); overflow: hidden; }
.factory-node[open] { box-shadow: 0 10px 30px rgba(16,41,60,.07); }
.factory-node > summary { position: relative; display: grid; grid-template-columns: minmax(220px, 1fr) auto auto; align-items: center; gap: 18px; padding: 18px 20px; cursor: pointer; list-style: none; }
.factory-node > summary::-webkit-details-marker { display: none; }
.factory-node > summary::before { content: "›"; grid-column: 1; position: absolute; margin-left: -11px; color: var(--accent); font-size: 21px; font-weight: 800; transition: transform .15s ease; }
.factory-node[open] > summary::before { transform: rotate(90deg); }
.factory-node > summary > span:first-child { padding-left: 10px; }
.factory-node > summary strong, .factory-node > summary small { display: block; }
.factory-node > summary strong { font-size: 18px; }
.factory-node > summary small { margin-top: 3px; color: var(--muted); }
.factory-node-counts { color: var(--muted); white-space: nowrap; font-size: 13px; }
.factory-node-counts b { color: var(--ink); }
.factory-node-body { padding: 0 20px 20px; border-top: 1px solid var(--line); background: #fafbfa; }
.factory-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; }
.contract-tree { display: grid; gap: 14px; }
.contract-node { border: 1px solid var(--line); border-left: 4px solid var(--nav-soft); border-radius: 11px; background: var(--paper); overflow: hidden; }
.contract-node-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 17px; }
.contract-node-head > div:first-child { display: grid; gap: 3px; }
.contract-link { font-size: 16px; font-weight: 780; }
.contract-node .table-wrap { border-top: 1px solid var(--line); }
.unlinked-node { border-left-color: var(--amber); }
.hierarchy-empty { padding: 24px; border: 1px dashed #cfd7dc; border-radius: 10px; color: var(--muted); text-align: center; background: white; }
.specification-table { min-width: 900px; }
.reference-tabs { display: flex; gap: 8px; margin-bottom: 18px; padding: 5px; width: fit-content; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.reference-tabs button { border: 0; border-radius: 8px; padding: 9px 14px; background: transparent; color: var(--muted); font-weight: 700; }
.reference-tabs button.active { background: var(--nav); color: white; }
.items-table { min-width: 1500px; }
.inline-facts { display: flex; flex-wrap: wrap; gap: 12px; }
.inline-facts span { min-width: 130px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); }
.inline-facts strong { display: block; color: var(--ink); font-size: 21px; margin-bottom: 3px; }

dialog { width: min(760px, calc(100vw - 30px)); border: 0; border-radius: 16px; padding: 0; box-shadow: 0 30px 100px rgba(16,41,60,.35); }
dialog::backdrop { background: rgba(12,28,40,.62); backdrop-filter: blur(3px); }
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 24px; max-height: 75vh; overflow: auto; }
.icon-button { border: 0; background: transparent; font-size: 24px; color: var(--muted); }
#toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; padding: 13px 17px; border-radius: 10px; background: var(--nav); color: white; transform: translateY(120px); opacity: 0; transition: .2s ease; box-shadow: 0 10px 35px rgba(0,0,0,.2); }
#toast.show { transform: none; opacity: 1; }
#toast.error { background: var(--red); }
.loading { padding: 80px; text-align: center; color: var(--muted); }

@media (max-width: 1050px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .data-counts { grid-template-columns: repeat(2, 1fr); }
  .factory-node > summary { grid-template-columns: minmax(180px, 1fr) auto; }
  .factory-node > summary > .status { display: none; }
}
@media (max-width: 760px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-story { display: none; }
  .shell { display: block; }
  .sidebar { position: static; height: auto; padding: 14px; }
  .brand { padding-bottom: 12px; }
  .nav { grid-auto-flow: column; grid-auto-columns: minmax(100px, 1fr); overflow: auto; }
  .nav button { text-align: center; padding: 9px 7px; font-size: 12px; white-space: nowrap; }
  .user { display: none; }
  .topbar { position: static; min-height: 70px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .detail-header { display: block; }
  .factory-node > summary { display: flex; align-items: flex-start; flex-direction: column; }
  .factory-node > summary::before { display: none; }
  .factory-node > summary > span:first-child { padding-left: 0; }
  .factory-actions, .contract-node-head { align-items: flex-start; flex-direction: column; }
  .reference-tabs { width: 100%; overflow: auto; }
  .reference-tabs button { white-space: nowrap; }
}
