/* =========================================================================
   ERP Indonesia — Design System
   A modern, professional look for a self-hosted accounting ERP.
   Brand: indigo/violet on a soft slate canvas with a graphite sidebar.
   ========================================================================= */

/* ---- Design tokens ---- */
:root {
  /* Brand (indigo → violet gradient feel) */
  --brand: #6366f1;          /* indigo-500 */
  --brand-dark: #4f46e5;     /* indigo-600 */
  --brand-darker: #3730a3;   /* indigo-800 */
  --brand-light: #e0e7ff;    /* indigo-100 */
  --brand-soft: #eef2ff;     /* indigo-50 */

  /* Neutrals (slate scale) */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;

  /* Status palette */
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0ea5e9;           /* sky-500 — fresher than blue */
  --info-bg: #e0f2fe;
  --neutral-bg: #f1f5f9;

  /* Sidebar (graphite, slightly warmer than pure slate) */
  --sidebar-bg: #18181b;     /* zinc-900 */
  --sidebar-bg-2: #27272a;   /* zinc-800 */
  --sidebar-text: #d4d4d8;   /* zinc-300 */
  --sidebar-text-dim: #71717a; /* zinc-500 */
  --sidebar-active: #818cf8;   /* indigo-400 — pops on dark */

  /* Layout */
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-sm: 5px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", Consolas, monospace;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 0.5rem; font-weight: 600; color: var(--text); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.5rem; }
small { color: var(--text-3); }

/* ---- App shell ---- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--sidebar-bg-2);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.sidebar-brand .logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--brand), var(--brand-active));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
  box-shadow: 0 2px 6px rgba(20, 184, 166, 0.4);
}
.sidebar-brand .name { font-weight: 600; font-size: 0.95rem; color: #fff; }
.sidebar-brand .sub { font-size: 0.7rem; color: var(--sidebar-text-dim); }

.nav-section { padding: 0.75rem 0; border-bottom: 1px solid var(--sidebar-bg-2); }
.nav-section:last-child { border-bottom: 0; }
.nav-section .label {
  padding: 0.4rem 1.25rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text-dim);
  font-weight: 600;
}
summary.label {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  user-select: none;
}
summary.label::-webkit-details-marker { display: none; }
summary.label::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--sidebar-text-dim);
  border-bottom: 1.5px solid var(--sidebar-text-dim);
  transform: rotate(-45deg);
  transition: transform 0.15s;
  margin-right: 2px;
}
details[open] > summary.label::after { transform: rotate(45deg); }
details.nav-section summary.label:hover { color: #fff; }
.nav-section-body { overflow: hidden; }
details.nav-section:not([open]) > .nav-section-body { display: none; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 1.25rem;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.nav-item:hover { background: var(--sidebar-bg-2); color: #fff; text-decoration: none; }
.nav-item.active {
  background: var(--sidebar-bg-2);
  border-left-color: var(--sidebar-active);
  color: #fff;
  font-weight: 500;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-item .badge-count {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

/* ---- Main area ---- */
.main { display: flex; flex-direction: column; min-width: 0; }

/* ---- Topbar ---- */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .company-info { display: flex; flex-direction: column; line-height: 1.2; }
.topbar .company-info .name { font-weight: 600; font-size: 0.9rem; }
.topbar .company-info .meta { font-size: 0.72rem; color: var(--text-3); }
.topbar .spacer { flex: 1; }
.topbar .search {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  width: 280px;
  font-size: 0.85rem;
}
.topbar .user-menu {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.topbar .user-menu:hover { background: var(--surface-2); }
.topbar .avatar {
  width: 30px; height: 30px;
  background: var(--brand);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.78rem;
}
.topbar .user-info { line-height: 1.15; font-size: 0.78rem; }
.topbar .user-info .role { color: var(--text-3); font-size: 0.7rem; }

/* ---- Page content ---- */
.content { padding: 1.5rem; max-width: 1400px; width: 100%; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.page-head .subtitle { color: var(--text-2); font-size: 0.85rem; margin-top: 0.15rem; }
.page-head .actions { display: flex; gap: 0.5rem; align-items: center; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-head {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 0.95rem; }
.card-body { padding: 1.1rem; }
.card-body.flush { padding: 0; }

/* ---- KPI cards (dashboard) ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.kpi .label {
  font-size: 0.75rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  display: flex; align-items: center; gap: 0.4rem;
}
.kpi .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.kpi .delta {
  font-size: 0.75rem;
  font-weight: 500;
}
.kpi .delta.up { color: var(--success); }
.kpi .delta.down { color: var(--danger); }
.kpi .icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 0.4rem;
}
.kpi .icon svg { width: 18px; height: 18px; }
.kpi .icon.cash { background: var(--info-bg); color: var(--info); }
.kpi .icon.ar { background: var(--warning-bg); color: var(--warning); }
.kpi .icon.ap { background: var(--danger-bg); color: var(--danger); }
.kpi .icon.revenue { background: var(--success-bg); color: var(--success); }
.kpi .icon.health { background: var(--brand-light); color: var(--brand); }

/* ---- Status badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-success, .badge-posted, .badge-open, .badge-active, .badge-green {
  background: var(--success-bg); color: var(--success);
}
.badge-warning, .badge-draft, .badge-amber, .badge-pending, .badge-in_progress {
  background: var(--warning-bg); color: var(--warning);
}
.badge-danger, .badge-void, .badge-reversed, .badge-closed, .badge-overdue, .badge-red {
  background: var(--danger-bg); color: var(--danger);
}
.badge-info, .badge-blue { background: var(--info-bg); color: var(--info); }
.badge-neutral, .badge-slate { background: var(--neutral-bg); color: var(--text-2); }

/* ---- Data tables ---- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: var(--surface);
}
table.data thead th {
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.7rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.data tbody td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--brand-soft); }
table.data td.num, table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
table.data tfoot td, table.data tfoot th {
  background: var(--surface-2);
  font-weight: 600;
  padding: 0.7rem 0.9rem;
  border-top: 2px solid var(--border-strong);
}
table.data tr.muted { color: var(--text-3); }
table.data .empty-row td {
  text-align: center;
  padding: 2rem;
  color: var(--text-3);
  font-style: italic;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--brand);
  color: #fff;
  border: 0;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, transform 0.05s;
  font-family: inherit;
}
.btn:hover { background: var(--brand-dark); color: #fff; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 14px; height: 14px; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  padding: 0.35rem 0.6rem;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn-link {
  background: transparent;
  color: var(--brand);
  padding: 0;
  border: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* ---- Forms ---- */
form label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 0.25rem;
}
input, select, textarea {
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15);
}
input[type="date"], input[type="number"] { width: auto; max-width: 200px; }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ---- Filter bar ---- */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.filter-bar label { margin-bottom: 0; }
.filter-bar .actions { margin-left: auto; display: flex; gap: 0.5rem; }

/* ---- Alerts / messages ---- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid transparent;
}
.messages li.msg-success, .messages li.success { background: var(--success-bg); color: #14532d; border-color: #bbf7d0; }
.messages li.msg-error, .messages li.error { background: var(--danger-bg); color: #7f1d1d; border-color: #fecaca; }
.messages li.msg-warning, .messages li.warning { background: var(--warning-bg); color: #78350f; border-color: #fde68a; }
.messages li.msg-info, .messages li.info { background: var(--info-bg); color: #1e3a8a; border-color: #bfdbfe; }

/* ---- Health score banner ---- */
.health-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-radius: var(--radius-lg);
  margin-bottom: 1.25rem;
  border-left: 6px solid;
}
.health-banner.green { background: var(--success-bg); border-color: var(--success); color: #14532d; }
.health-banner.amber { background: var(--warning-bg); border-color: var(--warning); color: #78350f; }
.health-banner.red { background: var(--danger-bg); border-color: var(--danger); color: #7f1d1d; }
.health-banner .score { font-size: 2rem; font-weight: 700; line-height: 1; }
.health-banner .label { font-size: 0.8rem; opacity: 0.85; }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-darker) 0%, var(--brand-dark) 100%);
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 380px;
}
.login-card .logo {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--brand), var(--brand-active));
  border-radius: 12px;
  margin: 0 auto 1rem;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px;
}
.login-card h1 { text-align: center; font-size: 1.15rem; margin-bottom: 0.25rem; }
.login-card .subtitle { text-align: center; color: var(--text-3); font-size: 0.8rem; margin-bottom: 1.5rem; }
.login-card form label { display: block; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 0.5rem; }

/* ---- Misc utilities ---- */
.text-right { text-align: right; }
.text-muted { color: var(--text-3); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-mono { font-family: var(--font-mono); }
.pill { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--neutral-bg); font-size: 0.7rem; color: var(--text-2); }
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.row { display: flex; gap: 0.5rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- Print ---- */
@media print {
  .sidebar, .topbar, .filter-bar, .actions, .btn { display: none !important; }
  .app { display: block; }
  .content { padding: 0; }
  .card { border: 0; box-shadow: none; }
  body { background: #fff; }
}

/* ---- Responsive (tablet / mobile) ---- */
@media (max-width: 1024px) {
  :root { --sidebar-w: 64px; }
  .sidebar-brand .name, .sidebar-brand .sub,
  .nav-item span:not(.badge-count), .nav-section .label { display: none; }
  .nav-item { justify-content: center; padding: 0.7rem 0; }
  .nav-item .badge-count { position: absolute; right: 8px; top: 4px; }
  .nav-item { position: relative; }
}
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar .search { display: none; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
