/* ===== Verena Utility Records – design tokens ===== */
:root {
  --bg: #FAFAF9;
  --panel: #FFFFFF;
  --panel-2: #F4F4F2;
  --line: #E7E5E1;
  --line-soft: #EFEDE8;
  --text: #171717;
  --text-2: #57534E;
  --text-3: #8A857E;
  --accent: #EA580C;
  --accent-soft: #FFF3EA;
  --accent-line: #FFE0CC;
  --success: #15803D;
  --warning: #B45309;
  --review: #6B21A8;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 16, 16, 0.04);
  --shadow-md: 0 4px 18px -8px rgba(16, 16, 16, 0.10), 0 1px 2px rgba(16, 16, 16, 0.04);
  --shadow-lg: 0 20px 50px -20px rgba(16, 16, 16, 0.18), 0 4px 12px -4px rgba(16, 16, 16, 0.06);
  --font-en: "Lato", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-th: "Sarabun", "Lato", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-en);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body.lang-th { font-family: var(--font-th); font-size: 15px; }
body.lang-th .num, body.lang-th .mono { font-family: var(--font-en); }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* ===== App shell ===== */
#root { min-height: 100%; }
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--text);
  color: #FFF8F1;
  display: grid; place-items: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
  position: relative;
  overflow: hidden;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 55%, var(--accent) 55%);
  opacity: 1;
}
.brand-mark span { position: relative; z-index: 1; }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-3); letter-spacing: 0.04em; text-transform: uppercase; }

.nav-section { padding: 6px 6px; }
.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 0 8px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  font-size: 13.5px;
  user-select: none;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { width: 16px; height: 16px; color: var(--text-3); flex-shrink: 0; }
.nav-item.active .nav-icon { color: var(--accent); }

.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--text); color: #FFF8F1;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.02em;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1; }
.user-name { font-size: 13px; font-weight: 600; }
.user-email { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Main column ===== */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: rgba(250, 250, 249, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 28px;
  display: flex; align-items: center; gap: 14px;
}
.search {
  flex: 1; max-width: 480px;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text-3);
  font-size: 13px;
}
.search input { border: none; background: transparent; flex: 1; font-size: 13px; }
.search input:focus { outline: none; }
.kbd { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3); padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-2); }

.lang-switch {
  display: flex; align-items: center;
  padding: 2px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 7px;
}
.lang-switch button {
  border: none; background: transparent;
  padding: 4px 9px;
  font-size: 12px; font-weight: 600;
  border-radius: 5px;
  color: var(--text-3);
}
.lang-switch button.active { background: var(--text); color: #FFF8F1; }

.icon-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-2);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn .dot { position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; background: var(--accent); border-radius: 50%; border: 1.5px solid var(--panel); }

