/* ── Reset & variables ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1d6f42;
  --primary-dark: #155234;
  --primary-light: #d1fae5;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --warning: #92400e;
  --warning-bg: #fef3c7;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Thai', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
.page {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  background: var(--primary);
  color: white;
  padding: 1rem 1.25rem 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 50%;
  background: white;
  padding: 2px;
  flex-shrink: 0;
}

.page-header .subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-top: 0.15rem;
}

/* ── Portal header row (base_portal.html) — additive only, .page-header
   itself stays untouched since claim_form.html/success.html/error.html
   rely on it stacking h1+subtitle vertically. ────────────────────────────── */
.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.header-logout {
  color: white;
  opacity: 0.85;
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 0.35rem 0.7rem;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 6px;
}

.header-logout:hover {
  opacity: 1;
  background: rgba(255,255,255,0.15);
}

.page-content {
  flex: 1;
  padding: 1rem 1rem 2rem;
}

/* ── Card / sections ───────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.section {
  margin-bottom: 1rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
}

.conditional-block {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.75rem;
  margin-top: 0.5rem;
}

/* ── Login page ────────────────────────────────────────────────────────────── */
.login-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: var(--bg);
}

.login-logo {
  margin-bottom: 0.75rem;
}

.login-logo-img {
  width: 90px;
  height: 90px;
  object-fit: contain;
  border-radius: 50%;
  background: white;
  padding: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}

.page-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 50%;
  background: white;
  padding: 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.10);
  margin-bottom: 0.75rem;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.25rem;
  text-align: center;
}

.login-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
  text-align: center;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
}

/* ── Form elements ─────────────────────────────────────────────────────────── */
.field {
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.field select,
.field input[type="text"],
.field input[type="password"],
.field input[type="date"],
.field textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  appearance: auto;
  -webkit-appearance: auto;
  font-family: inherit;
}

.field textarea {
  resize: vertical;
}

.field input[type="file"] {
  width: 100%;
  padding: 0.6rem;
  font-size: 0.85rem;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
}

.field select:focus,
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

.field select:disabled {
  opacity: 0.6;
}

/* ── Combobox (searchable branch picker) ──────────────────────────────────── */
.combobox-field {
  position: relative;
}

.combobox-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  margin-top: 0.25rem;
  max-height: 240px;
  overflow-y: auto;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}

.combobox-option {
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.combobox-option:last-child {
  border-bottom: none;
}

.combobox-option:hover,
.combobox-option:active {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.combobox-option-other {
  font-weight: 600;
  color: var(--muted);
}

.combobox-option-hint {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: default;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.field-hint.field-hint-ok {
  color: var(--primary-dark);
}

/* ── Radio pills ───────────────────────────────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 0.6rem;
}

.radio-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.85rem 0.5rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.radio-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.radio-pill:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.85rem 1.5rem;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-success {
  background: var(--success);
  color: white;
  width: 100%;
}

/* Destructive actions (cancel a claim, correct a decision) -- 2026-09-23.
 * Deliberately NOT the same shape as .btn-primary: these are the two buttons
 * in the app that undo somebody else's work, and they should not be
 * click-alike with "save". */
.btn-danger {
  background: var(--danger);
  color: white;
  width: 100%;
}

.btn-danger:hover { background: #b91c1c; }

.section-danger {
  border: 1px solid #fecaca;
  background: var(--danger-bg);
}

.section-danger .section-title { color: var(--danger); }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.alert-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fca5a5;
}

.alert-success {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid #86efac;
}

/* ── Success / error pages ────────────────────────────────────────────────── */
.success-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
  background: var(--bg);
}

.success-icon {
  font-size: 5rem;
  margin-bottom: 1rem;
}

.success-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--success);
  margin-bottom: 0.5rem;
}

.success-sub {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 2rem;
}

/* The ticket number, shown on the one screen a branch is guaranteed to see.
   Deliberately the loudest thing on the page after the tick. */
.success-claim-no {
  border: 2px dashed var(--primary);
  border-radius: 12px;
  padding: 1rem 0.75rem;
  margin: 0 0 1.25rem;
  background: #f4fbf7;
}

.success-claim-no-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.success-claim-no-value {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.success-claim-no-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.5rem;
  line-height: 1.5;
}

/* ── Tracking link (2026-09-23) ──────────────────────────────────────────
 * The branch has no account and the claim carries no email or phone, so this
 * link is the only way they ever learn what happened. It is given the same
 * visual weight as the ticket number for that reason. */
