/* Style A tokens — see docs/UI-GUIDELINES.md */
:root {
  --ink: #16202E;
  --quiet: #4A5565;
  --accent: #0F6B4F;
  --accent-dark: #0A4F3A;
  --accent-tint: #E7F2EE;
  --copied: #1F5FA8;
  --copied-tint: #EAF1FA;
  --line: #D5DAE1;
  --input-line: #A9B1BD;
  --ground: #F6F7F9;
  --error: #B42318;
  --error-tint: #FDECEA;
  --warning: #B25E00;
  --radius: 8px;
  --font: "IBM Plex Sans Thai", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--ground); }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

/* Buttons */
.btn { height: 44px; padding: 0 20px; font: inherit; font-size: 15px; font-weight: 600; border-radius: var(--radius); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn-primary { color: #fff; background: var(--accent); border: none; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-secondary { color: var(--accent); background: #fff; border: 1px solid var(--accent); }
.btn-neutral { color: var(--ink); background: #fff; border: 1px solid var(--input-line); }
.btn-neutral:hover { background: var(--ground); color: var(--ink); }
.btn-plain { height: 36px; padding: 0 14px; font: inherit; font-size: 14px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 15px; font-weight: 500; }
.field input { height: 44px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--ink); border: 1px solid var(--input-line); border-radius: var(--radius); background: #fff; }
.field input:focus { outline: none; border: 2px solid var(--accent); box-shadow: 0 0 0 3px #CFE6DC; }
.hint { margin: 0; font-size: 13px; color: var(--quiet); }
.alert-error { margin: 0; font-size: 14px; color: var(--error); background: var(--error-tint); border-radius: var(--radius); padding: 10px 12px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 48px 20px; }
.login-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 40px 36px; display: flex; flex-direction: column; gap: 20px; }
.logo { width: 44px; height: 44px; border-radius: 10px; background: var(--accent); display: flex; align-items: center; justify-content: center; }
.login-card h1 { margin: 12px 0 0; font-size: 26px; font-weight: 700; }
.login-card .sub { margin: 0; font-size: 15px; color: var(--quiet); }

/* App shell (header + tabs) */
.topbar { background: #fff; border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.topbar-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 8px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 17px; }
.brand .logo { width: 32px; height: 32px; border-radius: 8px; }
.userbar { display: flex; align-items: center; gap: 16px; font-size: 15px; color: var(--quiet); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: -1px; }
.tab { min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--quiet); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; }
.tab[aria-current="page"] { font-weight: 600; color: var(--ink); border-bottom-color: var(--accent); }
.page { max-width: 1200px; margin: 0 auto; padding: 28px 24px 64px; display: flex; flex-direction: column; gap: 16px; }
.page h1 { margin: 0; font-size: 28px; font-weight: 700; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.visually-hidden, .control-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Tab badge: how many cases have this document in the current generation */
.badge { min-width: 22px; height: 22px; padding: 0 7px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; line-height: 1; color: var(--quiet); background: var(--ground); border: 1px solid var(--line); border-radius: 11px; }
.tab[aria-current="page"] .badge { color: var(--accent-dark); background: var(--accent-tint); border-color: transparent; }

/* ชุดเอกสาร list */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.btn:disabled { color: var(--quiet); border-color: var(--line); background: var(--ground); cursor: not-allowed; }
.quiet { color: var(--quiet); font-size: 14px; }
.nowrap { white-space: nowrap; }

.field select, .field input[type="search"], .field input[type="text"], .field input[type="date"] { width: 100%; height: 44px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--ink); border: 1px solid var(--input-line); border-radius: var(--radius); background: #fff; }
.field select:focus, .field input[type="search"]:focus, .field input[type="text"]:focus, .field input[type="date"]:focus { outline: none; border: 2px solid var(--accent); box-shadow: 0 0 0 3px #CFE6DC; }
.field .label { font-size: 15px; font-weight: 500; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--quiet); pointer-events: none; }
/* Must be as specific as the .field input[type="search"] rule above, or its padding wins and the icon covers the text */
.field .input-icon input[type="search"], .field .input-icon input[type="text"] { padding-left: 40px; }
.field select:disabled, .field input:disabled { color: var(--quiet); background: var(--ground); cursor: not-allowed; }
.date-range { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.field .date-range select { flex: 0 0 140px; width: 140px; }
/* the selector and the two dates share a row; each date has a basis so they wrap only on a phone */
.field .date-range input[type="date"] { flex: 1 1 130px; width: auto; }
.date-range input { min-width: 0; }

/* The filter bar: search, generation, visit type, the panel button and the count */
.filters { display: flex; flex-direction: column; gap: 12px; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.filter-bar .search { flex: 1 1 260px; }
.filter-bar .gen { flex: 0 0 auto; }
.filter-bar .gen select { width: auto; min-width: 112px; }
.result-count { margin-left: auto; font-size: 14px; color: var(--quiet); white-space: nowrap; }
.result-count b { font-weight: 600; color: var(--ink); }
/* Without JavaScript this is the only way to send the bar. Stage 5 hides it when filters go live. */
.filters-submit { height: 44px; }

/* The visit-type switch: real radios, hidden; the label is the segment */
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.seg { display: inline-flex; padding: 4px; gap: 2px; background: #E8EBEF; border-radius: 10px; }
.seg-item { position: relative; cursor: pointer; }
.seg-item span { display: block; height: 36px; padding: 0 16px; line-height: 36px; font-size: 15px; color: var(--quiet); border-radius: 8px; white-space: nowrap; }
.seg-item input:checked + span { color: var(--ink); font-weight: 600; background: #fff; box-shadow: 0 1px 3px rgba(22, 32, 46, 0.18); }
.seg-item input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* "ตัวกรองเพิ่มเติม": the button is the <summary> of #more-filters; the panel is the next element
   and is shown while it is open. :has() is all it takes, so no JavaScript. Where :has() does not
   exist the panel is simply always shown. */
.more { display: inline-flex; }
.more-btn { list-style: none; display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px; font-size: 15px; font-weight: 500; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; white-space: nowrap; user-select: none; }
.more-btn::-webkit-details-marker { display: none; }
.more-btn:hover { border-color: var(--input-line); }
.more-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.more-btn.is-active { padding: 0 15px; color: var(--accent-dark); border: 2px solid var(--accent); }
.more-badge { min-width: 22px; height: 22px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; line-height: 1; color: #fff; background: var(--accent); border-radius: 11px; }
.more-panel { display: none; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.filters:has(#more-filters[open]) .more-panel { display: block; }
@supports not selector(:has(*)) { .more-panel { display: block; } }
.more-grid { display: grid; grid-template-columns: 1fr; gap: 20px 24px; }
@media (min-width: 800px) {
  .more-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .more-wide, .more-sort { grid-column: span 2; }
}
.more-field legend, .more-grid .field > label { padding: 0; font-size: 15px; font-weight: 500; }
.more-field legend { margin-bottom: 6px; }
.more-field .hint { margin-top: 6px; }

/* The company box: a text box with suggestions under it, or the picked company with a ×. */
.co-field { position: relative; }
.co-field .hint { margin: 6px 0 0; }
.co-search { position: relative; }
.co-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40; max-height: 360px; overflow-y: auto; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(22, 32, 46, 0.16); }
.co-option { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 40px; padding: 6px 12px; font: inherit; font-size: 15px; color: var(--ink); text-align: left; background: none; border: 0; border-radius: 6px; cursor: pointer; }
.co-option:hover, .co-option.is-active { background: var(--ground); }
.co-option.is-active { outline: 2px solid var(--accent); outline-offset: -2px; }
.co-option .co-name { min-width: 0; overflow-wrap: anywhere; }
.co-option .quiet { flex: none; font-size: 13px; }
.co-empty { margin: 0; padding: 10px 12px; font-size: 14px; color: var(--quiet); }
.co-picked { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 6px 0 14px; background: var(--accent-tint); border: 2px solid var(--accent); border-radius: var(--radius); }
.co-picked[hidden], .co-search[hidden], .co-list[hidden] { display: none; }
.co-picked-name { flex: 1; min-width: 0; overflow: hidden; font-size: 15px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.co-clear { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; font-size: 22px; line-height: 1; color: var(--accent-dark); text-decoration: none; border-radius: 6px; }
.co-clear:hover { background: #fff; color: var(--accent-dark); }
.co-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.more-grid .field-dates { gap: 0; }
.more-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.more-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; }

/* Branch tiles and status pills: real checkboxes / radios, hidden; the label is the control */
.tiles { display: flex; gap: 12px; }
.tile { position: relative; flex: 1 1 0; cursor: pointer; }
.tile-box { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px; font-size: 15px; font-weight: 600; background: #fff; border: 1px solid var(--input-line); border-radius: var(--radius); }
.tile-check { width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; color: transparent; background: #fff; border: 1.5px solid var(--input-line); border-radius: 4px; }
.tile input:checked + .tile-box { padding: 0 13px; background: var(--accent-tint); border: 2px solid var(--accent); }
.tile input:checked + .tile-box .tile-check { color: #fff; background: var(--accent); border-color: var(--accent); }
.tile input:focus-visible + .tile-box, .pill-radio input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.pill-radios { display: flex; flex-wrap: wrap; gap: 8px; }
.pill-radio { position: relative; cursor: pointer; }
.pill-radio span { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; font-size: 15px; background: #fff; border: 1px solid var(--input-line); border-radius: 20px; }
.pill-radio span::before { content: ""; width: 16px; height: 16px; border: 1.5px solid var(--input-line); border-radius: 50%; background: #fff; }
.pill-radio input:checked + span { color: var(--accent-dark); font-weight: 600; background: var(--accent-tint); border-color: var(--accent); }
.pill-radio input:checked + span::before { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px #fff; }

.table-card { padding: 0; overflow: hidden; }
/* position: relative keeps the visually-hidden header label (absolute) inside the scroll box */
.table-wrap { position: relative; overflow-x: auto; }
.cases-table { width: 100%; min-width: 960px; border-collapse: collapse; font-size: 15px; }
.cases-table th { text-align: left; font-size: 14px; font-weight: 600; color: var(--quiet); white-space: nowrap; background: var(--ground); }
.sort-marker { margin-left: 2px; font-size: 13px; color: var(--accent); font-weight: 700; }
.cases-table th, .cases-table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.cases-table tbody tr:last-child td { border-bottom: none; }
.cases-table tbody tr:hover { background: #FAFBFC; }
.cases-table td .quiet { margin-top: 2px; }
.dash { color: #A9B1BD; }
.open-link { font-weight: 600; text-decoration: underline; }

/* The type pill; its colours are inline (documents/requirements.py has them) */
.type-pill { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 12px; font-size: 13px; font-weight: 600; line-height: 1; text-decoration: none; white-space: nowrap; border-radius: 13px; }
a.type-pill:hover { filter: brightness(0.96); }
a.type-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pill-caret { display: inline-flex; margin-right: -4px; }

.dots { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; line-height: 1; color: var(--quiet); border-radius: 50%; background: #fff; border: 1.5px dashed var(--input-line); }
.dot-on { color: #fff; background: var(--accent); border: 1.5px solid var(--accent); }
.dot-sm { width: 20px; height: 20px; font-size: 12px; }
.dot-lg { width: 32px; height: 32px; font-size: 16px; }
.dots-gap { width: 6px; }
.dots-count { margin-left: 6px; font-size: 14px; color: var(--quiet); }

.table-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; padding: 12px 16px; border-top: 1px solid var(--line); }
.table-footer-end { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px 16px; margin-left: auto; }
/* The symbol legend: a bar above the table (cases/_legend.html) */
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 10px 16px; font-size: 13px; color: var(--quiet); background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.legend-title { font-weight: 600; color: var(--ink); }
.legend-group { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-num { font-weight: 600; color: var(--ink); }
.legend-sep { width: 1px; height: 20px; background: var(--line); }
@media (max-width: 899px) { .legend-sep { display: none; } }
.type-pill-sm { height: auto; padding: 1px 8px; font-size: 12px; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.page-link { min-width: 36px; height: 36px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; color: var(--ink); text-decoration: none; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
a.page-link:hover { border-color: var(--accent); color: var(--accent-dark); }
.page-link.current { color: #fff; font-weight: 600; background: var(--accent); border-color: var(--accent); }
.page-link.disabled { color: #8A93A0; background: var(--ground); }
.page-gap { padding: 0 4px; color: var(--quiet); }

/* Results */
[hidden] { display: none !important; }
#cases-page { display: flex; flex-direction: column; gap: 16px; }
#cases-results { display: flex; flex-direction: column; gap: 16px; }
#cases-results.htmx-request { opacity: 0.6; transition: opacity 150ms; }

/* Row selection */
.select-col { width: 44px; padding-right: 0 !important; }
.select-col input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
.selection-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 16px; background: var(--accent-tint); border: 1px solid #BFDCD0; border-radius: var(--radius); }
.selection-count { font-size: 15px; font-weight: 600; color: var(--accent-dark); }
.selection-bar .btn { height: 36px; margin-left: auto; }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 48px 24px; text-align: center; }
.empty-state p { margin: 0; font-size: 18px; font-weight: 600; }
.empty-state .placeholder-note { font-size: 15px; font-weight: 400; color: var(--quiet); }

/* Loading dialog (static/js/loading.js opens it when a request takes more than a moment) */
.loading-dialog { margin: auto; padding: 0; border: 0; background: transparent; }
.loading-dialog::backdrop { background: rgba(22, 32, 46, 0.35); }
.loading-card { display: flex; align-items: center; gap: 14px; padding: 20px 28px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgba(22, 32, 46, 0.2); }
.loading-card p { margin: 0; font-size: 16px; font-weight: 600; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--accent-tint); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* Live filters: the search button stays for the keyboard (it shows when focused) and as the way
   to send the bar without JavaScript */
.js .filters-submit { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.js .filters-submit:focus { position: static; width: auto; height: 44px; margin: 0; padding: 0 20px; overflow: visible; clip: auto; border: 1px solid var(--accent); }
.hint:empty { display: none; }

/* The type menu: a <details> on the pill. Without JavaScript its panel opens under the pill (out of the flow); with it,
   the panel is fixed and cases_list.js puts it under the pill (the table scrolls and would clip it). */
.type-menu { position: relative; display: inline-block; }
summary.type-pill { list-style: none; cursor: pointer; user-select: none; }
summary.type-pill::-webkit-details-marker { display: none; }
summary.type-pill:hover { filter: brightness(0.96); }
summary.type-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.type-menu-panel { position: absolute; top: 100%; left: 0; z-index: 30; min-width: 210px; margin-top: 4px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(22, 32, 46, 0.16); }
.js .type-menu-panel { position: fixed; margin-top: 0; }
.type-menu-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; font-size: 15px; color: var(--ink); text-decoration: none; white-space: nowrap; border-radius: 6px; }
.type-menu-item:hover, .type-menu-item:focus-visible { color: var(--ink); background: var(--ground); outline: none; }
.menu-dot { width: 10px; height: 10px; border-radius: 50%; }

/* Modal dialog (change to Hybrid, messages) and the same card as a page */
dialog.modal { width: calc(100% - 32px); max-width: 460px; padding: 0; margin: auto; color: var(--ink); background: #fff; border: 0; border-radius: 16px; box-shadow: 0 20px 50px rgba(22, 32, 46, 0.3); }
dialog.modal::backdrop { background: rgba(22, 32, 46, 0.45); }
.modal-card { display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.modal-card h1, .modal-card h2 { margin: 0; font-size: 22px; font-weight: 700; }
.modal-card h3 { margin: 8px 0 0; font-size: 15px; font-weight: 600; }
.modal-card p { margin: 0; }
.modal-student { font-size: 16px; }
.modal-types { display: flex; align-items: center; gap: 10px; }
.modal-arrow { color: var(--quiet); }
.added-docs { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.added-docs li { display: flex; align-items: center; gap: 12px; font-size: 16px; }
.modal-note { padding: 12px 14px; font-size: 14px; color: #8A4500; background: #FEF3E2; border-radius: var(--radius); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; margin-top: 8px; }
.page-card { max-width: 460px; padding: 0; }


/* New case page (cases/new.html). The case form's pieces: type cards, branch tiles, errors. */
.new-case { width: 100%; max-width: 880px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.new-case h1 { margin: 0; }
.new-case .sub { margin: 4px 0 0; font-size: 15px; color: var(--quiet); }
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; color: var(--quiet); }
.breadcrumb a { color: var(--quiet); }
.breadcrumb a:hover { color: var(--accent-dark); }
.new-case-form { display: flex; flex-direction: column; gap: 16px; }
.new-case .card > legend, .new-case .card > h2 { padding: 0; margin: 0 0 16px; font-size: 18px; font-weight: 600; }
/* A legend sits on the fieldset's border by default; floating it puts it inside the card's padding */
.new-case fieldset.card > legend { float: left; width: 100%; }
.new-case fieldset.card > legend + * { clear: both; }
.req { color: var(--error); }
.note { margin: 16px 0 0; font-size: 13px; color: var(--quiet); }
.new-case .card > .hint { margin-top: 12px; }

.type-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 639px) { .type-cards { grid-template-columns: 1fr; } }
.type-card { display: flex; flex-direction: column; gap: 10px; padding: 16px; background: #fff; border: 1px solid var(--input-line); border-radius: 12px; cursor: pointer; }
.type-card:hover { border-color: var(--quiet); }
.type-card:has(input:checked) { padding: 15px; background: #F3F9F6; border: 2px solid var(--accent); }
.type-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.type-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.type-card-top input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.type-card-desc { font-size: 14px; color: var(--quiet); }
.type-card-docs { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.doc-line { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.type-cards.has-error .type-card { border-color: var(--error); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 24px; }
@media (max-width: 639px) { .form-grid { grid-template-columns: 1fr; } }
.field legend { padding: 0; margin-bottom: 6px; font-size: 15px; font-weight: 500; }
.new-case fieldset.field { gap: 0; }
.field select { background: #fff; }
.branch-tiles { display: flex; gap: 12px; }
.branch-tile { position: relative; flex: 1 1 0; cursor: pointer; }
.branch-tile input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.branch-box { display: flex; flex-direction: column; justify-content: center; min-height: 44px; padding: 6px 14px; background: #fff; border: 1px solid var(--input-line); border-radius: var(--radius); }
.branch-box strong { font-size: 15px; }
.branch-box .quiet { font-size: 13px; }
.branch-tile input:checked + .branch-box { padding: 5px 13px; background: var(--accent-tint); border: 2px solid var(--accent); }
.branch-tile input:focus-visible + .branch-box { outline: 2px solid var(--accent); outline-offset: 2px; }

.has-error input, .has-error select { border: 2px solid var(--error); }
.has-error .branch-box { border-color: var(--error); }
.field-error { margin: 6px 0 0; font-size: 13px; color: var(--error); }
.field-error a { color: var(--error); font-weight: 600; }
.error-summary { padding: 14px 18px; color: var(--error); background: var(--error-tint); border: 1px solid #F0B8B2; border-radius: var(--radius); }
.error-summary h2 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.error-summary ul { margin: 0; padding-left: 20px; font-size: 14px; }
.error-summary a { color: var(--error); }

.form-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px 24px; }
.btn-link { font-size: 15px; font-weight: 500; color: var(--quiet); }

/* Document form page (documents/form.html): cards from the YAML sections, a 12-column grid. */
.doc-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin-bottom: 16px; }
.doc-page .card-head h2, .case-page .card-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.tag { padding: 2px 10px; font-size: 12px; color: var(--quiet); background: var(--ground); border: 1px solid var(--line); border-radius: 999px; }
.case-summary { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 40px; }
.case-name { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 16px; }
.case-student .quiet { margin: 4px 0 0; }
.case-facts { display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 0; }
.case-facts dt { font-size: 13px; color: var(--quiet); }
.case-facts dd { margin: 2px 0 0; font-size: 15px; font-weight: 500; }
.case-edit { margin-left: auto; font-size: 14px; font-weight: 500; }
.doc-page .note { margin-top: 12px; }

.doc-form { display: flex; flex-direction: column; gap: 16px; }
.doc-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px 24px; align-items: start; }
.doc-field, .doc-group, .addable { grid-column: span var(--span, 12); min-width: 0; }
@media (max-width: 639px) { .doc-field, .doc-group, .addable { grid-column: 1 / -1; } }
.doc-field .label { font-size: 15px; font-weight: 500; }
.doc-field input, .doc-field select { width: 100%; min-width: 0; }
.doc-field select { height: 44px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--ink); background: #fff; border: 1px solid var(--input-line); border-radius: var(--radius); }
.doc-field input.num { text-align: right; }
.doc-field input.derived { color: var(--ink); background: #EEF0F3; border-color: var(--line); }
.doc-field input.derived:focus { box-shadow: none; border: 1px solid var(--line); }
.affix { display: flex; align-items: stretch; }
.affix-text { display: inline-flex; align-items: center; padding: 0 12px; font-size: 16px; color: var(--quiet); background: var(--ground); border: 1px solid var(--input-line); border-right: 0; border-radius: var(--radius) 0 0 var(--radius); white-space: nowrap; }
.affix input { border-radius: 0 var(--radius) var(--radius) 0; }
.doc-group { padding: 4px 16px 16px; border: 1px solid var(--line); border-radius: 12px; }
.doc-group legend { padding: 0 8px; font-size: 15px; font-weight: 600; }
.addable { padding: 10px 16px; border: 1px dashed var(--accent); border-radius: 12px; }
.addable summary { cursor: pointer; font-size: 15px; font-weight: 500; color: var(--accent); }
.addable[open] summary { margin-bottom: 16px; }
.topics { display: flex; flex-direction: column; gap: 16px; }
.fixed-text { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; font-size: 16px; background: #EEF0F3; border: 1px solid var(--line); border-radius: var(--radius); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.fixed-text svg { flex: none; }

/* Document form, live parts: the two-column layout, the amber reminders, the orange "too long" state. */
.js-only { display: none; }
.js .js-only { display: inline; }
.doc-page { max-width: 1200px; }
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.doc-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.doc-side { position: sticky; top: 16px; }
@media (max-width: 1023px) { .doc-layout { grid-template-columns: 1fr; } .doc-side { position: static; } }
.summary-card h2 { margin: 0 0 12px; font-size: 18px; font-weight: 600; }
.summary-list { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.summary-list > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.summary-list dt { font-size: 14px; color: var(--quiet); }
.summary-list dd { margin: 0; font-size: 15px; text-align: right; }
.summary-list dd.strong { font-weight: 700; }
.pill { display: inline-block; padding: 2px 10px; font-size: 13px; font-weight: 600; border-radius: 999px; }
.pill-amber { color: #6B4700; background: #FFF1C2; border: 1px solid #A87400; }
.pill-green { color: #17603A; background: #DDF3E4; border: 1px solid #8CCBA3; }

.banner-box { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 12px 16px; color: #6B4700; background: #FFF8E1; border: 1px solid #A87400; border-radius: var(--radius); }
.banner-title { font-weight: 600; }
.banner-links { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.banner-links a { color: #6B4700; font-weight: 500; }
.banner-note { margin-left: auto; font-size: 13px; }

/* A required field left empty: an amber border and fill, and the hint says so. Not the red error. */
.doc-field:has(.hint.is-missing) input,
.doc-field:has(.hint.is-missing) select,
.doc-field:has(.hint.is-missing) .affix-text { background: #FFF8E1; border-color: #A87400; }
.hint.is-missing { color: #6B4700; }
.hint:empty { display: none; }
/* Text too long for its slot on the PDF: orange, separate from both. */
.has-overflow input, .has-overflow select { border: 2px solid var(--warning); background: #FEF3E2; }
.field-overflow { margin: 6px 0 0; font-size: 13px; font-weight: 500; color: #8A4500; }
.overflow-box { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px 18px; color: #8A4500; background: #FEF3E2; border: 1px solid var(--warning); border-radius: var(--radius); }
.overflow-box h2 { margin: 0; font-size: 16px; font-weight: 600; }
.overflow-box ul { margin: 0; padding-left: 20px; font-size: 14px; }
.overflow-box a { color: #8A4500; }
.overflow-box p { margin: 0; font-size: 14px; }

.label-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.label-row label { font-size: 15px; font-weight: 500; }
.reset-link { font-size: 13px; }

/* Optional rows added one by one (with JavaScript; without it they sit in a <details>). */
.doc-field[hidden] { display: none; }
.addable-row, .doc-field { position: relative; }
.row-remove { position: absolute; top: -2px; right: 0; width: 28px; height: 28px; padding: 0; font-size: 20px; line-height: 1; color: var(--quiet); background: none; border: 0; border-radius: 6px; cursor: pointer; }
.row-remove:hover { color: var(--error); background: var(--error-tint); }
.row-remove[hidden] { display: none; }
.add-row { grid-column: 1 / -1; justify-self: start; min-height: 40px; padding: 0 16px; font: inherit; font-size: 15px; font-weight: 500; color: var(--accent); background: #fff; border: 1px dashed var(--accent); border-radius: 12px; cursor: pointer; }
.add-row:hover { background: var(--accent-tint); }
.add-row[hidden] { display: none; }

/* One-time messages after a redirect, and the save dialog's list. */
.flash { padding: 12px 16px; font-size: 15px; border-radius: var(--radius); }
.flash-ok { color: #17603A; background: #DDF3E4; border: 1px solid #8CCBA3; }
.flash-warn { color: #6B4700; background: #FFF8E1; border: 1px solid #A87400; }
.flash-error { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--error); background: var(--error-tint); border: 1px solid var(--error); }
.flash-close { flex: none; width: 32px; height: 32px; padding: 0; font: inherit; font-size: 22px; line-height: 1; color: var(--error); background: none; border: 0; border-radius: 6px; cursor: pointer; }
.flash-close:hover { background: #fff; }
/* Fixed, so an error bar is seen wherever the page is scrolled and never moves the form. */
.flash-region { position: fixed; top: 12px; left: 50%; z-index: 1000; width: min(640px, calc(100% - 32px)); transform: translateX(-50%); }
.flash-region:empty { display: none; }
/* The 500 page. */
.error-card { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; }
.error-card p, .login-card .ref-line { margin: 0; }
.ref-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ref-label { font-size: 14px; color: var(--quiet); }
.ref-chip { padding: 2px 10px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 15px; color: var(--ink); background: var(--ground); border: 1px solid var(--line); border-radius: 6px; }
.error-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.confirm-list { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.confirm-list > div { display: flex; justify-content: space-between; gap: 16px; }
.confirm-list dt { font-size: 14px; color: var(--quiet); }
.confirm-list dd { margin: 0; font-size: 15px; text-align: right; }
.modal-card .banner-box, .modal-card .overflow-box { font-size: 14px; }
.confirm-page { max-width: 520px; margin: 0 auto; padding: 0; }
.modal-card .overflow-box h3 { margin: 0; font-size: 15px; }
.modal-card .banner-box p, .modal-card .overflow-box p { margin: 4px 0 0; }
.modal-actions button { min-width: 120px; }

/* The Case page (cases/show.html): the header, a card per document, the history. */
.case-page { display: flex; flex-direction: column; gap: 24px; width: 100%; }
.case-page h1 { margin: 0; }
.case-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 16px; }
.case-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.case-page .sub { margin: 6px 0 0; font-size: 15px; color: var(--quiet); }
.case-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.case-actions .btn { height: 44px; }
.case-facts-row { display: flex; flex-wrap: wrap; gap: 12px 48px; margin: 0; }
.case-facts-row dt { font-size: 13px; color: var(--quiet); }
.case-facts-row dd { margin: 4px 0 0; font-size: 15px; font-weight: 600; }
.case-facts-row dd .quiet { font-weight: 400; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.group-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.slot-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1023px) { .slot-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 639px) { .slot-cards { grid-template-columns: 1fr; } }
.slot-card { display: flex; flex-direction: column; gap: 8px; padding: 20px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.slot-empty { border: 1px dashed var(--input-line); }
.slot-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.slot-card h3 { margin: 6px 0 0; font-size: 17px; font-weight: 600; }
.slot-note { margin: 0; font-size: 14px; }
.slot-none { font-size: 13px; color: var(--quiet); }
.slot-pill { display: inline-block; padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; border-radius: 999px; }
.slot-pill-green { color: #17603A; background: #E3F1EA; }
.slot-pill-amber { color: #6B4700; background: #FFF8E1; border: 1px solid #A87400; }
.slot-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 12px; }
.slot-actions .btn { height: 40px; padding: 0 16px; font-size: 14px; }
.history-card { padding: 0; }
.history-scroll { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.history-table th { padding: 14px 20px; font-size: 13px; font-weight: 400; color: var(--quiet); text-align: left; border-bottom: 1px solid var(--line); }
.history-table td { padding: 14px 20px; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.history-table tr:last-child td { border-bottom: 0; }
.latest-mark { margin-left: 4px; font-size: 12px; font-weight: 600; color: var(--accent); }
@media (max-width: 639px) { .history-table .nowrap { white-space: normal; } .history-table th, .history-table td { padding: 12px; } .history-table td a { overflow-wrap: anywhere; } }

/* The type of a case that has documents, shown read-only on the edit page. */
.type-fixed { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 14px 16px; background: var(--ground); border: 1px solid var(--line); border-radius: 12px; }
.type-fixed-docs { display: flex; flex-wrap: wrap; gap: 8px 20px; }

/* The UAT server's banner: above the header of every page when APP_ENV=uat. 32 px, one line. */
.uat-banner { box-sizing: border-box; height: 32px; padding: 0 16px; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; font-weight: 500; color: #6B4700; background: #FFF8E1; border-bottom: 1px solid #A87400; }
.uat-banner ~ .login-wrap { min-height: calc(100vh - 32px); }
