@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Geist+Mono:wght@400;500;600&family=Geist:wght@300;400;500;600;700&display=swap');

/* ── Variables ── */
:root {
  --bg:         #f4f6f9;
  --surface:    #ffffff;
  --surface2:   #f8f9fb;
  --border:     #e4e8ef;
  --border2:    #d0d7e3;
  --primary:    #2563eb;
  --primary-bg: #eff4ff;
  --primary-border: #c7d9fd;
  --text:       #0f172a;
  --text2:      #475569;
  --muted:      #94a3b8;
  --red:        #ef4444;
  --red-bg:     #fef2f2;
  --green:      #10b981;
  --green-bg:   #f0fdf4;
  --blue-bg:    #eff6ff;
  --slate-bg:   #f8fafc;
  --shadow:     0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04);
  --radius:     12px;
  --sans:       'Geist', system-ui, sans-serif;
  --mono:       'Geist Mono', monospace;
  --serif:      'Instrument Serif', Georgia, serif;
  --sidebar-w:  248px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ── App Layout ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}

.sidebar-logo {
  height: 60px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-logo-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-logo-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logo-sub {
  font-size: .67rem;
  color: var(--muted);
  line-height: 1.3;
}

.sidebar-close {
  display: none;
  width: 28px; height: 28px;
  border: none; background: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 7px;
  align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sidebar-close:hover { background: var(--surface2); color: var(--text); }

.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  overflow-y: auto;
}

.sidebar-nav-label {
  font-size: .62rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 0 8px;
  margin-bottom: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--text2);
  font-size: .83rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  margin-bottom: 2px;
  user-select: none;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
}

.nav-item-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface2);
  flex-shrink: 0;
  transition: background .15s;
}

.nav-item.active .nav-item-icon {
  background: rgba(37,99,235,.12);
}

.nav-item-text {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.nav-item-text span { line-height: 1.3; }
.nav-item-text small {
  font-size: .67rem;
  color: var(--muted);
  font-weight: 400;
  line-height: 1.3;
}

.nav-chevron {
  color: var(--muted);
  opacity: 0;
  flex-shrink: 0;
  transition: opacity .15s;
}

.nav-item.active .nav-chevron { opacity: 1; color: var(--primary); }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-footer-icon {
  width: 28px; height: 28px;
  background: var(--surface2);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
}

.sidebar-footer-title {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-footer-sub {
  font-size: .64rem;
  color: var(--muted);
  line-height: 1.3;
}

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,23,42,.3);
  backdrop-filter: blur(4px);
  z-index: 40;
}

/* ── Main area ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  height: 60px;
  padding: 0 20px 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-shrink: 0;
}

.topbar-menu {
  display: none;
  width: 34px; height: 34px;
  border: none; background: none;
  color: var(--text2);
  cursor: pointer;
  border-radius: 8px;
  align-items: center; justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}

.topbar-menu:hover { background: var(--surface2); }

.topbar-title {
  font-size: .92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.topbar-sub {
  font-size: .68rem;
  color: var(--muted);
  line-height: 1.2;
}

/* ── Page content ── */
.page-content {
  flex: 1;
  padding: 24px 24px 40px;
  max-width: 1400px;
  width: 100%;
}

.hidden { display: none !important; }

