/* ระบบบริหารพัสดุ สำนักวิจัย — สไตล์หลัก
   โทนสีและระยะทั้งหมดถอดมาจากไฟล์ออกแบบ ระบบบริหารพัสดุ.dc.html */

:root {
  /* พื้นหลัง / พื้นผิว */
  --bg:            oklch(97.5% 0.006 85);
  --surface:       oklch(99.2% 0.002 85);
  --surface-alt:   oklch(96% 0.006 85);
  --border:        oklch(90% 0.006 85);
  --border-soft:   oklch(94% 0.004 85);
  --border-input:  oklch(88% 0.006 85);

  /* ตัวอักษร */
  --text:          oklch(22% 0.01 85);
  --text-muted:    oklch(50% 0.01 85);
  --text-dim:      oklch(60% 0.006 85);
  --text-head:     oklch(45% 0.01 85);
  --text-soft:     oklch(55% 0.01 85);
  --text-body:     oklch(40% 0.01 85);

  /* แถบหัว / เมนูข้าง */
  --nav:           oklch(28% 0.045 165);
  --nav-deep:      oklch(24% 0.04 165);
  --nav-hover:     oklch(30% 0.05 165);
  --nav-border:    oklch(45% 0.03 165);
  --nav-divider:   oklch(35% 0.02 165);
  --nav-sub:       oklch(85% 0.02 165);
  --nav-idle:      oklch(62% 0.01 165);
  --nav-idle2:     oklch(70% 0.02 165);
  --badge-bg:      oklch(34% 0.02 165);
  --badge-fg:      oklch(75% 0.02 165);
  --active:        oklch(35% 0.06 155);

  /* ปุ่มหลัก */
  --accent:        oklch(52% 0.13 150);
  --primary:       oklch(48% 0.12 155);
  --edit-bg:       oklch(95% 0.03 155);
  --edit-border:   oklch(80% 0.08 155);
  --edit-fg:       oklch(32% 0.1 155);

  --scrim:         oklch(20% 0.01 85 / .5);
  --shadow:        0 20px 50px oklch(20% 0.01 85 / .25);

  --th:            'Noto Sans Thai', 'Inter', sans-serif;
  --en:            Inter, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--th);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
a:hover { opacity: .88; }
input, select, button, textarea { font-family: inherit; }

