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

/* ── Design tokens ── */
:root {
  --accent:        #6366f1;
  --accent-dark:   #4f46e5;
  --accent-light:  #eef2ff;
  --accent-glow:   rgba(99,102,241,0.15);

  --sidebar-bg:    #0f0f17;
  --sidebar-w:     220px;

  --surface:       #ffffff;
  --surface-2:     #f8f8fc;
  --surface-3:     #f1f1f7;
  --border:        #e8e8f0;
  --border-light:  #f0f0f6;

  --text-primary:   #0d0d14;
  --text-secondary: #6b6b80;
  --text-muted:     #a0a0b8;

  --green:   #16a34a;
  --green-bg:#dcfce7;
  --red:     #dc2626;
  --red-bg:  #fee2e2;
  --amber:   #d97706;
  --amber-bg:#fef3c7;

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  18px;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 6px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.06);

  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Base ── */
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface-2);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 200;
  padding: 20px 12px;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 8px;
}
.brand-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.04);
}

.nav-user-name {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-logout {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.4);
  padding: 3px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
.nav-logout:hover { color: rgba(255,255,255,0.8); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  color: rgba(255,255,255,0.5);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  letter-spacing: -0.01em;
}
.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.85);
}
.nav-item.active {
  background: var(--accent-glow);
  color: #a5b4fc;
}
.nav-item.active .nav-icon { opacity: 1; }

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 8px 0;
}

/* ── Main area ── */
.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 28px;
}

/* ── Typography ── */
h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}
h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  color: var(--text-primary);
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 12px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

/* ── Stat grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  display: block;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  opacity: 0;
  transition: opacity var(--transition);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: #d4d4e8;
}
.stat-card:hover::before { opacity: 1; }
.stat-card.warn::before { background: linear-gradient(90deg, var(--red), #f87171); opacity: 1; }
.stat-card.warn .stat-value { color: var(--red); }

.stat-value {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  margin: 8px 0 6px;
  color: var(--text-primary);
}
.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Tables ── */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
th {
  background: var(--surface-2);
  text-align: left;
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13.5px;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover td { background: var(--surface-2); }
tr.unmatched td { background: #fffbeb; }

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-weight: 500;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  padding: 8px 18px;
  border-radius: var(--radius-xl);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: -0.01em;
  border: none;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(99,102,241,0.3), 0 0 0 0 var(--accent-glow);
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn:hover {
  background: var(--accent-dark);
  box-shadow: 0 4px 12px rgba(99,102,241,0.35);
  transform: translateY(-1px);
}
.btn:active { transform: none; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background: var(--surface-3);
  box-shadow: var(--shadow-sm);
  border-color: #d0d0e4;
}

.btn-danger {
  background: none;
  border: 1px solid #fca5a5;
  color: var(--red);
  padding: 6px 12px;
  border-radius: var(--radius-xl);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-danger:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  padding: 0;
  text-decoration: none;
  font-weight: 500;
}
.btn-link:hover { text-decoration: underline; opacity: 0.8; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ── Flash messages ── */
.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
}
.flash-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.flash.success {
  background: var(--green-bg);
  color: #14532d;
  border-color: #bbf7d0;
}
.flash.success .flash-icon { background: var(--green); color: #fff; }
.flash.error {
  background: var(--red-bg);
  color: #7f1d1d;
  border-color: #fecaca;
}
.flash.error .flash-icon { background: var(--red); color: #fff; }

/* ── Status colors ── */
.positive { color: var(--green); font-weight: 600; }
.negative { color: var(--red);   font-weight: 600; }
.hint     { color: var(--text-muted); font-size: 11px; }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  margin-top: 4px;
}
.pag-info {
  font-size: 12px;
  color: var(--text-muted);
}
.pag-pages {
  display: flex;
  align-items: center;
  gap: 3px;
}
.pag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.pag-btn:hover:not(.disabled):not(.active) {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-primary);
}
.pag-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-color: var(--accent);
}
.pag-btn.disabled {
  color: var(--text-muted);
  cursor: default;
}

/* ── Stat card sub-line ── */
.stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.stat-sub.positive { color: var(--green); font-weight: 500; }
.stat-sub.negative { color: var(--red);   font-weight: 500; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar input,
.filter-bar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.filter-bar input:focus,
.filter-bar select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.filter-bar button {
  padding: 8px 16px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background var(--transition), border-color var(--transition);
}
.filter-bar button:hover { background: var(--surface-3); border-color: #d0d0e4; }

/* ── Inline form ── */
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input,
.inline-form select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.inline-form input:focus,
.inline-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Full forms ── */
form input,
form select,
form textarea {
  display: block;
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-family: inherit;
  margin-top: 5px;
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}
form input:focus,
form select:focus,
form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
form label {
  display: block;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 14px;
  font-weight: 500;
}
form textarea { height: 80px; resize: vertical; }
form .actions { margin-top: 28px; display: flex; gap: 10px; }

dl { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
dt { color: var(--text-secondary); font-size: 13px; }
dd { font-size: 13px; font-weight: 500; }

.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input { width: auto; display: inline; cursor: pointer; }

section { margin-top: 32px; }

/* ── Alert bar ── */
.alert-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.alert-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  text-decoration: none;
  font-weight: 500;
  transition: opacity var(--transition);
  border: 1px solid transparent;
}
.alert-item:hover { opacity: 0.85; }
.alert-item.warn {
  background: var(--amber-bg);
  color: #92400e;
  border-color: #fcd34d;
}

/* ── Report sections ── */
.report-section {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}
.report-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 18px;
  background: linear-gradient(135deg, var(--accent) 0%, #818cf8 100%);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
}
.report-section-header .hint { color: rgba(255,255,255,0.65); font-size: 11px; }
.section-totals { display: flex; gap: 10px; align-items: center; font-size: 13px; }
.section-totals .hint { color: rgba(255,255,255,0.6); }

.subtype-section { border-top: 1px solid var(--border-light); }
.subtype-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 18px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Tables inside report sections lose the wrapper border-radius */
.report-section table { border-radius: 0; box-shadow: none; border: none; }
.report-section th { background: var(--surface-3); }
.report-section td { border-bottom-color: var(--border-light); }

/* ── Collapsible cat blocks ── */
.cat-block {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  margin-bottom: 10px;
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.cat-block:hover { box-shadow: var(--shadow-sm); }
.cat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.cat-header:hover { background: var(--surface-2); }
.cat-name { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
.cat-arrow {
  font-size: 10px;
  color: var(--text-muted);
  width: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition);
}
.cat-body-inner { padding: 0; border-top: 1px solid var(--border-light); }
.cat-body-inner table { margin: 0; box-shadow: none; border: none; border-radius: 0; }
.cat-body-inner th { background: var(--surface-2); }
