:root {
  --navy: #1e3a5f;
  --navy-dark: #162c48;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --line: #e2e6ec;
  --text: #1f2937;
  --muted: #6b7280;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .18);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
body { display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }

/* ---------- top bar ---------- */
#topbar { display: flex; align-items: center; gap: 14px; height: 52px; padding: 0 18px; background: var(--navy); color: #fff; box-shadow: var(--shadow); position: sticky; top: 0; z-index: 50; }
#topbar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; letter-spacing: .2px; }
#topbar .brand:hover { text-decoration: none; }
#topbar .logo { width: 26px; height: 26px; border-radius: 6px; display: inline-block; background: #fff; }
#crumbs { display: flex; align-items: center; gap: 6px; color: #cbd5e1; font-size: .95rem; min-width: 0; overflow: hidden; white-space: nowrap; }
#crumbs a { color: #e2e8f0; }
#crumbs span.sep { opacity: .5; }
#crumbs .cur { color: #fff; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
#topbar .spacer { flex: 1; }
#topbar-right { display: flex; align-items: center; gap: 10px; }
#topbar-right .user { color: #e2e8f0; font-size: .9rem; }
.menu-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.menu-btn:hover { background: rgba(255,255,255,.2); }

/* ---------- layout ---------- */
#app { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.page { max-width: 1400px; width: 100%; margin: 0 auto; padding: 22px 18px 40px; }
.page.full { max-width: none; padding: 0; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel .panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel .panel-head h2 { margin: 0; }
.panel .panel-body { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; }
.right { margin-left: auto; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
.hidden { display: none !important; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 6px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 500; line-height: 1.2; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--bad); border-color: #fca5a5; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef2f7; }
.btn.sm { padding: 4px 9px; font-size: .85rem; }
.btn.icon { padding: 6px 8px; }
.btn.on { background: var(--accent-soft); border-color: #93c5fd; color: #1e40af; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .85rem; font-weight: 500; color: #374151; }
.input, select.input, textarea.input { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; width: 100%; }
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.input.sm { padding: 4px 7px; font-size: .9rem; }
.input.invalid { border-color: var(--bad); background: #fff7f7; }
.form-error { color: var(--bad); font-size: .9rem; margin: 6px 0; }
.search { max-width: 340px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: #166534; }
.badge.warn { background: var(--warn-soft); color: #92400e; }
.badge.bad { background: var(--bad-soft); color: #991b1b; }
.badge.info { background: var(--accent-soft); color: #1e40af; }
.badge.gray { background: #eef2f7; color: #475569; }
.badge.navy { background: var(--navy); color: #fff; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.high { background: var(--ok); } .dot.medium { background: var(--warn); } .dot.low, .dot.none { background: var(--bad); }

/* ---------- tables ---------- */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover td { background: #f8fafc; }
table.grid tr.group-row td { background: #eef2f7; font-weight: 600; padding: 7px 12px; color: var(--navy); }
.thumb { width: 84px; height: 56px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 4px; display: block; }
.thumb.lg { width: 120px; height: 80px; }
.sheet-num { font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .95rem; }

/* ---------- projects ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); cursor: pointer; transition: transform .1s, box-shadow .1s; }
.card:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.card h3 { margin-bottom: 4px; }
.card .stats { display: flex; gap: 14px; color: var(--muted); font-size: .9rem; margin-top: 10px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- project page ---------- */
.project-layout { display: grid; grid-template-columns: 230px 1fr; gap: 18px; align-items: start; }
.side-nav { position: sticky; top: 68px; }
.side-nav a { display: flex; justify-content: space-between; padding: 7px 12px; border-radius: 6px; color: var(--text); }
.side-nav a:hover { background: #eef2f7; text-decoration: none; }
.side-nav a.on { background: var(--accent-soft); color: #1e40af; font-weight: 600; }
.side-nav .cnt { color: var(--muted); font-size: .85rem; }
.side-nav h3 { padding: 6px 12px; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.imports-list .imp { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.imports-list .imp:last-child { border-bottom: 0; }
.progress { height: 8px; background: #e5e7eb; border-radius: 4px; overflow: hidden; width: 180px; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.dropzone { border: 2px dashed #cbd5e1; border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); background: #fafbfc; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: #1e40af; }
.dropzone .file-name { color: var(--text); font-weight: 600; margin-top: 6px; }

/* ---------- review ---------- */
.review-summary { display: flex; gap: 10px; flex-wrap: wrap; }
.review-summary .stat { padding: 8px 14px; border-radius: 6px; background: #fff; border: 1px solid var(--line); font-weight: 600; }
.review-summary .stat.new { border-color: #93c5fd; color: #1e40af; background: #eff6ff; }
.review-summary .stat.upd { border-color: #86efac; color: #166534; background: #f0fdf4; }
.review-summary .stat.skip { color: var(--muted); }
.review-summary .stat.att { border-color: #fca5a5; color: #991b1b; background: #fef2f2; }
table.review td { vertical-align: top; }
table.review .num-input { width: 110px; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
table.review .title-input { width: 100%; min-width: 220px; }
table.review .disc-input { width: 190px; }
table.review tr.skip td { opacity: .55; }
table.review tr.attention td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.thumb-btn { border: 0; background: none; padding: 0; cursor: pointer; }
.match-select { max-width: 320px; }
.review-footer { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; gap: 10px; box-shadow: 0 -4px 12px rgba(16,24,40,.06); }

/* ---------- sheet viewer ---------- */
.viewer-page { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .title { font-weight: 600; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.toolbar .title .num { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.05rem; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.viewer-layout { flex: 1; display: flex; min-height: 0; }
.osd { flex: 1; background: #d9dee5; min-height: 0; position: relative; }
.osd .osd-loading { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--muted); pointer-events: none; }
.versions-side { width: 320px; background: #fff; border-left: 1px solid var(--line); overflow-y: auto; }
.versions-side h3 { padding: 12px 14px 4px; }
.versions-side .hint { padding: 0 14px 8px; }
.ver { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 10px; cursor: pointer; }
.ver:hover { background: #f8fafc; }
.ver.on { background: var(--accent-soft); }
.ver .thumb { width: 72px; height: 48px; flex: none; }
.ver .meta { flex: 1; min-width: 0; font-size: .85rem; }
.ver .meta .top { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: .95rem; }
.ver .meta .line { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ver .acts { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }

/* ---------- compare ---------- */
.compare-toolbar .modes { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.compare-toolbar .modes button { border: 0; background: #fff; padding: 6px 11px; cursor: pointer; border-right: 1px solid var(--line); }
.compare-toolbar .modes button:last-child { border-right: 0; }
.compare-toolbar .modes button.on { background: var(--accent-soft); color: #1e40af; font-weight: 600; }
.legend { display: inline-flex; align-items: center; gap: 12px; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; }
.legend i.red { background: #e11d48; } .legend i.blue { background: #2563eb; } .legend i.black { background: #111; }
.slider { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; }
.slider input { width: 90px; }
.nudge { display: inline-grid; grid-template-columns: repeat(3, 24px); grid-template-rows: repeat(2, 20px); gap: 2px; }
.nudge button { border: 1px solid var(--line); background: #fff; border-radius: 4px; cursor: pointer; font-size: .75rem; padding: 0; line-height: 1; }
.nudge button:hover { background: #eef2f7; }
.split { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; min-height: 0; }
.split .osd { position: relative; }
.split .pane-label { position: absolute; top: 8px; left: 8px; z-index: 5; background: rgba(255,255,255,.9); padding: 3px 8px; border-radius: 4px; font-size: .8rem; font-weight: 600; }
.pane-label.old { color: #b91c1c; } .pane-label.new { color: #1d4ed8; }
select.ver-select { padding: 5px 8px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; }

/* ---------- modal & toast ---------- */
#modal-root .backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 10px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 92vh; display: flex; flex-direction: column; }
.modal.wide { max-width: 1100px; }
.modal.xl { max-width: 96vw; height: 92vh; }
.modal .m-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .m-head h2 { margin: 0; flex: 1; }
.modal .m-body { padding: 18px; overflow: auto; flex: 1; min-height: 0; }
.modal .m-body.tight { padding: 0; display: flex; flex-direction: column; }
.modal .m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal .x { border: 0; background: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); line-height: 1; }
#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: .9rem; max-width: 360px; animation: fadein .15s; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }
.toast.warn { background: var(--warn, #b26a00); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.preview-img { max-width: 100%; display: block; margin: 0 auto; border: 1px solid var(--line); background: #fff; }
.pv-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
.pv-grid img { width: 100%; border: 1px solid var(--line); background: #fff; }
.login-box { max-width: 380px; margin: 60px auto; }
.login-box .logo-big { display: flex; justify-content: center; margin: 4px 0 18px; }
.login-box .logo-big img { height: 56px; }
.spinner { width: 18px; height: 18px; border: 2px solid #cbd5e1; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
kbd { background: #eef2f7; border: 1px solid #cbd5e1; border-radius: 4px; padding: 0 5px; font-size: .8em; font-family: inherit; }

@media (max-width: 900px) {
  .project-layout { grid-template-columns: 1fr; }
  .side-nav { position: static; display: flex; flex-wrap: wrap; gap: 4px; }
  .side-nav h3 { width: 100%; }
  .versions-side { width: 260px; }
  .pv-grid { grid-template-columns: 1fr; }
  #crumbs { display: none; }
}
@media (max-width: 640px) {
  .viewer-layout { flex-direction: column; }
  .versions-side { width: auto; max-height: 40vh; border-left: 0; border-top: 1px solid var(--line); }
  .split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  table.grid th:nth-child(n+5), table.grid td:nth-child(n+5) { display: none; }
}

/* ---------- sheet browser: list toolbar, card grid, revision flags ---------- */
.toolbar { align-items: center; gap: 10px; }
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); flex: none; }
.view-toggle button { border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); font-size: 1rem; line-height: 1; }
.view-toggle button + button { border-left: 1px solid var(--line); }
.view-toggle button:hover { background: #f1f5f9; color: var(--text); }
.view-toggle button.on { background: var(--navy); color: #fff; }

.disc-code { display: inline-block; min-width: 26px; padding: 1px 6px; margin-right: 6px; border-radius: 4px;
  background: var(--navy); color: #fff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; text-align: center; }
table.grid tr.group-row .disc-code { background: var(--navy); }
table.grid.sheets thead th { position: sticky; top: 52px; z-index: 2; }

.disc-head { display: flex; align-items: center; margin: 16px 0 8px; font-weight: 600; color: var(--navy);
  font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; }
.disc-head:first-child { margin-top: 0; }
.sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.sheet-card { display: flex; flex-direction: column; text-align: left; padding: 0; cursor: pointer; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: box-shadow .12s, border-color .12s, transform .12s; }
.sheet-card:hover { border-color: #b9c6d8; box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.sheet-card .sc-thumb { position: relative; aspect-ratio: 3 / 2; background:
  repeating-conic-gradient(#f8fafc 0% 25%, #eef2f7 0% 50%) 50% / 14px 14px; display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--line); }
.sheet-card .sc-thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.sheet-card .sc-thumb .badge { position: absolute; top: 6px; right: 6px; }
.sheet-card .sc-meta { padding: 8px 10px 10px; min-width: 0; }
.sheet-card .sc-num { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; color: var(--navy); font-size: .95rem; }
.sheet-card .sc-title { color: var(--text); font-size: .82rem; line-height: 1.3; margin: 2px 0 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.1em; }
.sheet-card .sc-foot { display: flex; align-items: center; gap: 6px; }

.badge.rev { background: #fff1e6; color: #9a3412; border: 1px solid #fdba74; }

@media (max-width: 820px) {
  .project-layout { grid-template-columns: 1fr; }
  .side-nav { position: static; }
  .sheet-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  table.grid.sheets thead th { position: static; }
}
