/* ==========================================================================
   ILMS v9 — Design Tokens & Base Layer
   ប្រព័ន្ធពណ៌ អក្សរ និងគ្រឹះ layout
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Kantumruy+Pro:wght@300;400;500;600;700;800&family=Inter:wght@400;500;600;700;800&display=swap');

/* ---------- 1. Tokens : Light ---------- */
:root {
  /* Brand ramp */
  --brand-50:  #eef4ff;
  --brand-100: #dbe7ff;
  --brand-200: #bcd2ff;
  --brand-300: #8fb3ff;
  --brand-400: #5b8bfc;
  --brand-500: #3563f0;
  --brand-600: #2148d6;
  --brand-700: #1b39ac;
  --brand-800: #1a3288;
  --brand-900: #1b2e6c;

  /* Semantic */
  --ok-bg:   #ecfdf5;  --ok-fg:   #047857;  --ok-br:   #a7f3d0;  --ok:   #10b981;
  --warn-bg: #fffbeb;  --warn-fg: #b45309;  --warn-br: #fde68a;  --warn: #f59e0b;
  --bad-bg:  #fef2f2;  --bad-fg:  #b91c1c;  --bad-br:  #fecaca;  --bad:  #ef4444;
  --info-bg: #eff6ff;  --info-fg: #1d4ed8;  --info-br: #bfdbfe;  --info: #3b82f6;

  /* Surfaces */
  --bg:        #f4f6fb;
  --bg-grad:   radial-gradient(1200px 600px at 12% -10%, #e6edff 0%, transparent 55%),
               radial-gradient(900px 500px at 100% 0%, #eaf6f1 0%, transparent 50%);
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --overlay:   rgba(15, 23, 42, .45);

  /* Text */
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #94a3b8;
  --text-inv:  #ffffff;

  /* Lines */
  --line:      #e6eaf2;
  --line-2:    #d6dce8;

  /* Elevation */
  --sh-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --sh-sm: 0 2px 6px rgba(16, 24, 40, .06);
  --sh-md: 0 8px 20px -6px rgba(16, 24, 40, .12);
  --sh-lg: 0 24px 48px -16px rgba(16, 24, 40, .22);
  --sh-brand: 0 10px 24px -8px rgba(53, 99, 240, .45);

  /* Geometry */
  --r-xs: 8px;  --r-sm: 12px;  --r-md: 16px;  --r-lg: 22px;  --r-full: 999px;
  --sidebar-w: 264px;
  --header-h: 68px;

  /* Motion */
  --ease: cubic-bezier(.16, 1, .3, 1);
  --t-fast: .15s var(--ease);
  --t: .25s var(--ease);

  /* Type */
  --font: 'Kantumruy Pro', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-num: 'Inter', 'Kantumruy Pro', system-ui, sans-serif;
}

/* ---------- 2. Tokens : Dark ---------- */
[data-theme='dark'] {
  --bg:        #0b1020;
  --bg-grad:   radial-gradient(1200px 600px at 12% -10%, #16205c 0%, transparent 55%),
               radial-gradient(900px 500px at 100% 0%, #0f2f2a 0%, transparent 50%);
  --surface:   #121a2e;
  --surface-2: #172038;
  --surface-3: #1e2942;
  --overlay:   rgba(2, 6, 18, .66);

  --text:      #e8edf7;
  --text-2:    #a5b2ca;
  --text-3:    #6b7a98;

  --line:      #22304e;
  --line-2:    #2c3c5f;

  --ok-bg:   #06251a;  --ok-fg:   #4ade80;  --ok-br:   #14532d;
  --warn-bg: #2a1d05;  --warn-fg: #fbbf24;  --warn-br: #52370a;
  --bad-bg:  #2a0d0d;  --bad-fg:  #f87171;  --bad-br:  #5a1616;
  --info-bg: #0d1c3a;  --info-fg: #7fa9ff;  --info-br: #1e3a72;

  --sh-xs: 0 1px 2px rgba(0, 0, 0, .5);
  --sh-sm: 0 2px 8px rgba(0, 0, 0, .45);
  --sh-md: 0 10px 26px -8px rgba(0, 0, 0, .6);
  --sh-lg: 0 28px 56px -20px rgba(0, 0, 0, .75);
}

/* ---------- 3. Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--t), color var(--t);
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.35; letter-spacing: -.01em; }
p  { margin: 0; }
a  { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

img { max-width: 100%; display: block; }

table { border-collapse: collapse; width: 100%; }

/* លេខ — ប្រើ tabular figures ដើម្បីតម្រឹមជួរ */
.num, td.num, .stat-value, .money {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

/* ---------- 4. Focus & a11y ---------- */
:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: 6px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 999;
  background: var(--brand-600); color: #fff; padding: 10px 16px; border-radius: var(--r-sm);
}
.skip-link:focus { left: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 5. Scrollbar ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-2); border-radius: var(--r-full);
  border: 3px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ---------- 6. App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.app.is-collapsed { --sidebar-w: 92px; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  gap: 6px;
  overflow: hidden;
  transition: width var(--t);
  z-index: 40;
}

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

.topbar {
  position: sticky; top: 0; z-index: 30;
  min-height: var(--header-h);
  display: flex; align-items: center; gap: 14px;
  padding: 12px 26px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.content { padding: 26px; flex: 1; }
.view { display: none; animation: viewIn .35s var(--ease); }
.view.is-active { display: block; }

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- 7. Utility ---------- */
.hidden { display: none !important; }
.row    { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap   { flex-wrap: wrap; }
.grow   { flex: 1 1 auto; min-width: 0; }
.right  { text-align: right; }
.center { text-align: center; }
.mono   { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: .8em; }
.muted  { color: var(--text-2); }
.dim    { color: var(--text-3); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }

.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stack   { display: flex; flex-direction: column; gap: 6px; }
.stack-lg { display: flex; flex-direction: column; gap: 18px; }

.t-xs { font-size: 11px; }
.t-sm { font-size: 12.5px; }
.t-lg { font-size: 16px; }
.b6 { font-weight: 600; } .b7 { font-weight: 700; } .b8 { font-weight: 800; }

.c-ok   { color: var(--ok-fg); }
.c-warn { color: var(--warn-fg); }
.c-bad  { color: var(--bad-fg); }
.c-info { color: var(--info-fg); }

/* ---------- 8. Responsive ---------- */
@media (max-width: 1180px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* កាត់បន្ថយអក្សរលើប៊ូតុងរបារខាងលើនៅអេក្រង់តូច */
@media (max-width: 1100px) {
  .topbar .kbd { display: none; }
}
@media (max-width: 860px) {
  .topbar .lbl { display: none; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    transform: translateX(-102%); box-shadow: var(--sh-lg);
  }
  .sidebar.is-open { transform: none; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .g-2, .g-3, .g-4 { grid-template-columns: 1fr; }
}

/* ---------- 9. Print ---------- */
@media print {
  .sidebar, .topbar, .no-print, .toast-stack { display: none !important; }
  body { background: #fff !important; }
  .app { display: block; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
  .view { display: block !important; }
  .view:not(.is-active) { display: none !important; }
}
