/* PC Import — โทนเดียวกับ report/ (Sarabun · พื้น #f4f6f9 · brand #2f6df0 · ตัวอักษร #1f2733) */
:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1f2733; --muted: #6b7785; --line: #e6eaf0;
  --brand: #2f6df0; --brand-soft: #eaf1ff; --navy: #1e3a5f;
  --done: #1f9d6b; --done-soft: #e6f6ee; --warn: #d98a00; --warn-soft: #fdf3e0; --bad: #d63b3b; --bad-soft: #fdecec;
  --shadow: 0 1px 3px rgba(18,30,55,.06), 0 6px 20px rgba(18,30,55,.06); --r: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }   /* ต้องชนะ display ของ class (เช่น .drop-err inline-block) */
body { font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--ink); min-height: 100vh; display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, label.btn { font-family: inherit; cursor: pointer; }
code, kbd { font-family: ui-monospace, Consolas, monospace; background: var(--brand-soft); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.muted { color: var(--muted); }

/* ─── Topbar ─── */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 40px; height: 40px; background: #fff; border-radius: 10px; padding: 4px; display: flex; }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.brand-text { line-height: 1.15; }
.brand-text b { font-size: 18px; font-weight: 800; display: block; }
.brand-text small { font-size: 12px; opacity: .75; }
.back-hub { font-size: 13px; opacity: .85; white-space: nowrap; }
.back-hub:hover { opacity: 1; text-decoration: underline; }
.back-hub .short { display: none; }

/* ─── Layout ─── */
.wrap { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px 20px; }
.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 16px; }

/* ─── Drop zone ─── */
.drop { text-align: center; border: 2px dashed #c9d3e2; padding: 36px 20px; transition: .15s; }
.drop.is-over { border-color: var(--brand); background: var(--brand-soft); }
.drop-icon { font-size: 40px; }
.drop-title { font-size: 20px; font-weight: 700; margin-top: 8px; }
.drop-sub { margin-top: 10px; display: flex; gap: 8px; align-items: center; justify-content: center; }
.drop-note { margin-top: 14px; font-size: 13px; color: var(--muted); }
.drop-err { margin-top: 12px; color: var(--bad); background: var(--bad-soft); padding: 8px 12px; border-radius: 8px; display: inline-block; }

/* ─── Buttons ─── */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 600; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover { filter: brightness(1.05); }
.btn-ghost:hover { background: var(--bg); }
.btn-done { background: var(--done-soft); border-color: var(--done); color: var(--done); }

/* ─── Summary ─── */
.sum-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.sum-job { font-size: 18px; font-weight: 700; }
.sum-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px 14px; min-width: 110px; }
.stat b { display: block; font-size: 22px; font-weight: 800; color: var(--navy); }
.stat span { font-size: 12px; color: var(--muted); }

/* ─── Warnings ─── */
.warn { background: var(--warn-soft); border-left: 4px solid var(--warn); }
.warn ul { margin: 8px 0 0 20px; font-size: 14px; }
.warn li { margin: 3px 0; }

/* ─── Pills ─── */
.pills { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pills-label { font-weight: 700; margin-right: 4px; }
.pill { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 14px; font-weight: 700; font-size: 15px; display: flex; flex-direction: column; align-items: center; line-height: 1.1; min-width: 74px; }
.pill small { font-weight: 500; font-size: 11px; color: var(--muted); margin-top: 3px; }
.pill:hover { border-color: var(--brand); }
.pill.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pill.is-active small { color: rgba(255,255,255,.8); }
.pill.is-done { border-color: var(--done); }
.pill.is-done:not(.is-active) { background: var(--done-soft); color: var(--done); }

/* ─── Panel ─── */
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 20px; font-weight: 800; }
.panel-head h2 small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 8px; }
.copy-hint { margin-top: 10px; font-size: 13px; color: var(--muted); }
.copy-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px; margin-top: 10px; }
.copy-btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 8px; text-align: left; display: flex; flex-direction: column; gap: 2px; transition: .12s; }
.copy-btn b { font-size: 14px; }
.copy-btn small { font-size: 11px; color: var(--muted); }
.copy-btn:hover { border-color: var(--brand); background: var(--brand-soft); }
.copy-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.copy-btn.is-copied { border-color: var(--done); background: var(--done-soft); }
.copy-btn.is-copied b { color: var(--done); }
.copy-btn.alt { border-style: dashed; }

