:root {
  --brand: #0b4f8a;
  --brand-2: #1478c8;
  --brand-soft: #e8f1fa;
  --bg: #f4f6f9;
  --sidebar-w: 240px;
}

body {
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: #1f2933;
}

.brand-bar { background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,.18);
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.brand-logo.sm { width: 32px; height: 32px; font-size: 1.05rem; border-radius: 9px; }
.brand-img { height: 60px; width: auto; max-width: 240px; object-fit: contain; border-radius: 10px; background: #fff; padding: 4px; }
.brand-img.sm { height: 40px; max-width: 180px; padding: 3px; } /* แถบหลังบ้านสูง 56px (sidebar อิงค่านี้) */
.brand-img.lg { height: 110px; max-width: 320px; background: transparent; padding: 0; }
/* มือถือ: ลดลงเล็กน้อยไม่ให้ชนปุ่มเมนู */
@media (max-width: 575.98px) {
  .brand-img { height: 48px; max-width: 170px; }
  .brand-img.sm { height: 38px; max-width: 130px; }
  .brand-img.lg { height: 90px; }
}
.brand-logo.lg { width: 56px; height: 56px; font-size: 1.6rem; }
.logo-preview { width: 180px; height: 110px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(#e9ecef 0% 25%, #fff 0% 50%) 50% / 16px 16px; border: 1px solid #dee2e6; }
.logo-preview img { max-width: 160px; max-height: 96px; object-fit: contain; }
.logo-preview .bi { background: var(--brand); border-radius: 12px; padding: 4px 12px; }
.brand-sub { font-size: .72rem; opacity: .8; font-weight: 400; line-height: 1; }

.card { border: 0; border-radius: 14px; box-shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: #fff; border-bottom: 1px solid #edf0f3; border-radius: 14px 14px 0 0 !important; font-weight: 600; }
.form-label { font-weight: 500; margin-bottom: .3rem; }
.form-label .req { color: #dc3545; }
.form-text { font-size: .8rem; }
.btn { border-radius: 9px; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: #093f6e; color: #fff; }

/* ---------- Public ---------- */
.public-body main { min-height: calc(100vh - 140px); }
.hero-box { background: #fff; border-radius: 16px; padding: 1.25rem 1.5rem; border-left: 5px solid var(--brand-2); }
.hp-field { position: absolute !important; left: -10000px !important; width: 1px; height: 1px; overflow: hidden; }
.code-box {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 1.35rem; letter-spacing: .08em;
  background: var(--brand-soft); border: 2px dashed var(--brand-2); border-radius: 12px; padding: .7rem 1rem; word-break: break-all;
}
.timeline { list-style: none; padding-left: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.6rem; border-left: 2px solid #dbe3ea; margin-left: .5rem; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: ''; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--brand-2); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--brand-2);
}
.timeline li.reporter::before { background: #fd7e14; box-shadow: 0 0 0 2px #fd7e14; }
.timeline li.internal::before { background: #6f42c1; box-shadow: 0 0 0 2px #6f42c1; }

.msg { border-radius: 12px; padding: .75rem 1rem; margin-bottom: .75rem; }
.msg.public { background: #eef6ff; border: 1px solid #d3e6fb; }
.msg.reporter { background: #fff5eb; border: 1px solid #fde1c2; }
.msg.internal { background: #f5f0ff; border: 1px dashed #b9a2e6; }
.msg .meta { font-size: .78rem; color: #6c757d; margin-bottom: .25rem; }
.msg .body { white-space: normal; word-wrap: break-word; }

.steps { display: flex; gap: 4px; flex-wrap: wrap; }
.steps .step { flex: 1 1 0; min-width: 70px; text-align: center; font-size: .72rem; padding: .35rem .2rem; border-radius: 8px; background: #e9ecef; color: #6c757d; }
.steps .step.done { background: #d1e7dd; color: #0f5132; }
.steps .step.current { background: var(--brand); color: #fff; font-weight: 600; }

.pre-wrap { white-space: pre-wrap; word-wrap: break-word; }
.field-box { background: #f8fafc; border: 1px solid #edf0f3; border-radius: 10px; padding: .6rem .8rem; max-height: 320px; overflow: auto; }

/* ---------- Admin ---------- */
.admin-wrap { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: var(--sidebar-w); background: #fff; border-right: 1px solid #e5e9ef; }
@media (min-width: 992px) {
  .sidebar { position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; flex-shrink: 0; }
}
.sidebar .nav-link { color: #344054; display: flex; align-items: center; gap: .6rem; padding: .55rem 1.1rem; margin: 1px .5rem; border-radius: 9px; }
.sidebar .nav-link i { font-size: 1.05rem; }
.sidebar .nav-link:hover { background: #f2f5f8; }
.sidebar .nav-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sidebar-section { font-size: .72rem; text-transform: uppercase; color: #98a2b3; padding: 1rem 1.3rem .3rem; letter-spacing: .05em; }
.admin-main { flex: 1; min-width: 0; padding: 1.25rem; }
@media (max-width: 575.98px) { .admin-main { padding: .75rem; } }

.stat-card { border-radius: 14px; padding: 1rem 1.1rem; background: #fff; height: 100%; display: flex; gap: .8rem; align-items: center; text-decoration: none; color: inherit; transition: transform .1s; box-shadow: 0 1px 3px rgba(16,24,40,.06); }
.stat-card:hover { transform: translateY(-2px); color: inherit; }
.stat-card .icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.35rem; flex-shrink: 0; }
.stat-card .num { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.stat-card .lbl { font-size: .8rem; color: #667085; }

.table > :not(caption) > * > * { vertical-align: middle; }
table.dataTable { width: 100% !important; }
.dataTables_wrapper .dataTables_filter input { border-radius: 8px; }
.ticket-no { font-family: ui-monospace, Consolas, monospace; font-weight: 600; white-space: nowrap; }
.overdue-row { background: #fff4f4 !important; }
.text-overdue { color: #dc3545; font-weight: 600; }
.chart-box { position: relative; height: 280px; }
.perm-grid label { font-weight: 400; }
.wf-table th, .wf-table td { text-align: center; }
.wf-table td:first-child, .wf-table th:first-child { text-align: left; white-space: nowrap; }
.nav-tabs .nav-link { color: #475467; }
.small-muted { font-size: .8rem; color: #667085; }

@media print {
  .sidebar, header.navbar, .no-print, footer { display: none !important; }
  .admin-main { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  body { background: #fff; }
}
