/* ===== sunii UI foundation (UI-DESIGN-SPEC) ============================== */
@font-face {
  font-family: "Space Grotesk"; src: url("/static/fonts/SpaceGrotesk.ttf") format("truetype");
  font-weight: 300 700; font-display: swap;
}
@font-face {
  font-family: "Noto Sans Thai"; src: url("/static/fonts/NotoSansThai.ttf") format("truetype");
  font-weight: 100 900; font-display: swap;
}

:root {
  /* sunii palette */
  --sunii: #AAF0A0;
  --sunii-light: #E1FFDC;
  --sunii-dark: #144600;
  --ink: #000000;
  --paper: #FFFFFF;
  --grey: #BEBEBE;
  /* secondary families */
  --ease-light: #FFFADC;  --ease-dark: #646400;
  --hygiene-light: #DCFFFA; --hygiene-dark: #00285A;
  --solution-light: #FFE1E6; --solution-dark: #640014;

  /* functional aliases (keep names used across templates) */
  --bg: #f5faf2;
  --card: #FFFFFF;
  --muted: #5b6b58;
  --line: #dde7d8;
  --accent: var(--sunii-dark);
  --accent-ink: #FFFFFF;
  --danger: var(--solution-dark);
  --ok: var(--sunii-dark);
  --pending: var(--ease-dark);
  --radius: 12px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Space Grotesk", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { color: var(--sunii-dark); font-weight: 700; }
h1 { font-size: 1.45rem; margin: 0 0 0.8rem; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }

/* ===== Layout: sidebar + main ========================================== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px; flex: 0 0 224px; background: var(--paper);
  border-right: 1px solid var(--line); padding: 1rem 0.75rem;
  display: flex; flex-direction: column; gap: 0.4rem; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: 1.5rem;
  color: var(--sunii-dark); text-decoration: none; padding: 0.4rem 0.6rem 0.8rem;
  letter-spacing: -0.02em;
}
.sidebar .brand small { display:block; font-size:0.62rem; font-weight:500; color:var(--muted); letter-spacing:0; }
.sidenav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidenav .navlabel { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 0.8rem 0.6rem 0.2rem; }
/* Collapsible groups */
.sidenav .navgroup { display: flex; flex-direction: column; gap: 0.15rem; }
.sidenav .navgroup > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: space-between;
}
.sidenav .navgroup > summary::-webkit-details-marker { display: none; }
.sidenav .navgroup > summary::after {
  content: "\25B8"; font-size: 0.7rem; color: var(--muted);
  transition: transform 0.15s ease; margin-left: 0.4rem;
}
.sidenav .navgroup[open] > summary::after { transform: rotate(90deg); }
.sidenav .navgroup > summary:hover { color: var(--sunii-dark); }
.sidenav a {
  display: block; padding: 0.55rem 0.7rem; border-radius: var(--radius-sm);
  color: var(--sunii-dark); text-decoration: none; font-weight: 600; font-size: 0.95rem;
}
.sidenav a:hover { background: var(--sunii-light); }
.sidenav a.active { background: var(--sunii-dark); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.6rem 1.2rem; background: var(--paper); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: 0.88rem; }
.hamburger { display: none; background: none; border: none; font-size: 1.3rem; color: var(--sunii-dark); }
.lang-select { width: auto; margin: 0; padding: 0.3rem 0.5rem; font-size: 0.85rem;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; }
.inline { display: inline; margin: 0; }

.container { max-width: 1040px; margin: 1.5rem auto; padding: 0 1.2rem; width: 100%; }

/* ===== Cards & typography ============================================== */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.4rem; box-shadow: 0 1px 3px rgba(20, 70, 0, 0.05); margin-bottom: 1rem;
}
.card h2, .chart-grid .card h2 { font-size: 1.05rem; margin: 0 0 0.7rem; }

/* ===== Forms =========================================================== */
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.5rem; }
input, select, textarea {
  display: block; width: 100%; padding: 0.5rem 0.6rem; margin-top: 0.2rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 0.95rem; font-family: inherit; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sunii); border-color: var(--sunii-dark); }

