:root {
  --surface: #fcfcfb;
  --surface-2: #f4f6f9;
  --card: #ffffff;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --border: #e1e0d9;
  --blue: #2a78d6;
  --blue-dark: #1c5cab;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --sidebar-w: 220px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}

.hidden { display: none !important; }

/* ---------------------------------------------------- Login screen */
#screen-login, #screen-loading {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  max-width: 420px;
  box-shadow: 0 4px 24px rgba(11,11,11,0.06);
}

.login-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 8px 0 24px;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { background: #b8c6dc; cursor: not-allowed; }

#login-error {
  margin-top: 16px;
  color: var(--critical);
  font-size: 13px;
  background: #fdecea;
  border-radius: 6px;
  padding: 10px 12px;
  text-align: left;
}

#status-line {
  color: var(--text-secondary);
  font-size: 14px;
  min-height: 20px;
}

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

.sidebar {
  width: var(--sidebar-w);
  background: #12233f;
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 12px;
}

.nav-item {
  background: none;
  border: none;
  color: rgba(255,255,255,0.75);
  text-align: left;
  padding: 12px 20px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(42,120,214,0.25); color: #fff; border-right: 3px solid var(--blue); }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 0;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12px;
  color: rgba(255,255,255,0.6);
}
#user-name { display: block; color: #fff; font-weight: 600; margin-bottom: 8px; }
.link-btn {
  background: none;
  border: none;
  color: var(--blue);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.main {
  flex: 1;
  padding: 28px 32px;
  max-width: 1200px;
}

.tab-panel h2 {
  margin: 0 0 4px;
  font-size: 20px;
}
.tab-panel .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0 0 20px;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.btn-secondary {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--surface-2); }

input[type="text"], input[type="date"], input[type="number"], input[type="search"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}

/* ---------------------------------------------------- Dashboard */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.tile-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.tile-value {
  font-size: 22px;
  font-weight: 700;
}
.tile-value.text-good { color: var(--good); }
.tile-value.text-critical { color: var(--critical); }
.tile-value.text-muted { color: var(--muted); font-size: 15px; }

.section-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 24px 0 10px;
}

/* ---------------------------------------------------- Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  font-size: 13px;
}
thead th {
  text-align: left;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}
tbody tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-good { background: #e3f6e3; color: #0a7a0a; }
.badge-critical { background: #fbe2e1; color: #a12b2b; }

/* ---------------------------------------------------- New Journal Entry */
.je-header {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
  max-width: 700px;
}
.je-header label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

#je-period-warning {
  background: #fff6e0;
  border: 1px solid var(--warning);
  color: #7a5a00;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

#je-lines th, #je-lines td { font-size: 13px; }
#je-lines input { border: 1px solid transparent; background: transparent; padding: 6px; }
#je-lines input:focus { border-color: var(--blue); background: #fff; outline: none; }
.btn-remove-line {
  background: none;
  border: none;
  color: var(--critical);
  cursor: pointer;
  font-size: 14px;
}

.je-totals {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 14px 0 20px;
  font-size: 14px;
}
.je-totals strong { font-variant-numeric: tabular-nums; }

.je-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.je-result {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 700px;
}
.je-result-ok { background: #e3f6e3; color: #0a5c0a; border: 1px solid var(--good); }
.je-result-error { background: #fbe2e1; color: #8f1f1f; border: 1px solid var(--critical); }

.loading { opacity: 0.5; pointer-events: none; }

@media (max-width: 900px) {
  #screen-app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; padding: 10px; }
  .sidebar .brand, .sidebar-footer { display: none; }
  .je-header { grid-template-columns: 1fr; }
}
