/* ระบบจัดซื้อต่างประเทศ — ยึดค่ากลางจาก DESIGN.md ของระบบงานภายใน S.V. Interglass */
:root {
  --navy: #072A47;
  --deep: #0A3D66;
  --blue: #1673B8;
  --glass-edge: #6FD6F2;
  --ink: #0B1C2C;
  --steel: #4E6378;
  --on-dark: #FFFFFF;
  --on-dark-2: #C3DBEE;
  --line: #D5DFE8;
  --paper: #F7FAFC;
  --paper-2: #EAF1F7;
  --bg: #EEF3F7;
  --danger: #C0392F;
  --danger-bg: #FBEAE8;
  --ok: #1E7A46;
  --ok-bg: #E6F4EC;
  --warn: #8A5A00;
  --warn-bg: #FFF4D6;
  --focus: 0 0 0 3px rgba(22, 115, 184, .45);
  --shadow-card: 0 1px 2px rgba(11, 28, 44, .06), 0 2px 8px rgba(11, 28, 44, .06);
  --shadow-hover: 0 4px 16px rgba(11, 28, 44, .12);
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: "IBM Plex Sans Thai", "Sarabun", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; font-weight: 700; }
h2 { font-size: 1.15rem; margin: 0 0 12px; font-weight: 700; color: var(--deep); }
h3 { font-size: 1rem; margin: 16px 0 8px; font-weight: 700; }
p { margin: 0 0 8px; }
.mono { font-family: var(--mono); }
.muted { color: var(--steel); font-size: .9rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ===== แถบบน ===== */
.topbar { background: var(--navy); color: var(--on-dark); }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { color: var(--on-dark); font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand small { color: var(--on-dark-2); font-weight: 400; font-size: .85rem; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--on-dark-2); padding: 10px 12px; border-radius: 10px; font-size: .95rem; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; }
.nav a:hover { color: var(--on-dark); background: rgba(255, 255, 255, .08); text-decoration: none; }
.nav a.active { color: var(--on-dark); background: rgba(111, 214, 242, .16); box-shadow: inset 0 -2px 0 var(--glass-edge); }
.nav .badge { background: var(--danger); color: #fff; }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--on-dark-2); font-size: .9rem; }
.userbox form { margin: 0; }
.userbox button { background: transparent; border: 1px solid rgba(195, 219, 238, .4); color: var(--on-dark); border-radius: 10px; padding: 6px 12px; cursor: pointer; font: inherit; min-height: 36px; }

/* ===== โครงหน้า ===== */
.wrap { max-width: 1320px; margin: 0 auto; padding: 20px 16px 48px; }
.crumbs { font-size: .9rem; color: var(--steel); margin-bottom: 6px; }
.crumbs a { color: var(--steel); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.card { background: #fff; border-radius: 18px; box-shadow: var(--shadow-card); padding: 20px; margin-bottom: 16px; min-width: 0; }
.card > h2:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

/* ===== ตัวเลขสรุป ===== */
.stat { background: #fff; border-radius: 18px; box-shadow: var(--shadow-card); padding: 16px 20px; display: block; color: var(--ink); }
.stat:hover { box-shadow: var(--shadow-hover); text-decoration: none; }
.stat .label { color: var(--steel); font-size: .92rem; }
.stat .value { font-size: 1.9rem; font-weight: 700; color: var(--deep); font-family: var(--mono); line-height: 1.2; }

/* ===== ปุ่ม ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--deep); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--blue); text-decoration: none; }
.btn-primary { background: var(--deep); border-color: var(--deep); color: #fff; min-height: 48px; }
.btn-primary:hover { background: var(--navy); }
.btn-danger { color: var(--danger); border-color: #E7B7B2; }
.btn-danger:hover { border-color: var(--danger); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn-link { border: 0; background: none; color: var(--blue); padding: 0; min-height: 0; font-weight: 400; cursor: pointer; font: inherit; }
button[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; margin: 0; }

/* ===== ฟอร์ม ===== */
label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
.field { margin-bottom: 14px; min-width: 0; }
.field .hint { font-size: .85rem; color: var(--steel); font-weight: 400; margin-top: 2px; }
input[type=text], input[type=number], input[type=date], input[type=datetime-local], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; min-height: 44px; }
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: var(--focus); background: #fff; }
input[readonly] { background: var(--paper-2); }
.is-invalid { border-color: var(--danger) !important; }
.err { color: var(--danger); font-size: .88rem; margin-top: 2px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; min-height: 32px; }
.check input { width: 20px; height: 20px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.form-row { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 16px; margin-top: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters .field { margin: 0; min-width: 160px; }

/* ===== ตาราง ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.t th { text-align: left; font-weight: 600; color: var(--steel); background: var(--paper); border-bottom: 1px solid var(--line); padding: 10px 10px; white-space: nowrap; }
table.t td { border-bottom: 1px solid var(--line); padding: 10px 10px; vertical-align: top; }
table.t tbody tr:hover td { background: #FAFCFE; }
table.t tfoot td { font-weight: 700; background: var(--paper); }
table.t input, table.t select { min-height: 40px; padding: 6px 8px; }
table.t.edit td { padding: 6px 6px; }
.empty { text-align: center; color: var(--steel); padding: 24px; }

/* ===== ป้ายสถานะ ===== */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; background: var(--paper-2); color: var(--deep); white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: #EEF1F4; color: var(--steel); }
.badge-blue { background: #E2F0FB; color: var(--blue); }

/* ===== กล่องข้อความ ===== */
.alert { border-radius: 14px; padding: 12px 16px; margin-bottom: 16px; border: 1px solid; }
.alert-ok { background: var(--ok-bg); border-color: #B9DEC8; color: #145C33; }
.alert-error { background: var(--danger-bg); border-color: #EBC1BC; color: #8E2A22; }
.alert-warn { background: var(--warn-bg); border-color: #F0D795; color: #6B4600; }
.alert ul { margin: 4px 0 0 18px; padding: 0; }

/* ===== รายละเอียด ===== */
dl.kv { display: grid; grid-template-columns: minmax(130px, max-content) 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--steel); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ===== ไทม์ไลน์อนุมัติ ===== */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps .dot { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem;
  background: var(--paper-2); color: var(--steel); flex: none; }
.steps .dot.ok { background: var(--ok); color: #fff; }
.steps .dot.now { background: var(--blue); color: #fff; }
.steps .dot.bad { background: var(--danger); color: #fff; }

/* ===== ตารางเปรียบเทียบราคา ===== */
.cmp td.best { background: var(--ok-bg) !important; }
.cmp .star { color: var(--ok); font-weight: 700; }
.cmp label.pick { display: flex; gap: 6px; align-items: center; font-weight: 400; margin: 0; }

/* ===== ข้อความ (กระทู้) ===== */
.msgs { list-style: none; margin: 0 0 12px; padding: 0; }
.msgs li { padding: 10px 12px; border-radius: 12px; background: var(--paper); margin-bottom: 8px; }
.msgs li.from_supplier { background: #FFF8E6; }
.msgs li.to_supplier { background: #E9F4FC; }
.msgs .meta { font-size: .85rem; color: var(--steel); margin-bottom: 2px; }
.msgs .body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ===== หน้าล็อกอิน ===== */
.login-bg { min-height: 100vh; background: var(--deep); display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { background: #fff; border-radius: 18px; padding: 32px 28px; width: 100%; max-width: 420px; box-shadow: var(--shadow-hover); }
.login-card h1 { color: var(--deep); font-size: 1.4rem; }
.login-card .btn-primary { width: 100%; margin-top: 6px; }

.pagination { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.pagination a, .pagination span { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; padding: 0 10px; }
.pagination .current { background: var(--deep); color: #fff; border-color: var(--deep); }
.pagination .disabled { color: var(--line); }

details.box { border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; background: #fff; margin-bottom: 12px; }
details.box > summary { cursor: pointer; font-weight: 600; color: var(--deep); min-height: 32px; display: flex; align-items: center; }
details.box[open] > summary { margin-bottom: 10px; }

@media (max-width: 720px) {
  .wrap { padding: 14px 12px 40px; }
  .card { padding: 16px; border-radius: 14px; }
  h1 { font-size: 1.35rem; }
  dl.kv { grid-template-columns: 1fr; gap: 0 0; }
  dl.kv dt { margin-top: 8px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { .topbar, .no-print, .form-actions { display: none !important; } body { background: #fff; } .card { box-shadow: none; } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
