/* FoundationWork Phase 1A app — tokens from design.md v1.0 */
:root {
  --fw-white: #FFFFFF; --fw-ink: #102B56; --fw-blue: #0D6EFD; --fw-blue-hover: #0958CE; --fw-blue-soft: #E6F2FF;
  --fw-gold: #D4AF37; --fw-gold-soft: #FFF7DF; --fw-canvas: #F7F9FC; --fw-border: #E2E8F0; --fw-muted: #64748B; --fw-text: #1E293B;
  --fw-success: #15803D; --fw-success-soft: #EAF7EF; --fw-warning: #A16207; --fw-warning-soft: #FFF7E6; --fw-danger: #B42318; --fw-danger-soft: #FEF0EF;
  --fw-radius-sm: 8px; --fw-radius-md: 12px; --fw-radius-lg: 16px; --fw-shadow-card: 0 3px 14px rgba(16, 43, 86, .05);
  --fw-font: 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --sidebar-w: 256px; --topbar-h: 64px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--fw-font); font-size: 16px; line-height: 1.6; color: var(--fw-text); background: var(--fw-canvas); }
img, svg { display: block; max-width: 100%; }
a { color: var(--fw-blue-hover); }
h1, h2, h3 { color: var(--fw-ink); line-height: 1.3; margin: 0; }
h1 { font-size: clamp(24px, 2.4vw, 30px); font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
p { margin: 0 0 8px; }
code { font-size: 13px; background: var(--fw-canvas); padding: 1px 5px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.muted { color: var(--fw-muted); }
.small { font-size: 14px; }
.strong { font-weight: 700; color: var(--fw-ink); }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 100; background: var(--fw-ink); color: #fff; padding: 8px 14px; border-radius: 8px; }
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid rgba(13, 110, 253, .45); outline-offset: 2px; border-radius: 6px; }

/* Development banner — always visible */
.devbar { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; justify-content: center; padding: 6px 16px; background: var(--fw-ink); color: #fff; font-size: 13.5px; text-align: center; }
.devbar strong { color: #F6D97E; letter-spacing: .04em; }

/* Shell */
.shell { display: flex; min-height: calc(100vh - 34px); }
.sidebar { width: var(--sidebar-w); flex: none; background: #fff; border-right: 1px solid var(--fw-border); padding: 16px 12px 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; text-decoration: none; color: var(--fw-ink); font-weight: 700; font-size: 18px; }
.brand img { width: 44px; height: auto; }
.side-nav { display: grid; gap: 2px; }
.side-nav a, .nav-off { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 10px; color: var(--fw-ink); text-decoration: none; font-weight: 500; font-size: 15px; }
.side-nav a:hover { background: var(--fw-canvas); }
.side-nav a.is-active { background: var(--fw-blue-soft); color: var(--fw-blue-hover); font-weight: 600; }
.nav-group { margin: 14px 12px 4px; font-size: 12.5px; font-weight: 600; color: var(--fw-muted); letter-spacing: .02em; }
.nav-off { flex-direction: column; align-items: flex-start; gap: 0; color: #94A3B8; cursor: not-allowed; }
.nav-off small { font-size: 11.5px; line-height: 1.35; color: var(--fw-warning); }
.nav-tag { font-size: 11.5px; padding: 0 8px; border-radius: 999px; background: var(--fw-canvas); border: 1px solid var(--fw-border); color: var(--fw-muted); font-weight: 600; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; min-height: var(--topbar-h); padding: 8px 24px; background: rgba(255, 255, 255, .96); border-bottom: 1px solid var(--fw-border); }
.nav-btn { display: none; border: 1px solid var(--fw-border); background: #fff; border-radius: 10px; padding: 8px; cursor: pointer; color: var(--fw-ink); }
.nav-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.org { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; flex: 1; min-width: 0; }
.org-name { font-weight: 700; color: var(--fw-ink); }
.who { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.who small { color: var(--fw-muted); margin-left: 4px; }
.who form { margin: 0; }
.content { padding: 24px; max-width: 1500px; width: 100%; min-width: 0; overflow-wrap: break-word; }   /* long hashes/references must not widen the page */
.dl dd, .alert, code, .small, .muted { overflow-wrap: anywhere; min-width: 0; }   /* SHA-256 / idempotency keys have no break points */
.form-inline #fy-hint { flex: 1 1 100%; font-size: 13.5px; }

/* Page head */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; margin-bottom: 20px; }
.page-head .muted { margin-top: 4px; }
.crumb { margin: 0 0 2px; font-size: 14px; }
.crumb a { text-decoration: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { margin: 0; }

/* Cards, grids */
.card { background: #fff; border: 1px solid var(--fw-border); border-radius: var(--fw-radius-lg); box-shadow: var(--fw-shadow-card); padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.card-head a { font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpis-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpis .card { margin: 0; }
.kpi { display: grid; gap: 4px; }
.kpi-label { font-size: 14px; color: var(--fw-muted); }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--fw-ink); text-align: left; line-height: 1.2; }
.kpi-sub { font-size: 13px; color: var(--fw-muted); }
.empty { color: var(--fw-muted); padding: 12px 0; margin: 0; }

/* Notices & alerts */
.notice { border-radius: var(--fw-radius-md); padding: 12px 16px; margin-bottom: 20px; font-size: 15px; }
.notice strong { margin-right: 6px; }
.notice-draft { background: var(--fw-warning-soft); border: 1px solid #F3DDB0; color: #5B3B05; }
.notice-draft strong { color: var(--fw-warning); }
.alert { border-radius: var(--fw-radius-md); padding: 12px 16px; margin-bottom: 16px; border: 1px solid; }
.alert ul { margin: 6px 0; }
.alert-success { background: var(--fw-success-soft); border-color: #BFE3CB; color: #0F5C2C; }
.alert-warning { background: var(--fw-warning-soft); border-color: #F3DDB0; color: #5B3B05; }
.alert-danger { background: var(--fw-danger-soft); border-color: #F5C2BD; color: #8A1C13; }
.alert-info { background: var(--fw-blue-soft); border-color: #B9D3FB; color: #0B3F8F; }

/* Badges, chips */
.badge, .chip { display: inline-flex; align-items: center; gap: 6px; padding: 1px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; line-height: 1.7; white-space: nowrap; vertical-align: middle; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-neutral { background: var(--fw-canvas); color: #475569; border: 1px solid var(--fw-border); }
.badge-info { background: var(--fw-blue-soft); color: #0B52BF; }
.badge-success { background: var(--fw-success-soft); color: var(--fw-success); }
.badge-warning, .chip-warning { background: var(--fw-warning-soft); color: var(--fw-warning); }
.badge-danger { background: var(--fw-danger-soft); color: var(--fw-danger); }
.badge-gold { background: var(--fw-gold-soft); color: #7A5A06; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 15px; line-height: 1.2; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--fw-blue); color: #fff; }
.btn-primary:hover { background: var(--fw-blue-hover); }
.btn-secondary { background: #fff; color: var(--fw-blue-hover); border-color: #B9D3FB; }
.btn-secondary:hover { background: var(--fw-blue-soft); }
.btn-ghost { background: transparent; color: var(--fw-ink); border-color: var(--fw-border); }
.btn-ghost:hover { background: var(--fw-canvas); }
.btn-danger { background: var(--fw-danger); color: #fff; }
.btn-disabled { background: var(--fw-canvas); color: #94A3B8; border: 1px dashed #CBD5E1; cursor: not-allowed; font-weight: 500; font-size: 14px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 20px; }
.span-2 { grid-column: 1 / -1; }
.field { display: grid; gap: 4px; margin: 0 0 12px; border: 0; padding: 0; min-width: 0; }
.field label, .field legend { font-weight: 600; font-size: 14.5px; color: var(--fw-ink); padding: 0; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid #CBD5E1; border-radius: 10px; font: inherit; color: var(--fw-text); background: #fff;
}
textarea { min-height: 72px; resize: vertical; }
input.num { text-align: right; }
input[aria-invalid=true], select[aria-invalid=true], textarea[aria-invalid=true] { border-color: var(--fw-danger); background: #FFFBFA; }
.field-error { color: var(--fw-danger); font-size: 14px; margin: 0; }
.hint { color: var(--fw-muted); font-size: 13.5px; margin: 0; }
.req { color: var(--fw-danger); }
.radio-row { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.radio, .check { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; font-size: 15px; margin: 4px 0; }
.radio input, .check input { margin-top: 5px; width: 18px; height: 18px; }
.pii { border: 1px solid var(--fw-border); border-radius: var(--fw-radius-md); padding: 14px 16px 4px; margin-bottom: 12px; background: var(--fw-canvas); }
.pii-title { font-weight: 700; color: var(--fw-ink); }
.pii[hidden] { display: none; }
.confirm-dup { background: var(--fw-warning-soft); padding: 10px 12px; border-radius: 10px; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.form-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.form-inline input:not([type=file]) { width: auto; flex: 1 1 220px; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 16px; padding: 16px 20px 4px; }
.filters .field { flex: 1 1 180px; }
.filters .field-btn { flex: 0 0 auto; }

/* Tables */
/* position: relative keeps absolutely-positioned descendants (visually-hidden labels) inside the scroller */
.table-wrap { overflow-x: auto; position: relative; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th { text-align: left; font-size: 13.5px; font-weight: 600; color: var(--fw-muted); padding: 10px 12px; border-bottom: 1px solid var(--fw-border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid #EEF2F7; vertical-align: top; }
.table th.num { text-align: right; }
.table tbody tr:hover { background: #FAFCFF; }
.table tr:last-child td { border-bottom: 0; }
.table td > a:first-child { white-space: nowrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { margin: 0; }
.inline-form summary { list-style: none; }
.inline-form summary::-webkit-details-marker { display: none; }
.inline-form form { display: flex; gap: 6px; margin-top: 6px; }
.alloc-table td { min-width: 160px; }
.audit-table td { font-size: 14px; }

/* Definition lists, misc */
.dl { display: grid; grid-template-columns: minmax(120px, 36%) 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--fw-muted); font-size: 14.5px; }
.dl dd { margin: 0; text-align: left; }
.budget-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.budget-row { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
progress { width: 100%; height: 10px; border: 0; border-radius: 999px; background: var(--fw-canvas); overflow: hidden; accent-color: var(--fw-blue); }
progress::-webkit-progress-bar { background: #EEF2F7; border-radius: 999px; }
progress::-webkit-progress-value { background: var(--fw-blue); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--fw-blue); border-radius: 999px; }
.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14.5px; }
.activity li { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: space-between; border-bottom: 1px solid #EEF2F7; padding-bottom: 8px; }
.file-list { margin: 0 0 8px; padding-left: 18px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; }
.danger-zone { border-color: #F5C2BD; }
.disabled-card { max-width: 760px; }
.disabled-label { margin-bottom: 12px; }

/* Bare pages: login, errors */
.bare-main { max-width: 440px; margin: 48px auto; padding: 0 16px; }
.login-card { padding: 28px; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.login-title { font-size: 22px; font-weight: 700; color: var(--fw-ink); margin: 0; }
.login-note { margin-top: 16px; font-size: 13.5px; color: var(--fw-muted); }
.error-card { text-align: left; }
.error-code { font-size: 14px; font-weight: 700; color: var(--fw-muted); margin: 0; }
.error-card h1 { margin: 4px 0 8px; }

/* Bank statement import wizard */
.wizard-steps ol { list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; padding: 0; }
.wizard-step { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--fw-border); border-radius: var(--fw-radius-md); background: #fff; min-width: 0; }
.wizard-step a { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; min-width: 0; }
.wizard-num { flex: 0 0 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; background: var(--fw-canvas); color: var(--fw-muted); }
.wizard-label { font-size: 14.5px; font-weight: 600; overflow-wrap: anywhere; }
.wizard-step.is-current { border-color: var(--fw-blue); box-shadow: 0 0 0 2px var(--fw-blue-soft); }
.wizard-step.is-current .wizard-num { background: var(--fw-blue); color: #fff; }
.wizard-step.is-done .wizard-num { background: var(--fw-success-soft); color: var(--fw-success); }
.wizard-step.is-todo .wizard-label { color: var(--fw-muted); }
.wizard-file { margin: 0 0 16px; }
.two-panel { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.two-panel .card { margin: 0 0 20px; }
.source-grid { max-height: 520px; overflow: auto; }
.table-compact { font-size: 14px; }
.table-compact th, .table-compact td { padding: 6px 8px; }
.table-compact tr.is-header td { background: var(--fw-blue-soft); font-weight: 600; }
.row-error td { background: #FFF6F5; }
.row-warning td { background: #FFFBF0; }
.source-cells span { display: inline-block; margin-right: 6px; color: var(--fw-muted); }
.source-cells b { color: var(--fw-ink); font-weight: 600; }
.small-head { font-size: 15px; margin: 8px 0; }
.small-kpi { font-size: 18px; }
.static { margin: 6px 0 0; }
.hash { overflow-wrap: anywhere; }
.dropzone { position: relative; border: 2px dashed #B9D3FB; border-radius: var(--fw-radius-lg); background: #FBFDFF; padding: 20px; margin: 4px 0 12px; text-align: center; }
.dropzone.is-over { border-color: var(--fw-blue); background: var(--fw-blue-soft); }
.dropzone-label { display: grid; justify-items: center; gap: 8px; cursor: pointer; }
.dropzone-file { font-weight: 600; color: var(--fw-ink); overflow-wrap: anywhere; }
.dropzone input[type=file] { margin-top: 10px; max-width: 100%; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.tab { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--fw-border); background: #fff; color: var(--fw-ink); text-decoration: none; font-size: 14.5px; }
.tab.is-active { background: var(--fw-blue); border-color: var(--fw-blue); color: #fff; }
.row-excluded td { background: var(--fw-canvas); color: var(--fw-muted); text-decoration: line-through; }
.row-excluded td.row-tools, .row-excluded td:nth-child(2) { text-decoration: none; }
.is-corrected { background: var(--fw-blue-soft) !important; }
.row-tools { min-width: 96px; }
.row-edit summary { list-style: none; }
.row-edit summary::-webkit-details-marker { display: none; }
.row-edit-form { min-width: 240px; margin-top: 8px; padding: 10px; border: 1px solid var(--fw-border); border-radius: var(--fw-radius-md); background: #fff; }
.dup-bar { align-items: center; }
.dup-bar p { flex: 1 1 260px; margin: 0; }
.confirm-bar { display: flex; justify-content: space-between; align-items: center; }
.confirm-bar form { margin: 0; }
.inline-cancel { margin: 0 0 24px; text-align: right; }
@media (max-width: 960px) {
  .two-panel { grid-template-columns: minmax(0, 1fr); }
  .wizard-steps ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .wizard-label { font-size: 13px; }
  .confirm-bar { flex-direction: column-reverse; align-items: stretch; }
  .confirm-bar .btn { width: 100%; }
}

/* Fund-only mode */
.mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.mode-card { border: 1px solid var(--fw-border); border-radius: var(--fw-radius-md); padding: 16px; min-width: 0; }
.mode-card h3 { margin-top: 0; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.check-item { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.card-head h2 { margin: 0; }
.card-sub { margin: 8px 0; }
.scope-label { font-size: 15px; }
.public-fund { max-width: 980px; margin: 0 auto; }
@media (max-width: 960px) { .mode-grid { grid-template-columns: minmax(0, 1fr); } }

/* Responsive */
@media (max-width: 1280px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; transform: translateX(-100%); transition: transform .18s ease; box-shadow: 0 0 40px rgba(16, 43, 86, .18); }
  .sidebar.is-open { transform: none; }
  .nav-btn { display: inline-flex; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .who-name { display: none; }
}
@media (max-width: 640px) {
  .content { padding: 16px; }
  .topbar { padding: 8px 16px; gap: 10px; }
  .org .chip { display: none; }
  .kpis, .kpis-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .dl dd { margin-bottom: 8px; }
  .card { padding: 16px; }
  .page-head .btn { width: 100%; }
  .actions { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Phase 1B.3: Prompt for headings (Sarabun for text), loading state for workflow buttons */
h1, h2, h3, .brand span { font-family: 'Prompt', var(--fw-font); }
button[aria-busy="true"] { opacity: .7; cursor: progress; }
.activity { padding-left: 20px; }
.activity li { margin: 4px 0; }

/* public interactive demo */
.demo-landing { max-width: 720px; margin: 32px auto; }
.demo-banner { background: var(--fw-warning-soft); color: var(--fw-warning); border-radius: var(--fw-radius-lg); padding: 12px 16px; }
.demo-roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 12px 0; }
.demo-points { padding-left: 20px; }
.demo-switch { display: flex; gap: 6px; align-items: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.topbar { flex-wrap: wrap; row-gap: 6px; }
.who { flex-wrap: wrap; justify-content: flex-end; }
.org { min-width: 0; }

/* Phase 1F: onboarding steps + plain-language explanations */
.steps .check-item { padding: 6px 0; border-bottom: 1px solid var(--fw-border); }
.steps .check-item:last-child { border-bottom: 0; }
.step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 999px; background: var(--fw-canvas, #F4F6FA); font-size: 13px; font-weight: 600; flex: 0 0 auto; }
.check-item.is-done .step-no { background: #DCF5E7; }
.explain dl.dl { margin: 8px 0 0; }
.explain dt { font-weight: 600; margin-top: 6px; }
.explain dd { margin: 2px 0 0; }
