:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #657182;
  --line: #dfe5ed;
  --primary: #1f7a8c;
  --primary-dark: #15596a;
  --success: #287a4b;
  --warning: #a86c15;
  --danger: #b43d3d;
  --sidebar: #16323d;
  --shadow: 0 12px 34px rgba(24, 33, 47, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Tahoma, "Noto Sans Thai", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  background: #fff;
}
textarea { resize: vertical; }
label span {
  display: block;
  margin-bottom: 5px;
  color: #3d4857;
  font-size: 12px;
  font-weight: 800;
}
small { display: block; color: var(--muted); font-size: 12px; }
code { overflow-wrap: anywhere; }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 14px;
  color: #eef8f9;
  background: var(--sidebar);
}
.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 8px 18px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.brand-mark {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
}
.sidebar-brand strong { display: block; }
.sidebar-brand small { color: #a9c4ca; }
.nav-group { margin: 14px 0 18px; }
.nav-group p {
  margin: 0 0 6px;
  padding: 0 8px;
  color: #a9c4ca;
  font-size: 12px;
  font-weight: 900;
}
.nav-group a {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
}
.nav-group a:hover, .nav-group a.active { background: rgba(255,255,255,.12); }
.nav-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #76c7c0;
  flex: 0 0 auto;
}
.nav-dot.danger { background: #e48f8f; }
.main-shell { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 66px;
  padding: 14px 24px;
  background: rgba(244, 246, 248, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.topbar strong { display: block; font-size: 18px; }
.topbar span { color: var(--muted); font-size: 12px; }
.content { padding: 24px; }

.page-head, .form-title, .panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-head h1, .form-title h1 { margin: 0; font-size: 28px; }
.page-head p, .form-title p { margin: 4px 0 0; color: var(--muted); }
.panel {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel h2, .panel h3 { margin: 0 0 14px; }
.panel h2 { font-size: 18px; }
.panel h3 { margin-top: 18px; color: var(--primary-dark); font-size: 15px; }
.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  align-items: start;
}
.side-panel {
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 104px);
  overflow-y: auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric span { color: var(--muted); font-weight: 800; font-size: 12px; }
.metric strong { display: block; margin-top: 8px; font-size: 25px; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table { width: 100%; min-width: 780px; border-collapse: collapse; background: #fff; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #edf3f6; color: #455264; font-size: 12px; white-space: nowrap; }
td strong { display: block; }
tr:last-child td { border-bottom: 0; }
.empty { padding: 28px; color: var(--muted); text-align: center; }
.overdue-row { background: #fff8f8; }
.danger-text { color: var(--danger); font-weight: 800; }

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  color: #fff;
  background: var(--badge, #657182);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.button, .mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
}
.button { min-height: 40px; padding: 9px 14px; }
.mini-button { min-height: 30px; padding: 5px 9px; color: var(--primary-dark); background: #e5f2f4; }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary, .button.ghost { color: var(--primary-dark); background: #e5f2f4; }
.button.full { width: 100%; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.inline-form select { min-width: 120px; min-height: 32px; padding: 5px 8px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 30, 42, .38);
}
.modal-backdrop[hidden] { display: none; }
.status-modal {
  width: min(100%, 460px);
  max-height: min(720px, calc(100vh - 36px));
  overflow-y: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(18, 30, 42, .22);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.modal-head h2 {
  margin: 0;
  font-size: 20px;
}
.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
}
.modal-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  color: #334155;
  background: #edf3f6;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
.status-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.status-choice {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: #223044;
  background: #fff;
  cursor: pointer;
  font-weight: 900;
  text-align: left;
}
.status-choice span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--choice, #657182);
  flex: 0 0 auto;
}
.status-choice.active {
  border-color: var(--choice, var(--primary));
  background: #f2f8f9;
  box-shadow: inset 0 0 0 1px var(--choice, var(--primary));
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.stack-form { display: grid; gap: 12px; }
.form-grid { display: grid; gap: 10px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.size-grid { display: grid; grid-template-columns: repeat(8, minmax(72px, 1fr)); gap: 8px; }
.filter-bar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 180px 200px auto;
  gap: 10px;
  margin-bottom: 16px;
}
.check-row { display: flex; align-items: center; gap: 9px; }
.check-row input { width: auto; min-height: auto; }
.check-row span { margin: 0; }
.alert {
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: 8px;
  font-weight: 800;
}
.alert-success { color: #145233; background: #dff3e8; border: 1px solid #b8e0c8; }
.alert-danger { color: #7c2020; background: #f8dddd; border: 1px solid #ecc1c1; }

.login-page, .install-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eaf4f6, #f8f5ef);
}
.login-panel, .install-panel {
  width: min(100%, 540px);
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-panel { text-align: center; }
.login-panel .brand-mark { margin-bottom: 14px; }
.login-panel h1, .install-panel h1 { margin: 0; font-size: 24px; }
.login-panel p, .install-panel p { margin: 6px 0 18px; color: var(--muted); }
.install-shell { width: min(100%, 720px); }
.install-panel { width: 100%; }
.install-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.install-db, .ready-box {
  display: grid;
  gap: 6px;
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f8fb;
}
.sub-link { display: inline-block; margin-top: 14px; color: var(--primary-dark); font-weight: 800; }

.detail-grid dl {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px 14px;
  margin: 0;
}
.detail-grid dt { color: var(--muted); font-weight: 800; }
.detail-grid dd { margin: 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eef3f6;
  font-weight: 800;
}
.timeline { display: grid; gap: 10px; }
.timeline-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}
.timeline-item p { margin: 4px 0; color: #344153; }
.calendar-sort { display: flex; flex-wrap: wrap; gap: 8px; }
.calendar-sort .active { color: #fff; background: var(--primary); }
.calendar-board { display: grid; gap: 12px; }
.calendar-board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 900;
}
.calendar-list { display: grid; gap: 8px; }
.calendar-item {
  display: grid;
  grid-template-columns: 38px 48px minmax(0, 1fr) 190px auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.calendar-item.dragging { opacity: .55; border-color: var(--primary); }
.calendar-item.drag-over { box-shadow: inset 0 0 0 2px var(--primary); }
.drag-handle {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f4f7f9;
  cursor: grab;
  font-weight: 900;
}
.drag-handle:active { cursor: grabbing; }
.queue-rank {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  font-weight: 900;
}
.calendar-main { min-width: 0; }
.calendar-main strong,
.calendar-main span,
.calendar-meta span { display: block; }
.calendar-main span,
.calendar-meta { color: var(--muted); font-size: 12px; }
.calendar-meta { display: grid; gap: 2px; }
.notification-list { display: grid; gap: 8px; }
.notification {
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.notification.unread { border-color: var(--primary); background: #f0f8f9; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.settings-panel { max-width: 980px; }

.print-sheet {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.print-head, .print-meta {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 2px solid #1d2b3a;
}
.print-head h1, .print-head h2 { margin: 0 0 8px; }
.print-head > div:last-child, .print-meta > div:last-child { text-align: right; }
.print-table { min-width: 100%; }
.print-note { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .nav-group { display: inline-block; min-width: 190px; vertical-align: top; }
  .split-layout, .report-grid { grid-template-columns: 1fr; }
  .side-panel { position: relative; top: auto; max-height: none; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .content, .topbar { padding: 14px; }
  .topbar, .page-head, .form-title, .panel-head, .print-head, .print-meta { flex-direction: column; align-items: flex-start; }
  .metric-grid, .form-grid.two, .form-grid.three, .form-grid.four, .filter-bar, .calendar-item { grid-template-columns: 1fr; }
  .size-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid dl { grid-template-columns: 1fr; }
  .inline-form { align-items: stretch; flex-direction: column; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { background: #fff; color: #111827; font-size: 12px; }
  .sidebar, .topbar, .print-hidden, .alert { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; }
  .print-sheet {
    width: 190mm;
    max-width: 190mm;
    margin: 0 auto;
    padding: 8mm;
    border: 0;
    box-shadow: none;
    border-radius: 0;
  }
  .print-head,
  .print-meta {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    justify-content: space-between !important;
    gap: 18mm;
  }
  .print-head > div:last-child,
  .print-meta > div:last-child {
    text-align: right;
    min-width: 45mm;
  }
  .print-head h1 { font-size: 24px; }
  .print-head h2 { font-size: 18px; }
  .print-table { min-width: 100%; width: 100%; }
  .chip { background: #eef3f6 !important; }
}
