/* ---------------------------------------------------------------------
   Design tokens
   A financial ops tool: calm, legible, numbers-first. Deep ink sidebar,
   warm-neutral paper content area, one green accent for money-positive
   actions, amber for pending/attention, red reserved only for overdue.
--------------------------------------------------------------------- */
:root {
  --ink: #14181F;
  --ink-2: #1D232C;
  --paper: #F6F6F2;
  --surface: #FFFFFF;
  --line: #E2E2DC;
  --text: #1D232C;
  --text-muted: #62676F;
  --accent: #14603F;      /* deep green — money, confirmed */
  --accent-soft: #E4EFE9;
  --pending: #9A6B0D;      /* amber — awaiting action */
  --pending-soft: #F5EBD8;
  --danger: #A6332B;       /* overdue / errors only */
  --danger-soft: #F5E4E2;
  --radius: 6px;
  --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);
  color: var(--text);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0 0 0.5em; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* ---------------------------------------------------------------------
   Login page
--------------------------------------------------------------------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--ink);
}
.login-card {
  width: 340px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-mark {
  width: 40px; height: 40px; border-radius: 8px;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.2rem;
}
.login-brand h1 { font-size: 1.05rem; }
.first-run-note { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }

form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}
input, select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.error-text { color: var(--danger); font-size: 0.85rem; margin-bottom: 12px; }

/* ---------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: #0F4C33; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: rgba(255,255,255,0.06); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------------------------------------------------------------
   App shell
--------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--ink);
  color: #C9CDD3;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 20px; }
.sidebar-brand .mark {
  width: 28px; height: 28px; border-radius: 6px; background: var(--accent);
  color: white; display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.brand-text { color: white; font-weight: 600; font-size: 0.95rem; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: block;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: #C9CDD3;
  text-decoration: none;
  font-size: 0.9rem;
}
.nav a:hover { background: var(--ink-2); color: white; }
.nav a.active { background: var(--accent); color: white; }

.sidebar-footer { border-top: 1px solid #2A313C; padding-top: 12px; margin-top: 12px; }
.whoami { padding: 0 10px 10px; font-size: 0.82rem; color: #8B919B; }
.whoami strong { color: white; display: block; font-size: 0.9rem; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 28px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.view { padding: 24px 28px; flex: 1; }

/* ---------------------------------------------------------------------
   Data display: stat tiles, tables, cards
--------------------------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-tile .label { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 6px; }
.stat-tile .value { font-size: 1.5rem; font-weight: 600; }
.stat-tile .value.accent { color: var(--accent); }
.stat-tile .value.warn { color: var(--pending); }
.stat-tile .value.danger { color: var(--danger); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.panel-header h2 { font-size: 0.95rem; }
.panel-body { padding: 18px; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 9px 18px; border-bottom: 1px solid var(--line); }
th { color: var(--text-muted); font-weight: 500; font-size: 0.78rem; text-transform: none; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(20,96,63,0.03); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
}
.badge-success { background: var(--accent-soft); color: var(--accent); }
.badge-pending { background: var(--pending-soft); color: var(--pending); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: #EDEDE8; color: var(--text-muted); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--ink); color: white;
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 0.88rem; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.toast.error { background: var(--danger); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,24,31,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal-box {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-header h2 { font-size: 1rem; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 18px; }

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
  .nav { flex-direction: row; }
  .form-grid { grid-template-columns: 1fr; }
}

.view-as-banner {
  background: var(--pending-soft);
  color: var(--pending);
  border-bottom: 1px solid var(--pending);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: 0.88rem;
  font-weight: 600;
}
.view-as-banner .btn { font-weight: 500; }

.ac-wrap { position: relative; }
.ac-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 260px; overflow-y: auto;
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}
.ac-result { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.ac-result:last-child { border-bottom: none; }
.ac-result:hover { background: var(--accent-soft); }

.tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 10px 14px; font-size: 0.88rem; font-family: inherit; color: var(--text-muted);
  cursor: pointer; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.contract-paper {
  background: #fff; color: #111; max-width: 800px; margin: 0 auto;
  padding: 40px; border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  font-size: 0.92rem; line-height: 1.5;
}
.contract-paper h4 { margin: 20px 0 8px; }
.contract-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.contract-table td, .contract-table th { border: 1px solid #ccc; padding: 6px 10px; text-align: left; font-size: 0.88rem; }
.contract-table td:first-child { width: 45%; color: #555; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  #view { margin: 0 !important; padding: 0 !important; }
  .contract-paper { box-shadow: none; max-width: 100%; padding: 0; }
  body { background: #fff; }
}
