/* Lao AI design system (PLAN §4.6).
 *
 * Theming is Bootstrap 5.3's mechanism — the `data-bs-theme` attribute plus CSS custom
 * properties — and NOT two stylesheets, so a theme switch is one attribute change and the
 * cascade does the rest.
 *
 * Every colour is a token. The contrast of each foreground/background pair is asserted by
 * tests/web/test_contrast.py in BOTH themes, because dark themes are where contrast usually
 * fails and nobody notices until a customer squints at a grey label.
 */

:root,
[data-bs-theme="light"] {
  --laoai-bg: #ffffff;
  --laoai-surface: #f4f6f8;
  --laoai-surface-2: #eaeef2;
  --laoai-text: #14181f;
  --laoai-muted: #55606f;
  --laoai-border: #d3dae2;
  --laoai-primary: #0b6b5e;
  --laoai-on-primary: #ffffff;
  --laoai-danger: #9d2620;
  --laoai-on-danger: #ffffff;
  --laoai-warning-bg: #fdf3d8;
  --laoai-warning-text: #5c4413;
  --laoai-success-bg: #dff3ea;
  --laoai-success-text: #10493a;
  --laoai-focus: #0b6b5e;
  --laoai-shadow: 0 1px 2px rgba(20, 24, 31, 0.08), 0 4px 12px rgba(20, 24, 31, 0.06);
}

[data-bs-theme="dark"] {
  --laoai-bg: #12151a;
  --laoai-surface: #1b1f26;
  --laoai-surface-2: #242a33;
  --laoai-text: #e7ecf3;
  --laoai-muted: #a6b0be;
  --laoai-border: #333b46;
  --laoai-primary: #35b3a0;
  --laoai-on-primary: #052420;
  --laoai-danger: #f2837c;
  --laoai-on-danger: #2a0907;
  --laoai-warning-bg: #3a3116;
  --laoai-warning-text: #f5dfa6;
  --laoai-success-bg: #10312a;
  --laoai-success-text: #9fdcc9;
  --laoai-focus: #7fd8c9;
  --laoai-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 6px 16px rgba(0, 0, 0, 0.4);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--laoai-bg);
  color: var(--laoai-text);
  font-family: "Noto Sans Lao", "Noto Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

/* Lao has NO word boundaries, so a long string will not wrap at a sensible point unless we
 * say so. Without these two rules a Lao sentence overflows its card at narrow widths. */
body,
.card,
.cell,
.stat-value,
.message-body,
.empty-state {
  word-break: break-word;
  overflow-wrap: anywhere;
  line-break: normal;
}

:lang(lo) { line-height: 1.85; }  /* Lao stacks vowels above and below the baseline */

a { color: var(--laoai-primary); }

:focus-visible {
  outline: 3px solid var(--laoai-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--laoai-primary);
  color: var(--laoai-on-primary);
  padding: 0.6rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* --- shell ------------------------------------------------------------------------------- */

.layout { display: flex; min-height: 100vh; }

.sidenav {
  width: 240px;
  flex: 0 0 240px;
  background: var(--laoai-surface);
  border-right: 1px solid var(--laoai-border);
  padding: 1rem 0.75rem;
  transition: width 0.15s ease, flex-basis 0.15s ease;
}
.layout.nav-collapsed .sidenav { width: 68px; flex-basis: 68px; }
.layout.nav-collapsed .sidenav .nav-label { display: none; }

.sidenav .brand {
  font-weight: 700;
  padding: 0.5rem 0.75rem 1rem;
  display: block;
  color: var(--laoai-text);
  text-decoration: none;
}

.sidenav a.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: var(--laoai-text);
  text-decoration: none;
  margin-bottom: 2px;
}
.sidenav a.nav-item:hover { background: var(--laoai-surface-2); }
.sidenav a.nav-item[aria-current="page"] {
  background: var(--laoai-primary);
  color: var(--laoai-on-primary);
}
.nav-icon { width: 1.25rem; text-align: center; flex: 0 0 auto; }