/* ── แถบหัว ─────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 28px;
  background: var(--nav);
  color: #fff;
  flex-wrap: wrap;
}
.topbar__brand { display: flex; align-items: center; gap: 14px; }
.topbar__menu {
  display: none;
  border: 1px solid var(--nav-border);
  background: oklch(24% 0.04 165 / .6);
  color: #fff;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  padding: 9px 11px;
  cursor: pointer;
}
.topbar__logo {
  width: 46px; height: 46px;
  border-radius: 10px;
  background: oklch(99% 0.002 85);
  display: flex; align-items: center; justify-content: center;
  font: 700 17px var(--en);
  color: var(--nav);
  flex-shrink: 0;
}
.topbar__title { font: 700 18px var(--th); line-height: 1.3; }
.topbar__subtitle { font: 400 12px var(--th); color: var(--nav-sub); margin-top: 2px; }
.topbar__nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.btn-ghost-dark {
  padding: 9px 14px;
  border-radius: 8px;
  background: oklch(24% 0.04 165 / .6);
  border: 1px solid var(--nav-border);
  font: 500 13px var(--th);
}
.btn-accent {
  padding: 9px 18px;
  border-radius: 8px;
  background: var(--accent);
  font: 600 13px var(--th);
}

/* ── โครงหน้า ───────────────────────────────────────────────── */
.shell { display: flex; flex: 1; align-items: stretch; min-height: 0; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--nav-deep);
  padding: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar__item {
  width: 100%;
  padding: 13px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  border: none;
  background: none;
}
.sidebar__item--disabled { cursor: not-allowed; }
.sidebar__item--parent { cursor: pointer; background: var(--nav-hover); }
.sidebar__label { font: 500 14px var(--th); color: var(--nav-idle); }
.sidebar__label--active { font-weight: 600; color: #fff; }
.sidebar__badge {
  font: 600 10px var(--th);
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--badge-bg);
  color: var(--badge-fg);
  white-space: nowrap;
}
.sidebar__caret {
  font: 400 11px sans-serif;
  color: var(--badge-fg);
  transition: transform .15s ease;
}
.sidebar__caret--closed { transform: rotate(-90deg); }
.sidebar__divider { height: 1px; background: var(--nav-divider); margin: 8px 22px; }
.sidebar__submenu { display: flex; flex-direction: column; gap: 2px; }
.sidebar__submenu[hidden] { display: none; }
.sidebar__sub {
  padding: 11px 22px 11px 46px;
  cursor: pointer;
  font: 500 13.5px var(--th);
  text-align: left;
  border: none;
  background: transparent;
  color: var(--nav-idle2);
}
.sidebar__sub:hover { color: #fff; }
.sidebar__sub--active { background: var(--active); color: #fff; }

.content {
  flex: 1;
  min-width: 0;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.page { display: flex; flex-direction: column; gap: 22px; }
.page[hidden] { display: none; }
.page__title { font: 700 21px var(--th); color: var(--text); margin: 0; }
.page__subtitle { font: 400 13px var(--th); color: var(--text-muted); margin: 2px 0 0; }

/* ── การ์ด ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.card--pad { padding: 20px 22px; }
.card--clip { overflow: hidden; }
.card__title { font: 700 15px var(--th); color: var(--text); margin: 0 0 14px; }

/* ── สถิติ ──────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.stat__icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.stat__icon--amber  { background: oklch(94% 0.05 80); }
.stat__icon--blue   { background: oklch(93% 0.04 240); }
.stat__icon--green  { background: oklch(93% 0.06 155); }
.stat__icon--violet { background: oklch(94% 0.03 300); }
.glyph { display: block; }
.glyph--diamond   { width: 12px; height: 12px; background: oklch(55% 0.14 80); transform: rotate(45deg); }
.glyph--dot-blue  { width: 14px; height: 14px; border-radius: 50%; background: oklch(55% 0.12 240); }
.glyph--dot-green { width: 14px; height: 14px; border-radius: 50%; background: oklch(45% 0.11 155); }
.glyph--square    { width: 12px; height: 12px; background: oklch(52% 0.13 300); }
.stat__value { font: 700 26px var(--en); color: var(--text); }
.stat__label { font: 400 13px var(--th); color: var(--text-muted); margin-top: 2px; }

/* ── ตาราง ──────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table--plain { min-width: 680px; }
.table--grid  { min-width: 980px; }

.table--plain thead tr { border-bottom: 1px solid var(--border); }
.table--plain th {
  text-align: left;
  padding: 8px 10px;
  font: 600 12px var(--th);
  color: var(--text-muted);
}
.table--plain td { padding: 10px; }

.table--grid thead tr {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
.table--grid th {
  text-align: left;
  padding: 12px 14px;
  font: 600 12.5px var(--th);
  color: var(--text-head);
}
.table--grid td { padding: 12px 14px; }
.th--center { text-align: center !important; }

.table tbody tr { border-bottom: 1px solid var(--border-soft); }
.table tbody tr:last-child { border-bottom: none; }

.cell-code     { font: 500 13px var(--en); color: var(--text); }
.cell-serial   { font: 400 11px var(--en); color: var(--text-dim); margin-top: 2px; }
.cell-strong   { font: 400 13.5px var(--th); color: var(--text); }
.cell-muted    { font: 400 13px var(--th); color: var(--text-muted); }
.cell-po       { font: 500 13px var(--en); color: var(--text); }
.cell-text     { font: 400 13px var(--th); color: var(--text); }
.nowrap        { white-space: nowrap; }

.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font: 600 12px var(--th);
  white-space: nowrap;
}

.row-actions { display: flex; gap: 8px; justify-content: center; }
.empty-row {
  padding: 28px 14px;
  text-align: center;
  font: 400 13.5px var(--th);
  color: var(--text-muted);
}

/* ── ตัวกรอง / ฟอร์ม ────────────────────────────────────────── */
.filters {
  padding: 18px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.field--grow2 { flex: 2; min-width: 220px; }
.field--grow1 { flex: 1; min-width: 180px; }
.field__label { font: 500 12.5px var(--th); color: var(--text-muted); }
.input {
  padding: 9px 12px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  font: 400 13.5px var(--th);
  outline: none;
  background: #fff;
  color: var(--text);
  width: 100%;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px oklch(48% 0.12 155 / .14); }
select.input { cursor: pointer; }

.result-count { font: 400 13px var(--th); color: var(--text-muted); margin: 0; }

/* ── สถานะการโหลดข้อมูล ─────────────────────────────────────── */
.load-status {
  padding: 12px 16px;
  border-radius: 10px;
  background: oklch(93% 0.04 240);
  color: oklch(35% 0.09 240);
  font: 500 13px var(--th);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.load-status--error {
  background: oklch(94% 0.05 25);
  color: oklch(38% 0.14 25);
}
.load-status .btn-outline { padding: 6px 12px; font-size: 12.5px; }

.badge-sample {
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  padding: 2px 9px;
  border-radius: 20px;
  font: 600 10.5px var(--th);
  background: oklch(94% 0.05 80);
  color: oklch(40% 0.12 70);
}

/* ── ปุ่ม ───────────────────────────────────────────────────── */
.btn-outline {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-input);
  background: #fff;
  font: 500 13px var(--th);
  color: var(--text-body);
  cursor: pointer;
}
.btn-outline:hover { background: var(--surface-alt); }
.btn-primary {
  padding: 9px 20px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  font: 600 13.5px var(--th);
  cursor: pointer;
}
.btn-primary:hover { background: oklch(44% 0.12 155); }
.btn-row {
  padding: 6px 12px;
  border-radius: 7px;
  font: 500 12.5px var(--th);
  cursor: pointer;
  white-space: nowrap;
}
.btn-row--edit { border: 1px solid var(--edit-border); background: var(--edit-bg); color: var(--edit-fg); }
.btn-row--view { border: 1px solid var(--border-input); background: #fff; color: var(--text-body); }
.btn-row:hover { filter: brightness(.97); }

/* ── หน้าต่างซ้อน ───────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
}
.modal--sm { padding: 26px; width: min(460px, 100%); max-height: 88vh; overflow-y: auto; }
.modal--lg { padding: 28px; width: min(680px, 100%); max-height: 85vh; overflow-y: auto; gap: 18px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal__title { font: 700 16px var(--th); color: var(--text); margin: 0; }
.modal--lg .modal__title { font-size: 17px; }
.modal__close {
  border: none; background: none;
  font: 400 20px sans-serif;
  color: var(--text-soft);
  cursor: pointer;
  line-height: 1;
}
.modal__close--lg { font-size: 22px; }
.modal__body { display: flex; flex-direction: column; gap: 16px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px 24px;
}
.detail__label { font: 500 12px var(--th); color: var(--text-soft); }
.detail__value { font: 400 14px var(--th); color: var(--text); margin-top: 3px; }
.detail__value--code   { font: 600 14px var(--en); }
.detail__value--mono   { font: 500 14px var(--en); }
.detail__value--strong { font-weight: 500; }
.detail__pill { margin-top: 4px; }
.detail-rule { height: 1px; background: oklch(92% 0.005 85); }
.detail-heading { font: 700 13.5px var(--th); color: var(--text); }
.detail-stack { display: flex; flex-direction: column; gap: 18px; }

/* ── จอเล็ก ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .topbar { padding: 12px 16px; }
  .topbar__menu { display: block; }
  .topbar__title { font-size: 15px; }
  .shell { position: relative; }
  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar--open { transform: translateX(0); }
  .content { padding: 20px 16px; }
}
