:root {
  --bg: #eef7f5;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe7e5;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --blue: #2563eb;
  --yellow: #ca8a04;
  --red: #dc2626;
  --orange: #ea580c;
  --green: #16a34a;
  --shadow: 0 16px 42px rgba(15, 23, 42, 0.12);
  --radius: 18px;
  --font: "Noto Sans Lao", "Phetsarath OT", "Lao UI", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(135deg, #e0f2fe 0%, #ecfeff 48%, #f0fdf4 100%);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.86rem; line-height: 1.5; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(480px, 100%);
  background: rgba(255,255,255,0.88);
  border: 1px solid rgba(255,255,255,0.8);
  box-shadow: var(--shadow);
  border-radius: 28px;
  padding: 30px;
  backdrop-filter: blur(18px);
}
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row.center { justify-content: center; margin-bottom: 24px; }
.brand-row h1 { margin: 0; font-size: 1.8rem; }
.brand-row p, .brand-row span { margin: 3px 0 0; color: var(--muted); font-size: 0.95rem; display: block; }
.brand-logo { width: 64px; height: 64px; }
.brand-logo.small { width: 42px; height: 42px; }

.form-stack { display: grid; gap: 14px; }
.form-stack label { display: grid; gap: 7px; font-weight: 700; color: #334155; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  outline: none;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12); }
textarea { min-height: 92px; resize: vertical; }

.btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--primary); color: white; box-shadow: 0 10px 20px rgba(15, 118, 110, .25); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: #e0f2fe; color: #075985; }
.btn.ghost { background: transparent; color: var(--primary-dark); border: 1px solid var(--line); }
.btn.danger { background: #fee2e2; color: #991b1b; }
.btn.full { width: 100%; margin-top: 12px; }
.small-btn { padding: 8px 10px; font-size: .88rem; border-radius: 11px; }
.icon-btn { border: 0; background: #f1f5f9; width: 38px; height: 38px; border-radius: 12px; font-size: 1.4rem; line-height: 1; }

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 284px 1fr;
  padding: 18px;
  gap: 18px;
}
.sidebar {
  background: rgba(15, 118, 110, 0.95);
  color: white;
  border-radius: 28px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.sidebar .brand-row span { color: rgba(255,255,255,.72); }
.nav { margin-top: 24px; display: grid; gap: 8px; }
.nav-link {
  border: 0;
  color: rgba(255,255,255,.8);
  background: transparent;
  text-align: left;
  padding: 13px 14px;
  border-radius: 15px;
  font-weight: 800;
}
.nav-link.active, .nav-link:hover { background: rgba(255,255,255,.16); color: white; }
.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }

.workspace {
  min-width: 0;
  height: calc(100vh - 36px);
  overflow: auto;
  background: rgba(255,255,255,.62);
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 28px;
  padding: 22px;
  backdrop-filter: blur(18px);
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.topbar h1 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.4rem); }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.search { min-width: 280px; background: rgba(255,255,255,.9); }

.page { display: none; }
.page.active { display: block; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.kpi-card {
  background: rgba(255,255,255,.9);
  border: 1px solid rgba(219, 231, 229, .9);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
  min-height: 120px;
}
.kpi-card .label { color: var(--muted); font-weight: 800; font-size: .88rem; }
.kpi-card .value { font-size: 1.75rem; font-weight: 950; margin-top: 8px; letter-spacing: -0.03em; }
.kpi-card .foot { margin-top: 8px; color: var(--muted); font-size: .84rem; }
.kpi-card.green { border-left: 6px solid var(--green); }
.kpi-card.red { border-left: 6px solid var(--red); }
.kpi-card.yellow { border-left: 6px solid var(--yellow); }
.kpi-card.blue { border-left: 6px solid var(--blue); }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, .45fr);
  gap: 16px;
  align-items: start;
}
.panel {
  background: rgba(255,255,255,.93);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .05);
  min-width: 0;
}
.panel.wide { min-width: 0; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head.wrap { align-items: flex-start; flex-wrap: wrap; }
.panel h2 { margin: 0; font-size: 1.15rem; }
.filter-row { display: flex; gap: 10px; align-items: center; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0 8px; min-width: 760px; }
th {
  text-align: left;
  color: var(--muted);
  font-size: .82rem;
  padding: 0 12px 5px;
  white-space: nowrap;
}
td {
  background: var(--surface-2);
  padding: 12px;
  border-top: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}
td:first-child { border-left: 1px solid #e2e8f0; border-radius: 14px 0 0 14px; }
td:last-child { border-right: 1px solid #e2e8f0; border-radius: 0 14px 14px 0; }
tr:hover td { background: #f0fdfa; }
.cell-main { font-weight: 900; }
.cell-sub { color: var(--muted); font-size: .82rem; margin-top: 3px; }
.action-row { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: .78rem;
  font-weight: 900;
  white-space: nowrap;
}
.badge.neutral { background: #e2e8f0; color: #334155; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.yellow { background: #fef3c7; color: #92400e; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.orange { background: #ffedd5; color: #9a3412; }
.badge.teal { background: var(--primary-soft); color: var(--primary-dark); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 13px;
  font-weight: 900;
}
.tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.status-list { display: grid; gap: 10px; }
.status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid #e2e8f0;
}
.status-item strong { font-size: 1.2rem; }

.drawer, .modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, .45);
  display: flex;
  justify-content: flex-end;
  padding: 18px;
}
.modal { align-items: center; justify-content: center; }
.drawer-panel, .modal-card {
  background: white;
  border-radius: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.drawer-panel {
  width: min(820px, 100%);
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; }
.drawer-body { overflow: auto; padding: 20px; display: grid; gap: 16px; }
.modal-card { width: min(640px, 100%); padding: 18px; }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.detail-card { background: var(--surface-2); padding: 14px; border: 1px solid #e2e8f0; border-radius: 16px; }
.detail-card span { display: block; color: var(--muted); font-size: .82rem; font-weight: 800; }
.detail-card strong { display: block; margin-top: 4px; }

.report-card { display: grid; gap: 12px; }
.report-row { display: flex; justify-content: space-between; padding: 12px; background: var(--surface-2); border-radius: 14px; }
.code-block { background: #0f172a; color: #d1fae5; border-radius: 16px; padding: 16px; overflow: auto; }
.rule-list { margin: 0; padding-left: 20px; color: #334155; line-height: 1.8; }
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #0f172a;
  color: white;
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 100;
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 420px;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 1fr; overflow: auto; height: auto; min-height: 100vh; }
  body { overflow: auto; }
  .sidebar { position: static; }
  .nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workspace { height: auto; overflow: visible; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app-shell { padding: 10px; gap: 10px; }
  .workspace, .sidebar { border-radius: 20px; padding: 14px; }
  .topbar { display: grid; }
  .topbar-actions { justify-content: stretch; }
  .topbar-actions > * { width: 100%; }
  .search { min-width: 0; }
  .kpi-grid, .detail-grid { grid-template-columns: 1fr; }
  .nav { grid-template-columns: 1fr 1fr; }
  .drawer, .modal { padding: 8px; }
}