.content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--laoai-border);
  background: var(--laoai-surface);
  flex-wrap: wrap;
}
.topbar .spacer { flex: 1 1 auto; }
.breadcrumb { color: var(--laoai-muted); font-size: 0.95rem; }

main { padding: 1.25rem 1rem 3rem; max-width: 1100px; width: 100%; }

/* Below the md breakpoint the rail becomes a drawer: a rail too narrow to read is worse than
 * no rail at all (PLAN §4.6). */
@media (max-width: 767px) {
  .sidenav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    width: 260px;
    flex-basis: 260px;
  }
  .layout.nav-open .sidenav { transform: translateX(0); box-shadow: var(--laoai-shadow); }
  .layout.nav-collapsed .sidenav { width: 260px; flex-basis: 260px; }
  .layout.nav-collapsed .sidenav .nav-label { display: inline; }
  .scrim { display: none; }
  .layout.nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 40;
  }
}

/* --- cards ------------------------------------------------------------------------------- */

.card {
  background: var(--laoai-surface);
  border: 1px solid var(--laoai-border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  box-shadow: var(--laoai-shadow);
}
.card h2, .card h3 { margin: 0 0 0.75rem; font-size: 1.05rem; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.card-grid .card { margin-bottom: 0; }

.stat-label { color: var(--laoai-muted); font-size: 0.9rem; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.2; }
.stat-delta { font-size: 0.85rem; color: var(--laoai-muted); }

.empty-state { text-align: center; padding: 2rem 1rem; color: var(--laoai-muted); }
.empty-state h3 { color: var(--laoai-text); }

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: start;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--laoai-border);
  vertical-align: top;
}
th { color: var(--laoai-muted); font-weight: 600; font-size: 0.9rem; }
.table-scroll { overflow-x: auto; }

/* --- controls ---------------------------------------------------------------------------- */

label { display: block; margin-bottom: 0.25rem; font-weight: 600; font-size: 0.95rem; }
.field { margin-bottom: 0.9rem; }
.help { color: var(--laoai-muted); font-size: 0.87rem; }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--laoai-border);
  background: var(--laoai-bg);
  color: var(--laoai-text);
  font: inherit;
}
textarea { min-height: 8rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.95rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--laoai-primary);
  color: var(--laoai-on-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn.secondary {
  background: transparent;
  color: var(--laoai-text);
  border-color: var(--laoai-border);
}
.btn.danger { background: var(--laoai-danger); color: var(--laoai-on-danger); }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.badge {
  display: inline-block;
  min-width: 1.3rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--laoai-danger);
  color: var(--laoai-on-danger);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
}
.pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  background: var(--laoai-surface-2);
  color: var(--laoai-text);
  font-size: 0.82rem;
}

.alert { padding: 0.75rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.alert.warning { background: var(--laoai-warning-bg); color: var(--laoai-warning-text); }
.alert.success { background: var(--laoai-success-bg); color: var(--laoai-success-text); }
.alert.danger { background: var(--laoai-danger); color: var(--laoai-on-danger); }

code, pre, .mono {
  font-family: "Noto Sans Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}
pre {
  background: var(--laoai-surface-2);
  padding: 0.9rem;
  border-radius: 10px;
  overflow-x: auto;
}

.message { padding: 0.7rem 0.9rem; border-radius: 10px; margin-bottom: 0.6rem; max-width: 46rem; }
.message.from-staff { background: var(--laoai-surface-2); }
.message.from-me { background: var(--laoai-primary); color: var(--laoai-on-primary); }
.message .who { font-size: 0.82rem; opacity: 0.85; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* A bank QR code. White background regardless of theme: a dark-mode inversion makes the code
   unscannable, which is a silent failure — the customer just gets nothing when they point a
   banking app at it. */
.bank-qr {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  margin: 0.75rem 0;
  padding: 0.5rem;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid var(--laoai-border);
}
.bank-account { margin-bottom: 1.5rem; }
.bank-account:last-child { margin-bottom: 0; }
