/* Admin dashboard mapped to the Popiwat design system (design-tokens.css + shared-components.css).
   Loaded after styles.css: it re-points the dashboard's old colour variables at the shared tokens and
   restyles buttons, fields, tables, tabs and chips with them. Brand: Popiwat yellow action, token neutrals. */
@font-face { font-family: "Noto Sans Thai"; src: url("/fonts/noto-sans-thai-400.ttf") format("truetype"); font-style: normal; font-weight: 400; font-display: swap; }
@font-face { font-family: "Noto Sans Thai"; src: url("/fonts/noto-sans-thai-500.ttf") format("truetype"); font-style: normal; font-weight: 500; font-display: swap; }
@font-face { font-family: "Noto Sans Thai"; src: url("/fonts/noto-sans-thai-600.ttf") format("truetype"); font-style: normal; font-weight: 600; font-display: swap; }
@font-face { font-family: "Noto Sans Thai"; src: url("/fonts/noto-sans-thai-700.ttf") format("truetype"); font-style: normal; font-weight: 700; font-display: swap; }
:root {
  --primary: #f5d547; --primary-foreground: #171717;
  --ds-action: var(--primary); --ds-action-text: var(--primary-foreground); --ds-text: var(--foreground); --ds-muted-text: var(--muted-foreground);
  --ds-border: var(--input); --ds-surface: var(--background); --ds-upload-surface: #f3f4f6; --ds-focus: var(--ring);
  --ds-error: var(--destructive); --ds-error-surface: #fff6f5; --ds-control-radius: var(--radius-md);
  /* The dashboard's own variables now resolve to design tokens. */
  --ink: var(--foreground); --muted: var(--muted-foreground); --line: var(--border); --paper: var(--card); --page: var(--background);
  --yellow: var(--primary); --green: #e8f6ec; --red: #fdecea; --focus: var(--ring);
}
body { background: var(--background); color: var(--foreground); font: 1rem/1.5 var(--font-sans), "Noto Sans Thai", system-ui, sans-serif; }
.topbar { height: auto; min-height: 68px; padding: var(--space-3) max(var(--space-4), calc((100vw - 76rem) / 2)); background: var(--background); border-bottom: 1px solid var(--border); }
.brand { color: var(--foreground); font-weight: var(--weight-bold); }
.brandmark { border-radius: var(--radius-lg); background: var(--primary); color: var(--primary-foreground); }
.panel { padding: var(--space-6); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); box-shadow: none; }
h1, h2, h3 { color: var(--foreground); }
h1 { font-size: clamp(1.75rem, 3vw, 2.25rem); line-height: 1.2; font-weight: var(--weight-bold); }
h2 { font-size: 1.25rem; line-height: 1.4; font-weight: var(--weight-semibold); }
.eyebrow { color: var(--muted-foreground); font-weight: var(--weight-semibold); }
.small, .muted, .hint { color: var(--muted-foreground); }

/* Buttons: same sizing as .ds-button; primary uses the brand action colour. */
.admin-page button, .topbar button, .admin-table button { min-height: var(--size-control-md); border-radius: var(--ds-control-radius); font-weight: var(--weight-semibold); }
.admin-page .primary, .admin-table button.primary { border: 1px solid transparent; background: var(--ds-action); color: var(--ds-action-text); }
.admin-page .primary:hover, .admin-table button.primary:hover { background: var(--ds-action); filter: brightness(.96); }
.admin-page .secondary, .topbar .secondary, .admin-table button { border: 1px solid var(--border); background: var(--secondary); color: var(--secondary-foreground); }
.admin-page .secondary:hover, .topbar .secondary:hover, .admin-table button:hover { background: var(--accent); }
.admin-page button:disabled, .topbar button:disabled { opacity: .5; cursor: not-allowed; }
button.danger { color: var(--destructive); border-color: color-mix(in srgb, var(--destructive) 35%, white); }
.admin-page button:focus-visible, .admin-page input:focus-visible, .admin-page select:focus-visible, .topbar button:focus-visible { outline: 3px solid var(--ds-focus); outline-offset: 2px; }

