:root {
  --green: #2D6A4F;
  --green-dark: #1B4332;
  --greenpale: #D8F3DC;
  --greenpaler: #F0FBF3;
  --ink: #1C1917;
  --ink2: #57534E;
  --ink3: #A8A29E;
  --ink4: #E7E5E4;
  --ink5: #F5F5F0;
  --bg: #FAFAF8;
  --card: #FFFFFF;
  --amber: #F59E0B;
  --amberpale: #FFFBEB;
  --red: #EF4444;
  --redpale: #FEF2F2;
  --blue: #2563EB;
  --bluepale: #EFF6FF;
  --purple: #7C3AED;
  --purplepale: #F3EEFF;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Shell layout ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--ink4);
  padding: 18px 12px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.sidebar::-webkit-scrollbar { display: none; width: 0; height: 0; }
.brand { font-weight: 700; font-size: 15px; color: var(--green); padding: 6px 10px 18px; letter-spacing: 0.01em; }
.brand span { color: var(--ink3); font-weight: 600; font-size: 11px; letter-spacing: 0.08em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink3); padding: 14px 10px 4px; }
.nav-link { display: block; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink2); font-size: 13px; text-decoration: none; font-weight: 500; }
.nav-link:hover { background: var(--ink5); }
.nav-link.active { background: var(--greenpale); color: var(--green); font-weight: 700; }
.nav-link.disabled { color: var(--ink3); cursor: default; display: flex; justify-content: space-between; align-items: center; }
.nav-link.disabled em { font-style: normal; font-size: 9px; background: var(--ink5); color: var(--ink3); padding: 2px 6px; border-radius: 20px; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px; background: #fff; border-bottom: 1px solid var(--ink4);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

main { padding: 22px 26px 60px; max-width: 1320px; width: 100%; margin: 0 auto; }

.sidebar-toggle { display: none; position: fixed; top: 12px; left: 12px; z-index: 20; background: #fff; border: 1px solid var(--ink4); border-radius: var(--radius-sm); width: 36px; height: 36px; font-size: 16px; box-shadow: var(--shadow); }

/* ---------- Buttons ---------- */
button, .btn { padding: 9px 16px; background: var(--green); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; }
.btn-outline { background: #fff; color: var(--green); border: 1.5px solid var(--green); }
.btn-danger { background: #fff; color: var(--red); border: 1.5px solid var(--red); }
.btn-ghost { background: transparent; color: var(--ink2); border: 1px solid var(--ink4); }
.btn-small { padding: 6px 11px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-logout {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; font-size: 12.5px; font-weight: 600;
  background: #fff; color: var(--red); border: 1.5px solid var(--redpale);
  border-radius: var(--radius-sm); text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn-logout:hover { background: var(--redpale); border-color: var(--red); }
.btn-logout svg { flex: 0 0 auto; }

/* ---------- Cards / KPIs ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 15px 16px; }
.kpi-card .kpi-label { font-size: 11px; color: var(--ink3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-card .kpi-value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi-card .kpi-sub { font-size: 11px; color: var(--ink3); margin-top: 2px; }
.kpi-card.accent { background: var(--green-dark); }
.kpi-card.accent .kpi-label, .kpi-card.accent .kpi-sub { color: #B7DDC7; }
.kpi-card.accent .kpi-value { color: #fff; }

.section-title { font-size: 14px; font-weight: 700; margin: 26px 0 12px; display: flex; align-items: center; justify-content: space-between; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.chart-card h3 { font-size: 13px; font-weight: 700; margin-bottom: 12px; }
.chart-card .chart-empty { color: var(--ink3); font-size: 12px; padding: 30px 0; text-align: center; }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.filters input, .filters select { padding: 8px 11px; border: 1px solid var(--ink4); border-radius: var(--radius-sm); font-size: 12.5px; background: #fff; }
.filters input[type="search"] { min-width: 200px; }

/* ---------- Tables ---------- */
.table-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 11px 14px; font-size: 12.5px; border-bottom: 1px solid var(--ink5); white-space: nowrap; }
td.wrap { white-space: normal; }
th { color: var(--ink3); font-weight: 700; text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.03em; background: var(--ink5); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--greenpaler); }
tr.flash-row { animation: flash 2s ease-out; }
@keyframes flash { 0% { background: var(--greenpale); } 100% { background: transparent; } }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 10.5px; font-weight: 700; white-space: nowrap; }
.b-blue { background: var(--bluepale); color: var(--blue); }
.b-amber { background: var(--amberpale); color: var(--amber); }
.b-green { background: var(--greenpaler); color: var(--green); }
.b-red { background: var(--redpale); color: var(--red); }
.b-purple { background: var(--purplepale); color: var(--purple); }
.b-gray { background: var(--ink5); color: var(--ink2); }

/* ---------- States ---------- */
.state-block { padding: 48px 20px; text-align: center; color: var(--ink3); font-size: 13px; }
.state-block .state-icon { font-size: 28px; margin-bottom: 8px; }
.state-block.error { color: var(--red); }
.skeleton { background: linear-gradient(90deg, var(--ink5) 25%, #EFEFE9 37%, var(--ink5) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.skeleton-row { height: 42px; margin: 10px 14px; }

/* ---------- Drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(28,25,23,0.35); z-index: 30; opacity: 0; pointer-events: none; transition: opacity 0.18s; }
.overlay.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(480px, 100vw); background: #fff; z-index: 31; box-shadow: -8px 0 24px rgba(0,0,0,0.12); transform: translateX(100%); transition: transform 0.22s ease; display: flex; flex-direction: column; }
.drawer.open { transform: translateX(0); }
.drawer-header { padding: 18px 20px; border-bottom: 1px solid var(--ink4); display: flex; align-items: center; justify-content: space-between; }
.drawer-header h2 { font-size: 16px; }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }
.drawer-close { background: none; border: none; color: var(--ink3); font-size: 18px; padding: 4px 8px; }

/* ---------- Modal ---------- */
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; border-radius: var(--radius); box-shadow: 0 20px 50px rgba(0,0,0,0.2); z-index: 32; width: min(440px, 92vw); max-height: 85vh; overflow-y: auto; padding: 20px; display: none; }
.modal.open { display: block; }
.modal h2 { font-size: 15px; margin-bottom: 14px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink2); margin-bottom: 5px; }
.form-row input, .form-row select, .form-row textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--ink4); border-radius: var(--radius-sm); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 22px 26px; border-left: 2px solid var(--ink4); margin-left: 7px; }
.timeline li:last-child { border-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--ink4); border: 2px solid #fff; }
.timeline li.done::before { background: var(--green); }
.timeline li.now::before { background: var(--amber); box-shadow: 0 0 0 4px var(--amberpale); }
.timeline .t-status { font-weight: 700; font-size: 13px; }
.timeline .t-meta { font-size: 11.5px; color: var(--ink3); margin-top: 2px; }
.timeline li.pending .t-status { color: var(--ink3); font-weight: 600; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.kanban-col { flex: 0 0 240px; background: var(--ink5); border-radius: var(--radius); padding: 10px; }
.kanban-col h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink2); padding: 4px 6px 10px; display: flex; justify-content: space-between; }
.kanban-card { background: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 10px 11px; margin-bottom: 8px; font-size: 12px; }
.kanban-card .kc-id { font-weight: 700; }
.kanban-card .kc-meta { color: var(--ink3); font-size: 11px; margin-top: 3px; }
.kanban-card select { margin-top: 8px; width: 100%; font-size: 11px; padding: 5px 6px; }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 12.5px; box-shadow: var(--shadow); max-width: 320px; animation: toast-in 0.2s ease; }
.toast.success { background: var(--green-dark); }
.toast.error { background: var(--red); }
.toast strong { display: block; margin-bottom: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Misc ---------- */
.pill-group { display: flex; gap: 6px; flex-wrap: wrap; }
.text-muted { color: var(--ink3); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-bottom: 16px; }
.detail-grid .dl-label { font-size: 10.5px; color: var(--ink3); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-grid .dl-value { font-size: 13px; font-weight: 600; }
.totals-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 4px 0; }
.totals-row.grand { font-weight: 700; font-size: 14px; border-top: 1px solid var(--ink4); padding-top: 8px; margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar-toggle { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 19; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 8px 0 24px rgba(0,0,0,0.12); }
  .sidebar.open { transform: translateX(0); }
  main { padding: 68px 14px 40px; }
  .topbar { padding: 12px 14px 12px 58px; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .table-wrap table, .table-wrap thead { display: none; }
  .table-wrap tbody tr { display: block; background: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow); margin: 10px; padding: 10px 12px; }
  .table-wrap tbody td { display: flex; justify-content: space-between; gap: 10px; border: none; padding: 5px 2px; white-space: normal; }
  .table-wrap tbody td::before { content: attr(data-label); font-size: 10.5px; color: var(--ink3); font-weight: 700; text-transform: uppercase; }
}