/* ─── Table ─── */
.tbl-wrap { overflow-x: auto; margin-top: 14px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 760px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: center; white-space: nowrap; }
.tbl th { background: var(--bg); font-weight: 700; font-size: 13px; }
.tbl .l { text-align: left; }
.tbl .num { font-variant-numeric: tabular-nums; }
.tbl tr.grp td { border-top: 2px solid #c9d3e2; }
.tbl tr.grp td:nth-child(2) { font-weight: 700; }
.tbl tr.bad td { background: var(--bad-soft); }
.tbl td i { color: var(--bad); font-weight: 700; }
.tbl tr.total td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom: 0; }

/* ─── How-to / Toast ─── */
.howto ol { margin: 8px 0 8px 20px; font-size: 14px; }
.howto li { margin: 3px 0; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); z-index: 9; max-width: 92vw; }
.toast.is-ok { background: var(--done); }
.toast.is-err { background: var(--bad); }

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .brand-text small { display: none; }
  .back-hub .full { display: none; }
  .back-hub .short { display: inline; }
  .card { padding: 14px; }
  .copy-row { grid-template-columns: repeat(2, 1fr); }
}

/* ─── v1.1.0: materials page + badge ─── */
/* topbar: ลิงก์เสริมด้านขวา (หน้าหลัก "⚙️ จัดการวัสดุ" อยู่หน้าลิงก์กลับ Hub) */
.top-right { display: flex; align-items: center; gap: 4px; }
.top-link { color: #fff; font-size: 13px; opacity: .85; white-space: nowrap; margin-right: 14px; }
.top-link:hover { opacity: 1; text-decoration: underline; }

/* แถบแหล่งตารางใต้ topbar: ฐานข้อมูล (เขียว) / ตารางในตัว (ส้ม) */
.src-badge { font-size: 13px; padding: 8px 16px; text-align: center; }
.src-badge.is-db { background: var(--done-soft); color: var(--done); }
.src-badge.is-builtin { background: var(--warn-soft); color: var(--warn); }
.src-badge a { text-decoration: underline; margin-left: 8px; }

/* ปุ่มเล็ก (ปุ่ม/ลิงก์ inline เช่น "เพิ่มวัสดุนี้ →" · ↑↓ · คืนค่า) */
.btn-mini { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 3px 10px; font-size: 13px; font-weight: 600; line-height: 1.4; font-family: inherit; cursor: pointer; text-decoration: none; }
.btn-mini:hover { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.btn-mini:disabled { opacity: .35; cursor: default; pointer-events: none; }
.warn-actions { display: block; margin: 8px 0 12px; }
.warn-actions ul { margin-top: 6px; }
.warn-actions li { margin: 4px 0; }
.warn-actions .btn-mini { margin-left: 6px; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }

/* การ์ดสถานะ */
.db-err { background: var(--bad-soft); border-left: 4px solid var(--bad); font-size: 14px; line-height: 1.55; }
.db-err b { color: var(--bad); }
.db-err-hint { margin-top: 6px; color: var(--muted); }
.db-err .btn { margin-top: 12px; }
.ro-tag { font-size: 12px; background: var(--bg); color: var(--muted); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }

/* login */
.login-card > b { font-size: 16px; }
.login-sub { font-size: 13px; margin-top: 2px; }
.login-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.login-form select, .login-form input { font: inherit; font-size: 15px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.login-form select { min-width: 200px; }
.login-form input[type=password] { width: 120px; text-align: center; letter-spacing: .25em; }
.login-form select:focus, .login-form input:focus, .test-in:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.login-note { margin-top: 10px; font-size: 13px; color: var(--muted); }
.login-err { margin-top: 10px; color: var(--bad); background: var(--bad-soft); padding: 8px 12px; border-radius: 8px; display: inline-block; font-size: 14px; }

/* user bar (login แล้ว) */
.user-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.user-pill { display: inline-flex; align-items: center; gap: 6px; background: var(--done-soft); color: var(--done); border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 14px; }
.user-pill small { font-weight: 500; opacity: .85; }
.user-hint { font-size: 13px; flex: 1; }

/* ตารางแก้ไข (วัสดุ / หมายเหตุ) — input เต็มช่อง กะทัดรัด */
.edit-tbl { min-width: 720px; }
.edit-tbl th, .edit-tbl td { padding: 5px 6px; vertical-align: middle; }
.edit-tbl th.l, .edit-tbl td.l { text-align: left; }
.edit-tbl th.w-lg { min-width: 220px; }
.edit-tbl th.w-md { min-width: 130px; }
.edit-tbl td.num { width: 36px; color: var(--muted); }
.edit-tbl input[type=text] { width: 100%; min-width: 80px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 14px; color: var(--ink); background: #fff; }
.edit-tbl input[type=text]:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.edit-tbl input[type=text].short { min-width: 56px; width: 72px; text-align: center; }
.edit-tbl input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; vertical-align: middle; }
.edit-tbl tr.is-off { opacity: .55; }
.edit-tbl tr.is-dirty td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.edit-tbl tr.is-new td { background: var(--brand-soft); border-top: 2px solid #c9d3e2; }
.edit-tbl tr.is-busy, .hist-tbl tr.is-busy { opacity: .5; pointer-events: none; }
.edit-tbl .move { white-space: nowrap; width: 70px; }
.edit-tbl .move .btn-mini { padding: 3px 7px; }
.edit-tbl .move .btn-mini + .btn-mini { margin-left: 3px; }
.row-actions { white-space: nowrap; }
.row-actions button + button { margin-left: 6px; }

/* กล่องทดสอบ */
.test-in { width: 100%; min-height: 96px; margin-top: 12px; padding: 10px 12px; font: inherit; font-size: 14px; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; resize: vertical; background: #fff; display: block; }
.test-note { margin-top: 8px; font-size: 13px; color: var(--warn); }
.test-result { list-style: none; margin-top: 10px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.test-result li { padding: 6px 12px; border-radius: 8px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.test-result li .q { color: var(--ink); font-weight: 500; }
.test-result li .arrow { color: var(--muted); font-weight: 400; }
.test-result li.ok { background: var(--done-soft); color: var(--done); font-weight: 600; }
.test-result li.bad { background: var(--bad-soft); color: var(--bad); font-weight: 700; }

/* ประวัติ */
.hist-tbl { font-size: 13px; min-width: 640px; }
.hist-tbl th, .hist-tbl td { padding: 5px 8px; text-align: left; }
.hist-tbl td.sum { white-space: normal; min-width: 200px; max-width: 360px; }
.hist-tbl .act { font-weight: 700; }
.hist-tbl .act-insert { color: var(--done); }
.hist-tbl .act-delete, .hist-tbl .act-deactivate { color: var(--bad); }
.hist-tbl .act-restore { color: var(--brand); }
.hist-empty { margin-top: 10px; }

@media (max-width: 640px) {
  .top-link { margin-right: 8px; }
  .src-badge { font-size: 12px; padding: 6px 12px; }
  .login-form select, .login-form input[type=text] { flex: 1 1 160px; }
  .user-hint { display: none; }
  .tbl-wrap { -webkit-overflow-scrolling: touch; }   /* ตารางแก้ไข/ประวัติกว้างกว่าจอ → เลื่อนในกรอบ ไม่ดันหน้าทั้งหน้า */
  .edit-tbl { min-width: 680px; }
}