/* Fields: same look as .ds-control. */
.admin-page input:not([type=checkbox]):not([type=radio]):not([type=file]), .admin-page select, .admin-page textarea {
  min-height: var(--size-control-md); padding: 8px 12px; border: 1px solid var(--ds-border); border-radius: var(--ds-control-radius); background-color: var(--ds-surface); color: var(--ds-text);
}
.admin-page input[readonly] { background-color: var(--secondary); color: var(--muted-foreground); }
.admin-page input:disabled, .admin-page select:disabled { background-color: var(--secondary); opacity: .6; }
.admin-form label, .search-field, .filter-group-label { color: var(--foreground); font-weight: var(--weight-semibold); }

/* Tabs, tables, chips and cards. */
.admin-tabs { border-bottom: 1px solid var(--border); }
.admin-tabs [role=tab] { color: var(--muted-foreground); font-weight: var(--weight-semibold); }
.admin-tabs [role=tab][aria-selected=true] { color: var(--foreground); border-bottom-color: var(--primary); }
.table-scroll, .claims-scroll, .summary-card, .family-card, .advanced-filters, .add-family-form { border-color: var(--border); border-radius: var(--radius-lg); background: var(--card); }
.admin-table th { color: var(--muted-foreground); font-weight: var(--weight-semibold); }
.admin-table th, .admin-table td { border-top-color: var(--border); }
.claims-table th, .family-card>.family-card-title { background: var(--secondary); }
.count-badge, .member-chip, .filter-chip { border-color: var(--border); background: var(--secondary); color: var(--secondary-foreground); }
.filter-chip.active { border-color: var(--primary); background: var(--primary); color: var(--primary-foreground); }
.pending-group { border-left-width: 1px; border-color: var(--border); background: var(--card); }
.summary-bar { accent-color: var(--primary); }
.message.error, .notice.error { background: var(--red); color: #8c2f21; }

/* Action columns hold up to three stacked buttons; give them room and a common width. */
.manage-table th:last-child, .manage-table td:last-child, .pending-table th:last-child, .pending-table td:last-child { width: 150px; }
.manage-table td:last-child button, .pending-table td:last-child button { display: block; width: 100%; margin: 4px 0; }
@media (max-width: 760px) { .manage-table td:last-child button, .pending-table td:last-child button { display: inline-flex; width: auto; } }

/* Claims by benefit: doughnut of allowance used. Approved green and pending amber are the status colours;
   the legend beside the chart names every segment so colour is never the only cue. */
.summary-body { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: var(--space-4); align-items: center; }
.doughnut { width: 140px; height: 140px; }
.doughnut-arc { stroke-linecap: butt; }
.arc-approved { stroke: #1a7f4b; } .arc-pending { stroke: #e0a100; } .arc-remaining { stroke: var(--border); }
.doughnut-value { fill: var(--foreground); font-size: 24px; font-weight: 700; } .doughnut-caption { fill: var(--muted-foreground); font-size: 12px; }
.summary-side .small { margin: 0 0 var(--space-2); }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; }
.swatch-approved { background: #1a7f4b; } .swatch-pending { background: #e0a100; } .swatch-remaining { background: var(--border); border: 1px solid #c9c9c9; }
@media (max-width: 480px) { .summary-body { grid-template-columns: 1fr; justify-items: center; } .summary-side { width: 100%; } }
.summary-row, .summary-row dt, .summary-row dd { color: var(--foreground); }
.summary-row dt { font-weight: var(--weight-semibold); }

/* Allowances: two groups of money fields, edit controls in the heading. */
.allowance-panel .section-heading { align-items: flex-start; }
.allowance-actions { display: flex; gap: var(--space-2); margin: 0; }
.allowance-form { display: grid; gap: var(--space-4); max-width: none; margin-top: var(--space-4); }
.allowance-group { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--space-4); padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--secondary); }
.allowance-group-head h3 { margin: 0 0 2px; font-size: 1rem; } .allowance-group-head .small { margin: 0; }
.allowance-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-3); }
.money-field { display: grid; gap: 6px; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); }
.money-label { display: grid; gap: 0; } .money-label .small { margin: 0; }
.money-input { display: flex; align-items: center; gap: 0; }
.money-input i { display: grid; place-items: center; min-width: 40px; min-height: var(--size-control-md); border: 1px solid var(--ds-border); border-right: 0; border-radius: var(--ds-control-radius) 0 0 var(--ds-control-radius); background: var(--secondary); color: var(--muted-foreground); font-style: normal; font-weight: var(--weight-semibold); }
.money-input input { max-width: none !important; border-radius: 0 var(--ds-control-radius) var(--ds-control-radius) 0 !important; font-variant-numeric: tabular-nums; font-weight: var(--weight-semibold); }
.allowance-form.is-editing .money-field { border-color: var(--primary); }
.allowance-form.is-editing .money-input input { background-color: #fff; }
@media (max-width: 760px) { .allowance-group { grid-template-columns: 1fr; } .allowance-actions { width: 100%; } .allowance-actions button { flex: 1; } }

/* Account rows: role pill, waiting-since note, and a compact "⋯" menu for secondary actions. */
.line-profile-name { display: grid; gap: 2px; }
.role-pill { justify-self: start; padding: 0 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--secondary); color: var(--muted-foreground); font-size: .72rem; font-weight: var(--weight-semibold); }
.role-pill.is-secretary { border-color: #e0c24a; background: #fdf6d6; color: #5c4a00; }
.profile-sub { font-weight: 400; }
.row-actions { display: flex; gap: 6px; align-items: center; }
.row-actions > button { flex: 1 1 auto; width: auto !important; margin: 0 !important; }
.row-menu { position: relative; }
.row-menu > summary { list-style: none; display: grid; place-items: center; width: var(--size-control-md); height: var(--size-control-md); border: 1px solid var(--border); border-radius: var(--ds-control-radius); background: var(--secondary); cursor: pointer; font-weight: 700; user-select: none; }
.row-menu > summary::-webkit-details-marker { display: none; }
.row-menu > summary:hover { background: var(--accent); }
.row-menu-list { position: absolute; z-index: 30; right: 0; top: calc(100% + 4px); display: grid; gap: 4px; min-width: 170px; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); box-shadow: var(--shadow-md); }
.row-menu-list button { width: 100%; justify-content: flex-start; text-align: left; margin: 0 !important; }
.manage-table th:last-child, .manage-table td:last-child, .pending-table th:last-child, .pending-table td:last-child { width: 170px; }
@media (min-width: 1100px), (max-width: 760px) { .table-scroll { overflow: visible; } }
.summary-rows .summary-row :is(dt, dd) { color: var(--foreground); }
.row-actions > button { white-space: nowrap; }
@media (max-width: 760px) { .row-actions { flex-wrap: wrap; width: 100%; } .row-actions > button { flex: 1 1 130px; min-width: 130px !important; } .row-actions > .row-menu { flex: 0 0 auto; } .row-actions > .row-menu > summary { min-width: 0; } .row-menu-list { right: auto; left: 0; } }

