:root {
  --bg: #0c1f17;
  --surface: #ffffff;
  --surface-2: #f5f8f6;
  --border: #e3eae6;
  --text: #0f1f18;
  --text-soft: #5f7068;
  --muted: #94a3a0;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-soft: #f0fdf4;
  --primary-border: #bbf7d0;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(12,31,23,.06), 0 8px 24px rgba(12,31,23,.06);
  --shadow-lg: 0 10px 40px rgba(12,31,23,.18);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--surface-2); color: var(--text); font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- LOGIN ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #dcfce7 0%, var(--surface-2) 55%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 36px 30px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand .logo { width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(135deg,var(--primary),#22c55e);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; box-shadow: 0 8px 20px rgba(22,163,74,.35); }
.login-brand h1 { font-size: 19px; font-weight: 800; }
.login-brand p { color: var(--text-soft); font-size: 13px; }
.demo-hint { background: var(--primary-soft); border: 1px solid var(--primary-border); color: var(--primary-dark);
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 12.5px; margin-top: 16px; text-align: center; }

/* ---------- FORM ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: #2d3d36; }
.field .req { color: var(--danger); }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,163,74,.14); }
.textarea { resize: vertical; min-height: 76px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 0 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 0 16px; }
.col-span-2 { grid-column: span 2; }
@media (max-width: 720px) { .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; } .col-span-2 { grid-column: auto; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; transition: background .15s, transform .05s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text-soft); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); color: var(--text-soft); display: inline-grid; place-items: center; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ---------- SHELL ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--bg); color: #b8c7bf; padding: 20px 14px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 30; }
.sidebar .brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 20px; }
.sidebar .brand .logo { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg,var(--primary),#22c55e); color:#fff; display: grid; place-items: center; font-weight: 800; }
.sidebar .brand .name { font-weight: 700; color: #fff; font-size: 15px; line-height: 1.2; }
.sidebar .brand .name small { display:block; color: var(--muted); font-weight: 500; font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #5b6f65; margin: 16px 8px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); color: #b8c7bf; font-weight: 500; transition: background .15s, color .15s; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .spacer { flex: 1; }
.user-box { border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.user-box .info { flex: 1; min-width: 0; }
.user-box .info .n { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .info .r { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 14px 24px; display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 19px; font-weight: 700; }
.topbar .crumb { color: var(--text-soft); font-size: 13px; }
.menu-btn { display: none; }
.content { padding: 24px; flex: 1; }
.scrim { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .22s ease; }
  .shell.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-grid; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(12,31,23,.5); z-index: 20; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

/* ---------- STATS / CARDS ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; }
.stat .ic svg { width: 19px; height: 19px; }
.stat .label { color: var(--text-soft); font-size: 12.5px; margin-top: 12px; font-weight: 500; }
.stat .value { font-size: 23px; font-weight: 800; margin-top: 2px; }
.ic-green { background: var(--success-soft); color: var(--success); }
.ic-amber { background: var(--warning-soft); color: var(--warning); }
.ic-red { background: var(--danger-soft); color: var(--danger); }
.ic-soft { background: var(--primary-soft); color: var(--primary); }

.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 15.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-head h2 svg { width: 18px; height: 18px; color: inherit; }
.card-head .tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search input { padding-left: 34px; min-width: 220px; }

/* ---------- TABLE ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-soft); font-weight: 600; padding: 11px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
tbody td { padding: 12px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.cell-strong { font-weight: 600; }
.cell-sub { color: var(--text-soft); font-size: 12px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.clickable { cursor: pointer; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-gray { background: #eef2f0; color: var(--text-soft); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.empty { text-align: center; padding: 48px 20px; color: var(--text-soft); }
.empty svg { width: 44px; height: 44px; color: var(--muted); margin-bottom: 10px; }
.empty p { margin-bottom: 4px; font-weight: 600; color: var(--text); }

/* ---------- MODAL ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(12,31,23,.55); backdrop-filter: blur(2px); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 720px; max-height: 94vh; display: flex; flex-direction: column; overflow: hidden; animation: pop .15s ease; }
.modal.modal-lg { max-width: 940px; }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal > form { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; overflow: hidden; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); flex-shrink: 0; flex-wrap: wrap; }

.section-title { font-weight: 700; font-size: 12.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 8px 0 14px; display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.items-table input, .items-table select { padding: 7px 9px; }
.items-table td { padding: 6px 6px; }
.items-table thead th { padding: 8px 6px; }
.chk { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button { padding: 7px 12px; border-radius: 6px; font-weight: 600; font-size: 13px; color: var(--text-soft); }
.seg button.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav .lbl { font-weight: 700; min-width: 140px; text-align: center; text-transform: capitalize; }

/* toast */
#toast-root { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius-sm); padding: 12px 16px; box-shadow: var(--shadow-lg); min-width: 250px; display: flex; align-items: center; gap: 10px; animation: slidein .2s ease; font-weight: 500; }
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.page-loader { display: grid; place-items: center; height: 50vh; }
.page-loader .spinner { width: 32px; height: 32px; border-color: rgba(22,163,74,.2); border-top-color: var(--primary); }

.bar-row { margin-bottom: 13px; }
.bar-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg,var(--primary),#4ade80); }
.hint-card { background: var(--primary-soft); border: 1px solid var(--primary-border); border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13px; color: var(--primary-dark); margin-bottom: 16px; }