/* ── Upload Zone ── */
.upload-zone {
  border: 2px dashed var(--border2);
  border-radius: 16px;
  background: var(--surface);
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 16px;
  overflow: hidden;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.upload-zone input { display: none; }

.upload-zone-inner {
  padding: 44px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.upload-icon-wrap {
  width: 60px; height: 60px;
  border-radius: 16px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  margin-bottom: 6px;
  transition: all .2s;
  border: 1px solid var(--border);
}

.upload-zone:hover .upload-icon-wrap,
.upload-zone.drag-over .upload-icon-wrap {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: scale(1.05);
}

#uploadTitle {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

#uploadSub {
  font-size: .8rem;
  color: var(--muted);
}

.choose-btn {
  margin-top: 8px;
  padding: 9px 22px;
  border-radius: 9px;
  border: 1px solid var(--primary-border);
  background: var(--primary-bg);
  color: var(--primary);
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

.choose-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* ── Spinner ── */
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── File chips ── */
.file-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 9px;
  border-radius: 100px;
  font-size: .74rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  transition: all .2s;
}

.chip.loading { border-color: var(--primary-border); background: var(--primary-bg); color: var(--primary); }
.chip.done    { border-color: #bbf7d0; background: var(--green-bg); color: #059669; }
.chip.error   { border-color: #fecaca; background: var(--red-bg); color: var(--red); }

.chip-icon { width: 14px; height: 14px; flex-shrink: 0; }
.chip-spin { animation: spin .8s linear infinite; }
.chip-count { opacity: .65; font-size: .68rem; }

/* ── Status bar ── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  font-size: .82rem;
  transition: border-color .2s;
}

.status-bar.processing { border-color: var(--primary-border); }
.status-bar.done       { border-color: #bbf7d0; }
.status-bar.error      { border-color: #fecaca; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
  animation: pulse 1.4s ease-in-out infinite;
}

.status-bar.done .status-dot { background: var(--green); animation: none; }
.status-bar.error .status-dot { background: var(--red); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.85); }
}

.status-content { flex: 1; }

.progress-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 2px;
  transition: width .4s ease;
  width: 0%;
}

/* ── Summary cards ── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.scard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  transition: box-shadow .2s, transform .2s;
}

.scard:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.scard-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.scard-label {
  font-size: .65rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  line-height: 1.4;
}

.scard-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.scard-icon.blue  { background: #eff6ff; color: #3b82f6; }
.scard-icon.red   { background: #fef2f2; color: #ef4444; }
.scard-icon.green { background: #f0fdf4; color: #10b981; }
.scard-icon.slate { background: #f8fafc; color: #64748b; }

.scard-val {
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.02em;
}

.scard-val.red-val { color: var(--red); }

/* ── Results header ── */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.results-title-wrap { display: flex; align-items: center; gap: 10px; }

.results-title {
  font-size: .98rem;
  font-weight: 700;
  color: var(--text);
}

.row-badge {
  padding: 3px 10px;
  border-radius: 100px;
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  font-size: .7rem;
  font-weight: 600;
  font-family: var(--mono);
}

.results-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Action buttons ── */
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
}

.action-btn.ghost {
  background: transparent;
  color: var(--text2);
  border-color: var(--border);
}
.action-btn.ghost:hover { background: var(--red-bg); color: var(--red); border-color: #fecaca; }

.action-btn.outline {
  background: var(--surface);
  color: var(--text2);
  border-color: var(--border);
}
.action-btn.outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

.action-btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.action-btn.primary:hover { background: #1d4ed8; }

/* ── Table ── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .78rem;
}

thead { background: var(--surface2); }

thead th {
  padding: 11px 14px;
  text-align: left;
  font-family: var(--mono);
  font-size: .64rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

thead th.r { text-align: right; }
thead th.th-num { width: 42px; }

.sortable { cursor: pointer; transition: color .15s; }
.sortable:hover { color: var(--text); }

.sort-icon {
  font-size: .7rem;
  opacity: .4;
  margin-left: 2px;
}

.sort-icon.asc::after { content: '↑'; }
.sort-icon.desc::after { content: '↓'; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}

tbody tr:hover { background: var(--surface2); }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: 11px 14px; vertical-align: middle; }

.td-num {
  font-family: var(--mono);
  font-size: .7rem;
  color: var(--muted);
}

.tx-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  font-family: var(--mono);
  font-size: .72rem;
  font-weight: 500;
  white-space: nowrap;
}

.td-store { font-size: .74rem; max-width: 160px; word-break: break-word; }
.td-mono  { font-family: var(--mono); font-size: .71rem; color: var(--text2); white-space: nowrap; }
.td-desc  { font-size: .74rem; max-width: 200px; }

.num {
  font-family: var(--mono);
  text-align: right;
  font-size: .78rem;
}

.neg {
  font-family: var(--mono);
  text-align: right;
  font-size: .78rem;
  color: var(--red);
}

tfoot {
  background: var(--surface2);
  border-top: 2px solid var(--primary-border);
}

tfoot td {
  padding: 11px 14px;
  font-weight: 700;
  font-family: var(--mono);
  font-size: .78rem;
}

.total-label { color: var(--muted); font-size: .7rem; letter-spacing: .05em; text-transform: uppercase; }

/* ── Empty state ── */
.empty-state {
  margin-top: 8px;
  border: 1px dashed var(--border2);
  border-radius: 14px;
  padding: 44px 24px;
  text-align: center;
  background: var(--surface);
}

.empty-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  margin: 0 auto 12px;
}

.empty-title { font-size: .9rem; font-weight: 700; color: var(--text2); margin-bottom: 4px; }
.empty-sub   { font-size: .78rem; color: var(--muted); }

/* ── History page ── */
.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.history-sub { font-size: .74rem; color: var(--muted); margin-top: 3px; }

.history-session {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  transition: box-shadow .2s;
}

.history-session:hover { box-shadow: var(--shadow-md); }

.session-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background .15s;
}

.session-header:hover { background: var(--surface2); }

.session-file-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--primary-bg);
  border: 1px solid var(--primary-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.session-info { flex: 1; min-width: 0; }

.session-name {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-meta {
  font-size: .7rem;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.session-stats {
  display: flex;
  gap: 20px;
  flex-shrink: 0;
}

.session-stat { text-align: right; }

.session-stat-label {
  font-size: .6rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  display: block;
}

.session-stat-val {
  font-family: var(--mono);
  font-size: .84rem;
  font-weight: 700;
  color: var(--text);
}

.session-chevron {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
  transition: background .15s, transform .2s;
}

.session-header:hover .session-chevron { background: var(--border); }
.session-chevron.open { transform: rotate(90deg); }

.session-delete {
  width: 28px; height: 28px;
  border-radius: 7px;
  border: none;
  background: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all .15s;
}

.session-delete:hover { background: var(--red-bg); color: var(--red); }

.session-rows {
  border-top: 1px solid var(--border);
  display: none;
}

.session-rows.open { display: block; }

.session-rows table { font-size: .76rem; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .sidebar-overlay.show { display: block; }
  .sidebar-close { display: flex; }
  .topbar-menu { display: flex; }
  .page-content { padding: 16px 14px 32px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .session-stats { display: none; }
}

@media (max-width: 520px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .results-header { flex-direction: column; align-items: flex-start; }
  .scard-val { font-size: 1.1rem; }
}