/* Account tables: one tidy rhythm. Cells align to the top, controls share one height, chips stay compact. */
.manage-table td, .pending-table td { vertical-align: middle; padding-top: 14px; padding-bottom: 14px; }
.manage-table th, .pending-table th { vertical-align: bottom; white-space: nowrap; }
.manage-table th:last-child, .manage-table td:last-child, .pending-table th:last-child, .pending-table td:last-child { width: 190px; }
.manage-table td:last-child, .pending-table td:last-child { white-space: nowrap; }
.row-actions > button:not(.row-menu button) { flex: 1 1 auto; min-width: 100px; }
.pending-table select, .manage-table select { width: 100%; min-width: 150px; }
.beneficiary-picker { display: grid; gap: 8px; min-width: 190px; }
.beneficiary-options > summary { display: flex; align-items: center; min-height: var(--size-control-md); padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--ds-control-radius); background: var(--card); font-size: .875rem; font-weight: var(--weight-semibold); line-height: 1.25; cursor: pointer; list-style: none; }
.beneficiary-options > summary::-webkit-details-marker { display: none; }
.beneficiary-options > summary::after { content: "▾"; margin-left: auto; padding-left: 8px; color: var(--muted-foreground); }
.selected-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.selected-chips .member-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 0; padding: 3px 4px 3px 10px; border-radius: var(--radius-md); font-size: .8rem; line-height: 1.3; }
.selected-chips .chip-remove { display: grid; place-items: center; width: 20px; min-width: 20px; height: 20px; min-height: 20px; padding: 0; border-radius: 50%; line-height: 1; }
.manage-table .education-control, .manage-table td .switch-label { white-space: nowrap; }
.manage-table td select[aria-label*="ducation"], .manage-table td:nth-child(5) select { min-width: 140px; }
@media (max-width: 760px) { .manage-table td:last-child, .pending-table td:last-child { white-space: normal; width: auto; } .beneficiary-picker { min-width: 0; } }
@media (min-width: 761px) { .pending-table, .manage-table { min-width: 0; width: 100%; } }
.pending-table td:last-child .row-actions > button:first-child { min-width: 120px; }
@media (min-width: 761px) { .table-scroll .pending-table.admin-table, .table-scroll .manage-table.admin-table { min-width: 0; } }
.pending-table td:last-child .row-actions > button:first-child { white-space: nowrap; padding-left: 12px; padding-right: 12px; }
.pending-table th:last-child, .pending-table td:last-child { width: 210px; }

