:root {
  color-scheme: light;
  --ink: #172640;
  --muted: #66758d;
  --line: #e2e9f3;
  --blue: #2c71d2;
  --teal: #149f9c;
  --surface: #fff;
  --shadow: 0 22px 60px rgba(20, 43, 80, .09);
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; background: #eef3fa; }
body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  font-family: 'Kanit', system-ui, sans-serif;
  font-weight: 400;
  line-height: 1.5;
  background:
    radial-gradient(circle at 0 0, rgba(68, 167, 211, .13), transparent 35rem),
    radial-gradient(circle at 100% 12%, rgba(49, 104, 195, .11), transparent 34rem),
    #eef3fa;
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.page-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
  padding: clamp(18px, 2vw, 40px) clamp(18px, 2.4vw, 52px);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: none;
  min-height: clamp(94px, 6vw, 112px);
  margin-bottom: clamp(12px, .9vw, 18px);
  padding: clamp(14px, 1vw, 20px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 20px;
  background:
    radial-gradient(circle at 85% 0, rgba(53, 183, 192, .23), transparent 29rem),
    linear-gradient(115deg, #172c4c, #203f67 68%, #1b5270);
  box-shadow: 0 22px 46px rgba(26, 52, 89, .16);
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-copy { min-width: 0; }
.brand-mark {
  width: clamp(50px, 2.8vw, 60px);
  height: clamp(50px, 2.8vw, 60px);
  flex: none;
  display: grid;
  place-items: center;
  color: #aaf5ed;
  border: 1px solid rgba(161, 244, 234, .3);
  border-radius: 16px;
  background: rgba(255, 255, 255, .1);
  box-shadow: inset 0 1px rgba(255, 255, 255, .12);
}
.brand-mark svg { width: 46%; height: 46%; }
.eyebrow {
  margin: 0;
  color: #9cf1e6;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: .11em;
}
h1 { margin: 0; font-size: clamp(25px, 2.1vw, 31px); font-weight: 600; line-height: 1.15; }
.header-subtitle { margin: 2px 0 0; color: rgba(255, 255, 255, .72); font-size: 12px; line-height: 1.3; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.admin-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 11px;
  color: #defcf6;
  border: 1px solid rgba(171, 247, 237, .22);
  border-radius: 10px;
  background: rgba(22, 162, 166, .14);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.admin-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #7be6d7; box-shadow: 0 0 0 4px rgba(123, 230, 215, .13); }
.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 15px;
  color: #29415f;
  border: 1px solid #dce5ef;
  border-radius: 12px;
  background: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .18s ease, border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.button:hover { border-color: #bfd2e7; background: #f8fbff; box-shadow: 0 7px 18px rgba(29, 55, 91, .08); transform: translateY(-1px); }
.button:active { transform: scale(.98); }
.button:disabled { opacity: .6; cursor: wait; transform: none; }
.button svg { width: 17px; height: 17px; flex: none; }
.button-primary { color: #fff; border-color: transparent; background: linear-gradient(110deg, #2b75d1, #169eaa); box-shadow: 0 8px 20px rgba(34, 131, 177, .18); }
.button-primary:hover { color: #fff; border-color: transparent; background: linear-gradient(110deg, #2167c3, #128d9d); }
.button-import { color: #197f83; border-color: #bfe6e4; background: #f0fbfa; }
.button-import:hover { color: #116f73; border-color: #84d2cf; background: #e7f8f7; }
.topbar .button { min-height: 36px; padding: 6px 12px; color: #fff; border-color: rgba(255, 255, 255, .23); border-radius: 10px; background: rgba(255, 255, 255, .08); font-size: 13px; }
.topbar .button svg { width: 16px; height: 16px; }
.topbar .button:hover { border-color: rgba(255, 255, 255, .43); background: rgba(255, 255, 255, .16); }
.topbar .close-window-button { width: 36px; min-width: 36px; padding: 6px; }
.topbar .close-window-button:hover { color: #ffd7dc; }

.data-card {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #dce5f0;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card-toolbar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: clamp(18px, 1.3vw, 26px) clamp(20px, 1.5vw, 32px);
  border-bottom: 1px solid var(--line);
}
.tabs { display: inline-flex; align-items: center; gap: 4px; padding: 4px; border: 1px solid #e3eaf3; border-radius: 14px; background: #f2f6fb; }
.tab { min-height: 40px; padding: 7px 18px; color: #63748d; border: 0; border-radius: 10px; background: transparent; font-size: 14px; font-weight: 500; white-space: nowrap; transition: color .18s ease, background .18s ease, box-shadow .18s ease; }
.tab:hover { color: #285788; }
.tab[aria-selected="true"] { color: #20588e; background: #fff; box-shadow: 0 2px 8px rgba(20, 44, 78, .1); }
.toolbar-tools { display: flex; align-items: center; justify-content: flex-end; gap: 10px; min-width: 0; }
.search-wrap { position: relative; width: clamp(220px, 22vw, 420px); min-width: 0; }
.search-wrap svg { position: absolute; top: 50%; left: 14px; width: 18px; height: 18px; color: #8798af; transform: translateY(-50%); pointer-events: none; }
.search-input { width: 100%; height: 44px; padding: 8px 13px 8px 42px; color: var(--ink); border: 1px solid #dbe5ef; border-radius: 12px; outline: none; background: #fbfcfe; font-size: 14px; transition: border-color .18s ease, box-shadow .18s ease; }
.search-input::placeholder { color: #92a1b4; }
.search-input:focus, .field input:focus, .field textarea:focus { border-color: #4f9dcc; box-shadow: 0 0 0 3px rgba(48, 135, 195, .14); }
.count { flex: none; padding: 13px clamp(20px, 1.5vw, 32px); color: #76869b; font-size: clamp(13px, .72vw, 15px); }
.table-scroll { flex: 1; min-height: 0; overflow: auto; }
table { width: 100%; min-width: 900px; border-collapse: separate; border-spacing: 0; }
th { position: sticky; top: 0; z-index: 1; padding: 12px clamp(15px, 1vw, 24px); color: #72829a; background: #f5f8fc; font-size: clamp(12px, .7vw, 14px); font-weight: 500; text-align: left; white-space: nowrap; }
th:last-child { text-align: right; }
td { padding: 14px clamp(15px, 1vw, 24px); color: #41536c; border-top: 1px solid #edf1f6; font-size: clamp(13px, .75vw, 16px); vertical-align: middle; overflow-wrap: anywhere; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #f7fbff; }
tbody tr:first-child td { border-top: 0; }
td:first-child { color: #5f718a; font-variant-numeric: tabular-nums; }
.cell-main { color: #1e3554; font-size: clamp(14px, .85vw, 18px); font-weight: 600; }
.cell-code { display: inline-block; min-width: 70px; padding: 4px 8px; color: #285c90; border: 1px solid #dceaf9; border-radius: 8px; background: #f2f8ff; font-size: 12px; text-align: center; }
.cell-department { display: inline-block; padding: 4px 9px; color: #24726e; border-radius: 8px; background: #eaf8f5; font-size: 12px; white-space: nowrap; }
.cell-coordinates { color: #526983; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-note { display: -webkit-box; max-width: 300px; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.4; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.row-action { min-height: clamp(34px, 2vw, 40px); padding: 5px 11px; color: #2c628e; border: 1px solid #dce7f2; border-radius: 9px; background: #fff; font-size: clamp(12px, .72vw, 14px); font-weight: 500; white-space: nowrap; }
.row-action:hover { border-color: #b7d0e8; background: #f3f9ff; }
.row-action.delete { color: #bf5662; }
.row-action.delete:hover { border-color: #edc6cb; background: #fff4f4; }
.empty-state, .loading-state { padding: 54px 20px; color: #8392a6; font-size: 14px; text-align: center; }
.empty-state strong { display: block; margin-bottom: 3px; color: #3c5270; font-size: 17px; font-weight: 600; }
.loading-state::before { content: ''; display: block; width: 28px; height: 28px; margin: 0 auto 12px; border: 3px solid #e0e9f3; border-top-color: #379ac1; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-gate { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(239, 245, 251, .87); backdrop-filter: blur(14px); }
.gate-card { width: min(420px, 100%); padding: 32px; border: 1px solid #dce6f1; border-radius: 24px; background: #fff; box-shadow: var(--shadow); text-align: center; }
.gate-icon { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 16px; color: #2a79bb; border-radius: 18px; background: #eaf5ff; }
.gate-icon svg { width: 28px; height: 28px; }
.gate-card h2 { margin: 0 0 5px; font-size: 22px; font-weight: 600; }
.gate-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

dialog { width: min(640px, calc(100% - 28px)); max-width: 640px; max-height: min(90vh, 850px); padding: 0; overflow: auto; color: var(--ink); border: 1px solid #dce5ef; border-radius: 22px; background: #fff; box-shadow: 0 28px 90px rgba(13, 33, 64, .27); }
dialog::backdrop { background: rgba(12, 27, 49, .52); backdrop-filter: blur(4px); }
.dialog-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 23px 26px 18px; border-bottom: 1px solid var(--line); background: #fff; }
.dialog-head h2 { margin: 0; font-size: 23px; font-weight: 600; line-height: 1.3; }
.dialog-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.icon-button { width: 38px; height: 38px; flex: none; display: grid; place-items: center; color: #667991; border: 0; border-radius: 11px; background: #f1f5fa; }
.icon-button:hover { background: #e9f0f7; }
.icon-button svg { width: 18px; height: 18px; }
.dialog-body { padding: 20px 26px 25px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; color: #52657d; font-size: 13px; font-weight: 500; }
.field.full { grid-column: 1 / -1; }
.field input, .field textarea { width: 100%; min-height: 44px; padding: 9px 12px; color: var(--ink); border: 1px solid #dce5ef; border-radius: 11px; outline: none; background: #fbfcfe; font-size: 15px; font-weight: 400; transition: border-color .18s ease, box-shadow .18s ease; }
.field textarea { min-height: 92px; resize: vertical; }
.field input:focus, .field textarea:focus { background: #fff; }
.record-meta { margin: 0 0 14px; color: #7c8ca1; font-size: 12px; }
.import-file-field input { padding: 10px; cursor: pointer; }
.import-file-field input::file-selector-button { margin-right: 12px; padding: 8px 11px; color: #216c86; border: 1px solid #cce5ed; border-radius: 8px; background: #eef9fc; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.import-help { margin: 10px 0 0; color: #78889b; font-size: 12px; line-height: 1.6; }
.import-error { margin: 14px 0 0; padding: 10px 13px; color: #a44350; border: 1px solid #f3cdd1; border-radius: 10px; background: #fff4f5; font-size: 13px; }
.import-preview { margin-top: 18px; padding: 16px; border: 1px solid #dbe9ed; border-radius: 14px; background: #f8fcfd; }
.import-preview-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; color: #244563; font-size: 14px; }
.import-preview-head strong { font-weight: 600; overflow-wrap: anywhere; }
.import-preview-head span { flex: none; color: #1d868b; font-weight: 600; }
.import-groups { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.import-group { display: inline-flex; align-items: center; gap: 7px; padding: 5px 9px; color: #2a6f75; border-radius: 9px; background: #e8f5f4; font-size: 12px; }
.import-group b { font-weight: 600; }
.import-changes { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 13px; }
.import-change { display: inline-flex; align-items: center; gap: 7px; padding: 5px 9px; color: #46617b; border: 1px solid #dce7ef; border-radius: 9px; background: #fff; font-size: 12px; }
.import-change b { font-weight: 600; }
.import-change.remove { color: #a64252; border-color: #f0cbd0; background: #fff4f5; }
.import-removals { margin-top: 15px; padding: 13px; border: 1px solid #f0cbd0; border-radius: 12px; background: #fff8f8; }
.import-removals h3 { display: flex; justify-content: space-between; gap: 10px; margin: 0; color: #a33f4e; font-size: 14px; font-weight: 600; }
.import-removals p { margin: 3px 0 9px; color: #a55b67; font-size: 12px; }
.import-removal-list { max-height: 180px; overflow: auto; border-top: 1px solid #f1d8dc; }
.import-removal-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid #f5e5e7; font-size: 12px; }
.import-removal-row:last-child { border-bottom: 0; }
.import-removal-row strong { color: #81434e; font-weight: 500; }
.import-removal-row span { flex: none; color: #af6f78; }
.import-sample-label { margin: 15px 0 5px; color: #8391a2; font-size: 11px; }
.import-sample { border-top: 1px solid #e1ebf0; }
.import-sample-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #e9f0f4; font-size: 12px; }
.import-sample-row:last-child { border-bottom: 0; padding-bottom: 0; }
.import-sample-row strong { color: #304e69; font-weight: 500; }
.import-sample-row span { color: #77899a; text-align: right; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.toast { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 20; max-width: min(420px, calc(100vw - 36px)); padding: 12px 17px; color: #fff; border-radius: 12px; background: #183957; box-shadow: 0 10px 30px rgba(12, 30, 55, .22); opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
:focus-visible { outline: 3px solid rgba(55, 150, 196, .55); outline-offset: 3px; }

@media (max-width: 1100px) {
  .topbar { align-items: center; }
  .top-actions { max-width: 365px; }
  .admin-chip { display: none; }
}

@media (max-width: 980px) {
  .page-shell { height: auto; min-height: 100svh; }
  .data-card { flex: none; min-height: auto; }
  .table-scroll { flex: none; min-height: auto; overflow: visible; }
  table { display: block; min-width: 0; }
  thead { display: none; }
  tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 4px 16px 18px; }
  tbody tr { display: block; min-width: 0; overflow: hidden; border: 1px solid #e1e9f2; border-radius: 16px; background: #fff; }
  tbody tr:hover { background: #fff; box-shadow: 0 7px 20px rgba(24, 58, 99, .07); }
  tbody td { display: grid; grid-template-columns: minmax(82px, 32%) minmax(0, 1fr); align-items: start; gap: 9px; padding: 8px 12px; border-top: 0; font-size: 13px; }
  tbody td:first-child { padding-top: 14px; }
  tbody td:last-child { padding-bottom: 13px; }
  tbody td::before { content: attr(data-label); color: #7d8ca0; font-size: 12px; }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  .cell-note { max-width: none; }
  tbody tr.state-row { grid-column: 1 / -1; }
  tbody tr.state-row td { display: block; padding: 0; }
  tbody tr.state-row td::before { display: none; }
}

@media (max-width: 760px) {
  .page-shell { padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 30px max(14px, env(safe-area-inset-left)); }
  .topbar { align-items: stretch; flex-direction: column; gap: 12px; min-height: 0; padding: 16px; border-radius: 18px; }
  .brand-mark { width: 48px; height: 48px; border-radius: 14px; }
  .brand-mark svg { width: 25px; height: 25px; }
  .top-actions { max-width: none; justify-content: flex-start; }
  .card-toolbar { align-items: stretch; flex-direction: column; padding: 16px; }
  .tabs { align-self: flex-start; }
  .toolbar-tools { justify-content: flex-start; }
  .search-wrap { width: auto; flex: 1; }
  .count { padding: 11px 16px; }
}

@media (max-width: 650px) {
  tbody { grid-template-columns: 1fr; }
  .data-card { border-radius: 19px; }
}

@media (max-width: 480px) {
  h1 { font-size: 25px; }
  .header-subtitle { font-size: 12px; }
  .topbar .button { flex: 1; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding-inline: 8px; }
  .toolbar-tools { flex-direction: column; align-items: stretch; }
  .search-wrap { width: 100%; }
  .search-input { font-size: 16px; }
  .toolbar-tools .button { width: 100%; }
  tbody { padding-inline: 12px; }
  tbody td { grid-template-columns: minmax(84px, 31%) minmax(0, 1fr); }
  dialog { position: fixed; inset: auto 0 0; width: 100%; max-width: none; max-height: calc(100dvh - max(14px, env(safe-area-inset-top))); margin: 0; border-radius: 22px 22px 0 0; }
  .dialog-head { padding: 20px 18px 15px; }
  .dialog-body { padding: 18px 18px max(24px, env(safe-area-inset-bottom)); }
  .form-grid { grid-template-columns: 1fr; gap: 14px; }
  .field.full { grid-column: auto; }
  .field input, .field textarea { font-size: 16px; }
  .dialog-actions .button { flex: 1; }
  .import-preview-head, .import-sample-row { align-items: flex-start; }
  .import-sample-row, .import-removal-row { flex-direction: column; gap: 2px; }
  .import-sample-row span { text-align: left; }
  .toast { left: 18px; right: 18px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
