:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --ok-bg: #dcfce7; --ok-fg: #15803d;
  --info-bg: #dbeafe; --info-fg: #1d4ed8;
  --warn-bg: #fef3c7; --warn-fg: #b45309;
  --danger-bg: #fee2e2; --danger-fg: #b91c1c;
  --neutral-bg: #eef2f6; --neutral-fg: #475569;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); font-size: 13px; line-height: 1.45; color: var(--text); background: var(--bg); }
button { font: inherit; }
#root { height: 100%; }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 15px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.topbar .proj { color: var(--muted); font-size: 12.5px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--faint); font-size: 12px; }

.workspace {
  flex: 1; min-height: 0;
  display: grid; gap: 12px; padding: 12px;
  grid-template-columns: minmax(300px, 0.9fr) minmax(380px, 1.2fr) minmax(420px, 1.6fr);
}
.pane { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pane-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; font-weight: 700; }
.pane-head .count { color: var(--faint); font-size: 12px; }
.pane-body { flex: 1; overflow: auto; min-height: 0; }
.pane-body.pad { padding: 12px; }

/* Medium: list on the left, detail over files on the right. */
@media (max-width: 1279.98px) {
  .workspace { grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.6fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1.2fr); }
  .workspace .list-pane { grid-row: 1 / span 2; }
}
/* Narrow: one column, page scrolls. */
@media (max-width: 759.98px) {
  .shell { height: auto; min-height: 100vh; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; padding: 8px; gap: 8px; }
  .workspace .list-pane { grid-row: auto; max-height: 50vh; }
  .workspace .files-pane { min-height: 70vh; }
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: 1px solid var(--primary); border-radius: 8px;
  font-weight: 600; font-size: 12.5px; padding: 6px 11px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.ghost:hover { background: #f8fafc; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn.icon { padding: 4px 7px; }
.btn.block { width: 100%; padding: 9px 12px; }
.in {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 6px 9px; min-width: 0;
}
.in:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.filters { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.filters .in.search { flex: 1 1 160px; }

/* ---------- invoice list ---------- */
.inv-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px;
  width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--border);
  padding: 10px 12px; cursor: pointer; color: inherit;
}
.inv-row:hover { background: #f8fafc; }
.inv-row.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.inv-row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-row .s { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-row .r { text-align: right; }
.inv-row .amt { font-weight: 600; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); }
.tab { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; border-bottom: 2px solid transparent; padding: 7px 10px 8px; margin-bottom: -1px; color: var(--muted); font-weight: 600; font-size: 12.5px; cursor: pointer; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--primary); border-bottom-color: var(--primary); }
.tab-count { background: var(--neutral-bg); color: var(--neutral-fg); border-radius: 999px; padding: 0 7px; font-size: 11px; line-height: 18px; }
.tab.on .tab-count { background: var(--info-bg); color: var(--info-fg); }
.list-foot { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; color: var(--muted); font-size: 12px; }
.spin.sm { width: 14px; height: 14px; border-width: 2px; margin: 0; }
mark { background: #dbeafe; color: inherit; border-radius: 2px; padding: 0 1px; }

/* ---------- cards ---------- */
.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 12px; }
.card.selectable { cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.card.selectable:hover { border-color: var(--border-strong); }
.card.selected { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.card-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 12px 8px; }
.card-head .ttl { flex: 1; min-width: 0; }
.card-head .kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.card-head h3 { font-size: 15px; margin: 2px 0 0; overflow-wrap: anywhere; }
.card-head .sub { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); border-top: 1px solid var(--border); overflow: hidden; }
.stat { padding: 8px 12px; box-shadow: 1px 1px 0 var(--border); }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .v.big { font-size: 15px; }
.progress { height: 6px; border-radius: 99px; background: var(--neutral-bg); overflow: hidden; margin: 0 12px 10px; }
.progress > span { display: block; height: 100%; background: var(--primary); }
.progress-label { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); padding: 0 12px 4px; }
.card-foot { display: flex; gap: 6px; padding: 8px 12px 12px; flex-wrap: wrap; }
details.more { border-top: 1px solid var(--border); padding: 6px 12px 10px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.more dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; margin: 8px 0 0; font-size: 12px; }
details.more dt { color: var(--muted); }
details.more dd { margin: 0; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.info { background: var(--info-bg); color: var(--info-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.danger { background: var(--danger-bg); color: var(--danger-fg); }
.respond { border-top: 1px solid var(--border); padding: 10px 12px 12px; background: var(--primary-soft); display: flex; flex-direction: column; gap: 8px; }
.respond-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 12.5px; flex-wrap: wrap; }
.respond textarea.in { width: 100%; resize: vertical; font-size: 13px; }
.respond-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.approve { background: var(--ok-fg); border-color: var(--ok-fg); }
.btn.approve:hover { background: #166534; }
.btn.reject { background: var(--surface); color: var(--danger-fg); border-color: #fecaca; }
.btn.reject:hover { background: var(--danger-bg); }
.pane-head .spacer { flex: 1; }
.head-actions { display: flex; gap: 6px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: 0 20px 50px rgba(15, 23, 42, .3); width: min(520px, 100%); padding: 18px; }
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal textarea.in { width: 100%; resize: vertical; }
.modal-error { color: var(--danger-fg); font-size: 12.5px; min-height: 18px; margin-top: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.btn.danger { background: var(--danger-fg); border-color: var(--danger-fg); }
.btn.danger:hover { background: #991b1b; }
.ok-box { background: var(--ok-bg); color: var(--ok-fg); border-radius: 8px; padding: 10px 12px; }
.badge.mine { background: var(--primary); color: #fff; }
.badge.neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 4px 0 8px; display: flex; align-items: center; gap: 8px; }
.section-title .count { color: var(--faint); font-weight: 600; }

.mini-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.mini-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--surface); border: 0; border-bottom: 1px solid var(--border); padding: 8px 12px; cursor: pointer; color: inherit; }
.mini-row:last-child { border-bottom: 0; }
.mini-row:hover { background: #f8fafc; }
.mini-row.current { background: var(--primary-soft); cursor: default; }
.mini-row .grow { flex: 1; min-width: 0; }
.mini-row .amt { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- files ---------- */
.files-split { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.file-groups { overflow: auto; max-height: 40%; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.file-group-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #f8fafc; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1; }
.file-group-head .lbl { font-weight: 700; font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.file-row:hover { background: #f8fafc; }
.file-row.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.file-row .ext { flex: 0 0 38px; text-align: center; font-size: 10px; font-weight: 700; border-radius: 5px; padding: 3px 0; background: var(--neutral-bg); color: var(--neutral-fg); text-transform: uppercase; }
.file-row .ext.pdf { background: var(--danger-bg); color: var(--danger-fg); }
.file-row .ext.img { background: var(--info-bg); color: var(--info-fg); }
.file-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .dt { color: var(--faint); font-size: 11.5px; white-space: nowrap; }
.file-row .acts { display: flex; gap: 4px; }
.empty { color: var(--faint); padding: 14px 12px; font-size: 12.5px; }

.viewer { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.viewer-bar .nm { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1; overflow: auto; background: #eef1f5; padding: 10px; min-height: 0; }
.viewer-body canvas, .viewer-body img { display: block; max-width: 100%; margin: 0 auto 10px; background: #fff; box-shadow: 0 1px 4px rgba(15, 23, 42, .18); }
.viewer-body .note { text-align: center; color: var(--muted); padding: 40px 12px; }
.kbd { font-size: 11px; color: var(--faint); }

/* ---------- panel (400px side panel) ---------- */
.panel { padding: 12px; }
.panel .card-head h3 { font-size: 14px; }
.popup-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(15, 23, 42, .55); padding: 16px; display: flex; }
.popup { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: 0 20px 50px rgba(15, 23, 42, .35); }
.popup:fullscreen { border-radius: 0; }
@media (max-width: 759.98px) { .popup-backdrop { padding: 0; } .popup { border-radius: 0; } }

/* ---------- misc ---------- */
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 60vh; padding: 24px; }
.center h1 { font-size: 17px; margin: 0 0 6px; }
.center p { color: var(--muted); max-width: 420px; margin: 0 0 16px; }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; margin: 18px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: var(--danger-bg); color: var(--danger-fg); border-radius: 8px; padding: 10px 12px; margin: 12px; }
.muted { color: var(--muted); }