/* ===== Page wrapper ===== */
.page { padding: 28px 28px 64px; max-width: 1280px; margin: 0 auto; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
body.lang-th .page-title { font-size: 28px; }
.page-sub { font-size: 13.5px; color: var(--text-2); margin: 0; max-width: 640px; }
body.lang-th .page-sub { font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  transition: background 120ms;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--text); color: #FFF8F1; border-color: var(--text); }
.btn.primary:hover { background: #2a2a2a; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.btn.accent:hover { filter: brightness(0.95); }
.btn.subtle { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.subtle:hover { background: var(--panel-2); color: var(--text); }
.btn.danger { color: #B91C1C; }
.btn.danger:hover { background: #FEF2F2; }
.btn .ico { width: 14px; height: 14px; }

.header-actions { display: flex; gap: 8px; align-items: center; }

/* ===== Cards & panels ===== */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-head { padding: 16px 18px 8px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title { font-size: 14px; font-weight: 700; letter-spacing: -0.005em; margin: 0; }
.card-sub { font-size: 12.5px; color: var(--text-3); margin: 2px 0 0; }
.card-body { padding: 8px 18px 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--text-3); }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
  overflow: hidden;
}
.kpi-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.kpi-dot { width: 8px; height: 8px; border-radius: 50%; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-feature-settings: "tnum"; }
.kpi-value .unit { font-size: 14px; color: var(--text-3); font-weight: 600; margin-left: 4px; }
.kpi-delta { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 5px; }
.kpi-delta .up { color: var(--accent); font-weight: 600; }
.kpi-delta .down { color: var(--success); font-weight: 600; }
.kpi-spark { position: absolute; bottom: 0; right: 0; width: 120px; height: 36px; opacity: 0.9; pointer-events: none; }

/* ===== Grids ===== */
.row { display: grid; gap: 14px; }
.row.two-thirds { grid-template-columns: 2fr 1fr; }
.row.halves { grid-template-columns: 1fr 1fr; }
.row.thirds { grid-template-columns: repeat(3, 1fr); }
.row + .row { margin-top: 14px; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data thead th {
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
table.data tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.cell-mono { font-family: var(--font-mono); font-size: 12.5px; }
.cell-num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.cell-strong { font-weight: 600; }

/* status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; border-radius: 999px; border: 1px solid; }
.pill .pdot { width: 6px; height: 6px; border-radius: 50%; }
.pill.approved { color: var(--success); border-color: #C6EAD2; background: #F1FAF4; }
.pill.approved .pdot { background: var(--success); }
.pill.pending { color: var(--warning); border-color: #F2D9B4; background: #FDF6EC; }
.pill.pending .pdot { background: var(--warning); }
.pill.review { color: var(--review); border-color: #E0CCF0; background: #FAF4FE; }
.pill.review .pdot { background: var(--review); }
.pill.admin { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.pill.admin .pdot { background: var(--accent); }
.pill.user { color: var(--text-2); border-color: var(--line); background: var(--panel-2); }
.pill.user .pdot { background: var(--text-3); }
.pill.viewer { color: var(--text-3); border-color: var(--line); background: var(--panel-2); }
.pill.viewer .pdot { background: var(--text-3); }

/* type badges */
.type-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; }
.type-badge .swatch { width: 8px; height: 8px; border-radius: 2px; }

/* ===== Filters bar ===== */
.filter-bar {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.filter-bar label { font-size: 11.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.filter-bar select, .filter-bar input[type="text"] {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--text);
}

/* ===== Chart styling ===== */
.chart-wrap { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-axis-text { font-size: 10.5px; fill: var(--text-3); font-family: var(--font-en); }
.chart-tooltip {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  background: var(--text);
  color: #F8F4EE;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11.5px;
  min-width: 130px;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}
.tt-label { font-weight: 700; margin-bottom: 4px; font-size: 11px; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.05em; }
.tt-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.tt-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.tt-name { flex: 1; font-size: 11.5px; }
.tt-val { font-weight: 700; font-variant-numeric: tabular-nums; }

.donut-center-num { font-size: 22px; font-weight: 700; fill: var(--text); font-family: var(--font-en); font-variant-numeric: tabular-nums; }
.donut-center-label { font-size: 10.5px; fill: var(--text-3); font-family: var(--font-en); letter-spacing: 0.1em; text-transform: uppercase; }

.legend { display: flex; flex-direction: column; gap: 8px; min-width: 160px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend-row .swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.legend-row .lbl { color: var(--text-2); flex: 1; }
.legend-row .val { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.field .hint { font-size: 11.5px; color: var(--text-3); }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="number"], .field input[type="date"], .field select, .field textarea {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text);
  width: 100%;
}
.field textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.field .req { color: var(--accent); margin-left: 2px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 28px 18px;
  text-align: center;
  color: var(--text-2);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .browse { color: var(--accent); font-weight: 600; cursor: pointer; }
.dropzone .file-icon { width: 40px; height: 40px; color: var(--text-3); }
.photo-preview {
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line);
  aspect-ratio: 4/3;
  display: grid; place-items: center;
}
.photo-preview .placeholder-img {
  width: 100%; height: 100%;
  background:
    repeating-linear-gradient(135deg, rgba(0,0,0,0.04) 0 8px, transparent 8px 16px),
    linear-gradient(180deg, #f0ece3, #e6e1d6);
  display: grid; place-items: center;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ===== Toast ===== */
.toast-rack { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  background: var(--text); color: #FFF8F1;
  border-radius: 9px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  pointer-events: auto;
  animation: toast-in 280ms cubic-bezier(0.2, 0.7, 0.3, 1);
}
.toast .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== Modal ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 18, 14, 0.4); z-index: 200; display: grid; place-items: center; padding: 24px; }
.modal { background: var(--panel); border-radius: var(--radius-lg); width: 100%; max-width: 480px; box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-head { padding: 18px 22px 4px; }
.modal-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.modal-sub { font-size: 12.5px; color: var(--text-3); margin: 4px 0 0; }
.modal-body { padding: 14px 22px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 8px; background: var(--panel-2); }

/* ===== Login page ===== */
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1.05fr;
  background: var(--bg);
}
.login-pane {
  display: flex; flex-direction: column;
  padding: 40px 56px;
  min-height: 100vh;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: auto; }
.login-form-wrap { max-width: 380px; width: 100%; margin: auto 0; }
.login-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
body.lang-th .login-title { font-size: 30px; }
.login-th-title { font-size: 16px; color: var(--text-2); margin: 0 0 28px; }
body.lang-th .login-th-title { font-size: 17px; }
.login-foot { font-size: 11.5px; color: var(--text-3); margin-top: auto; }

.login-art {
  background: var(--panel-2);
  border-left: 1px solid var(--line);
  padding: 40px;
  display: flex; flex-direction: column; justify-content: center;
  position: relative;
  overflow: hidden;
}
.login-art-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-md);
  max-width: 420px;
  margin: 0 auto;
}
.login-art-card + .login-art-card { margin-top: 14px; }
.login-art-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line-soft); font-size: 12.5px; }
.login-art-row:last-child { border-bottom: none; }
.login-art-label { color: var(--text-3); }
.login-art-val { font-weight: 600; font-variant-numeric: tabular-nums; }

.divider-or { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--text-3); font-size: 12px; }
.divider-or::before, .divider-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.sso-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 13px; font-weight: 600;
  color: var(--text);
}
.sso-btn:hover { background: var(--panel-2); }
.sso-btn + .sso-btn { margin-top: 8px; }
.sso-btn .glyph { width: 16px; height: 16px; display: grid; place-items: center; font-size: 14px; font-weight: 800; }

/* ===== Empty state ===== */
.empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

/* ===== Misc helpers ===== */
.row-flex { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.hr { height: 1px; background: var(--line-soft); border: 0; margin: 14px 0; }

.section-list { display: flex; flex-direction: column; }
.section-list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.section-list-item:last-child { border-bottom: none; }

/* responsive */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .row.two-thirds, .row.halves, .row.thirds { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .page { padding: 18px 16px 64px; }
  .topbar { padding: 10px 14px; }
  .search { display: none; }
  .login-shell { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .login-pane { padding: 28px 22px; }
  .field-row { grid-template-columns: 1fr; }
}
