:root {
  --bg: #f4f6f9;
  --sidebar: #0f172a;
  --sidebar-muted: #94a3b8;
  --accent: #10b981;
  --accent-strong: #059669;
  --accent-soft: #d1fae5;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --card: #ffffff;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.10);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  padding: 0 0 16px;
}

.brand {
  padding: 22px 20px 18px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand .logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #10b981, #059669);
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px; color: #fff;
}
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--sidebar-muted); }

.nav { padding: 8px 12px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--sidebar-muted);
  font-weight: 500;
  margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; }
.nav a .ic { width: 18px; text-align: center; font-size: 15px; }

.sidebar-foot {
  margin: 8px 16px 0;
  padding: 12px 14px;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  font-size: 12px;
  color: var(--sidebar-muted);
}
.sidebar-foot .lbl { text-transform: uppercase; letter-spacing: .06em; font-size: 10px; margin-bottom: 4px; }
.sidebar-foot .val { font-size: 16px; font-weight: 700; color: #fff; }

.sidebar-user {
  margin: 10px 16px 0;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-user .who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.sidebar-user .avatar {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}
.sidebar-user .meta { min-width: 0; }
.sidebar-user .uname {
  color: #fff; font-weight: 600; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .umail {
  color: var(--sidebar-muted); font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .signout { width: 100%; justify-content: center; }

.main { flex: 1; margin-left: 240px; min-width: 0; }

/* ---------- Small screens ----------
   The sidebar is fixed at 240px with the content offset by the same amount, which
   leaves almost nothing on a phone. Below 960px it becomes a stacked header and
   the content takes the full width. */
@media (max-width: 960px) {
  .app { display: block; }
  .sidebar {
    position: static;
    inset: auto;
    width: 100%;
    padding-bottom: 10px;
  }
  .nav { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 12px 2px; }
  .nav a { margin-bottom: 0; }
  .sidebar-foot {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 10px 16px 0;
  }
  .sidebar-foot .lbl { margin-bottom: 0; }
  .sidebar-foot .val { font-size: 14px; }
  .sidebar-user { flex-direction: row; align-items: center; justify-content: space-between; }
  .sidebar-user .who { min-width: 0; }
  .sidebar-user .signout { width: auto; }
  .main { margin-left: 0; }
  .topbar { padding: 14px 18px; }
  .content { padding: 18px; }
}

@media (max-width: 640px) {
  .modal { padding: 16px 10px; }
  .modal-dialog { max-width: 100%; }
  .modal-body { padding: 18px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; justify-content: center; }
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; }
.topbar .sub { color: var(--muted); font-size: 13px; }

.content { padding: 28px; max-width: 1240px; }

/* ---------- Flash ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-weight: 500;
  border: 1px solid;
}
.alert.success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert.error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ---------- Cards ---------- */
.grid { display: grid; gap: 20px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stat .delta { font-size: 12px; margin-top: 6px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.neutral { color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.card-body { padding: 20px; }
/* Tables live here and can be wider than a narrow viewport. `.card` clips for its
   rounded corners, so this element has to be the horizontal scroll container —
   without it the last column (row actions) is unreachable below ~955px. */
.card-body.no-pad { padding: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 900px) { .two-col, .three-col { grid-template-columns: 1fr; } }

.chart-box { position: relative; height: 300px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.pos { color: var(--green); }
.amount.neg { color: var(--red); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge.gray { background: #f1f5f9; color: #475569; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.purple { background: #f3e8ff; color: #6b21a8; }
.badge.teal { background: #ccfbf1; color: #115e59; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 11px; color: var(--muted); }

input[type=text], input[type=number], input[type=date], input[type=file], input[type=email], input[type=password], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit;
  transition: background .15s, opacity .15s;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: #f8fafc; }
.btn.danger { background: #fff; border-color: #fecaca; color: var(--red); }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; }
.toolbar .grow { flex: 1; }
.toolbar form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal.open { display: flex; }
.modal-dialog {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); color: var(--text); font-weight: 500;
}
.pagination .active, .pagination span.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.space-between { justify-content: space-between; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.legend { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.legend-item { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.legend-item .name { display: flex; align-items: center; color: var(--muted); }
.progress { height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- Auth screens ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 18px;
  background:
    radial-gradient(1100px 500px at 50% -10%, #e7fdf4 0%, transparent 60%),
    var(--bg);
}

.auth { width: 100%; max-width: 400px; }

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 26px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.auth-brand .logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #10b981, #059669);
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px; color: #fff;
}
.auth-brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }

.auth-head { padding: 20px 0 18px; }
.auth-head h1 { margin: 0 0 4px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.auth-head p { margin: 0; }

.auth-form { display: flex; flex-direction: column; gap: 15px; }
.auth-form .alert { margin-bottom: 0; }

.field .error-text { font-size: 11px; color: var(--red); font-weight: 500; }
input.invalid { border-color: #fecaca; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.check input { width: auto; margin: 0; accent-color: var(--accent); }

.btn.block { width: 100%; justify-content: center; }

.auth-foot { text-align: center; margin: 16px 0 0; }

