:root {
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --muted-bg: #f8fafc;
  --border: #e2e8f0;
  --card: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-fg: #f1f5f9;
  --sidebar-border: #1e293b;
  --sidebar-accent: #1e293b;
  --gold: #c49c3c;
  --danger: #dc2626;
}
.dark {
  --bg: #0f172a;
  --fg: #f1f5f9;
  --muted: #94a3b8;
  --muted-bg: #1e293b;
  --border: #1e293b;
  --card: #1e293b;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold); text-decoration: none; }
input, select, textarea, button { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
.hidden { display: none !important; }

/* Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--sidebar-bg); padding: 16px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card); color: var(--fg);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25); padding: 32px;
}
.login-logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-logo img { height: 96px; width: 96px; object-fit: contain; }
.login-logo h1 { margin: 0; font-size: 20px; }
.login-logo p { margin: 0; color: var(--muted); font-size: 14px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--fg);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--gold); outline-offset: -1px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500;
  transition: opacity 0.15s; border: 1px solid transparent;
}
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--fg); color: var(--bg); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--fg); }
.btn-ghost { background: transparent; color: var(--fg); padding: 6px 10px; }
.btn-ghost:hover { background: var(--muted-bg); }
.btn-block { width: 100%; }

/* App shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; background: var(--sidebar-bg); color: var(--sidebar-fg);
  border-right: 1px solid var(--sidebar-border); position: relative;
  flex-shrink: 0;
}
.sidebar-header { display: flex; align-items: center; gap: 12px; padding: 20px; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-header img { height: 40px; width: 40px; object-fit: contain; }
.sidebar-header .brand { line-height: 1.2; }
.sidebar-header .brand-name { font-weight: 600; color: var(--gold); }
.sidebar-header .brand-sub { font-size: 13px; color: rgba(241,245,249,0.7); }
.sidebar-nav { padding: 16px 12px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 6px; font-size: 14px;
  color: rgba(241,245,249,0.8); margin-bottom: 4px;
}
.sidebar-nav a:hover { background: var(--sidebar-accent); color: #fff; }
.sidebar-nav a.active { background: var(--gold); color: #0f172a; font-weight: 500; }
.sidebar-footer {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 16px; border-top: 1px solid var(--sidebar-border);
}
.sidebar-footer button {
  display: flex; width: 100%; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 6px; font-size: 14px;
  color: rgba(241,245,249,0.8);
}
.sidebar-footer button:hover { background: var(--sidebar-accent); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 600; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.menu-toggle { display: none; padding: 4px; }
.content { padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 20px; overflow: hidden;
}
.card-header { padding: 20px 20px 0; }
.card-header h2 { margin: 0; font-size: 16px; }
.card-header p { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.card-body { padding: 20px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}

.stat-card .label {
  font-size: 11px; text-transform: uppercase; color: var(--muted);
  letter-spacing: 0.05em;
}
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 8px; }
.stat-card .icon { float: right; color: var(--gold); }

.row { display: flex; gap: 12px; align-items: center; }
.row-end { justify-content: flex-end; }
.spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th { text-align: left; padding: 8px 12px 8px 0; color: var(--muted); border-bottom: 1px solid var(--border); font-weight: 500; }
table td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--border); }
table tr:last-child td { border-bottom: none; }
.amt { text-align: right; color: var(--gold); font-weight: 600; }
.text-muted { color: var(--muted); font-size: 14px; }
.text-right { text-align: right; }
.font-bold { font-weight: 600; }
.text-gold { color: var(--gold); }

.welcome h2 { margin: 0 0 4px; font-size: 24px; }
.welcome p { margin: 0; color: var(--muted); font-size: 14px; }
.section-title { margin: 20px 0 12px; font-size: 16px; font-weight: 600; }

/* Toast */
#toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--card); color: var(--fg);
  border: 1px solid var(--border); border-left: 4px solid var(--gold);
  padding: 12px 16px; border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1); font-size: 14px;
  min-width: 240px; animation: slideIn 0.2s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: #16a34a; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Mobile */
@media (max-width: 1024px) {
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.2s;
  }
  .sidebar.open { transform: none; }
  .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 30; }
}

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.list li:last-child { border-bottom: none; }
.list .name { font-weight: 500; }
.list .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

code { background: var(--muted-bg); padding: 1px 6px; border-radius: 4px; font-size: 13px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
