/* ============================================================
   PermitOne — ระบบใบอนุญาตก่อสร้าง (แบบ อ.๑)
   Theme: "ตราครามประทับบนใบอนุญาตกระดาษราชการ"
   หมึกคราม (indigo) · กระดาษอุ่น (warm paper) · ตราทองเหลือง (brass)
   Impeccable: OKLCH, tinted neutrals, committed palette
   ============================================================ */

:root {
  /* ---- พื้น/ผิว (warm paper, ink-tinted neutrals) ---- */
  --paper:      oklch(0.975 0.008 90);   /* พื้นหลังหน้า */
  --surface:    oklch(1 0 0);            /* การ์ด */
  --surface-2:  oklch(0.985 0.006 90);   /* แถบ/อ่อน */
  --border:     oklch(0.905 0.010 90);
  --border-2:   oklch(0.855 0.012 90);

  /* ---- ตัวอักษร (indigo-charcoal) ---- */
  --ink:        oklch(0.275 0.025 265);
  --ink-muted:  oklch(0.500 0.020 265);
  --ink-faint:  oklch(0.640 0.018 265);

  /* ---- หมึกคราม (primary) ---- */
  --primary:    oklch(0.460 0.120 264);
  --primary-600:oklch(0.405 0.120 264);
  --primary-700:oklch(0.345 0.110 264);
  --primary-tint: oklch(0.955 0.020 264);

  /* ---- ตราทองเหลือง (accent/seal) ---- */
  --brass:      oklch(0.700 0.110 75);
  --brass-ink:  oklch(0.470 0.090 70);

  /* ---- สถานะ ---- */
  --success:    oklch(0.585 0.130 150);
  --warning:    oklch(0.760 0.130 75);
  --danger:     oklch(0.560 0.180 25);
  --info:       oklch(0.600 0.090 230);

  /* ---- sidebar (drenched: หมึกครามเข้ม) ---- */
  --side-bg:     oklch(0.300 0.045 265);
  --side-bg-2:   oklch(0.265 0.045 265);
  --side-ink:    oklch(0.940 0.012 265);
  --side-muted:  oklch(0.720 0.025 265);
  --side-active: oklch(0.380 0.060 265);

  /* ---- โครง ---- */
  --side-w: 260px;
  --top-h: 60px;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px oklch(0.30 0.04 265 / 0.06), 0 4px 16px oklch(0.30 0.04 265 / 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.text-muted-2 { color: var(--ink-muted); }
.num { font-variant-numeric: tabular-nums; }

/* ============================================================
   APP SHELL  — sidebar/topbar = fixed, content = margin-left + padding-top
   ⚠️ ห้าม display:flex บน wrapper + width:100% (กัน content ซ้อนใต้ sidebar)
   ============================================================ */
.app-sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--side-w); height: 100vh;
  background: linear-gradient(180deg, var(--side-bg), var(--side-bg-2));
  color: var(--side-ink);
  display: flex; flex-direction: column;
  z-index: 1030;
  overflow-y: auto;
}

