:root {
  --navy: #0f2d49;
  --navy-2: #14395c;
  --gold: #d7a73b;
  --gold-soft: #fff4d8;
  --ink: #102a43;
  --muted: #637083;
  --line: #d9e3ee;
  --bg: #f5f8fb;
  --white: #ffffff;
  --danger: #bd2a21;
  --ok: #1f7a4c;
  --shadow: 0 16px 36px rgba(15, 45, 73, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Sarabun", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff 0, var(--bg) 260px);
}

button, input, select, textarea { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 22px rgba(15, 45, 73, .06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  color: var(--navy);
  text-decoration: none;
}

.brand img {
  width: 54px;
  height: 54px;
  object-fit: contain;
}

.brand strong {
  display: block;
  font-size: clamp(20px, 2vw, 28px);
  line-height: 1.15;
}

.brand small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 16px;
}

.nav-actions, .toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn, .tab {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 18px;
  min-height: 44px;
  background: var(--white);
  color: var(--navy);
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.btn:hover, .tab:hover, .icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(15, 45, 73, .10);
}

.btn.navy, .tab.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
}

.btn.gold {
  background: var(--gold-soft);
  border-color: #e4bd63;
  color: var(--navy);
}

.page {
  width: min(1880px, calc(100% - 64px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.hero {
  padding: 30px 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0;
}

.hero h1 {
  margin: 0;
  color: var(--navy);
  font-size: clamp(34px, 4.4vw, 60px);
  line-height: 1.08;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 18px;
  margin: 26px 0;
}

.stat {
  min-height: 124px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.stat span { color: var(--muted); font-size: 21px; }
.stat strong { display: block; margin-top: 16px; color: var(--navy); font-size: 42px; line-height: 1; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.tab { font-size: 22px; }

.toolbar {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.toolbar input {
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
}

.panel {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th, td {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #edf4fa;
  color: var(--navy);
  font-size: 19px;
  white-space: nowrap;
}

td { font-size: 18px; }
.muted { color: var(--muted); }

tr:last-child td { border-bottom: 0; }

.empty {
  padding: 36px;
  color: var(--muted);
  font-size: 20px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #edf4fa;
  color: var(--navy);
  font-weight: 800;
  white-space: nowrap;
}

.badge.ok { background: #e8f6ef; color: var(--ok); }
.badge.warn { background: var(--gold-soft); color: #8b6108; }
.badge.off { background: #f5e8e5; color: var(--danger); }

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row-actions .btn {
  min-height: 36px;
  padding: 8px 12px;
}

.log-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 18px;
  margin: 0 0 24px;
}

.log-form {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.log-form h2 {
  margin: 0 0 18px;
  color: var(--navy);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--navy);
  font-weight: 800;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--ink);
  background: var(--white);
}

dialog {
  width: min(940px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(15, 45, 73, .28);
}

dialog::backdrop { background: rgba(15, 45, 73, .44); }

.dialog-card { padding: 24px; }

.dialog-head, .dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.dialog-head h2 {
  margin: 0;
  color: var(--navy);
  font-size: 28px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--navy);
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 22px 0;
}

.form-grid .wide { grid-column: 1 / -1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  transform: translateX(-50%);
  max-width: min(720px, calc(100% - 32px));
  padding: 16px 22px;
  border-radius: 8px;
  background: var(--navy);
  color: var(--white);
  font-size: 18px;
  box-shadow: 0 18px 40px rgba(15, 45, 73, .24);
}

.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

@media (max-width: 980px) {
  .topbar, .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-actions, .toolbar-actions { width: 100%; }
  .nav-actions .btn, .toolbar-actions .btn { flex: 1; text-align: center; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .log-layout, .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .brand img { width: 46px; height: 46px; }
  .page { width: min(100% - 28px, 1880px); padding-top: 18px; }
  .hero { padding: 24px; }
  .hero p:last-child { font-size: 19px; }
  .stats { grid-template-columns: 1fr; }
  .tab, .btn { width: 100%; }
}