button { cursor: pointer; font-size: 0.95rem; font-family: inherit; }
.primary {
  background: var(--sunii-dark); color: #fff; border: none;
  padding: 0.6rem 1.2rem; border-radius: 999px; font-weight: 700;
}
.primary:hover { background: #1b5e00; }
.primary:disabled { background: var(--grey); cursor: not-allowed; }
.secondary {
  background: #fff; color: var(--sunii-dark); border: 1.5px solid var(--sunii-dark);
  padding: 0.5rem 1rem; border-radius: 999px; font-weight: 700;
}
.secondary:hover { background: var(--sunii-light); }
.link-btn { background: none; border: none; color: var(--sunii-dark); padding: 0; font-weight: 600; }
.link-btn.danger { color: var(--danger); }
a { color: var(--sunii-dark); }

/* ===== Login =========================================================== */
.login-card { max-width: 380px; margin: 4rem auto; }
.login-card { background:
    linear-gradient(0deg, rgba(255,255,255,0.92), rgba(255,255,255,0.92)),
    repeating-linear-gradient(0deg, var(--sunii-light) 0 14px, #fff 14px 28px),
    repeating-linear-gradient(90deg, var(--sunii-light) 0 14px, #fff 14px 28px);
}
.login-card label { color: var(--ink); margin-bottom: 0.9rem; }
.login-brand { text-align: center; font-size: 2.2rem; font-weight: 700; color: var(--sunii-dark); letter-spacing: -0.02em; }
.login-brand small { display:block; font-size: 0.7rem; font-weight: 500; color: var(--muted); }

/* ===== Entry / generic rows =========================================== */
.entry-head { margin-bottom: 0.5rem; }
.row { display: flex; align-items: flex-end; gap: 1rem; }
.row.actions { justify-content: space-between; align-items: center; margin-top: 1rem; }
.row.submit-row { margin-top: 1.2rem; align-items: center; }
.date-field { width: 220px; }
.grow { flex: 1; }
.people { width: 160px; }

/* ===== Status badges (light bg + dark text, same family) ============== */
.badge, #status-badge .badge { display: inline-block; padding: 0.22rem 0.65rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.badge.pending  { background: var(--ease-light);     color: var(--ease-dark); }
.badge.approved { background: var(--sunii-light);    color: var(--sunii-dark); }
.badge.rejected { background: var(--solution-light); color: var(--solution-dark); }
.badge.info     { background: var(--hygiene-light);  color: var(--hygiene-dark); }
.rejection { background: var(--solution-light); border: 1px solid #f4c6cf; color: var(--solution-dark); padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); margin: 0.8rem 0; }
.warn { background: var(--ease-light); border: 1px solid #f0e3a6; color: var(--ease-dark); padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); margin: 0.8rem 0; font-weight: 600; }

/* ===== Dashboard ====================================================== */
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.3rem; }
.kpi-label { color: var(--muted); font-size: 0.85rem; }
.kpi-amount { font-size: 1.9rem; font-weight: 700; color: var(--sunii-dark); margin: 0.2rem 0; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--muted); font-size: 0.85rem; }
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.conv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; }
.conv-grid h3 { font-size: 0.9rem; margin: 0 0 0.4rem; color: var(--muted); }
@media (max-width: 760px) { .kpi-grid, .chart-grid, .conv-grid { grid-template-columns: 1fr; } }

/* ===== Reports / LINE ================================================== */
.rpt-summary { background: var(--sunii-light); border-color: #cfecc7; }
.rpt-table { width: 100%; }
.rpt-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.rpt-table tr.lvl-0 > td { font-weight: 700; border-top: 1px solid var(--line); }
.rpt-table tr.lvl-1 > td { font-weight: 600; }
.rpt-table tr.lvl-2 > td { color: var(--muted); font-weight: 400; }
.rpt-grand td { border-top: 2px solid var(--sunii-dark); background: var(--sunii-light); }
.line-preview { background: var(--sunii-dark); color: var(--sunii-light); padding: 1rem; border-radius: var(--radius-sm); white-space: pre-wrap; font-size: 0.85rem; max-height: 360px; overflow: auto; }
@media print {
  .sidebar, .topbar, .no-print, .lang-select { display: none !important; }
  .card { border: none; box-shadow: none; padding: 0.3rem 0; }
  .container { margin: 0; max-width: 100%; }
  .rpt-block { page-break-inside: avoid; }
}

/* ===== Visits / sale-line tables ====================================== */
.visit { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.9rem 1rem; margin: 1rem 0; }
.visit-head { margin-bottom: 0.6rem; }
.visit.locked { opacity: 0.85; }
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { text-align: left; font-size: 0.75rem; color: var(--muted); padding: 0.35rem 0.4rem; font-weight: 600; }
table.lines td { padding: 0.3rem 0.4rem; vertical-align: middle; }
table.lines input, table.lines select { margin-top: 0; }
.col-qty, .col-price, .col-amt { width: 120px; }
.amount-cell { font-variant-numeric: tabular-nums; text-align: right; padding-right: 0.6rem; }
.visit-total-wrap { margin-left: 1rem; color: var(--muted); }
.grand-total { font-size: 1.05rem; }
.save-msg { font-weight: 600; }
.save-msg.ok { color: var(--ok); }
.save-msg.err { color: var(--danger); }

/* ===== Admin master data ============================================== */
.master-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.master-tile { display: flex; flex-direction: column; gap: 0.3rem; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; text-decoration: none; color: var(--ink); }
.master-tile:hover { border-color: var(--sunii-dark); background: var(--sunii-light); }
.master-tile strong { color: var(--sunii-dark); }
.master-tile .muted { font-size: 0.82rem; }
.master-table { width: 100%; }
.master-table th { border-bottom: 1px solid var(--line); text-align: left; font-size: 0.8rem; color: var(--muted); padding: 0.4rem; }
.master-table td { border-bottom: 1px solid #eef3ea; padding: 0.4rem; }
.master-table .num, table.lines .num { text-align: right; font-variant-numeric: tabular-nums; }
.inactive-row { opacity: 0.55; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions a { margin-right: 0.6rem; }
.filter-bar { display: flex; align-items: flex-end; gap: 1rem; margin: 0.4rem 0 1rem; flex-wrap: wrap; }
.filter-field { width: 220px; margin: 0; }
.filter-bar .muted { padding-bottom: 0.5rem; }
.master-form { max-width: 560px; }
.master-form .field { margin-bottom: 0.9rem; }
.master-form label { color: var(--ink); }
.master-form label.checkbox { display: flex; align-items: center; gap: 0.5rem; }
.master-form label.checkbox input { width: auto; margin: 0; }
.req { color: var(--danger); }

/* ===== Approvals ====================================================== */
.tabs { display: flex; gap: 0.5rem; margin: 0.4rem 0 1rem; flex-wrap: wrap; }
.tab { text-decoration: none; color: var(--sunii-dark); text-transform: capitalize;
  border: 1px solid var(--line); border-radius: 999px; padding: 0.35rem 0.85rem; background: #fff; font-size: 0.9rem; }
.tab.active { background: var(--sunii-dark); color: #fff; border-color: var(--sunii-dark); }
.tab .count { opacity: 0.7; font-size: 0.8rem; }
.action-bar { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; flex-wrap: wrap; }
.reject-form { display: flex; align-items: center; gap: 0.5rem; margin: 0; margin-left: auto; }
.reject-form input { width: 240px; margin: 0; }

/* ===== Mobile ========================================================= */
@media (max-width: 820px) {
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; transform: translateX(-100%);
    transition: transform 0.2s ease; box-shadow: 0 0 40px rgba(0,0,0,0.2); }
  .layout.nav-open .sidebar { transform: translateX(0); }
  .hamburger { display: block; }
  .container { padding: 0 0.9rem; }

  /* Wide tables scroll horizontally instead of overflowing the screen. */
  table.lines, .master-table, .rpt-table {
    display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  /* Form rows stack; fixed-width fields go full width. */
  .row { flex-wrap: wrap; }
  .date-field, .people, .filter-field, .grow { width: 100%; }
  .reject-form { margin-left: 0; width: 100%; }
  .reject-form input { width: 100%; flex: 1; }
  .row.actions, .action-bar { gap: 0.6rem; }
  .who { display: none; }            /* free up the cramped top bar */
  h1 { font-size: 1.25rem; }
}