.app-topbar {
  position: fixed; top: 0; left: var(--side-w); right: 0;
  height: var(--top-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.25rem;
  z-index: 1020;
}

.app-content {
  margin-left: var(--side-w);
  padding-top: var(--top-h);
  min-height: 100vh;
  box-sizing: border-box;
  /* ไม่กำหนด width:100% โดยเด็ดขาด */
}
.app-content > .page {
  padding: 1.75rem 1.75rem 3rem;
}

/* ---- แบรนด์ในไซด์บาร์ (signature: ตราประทับ) ---- */
.brand {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 1.1rem 1.15rem;
  border-bottom: 1px solid oklch(1 0 0 / 0.08);
}
.brand .seal {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 50%;
  border: 2px solid var(--brass);
  display: grid; place-items: center;
  color: var(--brass);
  font-weight: 800; font-size: 13px;
  background: oklch(1 0 0 / 0.04);
}
.brand .brand-logo {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 50%; object-fit: contain;
  border: 2px solid var(--brass);
  background: #fff; padding: 2px;
}
.brand .name { font-weight: 800; font-size: 1.02rem; line-height: 1.15; color: #fff; }
.brand .eyebrow {
  font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--brass);
}

/* ---- เมนู ---- */
.side-nav { padding: 0.6rem 0.6rem; flex: 1; }
.side-section {
  font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--side-muted); padding: 0.9rem 0.65rem 0.35rem;
}
.side-link {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.6rem 0.7rem; margin: 0.1rem 0;
  border-radius: var(--radius-sm);
  color: var(--side-ink); text-decoration: none;
  font-size: 0.94rem;
  position: relative;
  transition: background 0.12s ease;
}
.side-link:hover { background: oklch(1 0 0 / 0.06); color: #fff; }
.side-link.active { background: var(--side-active); color: #fff; }
.side-link.active::before {
  content: ""; position: absolute; left: -0.6rem; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; border-radius: 0 3px 3px 0; background: var(--brass);
}
.side-link .ico { width: 18px; text-align: center; opacity: 0.85; }
.side-link.is-soon { opacity: 0.45; cursor: default; }
.side-link.is-soon:hover { background: transparent; }
.side-foot {
  padding: 0.85rem 1.15rem; font-size: 0.74rem; color: var(--side-muted);
  border-top: 1px solid oklch(1 0 0 / 0.08);
}

/* ---- topbar ---- */
.top-title { font-weight: 700; font-size: 1.05rem; }
.top-spacer { flex: 1; }
.top-user { display: flex; align-items: center; gap: 0.6rem; }
.top-user .who { text-align: right; line-height: 1.15; }
.top-user .who small { color: var(--ink-muted); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-tint); color: var(--primary-700);
  display: grid; place-items: center; font-weight: 700;
}

/* ---- toggle (mobile) ---- */
.side-toggle {
  display: none; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); width: 40px; height: 40px;
  color: var(--ink); font-size: 1.1rem;
}

/* ============================================================
   COMPONENTS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card .card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  font-weight: 700; padding: 0.9rem 1.15rem;
}
.card .card-body { padding: 1.15rem; }

/* page header */
.page-head { margin-bottom: 1.4rem; }
.page-head .eyebrow {
  font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--brass-ink); font-weight: 700;
}
.page-head h1 { font-size: 1.5rem; margin: 0.2rem 0 0.25rem; }
.page-head p { color: var(--ink-muted); margin: 0; }

/* ปุ่ม override Bootstrap */
.btn { border-radius: var(--radius-sm); font-weight: 600; }
.btn-primary {
  background: var(--primary); border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--primary-600); border-color: var(--primary-600);
}
.btn-outline-primary { color: var(--primary-700); border-color: var(--border-2); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }

/* badge สถานะ */
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.18rem 0.6rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--ink-muted);
}
.chip.is-build { color: var(--primary-700); background: var(--primary-tint); border-color: transparent; }

/* document panel (signature look) */
.doc-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    repeating-linear-gradient(180deg, transparent 0 38px, var(--border) 38px 39px) padding-box;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.doc-panel .doc-strip {
  height: 6px;
  background: linear-gradient(90deg, var(--primary-700), var(--primary), var(--brass));
}
.doc-panel .doc-body { padding: 1.6rem 1.6rem; }
.doc-panel .doc-seal {
  width: 60px; height: 60px; border-radius: 50%;
  border: 2.5px solid var(--brass); color: var(--brass-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 0.9rem;
  margin-bottom: 0.9rem;
}

/* steps list */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li {
  display: flex; gap: 0.8rem; padding: 0.55rem 0;
  border-bottom: 1px dashed var(--border);
}
.steps li:last-child { border-bottom: 0; }
.steps .k {
  flex: 0 0 1.7rem; height: 1.7rem; border-radius: 50%;
  background: var(--primary-tint); color: var(--primary-700);
  display: grid; place-items: center; font-weight: 700; font-size: 0.82rem;
}

/* ============================================================
   SCARD — stat cards (dashboard)
   ============================================================ */
.scard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 1.1rem;
  padding: 1.2rem 1.3rem;
  position: relative; overflow: hidden;
  transition: box-shadow 0.15s, transform 0.15s;
}
.scard::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; border-radius: var(--radius) 0 0 var(--radius);
}
.scard:hover { box-shadow: 0 6px 24px oklch(0.30 0.04 265 / 0.12); transform: translateY(-2px); }

.scard--blue::before  { background: var(--primary); }
.scard--green::before { background: var(--success); }
.scard--gold::before  { background: var(--brass); }
.scard--red::before   { background: var(--danger); }
.scard--gray::before  { background: var(--border-2); }

