:root {
  font-family: "Leelawadee UI", Tahoma, system-ui, sans-serif;
  color: #1f2d3d;
  background: #f4f7fb;
  font-synthesis: none;
  --blue: #1d4f91;
  --blue-dark: #16386b;
  --blue-soft: #e3edfb;
  --muted: #5b6b7c;
  --line: #dbe3ec;
  --ok: #26654d;
  --ok-bg: #e2f1e9;
  --warn: #8c611b;
  --warn-bg: #fff1d9;
  --bad: #9e3546;
  --bad-bg: #f9e5e8;
  --info: #1d4f91;
  --info-bg: #e3edfb;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button {
  border: 1px solid transparent;
  background: var(--blue);
  color: white;
  border-radius: 9px;
  padding: 10px 17px;
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}
button:hover { filter: brightness(.94); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #7fb3e8;
  outline-offset: 3px;
}
a { color: var(--blue); }
[hidden] { display: none !important; }
h1 { font-size: 30px; letter-spacing: -.7px; line-height: 1.35; margin: 7px 0 10px; }
h2 { font-size: 22px; margin: 0; }
.eyebrow { font-size: 12px; font-weight: 700; color: var(--blue); letter-spacing: 1px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.8; }
label { display: flex; flex-direction: column; gap: 7px; font-size: 14px; font-weight: 600; }
form { display: grid; gap: 18px; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #c3cfdd;
  background: white;
  border-radius: 8px;
  padding: 11px 12px;
  color: #1f2d3d;
}
textarea { resize: vertical; }
.error { color: var(--bad); font-size: 14px; line-height: 1.6; margin: 0; }
.error:empty { display: none; }
.quiet { background: transparent; color: var(--muted); }
.selected { background: var(--blue-soft); color: var(--blue-dark); }
.secondary { background: white; border-color: var(--line); color: #33506f; }
.danger { background: #a6323e; }
.sr-only, .honeypot { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.success { padding: 20px; background: var(--ok-bg); border-radius: 10px; line-height: 1.8; }

/* --- top bar ------------------------------------------------------------------ */
.topbar {
  background: white;
  border-bottom: 1px solid var(--line);
  min-height: 74px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 14px 28px;
  position: sticky;
  top: 0;
  z-index: 30;
}
#menu-toggle { display: none; width: 46px; height: 46px; font-size: 20px; place-items: center; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; font-weight: 700; font-size: 15px; overflow-wrap: anywhere; color: var(--ink, #1f2d3d); }
.mark { background: var(--blue); color: #fff; display: grid; place-items: center; height: 40px; min-width: 64px; border-radius: 12px; flex-shrink: 0; font-size: 15px; letter-spacing: .5px; padding: 0 8px; }
.topbar #account { display: flex; align-items: center; gap: 18px; font-size: 13px; }

/* --- layout: sidebar + content -------------------------------------------------- */
main { display: block; }
.auth-card {
  max-width: 450px;
  margin: 50px auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 34px;
  box-shadow: 0 16px 50px #16386b0d;
}
.layout { display: flex; align-items: flex-start; min-height: calc(100dvh - 75px); }
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: white;
  border-right: 1px solid var(--line);
  padding: 22px 14px 30px;
  position: sticky;
  top: 75px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-group { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: 1.2px; margin: 16px 10px 6px; }
.nav-group:first-child { margin-top: 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: #33506f;
  font-weight: 600;
  font-size: 14px;
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 44px;
}
.nav-item:hover { background: #f0f5fb; filter: none; }
.nav-item.selected { background: var(--blue-soft); color: var(--blue-dark); }
.nav-backdrop { position: fixed; inset: 0; background: #16386b66; z-index: 39; border: 0; padding: 0; min-height: 0; }
.content { flex: 1; min-width: 0; padding: 30px 34px 60px; max-width: 1240px; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 24px; }
.page-heading p { margin: 0; }

/* --- panels, toolbars, records --------------------------------------------------- */
.panel { border: 1px solid var(--line); background: white; border-radius: 16px; overflow: hidden; }
.toolbar { display: flex; gap: 12px; padding: 20px 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.search-label { flex: 1; min-width: 200px; }
.filter-label select { min-height: 44px; }
.list-message { margin: 0; padding: 0 22px; color: var(--muted); font-size: 14px; }
.list-message:not(:empty) { padding: 26px 22px; }
.records { display: block; }
.record { padding: 20px 22px; border-bottom: 1px solid #edf1f7; }
.record:last-child { border-bottom: 0; }
.record-main { min-width: 0; }
.record-title { font-size: 16px; overflow-wrap: anywhere; margin: 0 0 8px; font-weight: 700; }
.record-meta { color: var(--muted); font-size: 12.5px; line-height: 1.8; overflow-wrap: anywhere; }
.record-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.record-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.record-actions button { font-size: 12.5px; padding: 7px 11px; min-height: 36px; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding: 16px 22px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.pagination > div { display: flex; gap: 8px; }

/* --- badges ------------------------------------------------------------------------ */
.badge { display: inline-block; font-size: 12px; border-radius: 6px; padding: 6px 10px; background: #eef2f7; color: #4f645b; width: fit-content; font-weight: 600; }
.badge.info, .badge.admin { background: var(--info-bg); color: var(--info); }
.badge.pending, .badge.doing { background: var(--warn-bg); color: var(--warn); }
.badge.ready, .badge.done { background: var(--ok-bg); color: var(--ok); }
.badge.problem, .badge.off { background: var(--bad-bg); color: var(--bad); }

/* --- dashboard KPI cards + exceptions ------------------------------------------------- */
.section-heading { font-size: 15px; margin: 26px 0 12px; color: var(--blue-dark); letter-spacing: .2px; }
.view > .section-heading:first-child, #view-dashboard > .section-heading:first-child { margin-top: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi-card { background: white; border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi-num { font-size: 28px; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-card.ready .kpi-num { color: var(--ok); }
.kpi-card.pending .kpi-num { color: var(--warn); }
.kpi-card.problem .kpi-num { color: var(--bad); }
.kpi-card.info .kpi-num { color: var(--info); }
.exception-panel { display: flex; flex-direction: column; }
.exception-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: white;
  color: #1f2d3d;
  font-weight: 400;
  font-size: 14px;
  padding: 14px 22px;
  border-radius: 0;
  border-bottom: 1px solid #edf1f7;
  min-height: 0;
}
.exception-item:hover { background: #f6f9fd; filter: none; }
.exception-item:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.dot.pending { background: #e0a52e; }
.dot.problem { background: #c33b4e; }
.exception-text { line-height: 1.6; overflow-wrap: anywhere; }

/* --- sub tabs, masters, trace -------------------------------------------------------- */
.sub-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.master-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; }
.master-header p { margin: 0; }
.trace-panel { margin-top: 0; }
.trace-card { display: block; }
.trace-usage { padding: 12px 22px 12px 26px; border-bottom: 1px solid #edf1f7; border-left: 3px solid var(--blue-soft); font-size: 14px; line-height: 1.8; }
.trace-usage:last-child { border-bottom: 0; }
.trace-usage .muted { font-size: 12.5px; }
.recall-card { border-left: 4px solid var(--bad); }
.problem-text .summary-value { color: var(--bad); font-weight: 600; }

/* --- dialogs -------------------------------------------------------------------------- */
dialog { width: min(560px, calc(100% - 32px)); max-height: calc(100dvh - 32px); border: 1px solid var(--line); padding: 28px; border-radius: 18px; color: inherit; box-shadow: 0 30px 100px #102b3c33; }
dialog.wide { width: min(780px, calc(100% - 32px)); }
dialog::backdrop { background: #16386b59; backdrop-filter: blur(3px); }
.dialog-heading, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-actions { justify-content: flex-end; margin-top: 8px; }
fieldset { display: grid; gap: 18px; border: 0; padding: 0; margin: 0; min-width: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field-row { display: flex; gap: 10px; align-items: end; }
.field-row .grow { flex: 1; }
.checkbox { flex-direction: row; align-items: center; font-weight: 500; }
.checkbox input { width: 18px; height: 18px; }
.checklist { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.checklist legend { font-size: 12.5px; font-weight: 700; color: var(--blue-dark); padding: 0 6px; }
.summary-row { display: flex; gap: 14px; padding: 7px 0; border-bottom: 1px dashed #e6ecf4; font-size: 14px; }
.summary-row:last-child { border-bottom: 0; }
.summary-label { flex: 0 0 150px; color: var(--muted); font-weight: 600; }
.summary-value { flex: 1; overflow-wrap: anywhere; font-weight: 600; }
.verify-summary { border: 1px solid var(--line); border-radius: 12px; padding: 12px 18px; margin: 14px 0; }
.stock-info, .case-info { border: 1px solid var(--line); background: #f6f9fd; border-radius: 12px; padding: 12px 16px; font-size: 13.5px; line-height: 1.8; }

/* --- floating notice ------------------------------------------------------------------- */
.notice {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--blue-dark);
  color: white;
  border-radius: 10px;
  padding: 12px 22px;
  font-size: 14px;
  z-index: 60;
  box-shadow: 0 12px 40px #16386b40;
  max-width: min(560px, calc(100vw - 32px));
}
.notice:empty { display: none; }

/* --- responsive -------------------------------------------------------------------------- */
@media (max-width: 980px) {
  #menu-toggle { display: grid; }
  .layout { display: block; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: 272px;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 0 0 60px #16386b26;
    overflow-y: auto;
    padding-top: 20px;
  }
  .sidebar.open { transform: none; }
  .content { padding: 22px 18px 48px; }
}
@media (max-width: 650px) {
  .topbar { padding: 12px 14px; flex-wrap: wrap; gap: 10px; }
  .topbar #account { width: 100%; justify-content: space-between; gap: 8px; }
  .auth-card { margin: 15px auto; padding: 26px 22px; }
  h1 { font-size: 26px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 16px; }
  .page-heading > button { width: 100%; }
  .toolbar { padding: 16px; gap: 8px; }
  .search-label { flex-basis: 100%; }
  .toolbar > label:not(.search-label) { flex: 1; }
  .record { padding: 18px 16px; }
  .record-actions { justify-content: flex-start; }
  .form-grid, .checklist { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; align-items: stretch; }
  .summary-row { flex-direction: column; gap: 2px; }
  .summary-label { flex-basis: auto; }
  dialog { padding: 22px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