.success-track {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 0.85rem;
  margin: 0 0 1.25rem;
  background: var(--card);
  text-align: left;
}

.success-track-label {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.success-track-url {
  width: 100%;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 0.6rem;
}

.success-track-copy {
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
}

.success-track-hint {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.55;
  margin-top: 0.6rem;
}

.success-track-open {
  margin-top: 0.6rem;
  font-size: 0.9rem;
}

.success-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
}

.error-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
}

.error-detail {
  background: var(--danger-bg);
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--danger);
  margin: 1rem 0 1.5rem;
  text-align: left;
  word-break: break-all;
  max-width: 400px;
}

/* ── Internal remarks (case notes) — identical across qc/purchasing/admin
   claim detail pages, so this lives in the shared stylesheet rather than
   being duplicated per portal.css. ────────────────────────────────────────── */
.remark-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.remark-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.remark-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.remark-text {
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.remark-empty {
  color: var(--muted);
  text-align: center;
  padding: 1rem 0;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.remark-form textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  margin-bottom: 0.6rem;
}

.remark-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

/* Inline image thumbnails for attachments (2026-08-26) -- images render
   directly via the /media proxy; click still opens full size. Non-image
   files keep their portal's existing chip/link styling. */
.attach-thumb-link {
  display: inline-block;
  margin: 0.25rem 0.5rem 0.25rem 0;
}

.attach-thumb {
  display: block;
  max-width: 180px;
  max-height: 180px;
  border-radius: 8px;
  border: 1px solid #d8d8d8;
  background: #fafafa;
}

/* ── Desktop layout for portal pages (2026-08-26) ─────────────────────────
   The app is mobile-first (fixed 480px column, no media queries) -- below
   1024px NOTHING here applies, so phones render exactly as before. The
   .page-portal class exists only on base_portal.html's shell; the open
   branch claim form (claim_form.html, bare .page) deliberately keeps its
   phone-width column on desktop too. */
@media (min-width: 1024px) {
  .page-portal {
    max-width: 1100px;
  }

  .page-portal .page-content {
    padding: 1.5rem 2rem 3rem;
  }

  /* Wide inputs are bad UX -- cap forms (report form, remark boxes,
     supplier/password forms) at a readable column even inside wide cards. */
  .page-portal .card form {
    max-width: 640px;
  }
}

/* Intake-channel link boxes (_intake_link.html, 2026-08-26) */
.intake-link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.intake-link-label {
  flex: 0 0 90px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
}

.intake-link-url {
  flex: 1 1 260px;
  min-width: 0;
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

/* Per-claim stage timeline (_timeline.html, 2026-08-26) */
.tl-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 1rem;
  border-left: 2px solid var(--border);
}

.tl-item {
  position: relative;
  padding: 0 0 1rem 0.9rem;
}

.tl-item:last-child { padding-bottom: 0; }

.tl-item::before {
  content: "";
  position: absolute;
  left: -1.42rem;
  top: 0.35rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--card);
}

.tl-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}

.tl-when {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.tl-gap {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}

.tl-summary {
  font-size: 0.9rem;
  margin-top: 0.15rem;
  word-break: break-word;
}

.tl-actor {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

/* รายงานผลการทวนสอบ (PDF) download box -- shared partial
   templates/_report_pdf_link.html, used on the QC/จัดซื้อ/admin claim pages. */
.report-pdf-box {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.report-pdf-title {
  font-weight: 600;
  color: var(--primary);
}
.report-pdf-btn {
  width: auto;
  display: inline-flex;
  align-self: flex-start;
  white-space: nowrap;
}
@media (min-width: 700px) {
  .report-pdf-box {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .report-pdf-btn { align-self: center; }
}

/* ── เลขที่ใบเคลม -- the ticket number staff quote to each other, to a
   branch, and to a supplier (2026-08-27). Monospace and non-wrapping so the
   fixed-width PREFIX+YYMMDD-NNN shape stays scannable in a column and a
   mistyped digit is visible; tabular-nums keeps the date and sequence
   digits aligned down a list. Lives in the shared stylesheet rather than a
   per-portal one because every portal shows it. */
.claim-no {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--primary);
}

/* Prominent form: the identity line at the top of a claim detail page. */
.claim-no-lead {
  display: inline-block;
  margin-bottom: 0.35rem;
  font-size: 1.05rem;
}

/* Quiet form: inside a list row, where the item name is the headline and
   the number is the reference you read back. */
.claim-no-chip {
  font-size: 0.78rem;
  opacity: 0.85;
}
