/* ------------------------------------------------------------ Tokens */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #8a93a3;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #ffffff;
  --pos: #047857;
  --pos-soft: #ecfdf5;
  --neg: #b91c1c;
  --neg-soft: #fef2f2;
  --warn: #a16207;
  --warn-soft: #fefce8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f14;
    --surface: #161a22;
    --surface-2: #1b2029;
    --text: #eef0f4;
    --text-2: #b6bdc9;
    --muted: #7c8595;
    --border: #262c37;
    --border-strong: #343b48;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #1e1f3d;
    --accent-text: #0d0f14;
    --pos: #34d399;
    --pos-soft: #0f2a21;
    --neg: #f87171;
    --neg-soft: #2e1415;
    --warn: #facc15;
    --warn-soft: #2b2510;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ------------------------------------------------------------ Base */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14.5px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
button, input { font: inherit; color: inherit; }
svg { flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text);
  font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, opacity .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text-2); border-color: var(--border); font-weight: 500; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 32px; padding: 0 12px; font-size: .9rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.logo {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff;
}

/* ------------------------------------------------------------ Login */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 32px 28px 26px;
}
.login-card .logo { width: 44px; height: 44px; border-radius: 12px; margin-bottom: 18px; }
.login-card h1 { font-size: 1.35rem; }
.login-card .sub { color: var(--text-2); margin: 6px 0 24px; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: .9rem; }
.input-wrap { position: relative; }
.input {
  width: 100%; height: 42px; padding: 0 44px 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-wrap .icon-btn { position: absolute; right: 6px; top: 6px; }
.login-card .btn { width: 100%; justify-content: center; height: 42px; }
.alert {
  display: flex; gap: 8px; align-items: center;
  padding: 9px 12px; border-radius: var(--radius-sm); margin-bottom: 16px;
  background: var(--neg-soft); color: var(--neg); font-size: .9rem; font-weight: 500;
}
.login-foot {
  display: flex; gap: 8px; align-items: flex-start;
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: .85rem;
}

/* ------------------------------------------------------------ App shell */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 60px; padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .title { font-weight: 700; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 99px; font-size: .8rem; font-weight: 500;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}

.layout {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px;
  max-width: 1440px; margin: 0 auto; padding: 20px;
}

/* Sidebar */
.sidebar { display: flex; flex-direction: column; gap: 14px; align-self: start; position: sticky; top: 80px; }
.upload {
  display: flex; gap: 12px; align-items: center;
  padding: 14px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.upload:hover { border-color: var(--accent); background: var(--accent-soft); }
.upload .ico { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.upload strong { display: block; font-size: .95rem; }
.upload span { color: var(--muted); font-size: .82rem; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.filelist { padding: 6px; display: grid; gap: 2px; }
.filelist .label { padding: 8px 10px 4px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.fitem {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  width: 100%; padding: 9px 10px; border: 0; border-radius: var(--radius-sm);
  background: transparent; text-align: left; cursor: pointer;
}
.fitem:hover { background: var(--surface-2); }
.fitem.active { background: var(--accent-soft); }
.fitem .name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fitem .sub { font-size: .8rem; color: var(--muted); }
.fitem .count { font-size: .8rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.fitem .rm { opacity: 0; }
.fitem:hover .rm, .fitem:focus-within .rm { opacity: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--pos); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--neg); }
.dot.run { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.empty-list { padding: 18px 12px; color: var(--muted); font-size: .88rem; text-align: center; }

/* Content */
.content { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.content-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.content-head h1 { font-size: 1.35rem; word-break: break-word; }
.content-head .meta { color: var(--text-2); font-size: .88rem; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; }
.stat .k { font-size: .8rem; color: var(--muted); font-weight: 500; }
.stat .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.stat .v.pos { color: var(--pos); }
.stat .v.neg { color: var(--neg); }
.stat .s { font-size: .8rem; color: var(--text-2); margin-top: 2px; }

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: .9rem;
}
.banner.ok { background: var(--pos-soft); color: var(--pos); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--neg-soft); color: var(--neg); }
.banner ul { margin: 4px 0 0; padding-left: 18px; }
.banner b { font-weight: 600; }

/* Table */
.table-card { overflow: hidden; }
.table-tools { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 180px; max-width: 340px; }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.search input {
  width: 100%; height: 34px; padding: 0 10px 0 32px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.search input:focus { outline: 0; border-color: var(--accent); background: var(--surface); }
.table-tools .hint { color: var(--muted); font-size: .82rem; margin-left: auto; }
.table-wrap { overflow: auto; max-height: calc(100vh - 360px); min-height: 200px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .88rem; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-2);
  font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.date { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-2); }
td.party { font-weight: 600; min-width: 160px; }
td.purpose { color: var(--text-2); min-width: 240px; }
td.kind { white-space: nowrap; }
td.kind span { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: .8rem; color: var(--text-2); }
td.src { white-space: nowrap; color: var(--muted); font-size: .82rem; }
th.num, td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.num { font-weight: 600; }
td.num.pos { color: var(--pos); }
td.num.neg { color: var(--neg); }
td.invalid { background: var(--neg-soft) !important; box-shadow: inset 0 0 0 1px var(--neg); }
td[contenteditable] { cursor: text; border-radius: 4px; }
td[contenteditable]:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface); }
td.row-act { width: 1%; padding: 5px 6px; }
td.row-act .icon-btn { opacity: 0; }
tr:hover td.row-act .icon-btn, td.row-act .icon-btn:focus { opacity: 1; }
.no-rows { padding: 40px 16px; text-align: center; color: var(--muted); }

/* Skeleton */
.skeleton { display: grid; gap: 10px; padding: 18px; }
.skeleton div { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Empty state */
.hero {
  display: grid; place-items: center; text-align: center; gap: 14px;
  padding: 64px 24px; border: 2px dashed var(--border-strong); border-radius: 18px;
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.hero:hover { border-color: var(--accent); }
.hero .ico { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 18px; background: var(--accent-soft); color: var(--accent); }
.hero h2 { font-size: 1.25rem; }
.hero p { margin: 0; color: var(--text-2); max-width: 460px; }
.steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 4px; }
.step { padding: 16px; text-align: left; }
.step .n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .8rem; margin-bottom: 8px; }
.step b { display: block; margin-bottom: 2px; }
.step span { color: var(--text-2); font-size: .88rem; }

/* Error card */
.error-card { padding: 28px; display: grid; gap: 8px; justify-items: start; }
.error-card h2 { color: var(--neg); font-size: 1.1rem; }
.error-card p { margin: 0; color: var(--text-2); }

/* Drag overlay */
.drag-overlay {
  position: fixed; inset: 0; z-index: 50; display: none; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent); backdrop-filter: blur(3px);
}
.drag-overlay.show { display: grid; }
.drag-overlay div {
  padding: 28px 40px; border-radius: 18px; border: 2px dashed var(--accent);
  background: var(--surface); box-shadow: var(--shadow-lg); font-weight: 700; font-size: 1.1rem;
}

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg);
  font-weight: 500; white-space: nowrap; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ------------------------------------------------------------ Responsive */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .sidebar { position: static; }
  body.is-empty .sidebar { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-wrap { max-height: none; }
}
@media (max-width: 600px) {
  .topbar { padding: 0 16px; }
  .topbar .chip { display: none; }
  .steps { grid-template-columns: 1fr; }
  .hero { padding: 40px 16px; }
  .table-tools .hint { display: none; }
  .actions, .actions .btn { width: 100%; justify-content: center; }
}