.scard-icon {
  flex: 0 0 48px; height: 48px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 1.35rem;
}
.scard--blue  .scard-icon { background: var(--primary-tint);      color: var(--primary-700); }
.scard--green .scard-icon { background: oklch(0.95 0.04 150);     color: var(--success); }
.scard--gold  .scard-icon { background: oklch(0.96 0.06 75);      color: var(--brass-ink); }
.scard--red   .scard-icon { background: oklch(0.96 0.05 25);      color: var(--danger); }
.scard--gray  .scard-icon { background: var(--surface-2);         color: var(--ink-faint); }

.scard-val {
  font-size: 1.8rem; font-weight: 800; line-height: 1;
  color: var(--ink); letter-spacing: -0.02em;
}
.scard-lbl { font-size: 0.86rem; font-weight: 600; color: var(--ink-muted); margin-top: 0.2rem; }
.scard-sub { font-size: 0.75rem; color: var(--ink-faint); margin-top: 0.1rem; }

/* ============================================================
   TASK ROW (dashboard ต้องดำเนินการ)
   ============================================================ */
.task-row {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.task-row:last-child { border-bottom: 0; }
.task-row--active      { background: oklch(0.987 0.008 264); }
.task-row--active-warn { background: oklch(0.990 0.010 75); }

.task-num {
  flex: 0 0 2.1rem; height: 2.1rem; border-radius: 50%;
  background: var(--surface-2); border: 1.5px solid var(--border-2);
  color: var(--ink-faint); font-weight: 700; font-size: 0.85rem;
  display: grid; place-items: center;
}
.task-num--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.task-num--warn   { background: var(--warning); border-color: var(--warning); color: oklch(0.28 0.06 75); }

.task-icon-wrap {
  flex: 0 0 1.5rem; color: var(--ink-faint); font-size: 1rem; text-align: center;
}
.task-title { font-weight: 600; font-size: 0.93rem; }
.task-desc  { font-size: 0.80rem; color: var(--ink-muted); }

/* badge pill */
.badge-pill {
  display: inline-flex; align-items: center;
  padding: 0.18rem 0.65rem; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700;
  white-space: nowrap;
}
.badge-pill--danger { background: oklch(0.96 0.05 25); color: var(--danger); border: 1px solid oklch(0.88 0.07 25); }
.badge-pill--warn   { background: oklch(0.96 0.06 75); color: oklch(0.42 0.10 70); border: 1px solid oklch(0.88 0.08 75); }

/* expire row */
.expire-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--ink);
  transition: background 0.12s;
}
.expire-row:last-child { border-bottom: 0; }
.expire-row:hover { background: var(--surface-2); }
.expire-no   { font-weight: 700; font-size: 0.88rem; width: 100%; }
.expire-name { font-size: 0.78rem; flex: 1; }

/* ============================================================
   RESPONSIVE — sidebar เป็น off-canvas, content margin-left = 0
   ============================================================ */
.side-backdrop { display: none; }

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  body.side-open .app-sidebar { transform: translateX(0); }
  .app-topbar { left: 0; }
  .app-content { margin-left: 0; }
  .side-toggle { display: inline-grid; place-items: center; }
  body.side-open .side-backdrop {
    display: block; position: fixed; inset: 0; z-index: 1025;
    background: oklch(0.20 0.04 265 / 0.4);
  }
}

/* a11y */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- nav tabs (master data) ---- */
.master-tabs { border-bottom: none; gap: 0.15rem; }
.master-tabs .nav-link {
  border: none; color: var(--ink-muted); font-weight: 600;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0; padding: 0.55rem 1rem;
}
.master-tabs .nav-link:hover { color: var(--primary-700); background: var(--surface-2); }
.master-tabs .nav-link.active {
  color: var(--primary-700); background: var(--surface);
  box-shadow: inset 0 -2px 0 var(--primary);
}
.table > :not(caption) > * > * { padding: 0.65rem 0.75rem; }
.table thead th { color: var(--ink-muted); font-weight: 600; font-size: 0.85rem;
  border-bottom: 1px solid var(--border-2); }
.table td { border-color: var(--border); }
code { color: var(--primary-700); background: var(--primary-tint);
  padding: 0.1rem 0.4rem; border-radius: 5px; font-size: 0.85em; }

/* ---- segmented radio (ลักษณะการขออนุญาต) ---- */
.seg { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span {
  display: inline-block; padding: 0.5rem 1.1rem; border-radius: 999px;
  border: 1px solid var(--border-2); color: var(--ink-muted);
  font-weight: 600; font-size: 0.92rem; transition: all 0.12s ease;
}
.seg input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.bldg-row { background: var(--surface-2); border-color: var(--border); }
.bldg-row .card-body { padding: 0.85rem 1rem; }
