/* Shared design system for the sign-in pages and the App Portal. Colours are RGB triplets so Tailwind opacity works. */
/* Sarabun (SIL Open Font License), Thai characters only -- Latin text keeps the system font */
@font-face { font-family: 'Sarabun Thai'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/static/fonts/sarabun-thai-400.woff2') format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun Thai'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('/static/fonts/sarabun-thai-500.woff2') format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun Thai'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('/static/fonts/sarabun-thai-600.woff2') format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun Thai'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('/static/fonts/sarabun-thai-700.woff2') format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun Thai'; font-style: normal; font-weight: 800; font-display: swap;
  src: url('/static/fonts/sarabun-thai-800.woff2') format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
:root {
  color-scheme: light dark;
  --font: "Sarabun Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --r-sm: 10px; --r-md: 16px; --r-lg: 22px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
  --shadow-lift: 0 2px 4px rgba(16,24,40,.06), 0 16px 36px rgba(16,24,40,.10);

  --bg: 245 245 247; --card: 255 255 255; --fill: 238 238 241; --fill-2: 231 231 235; --fill-low: 242 242 244;
  --line: 210 210 216; --text: 29 29 31; --text-2: 90 90 96; --text-3: 118 118 124;
  --accent: 6 66 136; --accent-text: 255 255 255; --tint: 6 66 136; --soft: 220 232 248; --soft-text: 52 78 112;
  --danger: 186 26 26; --danger-soft: 255 225 222; --danger-text: 147 0 10;
}
@media (prefers-color-scheme: dark) {
  :root {
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    --shadow-lift: 0 2px 4px rgba(0,0,0,.5), 0 16px 36px rgba(0,0,0,.45);
    --bg: 18 18 20; --card: 30 30 33; --fill: 44 44 48; --fill-2: 56 56 61; --fill-low: 24 24 27;
    --line: 70 70 76; --text: 242 242 244; --text-2: 180 180 186; --text-3: 142 142 148;
    --accent: 38 103 196; --accent-text: 255 255 255; --tint: 122 170 240; --soft: 38 52 74; --soft-text: 178 202 235;
    --danger: 255 138 128; --danger-soft: 78 30 30; --danger-text: 255 190 184;
  }
}

body { font-family: var(--font); -webkit-font-smoothing: antialiased; }
a, button, input, select, textarea { transition: background-color .2s, border-color .2s, box-shadow .2s, transform .2s, opacity .2s; }

/* Continuous ("squircle") corners where supported; ordinary rounded corners elsewhere */
@supports (corner-shape: squircle) {
  .rounded-lg, .login-form-panel input, .card input, .card button[type="submit"], .login-form-panel button[type="submit"], .alert { corner-shape: squircle; border-radius: calc(var(--r-sm) * 1.7); }
  .rounded-xl, .app-icon { corner-shape: squircle; border-radius: calc(var(--r-md) * 1.7); }
  .rounded-2xl, .card, .login-wrapper { corner-shape: squircle; border-radius: calc(var(--r-lg) * 1.7); }
}

/* Letter tile for apps without an icon */
.app-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; border-radius: var(--r-md);
  color: #fff; font-weight: 600; letter-spacing: .02em; box-shadow: inset 0 1px 0 rgba(255,255,255,.25); }

/* ---- Portal ---- */
.glass { background: rgb(var(--bg) / .72); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
.nav-link { color: rgb(var(--text-2)); border-radius: var(--r-sm); }
.nav-link:hover { background: rgb(var(--fill)); }
.nav-link.active { background: rgb(var(--card)); color: rgb(var(--tint)); box-shadow: var(--shadow); }
.app-card { box-shadow: 0 1px 2px rgba(16,24,40,.04); }
@media (hover: hover) { .app-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); } }
.tabbar { border-top: 1px solid rgb(var(--line) / .6); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { color: rgb(var(--text-3)); min-height: 56px; }
.tabbar a.active { color: rgb(var(--tint)); }

/* Touch screens and small windows: 44px targets */
@media (max-width: 1023px), (pointer: coarse) {
  main button, main a.inline-flex, main select, main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  .login-form-panel .label-link, .card .link a { min-height: 44px; }
  main nav a, main a.text-xs, .login-form-panel .label-link, .card .link a { display: inline-flex; align-items: center; min-height: 44px; }
  main button, main .star-btn { min-width: 44px; }
  main input[type="checkbox"] { width: 22px; height: 22px; }
  .pw-toggle { min-width: 44px; min-height: 44px; justify-content: center; }
}

/* User list becomes cards on phones */
@media (max-width: 639px) {
  table:has(.user-row), table:has(.user-row) tbody, table:has(.user-row) thead, table:has(.user-row) thead tr { display: block; width: 100%; }
  table:has(.user-row) thead th { display: none; }
  table:has(.user-row) thead th:first-child { display: flex; align-items: center; gap: 10px; width: 100%; }
  table:has(.user-row) thead th:first-child::after { content: "Select all"; font-size: 13px; }
  .user-row { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; }
  .user-row td { padding-top: 12px; padding-bottom: 12px; }
}

/* Dark mode for the fixed palette classes used inside portal pages */
@media (prefers-color-scheme: dark) {
  html .bg-white { background-color: rgb(var(--card)); }
  html .bg-blue-50, html .bg-violet-100, html .bg-blue-100 { background-color: #1d2b45; }
  html .bg-emerald-50, html .bg-green-50, html .bg-emerald-100 { background-color: #15332a; }
  html .bg-amber-50, html .bg-amber-100 { background-color: #3a2e12; }
  html .bg-rose-100 { background-color: #43202a; }
  html .text-blue-900, html .text-blue-800, html .text-blue-700, html .text-blue-600, html .text-violet-700 { color: #a8c7fa; }
  html .text-emerald-800, html .text-emerald-700, html .text-green-700 { color: #86e0b5; }
  html .text-amber-800, html .text-amber-700 { color: #f5cd79; }
  html .text-rose-700 { color: #ffb3c1; }
  html .text-slate-500, html .text-slate-700 { color: rgb(var(--text-2)); }
  html .border-blue-200, html .border-emerald-200, html .border-green-200, html .border-amber-200, html .border-slate-200 { border-color: rgb(var(--line)); }
  html .bg-error { background-color: #b3261e; }
}

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

/* ---- Admin console ---- */
html .bg-primary { background-color: rgb(var(--accent)); color: rgb(var(--accent-text)); }
.jumpbar { scrollbar-width: none; }
main [id^="sec-"] { scroll-margin-top: 9.5rem; }
@media (max-width: 1023px) {
  main table:not(:has(.user-row)) { display: block; max-width: 100%; overflow-x: auto; }
  main table:not(:has(.user-row)) th { white-space: nowrap; }
}
@media (prefers-color-scheme: dark) {
  html .bg-red-50, html .bg-red-100, html .bg-red-200 { background-color: #3d1d1d; }
  html .bg-orange-100, html .bg-amber-100 { background-color: #3a2e12; }
  html .bg-green-100, html .bg-teal-100, html .bg-cyan-100 { background-color: #15332a; }
  html .bg-sky-50, html .bg-violet-50, html .bg-\[\#e1f5fe\] { background-color: #1d2b45; }
  html .bg-slate-50, html .bg-slate-100 { background-color: rgb(var(--fill)); }
  html .text-red-800, html .text-red-700, html .text-red-500 { color: #ffb4ab; }
  html .text-orange-900, html .text-orange-800, html .text-orange-700, html .text-amber-900 { color: #f5cd79; }
  html .text-green-800, html .text-teal-700, html .text-cyan-700 { color: #86e0b5; }
  html .text-sky-700, html .text-\[\#01579b\], html .text-\[\#0F172A\] { color: #a8c7fa; }
  html .text-slate-600 { color: rgb(var(--text-2)); }
  html .border-slate-100, html .border-red-200, html .border-orange-300, html .border-orange-400, html .border-amber-300, html .border-emerald-100 { border-color: rgb(var(--line)); }
  main svg text { fill: rgb(var(--text-2)); }
}

/* Employee hover card (audit trail) */
[data-person-name] { cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }
.person-tip { position: fixed; z-index: 70; min-width: 240px; max-width: min(340px, calc(100vw - 16px)); pointer-events: none;
  background: rgb(var(--card)); color: rgb(var(--text)); border: 1px solid rgb(var(--line)); border-radius: var(--r-md);
  box-shadow: var(--shadow-lift); padding: 12px 14px; font-family: var(--font); font-size: 12.5px; line-height: 1.5; text-align: left; }
.person-tip-name { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.person-tip-row { display: flex; gap: 12px; }
.person-tip-label { flex: 0 0 96px; color: rgb(var(--text-3)); }
.person-tip-value { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* Readability: faint greys and ambers in tables */
main thead tr.text-slate-400, main thead th.text-slate-400, main thead .text-slate-400 { color: rgb(var(--text-3)); }
main thead th { color: rgb(var(--text-2)); }
@media (prefers-color-scheme: light) { main .text-amber-500.text-xs { color: #b45309; } }