/* CMS shell: dark-ink top bar, fixed left navigation, content column with a page header. */
@media (min-width: 1024px) {
  body { background: var(--secondary); }
  .topbar { padding-left: max(24px, calc((100vw - 1440px) / 2 + 24px)); padding-right: max(24px, calc((100vw - 1440px) / 2 + 24px)); position: sticky; top: 0; z-index: 40; background: var(--foreground); color: var(--background); border-bottom: 0; }
  .topbar .brand, .topbar .brand span { color: var(--background); }
  .topbar .brandmark { background: var(--primary); color: var(--primary-foreground); }
  .topbar button.secondary { background: transparent; color: var(--background); border-color: rgba(255,255,255,.35); }
  .topbar button.secondary:hover { background: rgba(255,255,255,.12); }
  .admin-page { display: grid; grid-template-columns: 220px minmax(0, 1fr); column-gap: 28px; align-items: start; max-width: 1440px; margin: 0 auto; padding: 24px 24px 48px; }
  .admin-page > * { grid-column: 2; min-width: 0; }
  .admin-page > .admin-tabs { grid-column: 1; grid-row: 1 / span 12; position: sticky; top: 76px; display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); }
  .admin-tabs::before { content: "Manage"; padding: 4px 12px 8px; color: var(--muted-foreground); font-size: .72rem; font-weight: var(--weight-semibold); letter-spacing: .08em; text-transform: uppercase; }
  .admin-tabs [role=tab] { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 8px 12px; border: 0; border-left: 3px solid transparent; border-radius: var(--radius-md); background: transparent; text-align: left; }
  .admin-tabs [role=tab]::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--border); }
  .admin-tabs [role=tab]:hover { background: var(--secondary); color: var(--foreground); }
  .admin-tabs [role=tab][aria-selected=true] { background: var(--secondary); border-left-color: var(--primary); border-bottom-color: transparent; color: var(--foreground); }
  .admin-tabs [role=tab][aria-selected=true]::before { background: var(--primary); }
  .admin-banner { margin: 0 0 20px; padding: 0 0 16px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: transparent; box-shadow: none; }
  .admin-banner h1 { font-size: 1.5rem; }
  .admin-banner .period-panel { margin-top: 16px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); }
  .admin-section.panel, .tab-panel > .panel { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); box-shadow: var(--shadow-sm, none); }
  .section-heading { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
}
.role-pill.is-active { border-color: #1a7f4b; background: #e6f4ec; color: #14613a; }
.years-table td { vertical-align: middle; }
.years-table .year-link { margin-right: 12px; font-weight: var(--weight-semibold); }
.years-table th:last-child, .years-table td:last-child { width: 220px; }
@media (min-width: 761px) { .table-scroll .years-table.admin-table { min-width: 0; } }
.admin-form .checkbox-row { display: flex; align-items: center; gap: 10px; min-height: var(--size-control-md); }
.admin-form .checkbox-row input[type=checkbox] { width: 20px !important; height: 20px !important; min-height: 20px !important; flex: 0 0 20px; padding: 0; accent-color: var(--primary); }

/* Benefit dialog: English/Thai side by side, plus the question builder. */
.benefit-dialog{width:min(760px,calc(100vw - 32px))}
.bilingual[hidden]{display:none}
.bilingual{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.bilingual textarea{width:100%;resize:vertical}
.limits-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}
.field-builder{display:grid;gap:12px;border-top:1px solid var(--border,#d9dee5);padding-top:12px}
.field-list{display:grid;gap:12px}
.field-row{display:grid;gap:10px;padding:12px;border:1px solid var(--border,#d9dee5);border-radius:10px;background:var(--surface-2,#f7f8fa)}
.field-row-head{display:flex;flex-wrap:wrap;align-items:center;gap:12px}
.field-row-head select{min-width:150px}
.field-row-actions{display:flex;gap:6px;margin-left:auto}
.field-row .icon-button{min-width:40px;padding-inline:0}
@media (max-width:640px){.bilingual,.limits-grid{grid-template-columns:1fr}}

.choice-builder{display:grid;gap:8px}
.choice-builder[hidden]{display:none}
.choice-title{margin:0;font-weight:750}
.choice-list{display:grid;gap:8px}
.choice-row{display:grid;grid-template-columns:1fr 1fr auto;gap:8px;align-items:center}
.choice-row input{width:100%}
.choice-builder>button{justify-self:start}
@media (max-width:640px){.choice-row{grid-template-columns:1fr auto}.choice-row input:nth-child(2){grid-column:1}}

.field-system{display:grid;gap:4px;padding:12px;border:1px dashed var(--border,#d9dee5);border-radius:10px}
.field-system p{margin:0}

/* Sheets tab: one row per family-tab column. */
.heading-actions{display:flex;flex-wrap:wrap;gap:8px}
.column-list{display:flex;gap:0;overflow-x:auto;padding-bottom:12px;margin-bottom:12px;border:1px solid var(--line,#d8dde4);border-radius:10px;background:var(--surface,#fff)}
.sheet-col{display:grid;align-content:start;gap:8px;flex:0 0 190px;padding:8px;border-right:1px solid var(--line,#d8dde4);position:relative;background:var(--surface,#fff)}
.sheet-col:last-child{border-right:0}
.sheet-col input,.sheet-col select{width:100%;min-width:0}
.sheet-col-top{display:flex;align-items:center;gap:4px;background:var(--surface-2,#f1f3f6);border-radius:6px;padding:2px 4px}
.sheet-col-handle{cursor:grab;padding:8px 6px;color:var(--muted,#667);letter-spacing:-3px;font-weight:700;user-select:none;touch-action:none}
.sheet-col-letter{flex:1;text-align:center;font-weight:750}
.sheet-col-top .icon-button{min-width:32px;min-height:32px;padding:0}
.sheet-col-header{font-weight:650}
.sheet-col.dragging{opacity:.45}
.sheet-col.drop-before::before,.sheet-col.drop-after::after{content:"";position:absolute;top:0;bottom:0;width:3px;background:var(--accent,#2563eb)}
.sheet-col.drop-before::before{left:-2px}.sheet-col.drop-after::after{right:-2px}
.sheet-col-app{flex:0 0 150px;background:var(--surface-2,#f1f3f6);opacity:.8}
.sheet-col-note{margin-top:4px}


.sheet-columns-box{margin-top:16px}
.sheet-columns-box>summary{cursor:pointer;font-weight:600;min-height:44px;display:flex;align-items:center;gap:8px}
.sheet-columns-box[open]>summary{margin-bottom:12px}

/* Mobile: stack label above value so controls get full card width */
@media (max-width: 760px) {
  .admin-table tbody td { grid-template-columns: minmax(0, 1fr); gap: 6px; align-items: start; }
  .admin-table tbody td select, .admin-table tbody td input:not([type=checkbox]) { min-width: 0; width: 100%; }
  .admin-table tbody td .beneficiary-options, .admin-table tbody td .beneficiary-options > summary { width: 100%; }
  .admin-table tbody td .beneficiary-options > summary { white-space: normal; }
  .admin-table tbody td button, .admin-table tbody td summary { min-height: 44px; }
  .admin-tabs { overflow-x: auto; scrollbar-width: none; }
  .admin-tabs [role=tab] { min-height: 44px; white-space: nowrap; }
  .beneficiary-choice-list { max-width: calc(100vw - 24px); }
  .beneficiary-choice { min-height: 44px; }
}
@media (max-width: 760px) {
  .brand { min-height: 44px; }
  .claim-filters select, .claim-filter-bar select, .filter-select-chip select { min-height: 44px; }
  .add-person-button, .chip-remove { min-height: 44px; min-width: 44px; }
  .chip-remove { width: 44px; height: 44px; margin: -10px -12px -10px 0; }
  .row-menu-list { max-width: calc(100vw - 48px); }
  .row-menu-list button { min-height: 44px; white-space: normal; }
}
@media (max-width: 760px) {
  .admin-table tbody tr { grid-template-columns: minmax(0, 1fr); }
  .admin-table tbody td { width: auto !important; justify-self: stretch; min-width: 0; }
}
@media (max-width: 760px) {
  .education-control { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .education-control select { flex: 1 1 160px; min-width: 0; }
}
