/* ============================================================
   WareHouse | SRT
   Sidebar เข้ม + พื้นที่เนื้อหาสว่าง เน้นสีเขียว
   ไฟล์เดียว ไม่มี dependency ภายนอก ไม่เรียก CDN
   ============================================================ */

:root {
    /* ---- Sidebar (เข้มเกือบดำ) ---- */
    --side:        #12161d;
    --side-2:      #1a1f28;
    --side-3:      #232935;
    --side-line:   #262d38;
    --side-text:   #e8eaed;
    --side-muted:  #9aa4b2;
    --side-faint:  #6b7684;

    /* ---- พื้นที่เนื้อหา (สว่าง) ---- */
    --bg:          #f5f6f8;
    --surface:     #ffffff;
    --surface-2:   #fafbfc;
    --surface-3:   #f2f4f6;

    --line:        #e6e9ed;
    --line-2:      #d6dbe1;

    --text:        #111827;
    --text-2:      #5c6875;
    --text-3:      #8e99a5;

    /* ---- เขียวเป็นสีเน้นหลัก ---- */
    --green:       #00c853;
    --green-2:     #00b34a;
    --green-3:     #009940;
    --green-soft:  #e9faef;
    --green-line:  #b9edcb;

    --danger:      #e5484d;
    --danger-soft: #feecec;
    --danger-line: #f7c9cb;
    --warn:        #f59e0b;
    --warn-soft:   #fff7e6;
    --warn-line:   #fadfa6;
    --info-soft:   #eef2f7;

    --radius:      10px;
    --radius-sm:   7px;

    --shadow:      0 1px 2px rgba(16, 24, 40, .05);
    --shadow-md:   0 4px 14px rgba(16, 24, 40, .09);
    --shadow-lg:   0 18px 44px rgba(16, 24, 40, .16);

    --sidebar-w:   252px;
    --topbar-h:    62px;

    --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
    --sans: "Segoe UI", "Noto Sans Thai", "Leelawadee UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14.5px;
    line-height: 1.55;
}

a { color: var(--green-3); text-decoration: none; }
a:hover { text-decoration: underline; }

.icon { flex: 0 0 auto; vertical-align: -.18em; }

/* ============================================================
   โครงหน้า: sidebar ซ้าย + เนื้อหาขวา
   ============================================================ */

.layout { display: flex; min-height: 100vh; }

/* ---------------- Sidebar ---------------- */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--side);
    border-right: 1px solid var(--side-line);
    color: var(--side-text);
}

.side-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 18px 18px;
    border-bottom: 1px solid var(--side-line);
}
.side-brand .mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border-radius: 9px;
    background: var(--green);
    color: #04240f;
}
.side-brand .txt { min-width: 0; }
.side-brand strong {
    display: block;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.01em;
    color: #fff;
}
.side-brand small {
    display: block;
    color: var(--side-faint);
    font-size: 11.5px;
}

.side-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 18px;
}

.side-label {
    padding: 16px 10px 7px;
    color: var(--side-faint);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.side-nav > .side-label:first-child { padding-top: 4px; }

.side-nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 13px;
    margin-bottom: 3px;
    border-radius: 8px;
    color: var(--side-muted);
    font-size: 14px;
    font-weight: 500;
}
.side-nav a:hover {
    background: var(--side-2);
    color: var(--side-text);
    text-decoration: none;
}
.side-nav a.active {
    background: var(--green);
    color: #fff;
    font-weight: 600;
}
.side-nav a.active:hover { background: var(--green-2); color: #fff; }
.side-nav a .icon { opacity: .95; }

.side-foot {
    padding: 14px 16px 18px;
    border-top: 1px solid var(--side-line);
}
.side-user {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 11px;
    font-size: 13px;
    color: var(--side-text);
    min-width: 0;
}
.side-user .icon { color: var(--side-faint); }
.side-user .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.side-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--side-3);
    border-radius: 8px;
    background: transparent;
    color: var(--side-muted);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background .13s, color .13s, border-color .13s;
}
.side-logout:hover { background: var(--side-2); color: #fff; border-color: #333b49; }

.badge-role {
    padding: 1.5px 7px;
    border-radius: 99px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge-role.admin { background: var(--green); color: #fff; }
.badge-role.user  { background: var(--surface-3); color: var(--text-2); border: 1px solid var(--line-2); }
.side-user .badge-role.user { background: var(--side-3); color: var(--side-muted); border-color: transparent; }

/* ---------------- ฝั่งเนื้อหา ---------------- */

.content {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 14px;
    height: var(--topbar-h);
    padding: 0 26px;
    background: rgba(255, 255, 255, .92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
}
.topbar h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar .spacer { flex: 1; }

.menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
}
.menu-btn:hover { background: var(--surface-3); }

.whoami {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 11px 5px 9px;
    border: 1px solid var(--line);
    border-radius: 99px;
    background: var(--surface);
    font-size: 13px;
    white-space: nowrap;
}
.whoami .icon { color: var(--text-3); }

.main { flex: 1; padding: 22px 26px 56px; }

.footer {
    padding: 16px 26px 22px;
    color: var(--text-3);
    font-size: 12px;
}

/* overlay ตอน sidebar เปิดบนจอเล็ก */
.side-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(16, 24, 40, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .18s, visibility .18s;
}
body.nav-open .side-overlay { opacity: 1; visibility: visible; }

/* ============================================================
   ส่วนประกอบ
   ============================================================ */

.page-head {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 18px;
}
.page-head h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.01em;
}
.page-head .sub { margin: 3px 0 0; color: var(--text-2); font-size: 13.5px; }
.page-head .spacer { flex: 1; }

/* ---------------- ปุ่ม ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 15px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.3;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: background .13s, border-color .13s, color .13s;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { border-color: var(--green-2); background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-2); border-color: var(--green-3); color: #fff; }

.btn-danger { border-color: var(--danger-line); background: var(--danger-soft); color: #b3272c; }
.btn-danger:hover { background: #fddede; border-color: #efb2b5; color: #98191e; }

.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px; }

/* ---------------- การ์ด ---------------- */

.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card + .card { margin-top: 16px; }

/* หัวการ์ดบางใบมีทั้งชื่อ ปุ่มดาวน์โหลด และปุ่มลบอยู่แถวเดียวกัน
   ถ้าไม่ยอมให้ขึ้นบรรทัดใหม่ พอจอแคบชื่อจะถูกบีบจนเหลือคำละบรรทัด
   แล้วปุ่มยังล้นออกนอกการ์ดอยู่ดี — ใช้ flex-wrap เหมือน .page-head
   ปุ่มจะตกลงไปบรรทัดถัดไปเองเมื่อที่ไม่พอ จอกว้างยังเป็นแถวเดียวเหมือนเดิม */
.card-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 9px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    font-weight: 700;
    font-size: 14.5px;
}
.card-head .icon { color: var(--green-3); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }

/* ---------------- สถิติ ---------------- */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat {
    padding: 15px 17px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.stat .label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 500;
}
.stat .label .icon { color: var(--text-3); }
.stat .value {
    margin-top: 6px;
    font-family: var(--mono);
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.15;
}
.stat .value.sm { font-size: 16px; letter-spacing: 0; }
.stat.accent .value { color: var(--green-2); }
.stat .hint { margin-top: 3px; color: var(--text-3); font-size: 12.5px; }

/* ---------------- ค้นหา ---------------- */

.search-wrap { position: relative; flex: 1 1 360px; min-width: 240px; }

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    transition: border-color .13s, box-shadow .13s;
}
.search-box:focus-within {
    border-color: var(--green);
    box-shadow: 0 0 0 3px var(--green-soft);
}
.search-box .icon { color: var(--text-3); }
.search-box input {
    flex: 1;
    padding: 10px 0;
    border: 0;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 14.5px;
}
.search-box input:focus { outline: none; }
.search-box input::placeholder { color: var(--text-3); }

.suggest {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 30;
    max-height: 340px;
    overflow-y: auto;
    margin: 0;
    padding: 6px;
    list-style: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}
.suggest:empty, .suggest[hidden] { display: none; }
.suggest li { padding: 8px 11px; border-radius: var(--radius-sm); cursor: pointer; }
.suggest li:hover, .suggest li.is-active { background: var(--green-soft); }
.suggest .s-code { font-family: var(--mono); font-size: 12.5px; color: var(--green-3); font-weight: 600; }
.suggest .s-name { color: var(--text-2); font-size: 12.5px; margin-top: 1px; }
.suggest .s-empty { color: var(--text-3); cursor: default; }
.suggest .s-empty:hover { background: transparent; }

/* ---------------- ตาราง ---------------- */

/*
   หมายเหตุสำคัญ:
   .table-scroll มี overflow ทำให้มันกลายเป็น scroll container ของ position:sticky
   ดังนั้น thead ต้อง top:0 (ไม่ใช่ความสูงของ topbar) ไม่งั้นหัวตารางจะถูกดันลงมา
   ทับแถวข้อมูลแรก ซึ่งเป็นบั๊กที่เจอในเวอร์ชันก่อน
*/
.table-scroll {
    overflow: auto;
    max-height: calc(100vh - 210px);
}

table.data {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13.5px;
}
table.data th, table.data td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.data thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line-2);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}
table.data thead th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
table.data thead th a:hover { color: var(--green-3); text-decoration: none; }
table.data thead th a:hover .sort-hint { opacity: .7; }
table.data thead th.sorted { color: var(--green-3); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }

/* ลูกศรบอกว่าคอลัมน์นี้กดเรียงได้ ซ่อนไว้จนกว่าจะ hover */
.sort-hint { opacity: 0; transition: opacity .13s; }

td.code { font-family: var(--mono); font-size: 12.5px; color: var(--green-3); font-weight: 600; white-space: nowrap; }
td.num  { font-family: var(--mono); text-align: right; white-space: nowrap; }
/* ตัวเลขที่ต้องการให้เด่น ใช้เขียวเดียวกับรหัสสินค้า:
   - คงเหลือที่มีของ  ให้กวาดตาเห็นได้เร็วว่ารายการไหนมีของ
   - ราคารวม VAT      เป็นตัวเลขที่ผู้ใช้เอาไปใช้จริง */
td.num.in-stock,
td.num.vat { color: var(--green-3); font-weight: 600; }
td.num.zero { color: var(--text-3); }
td.actions { width: 1%; white-space: nowrap; }
td.actions form { display: inline; }
th.right, td.right { text-align: right; }

.unit-tag {
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--surface-3);
    color: var(--text-2);
    font-size: 11.5px;
    white-space: nowrap;
}

.empty { padding: 56px 20px; text-align: center; color: var(--text-3); }
.empty .icon { color: var(--line-2); margin-bottom: 10px; }
.empty p { margin: 0 0 4px; }

/* ---------------- แบ่งหน้า ---------------- */

.pager {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 13px 18px;
    border-top: 1px solid var(--line);
    background: var(--surface-2);
    font-size: 13px;
    color: var(--text-2);
}
.pager .spacer { flex: 1; }
.pager .pages { display: flex; gap: 4px; }
.pager .pages a, .pager .pages span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 31px;
    padding: 0 9px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
    font-size: 13px;
}
.pager .pages a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.pager .pages .current { background: var(--green); border-color: var(--green-2); color: #fff; font-weight: 700; }
.pager .pages .disabled { opacity: .4; }

/* ---------------- ฟอร์ม ---------------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }

.field label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
}
.field label .req { color: var(--danger); }

.field input, .field select, .field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 14.5px;
    transition: border-color .13s, box-shadow .13s;
}
.field input.mono { font-family: var(--mono); }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px var(--green-soft);
}
.field .help { color: var(--text-3); font-size: 12.5px; }

/* ---- ช่องที่กรอกไม่ผ่าน: กรอบแดง + ข้อความใต้ช่อง ---- */
.field.has-error > label { color: #b3272c; }
.field.has-error input,
.field.has-error select,
.field.has-error textarea {
    border-color: var(--danger);
    background: #fffbfb;
}
.field.has-error input:focus,
.field.has-error select:focus,
.field.has-error textarea:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-soft);
}
/* ข้อความอธิบายปกติจะซ่อนไว้เมื่อมี error เพื่อไม่ให้แย่งความสนใจกัน */
.field.has-error .help { display: none; }

/* รายการเกณฑ์ใต้ช่องรหัสผ่าน */
.rule-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    margin: 2px 0 0;
    padding: 0;
    list-style: none;
}
.rule-list li {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-2);
    font-size: 12.5px;
}
.rule-list .icon { color: var(--line-2); }

.field-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    color: #b3272c;
    font-size: 12.5px;
    font-weight: 600;
}
.field-error .icon { margin-top: 2px; color: var(--danger); }

.field input[type="file"] { padding: 8px; cursor: pointer; }
.field input[type="file"]::file-selector-button {
    margin-right: 11px;
    padding: 7px 13px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.field input[type="file"]::file-selector-button:hover { background: var(--line); }

.form-actions {
    display: flex;
    gap: 9px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 17px;
    border-top: 1px solid var(--line);
}
.form-actions .spacer { flex: 1; }

/* ---------------- แจ้งเตือน ---------------- */

.alerts { display: flex; flex-direction: column; gap: 10px; margin-bottom: 17px; }

.alert {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 12px 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 13.5px;
}
.alert .icon { margin-top: 1px; flex: 0 0 auto; }
.alert.success { border-color: var(--green-line); background: var(--green-soft); color: #10633a; }
.alert.success .icon { color: var(--green-2); }
.alert.error   { border-color: var(--danger-line); background: var(--danger-soft); color: #9c1f24; }
.alert.error .icon { color: var(--danger); }
.alert.warning { border-color: var(--warn-line); background: var(--warn-soft); color: #8a5a06; }
.alert.warning .icon { color: var(--warn); }
.alert.info    { background: var(--info-soft); color: var(--text-2); }
.alert.info .icon { color: var(--text-3); }
.alert strong { color: inherit; }

/* ---------------- หน้าเข้าสู่ระบบ ---------------- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 28px 20px;
    background:
        radial-gradient(760px 380px at 50% -12%, rgba(0, 200, 83, .1), transparent 70%),
        var(--bg);
}
.login-card {
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.login-card .top { padding: 30px 30px 24px; text-align: center; }
.login-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-bottom: 14px;
    border-radius: 13px;
    background: var(--green);
    color: #fff;
    box-shadow: 0 6px 18px rgba(0, 200, 83, .3);
}
.login-card h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.login-card .tag { margin: 5px 0 0; color: var(--text-2); font-size: 13.5px; }
.login-card .body { padding: 4px 30px 28px; }
.login-card .field + .field { margin-top: 15px; }
.login-card .btn { width: 100%; margin-top: 22px; padding: 11px; font-size: 15px; }
.login-foot {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    color: var(--text-3);
    font-size: 11.5px;
    text-align: center;
}

/* ---------------- หน้าแสดงข้อผิดพลาด ---------------- */

.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 28px 20px;
    text-align: center;
}
.error-page .code {
    font-family: var(--mono);
    font-size: 66px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -.03em;
    color: var(--green);
}
.error-page h1 { margin: 12px 0 6px; font-size: 21px; }
.error-page p { margin: 0 0 24px; color: var(--text-2); }
.error-page pre {
    max-width: 620px;
    margin: 0 auto 24px;
    padding: 13px 15px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
    font-size: 12.5px;
    text-align: left;
}

/* ---------------- นำเข้า CSV ---------------- */

.dropzone {
    padding: 30px 20px;
    border: 1.5px dashed var(--line-2);
    border-radius: var(--radius);
    background: var(--surface-2);
    text-align: center;
    transition: border-color .13s, background .13s;
}
.dropzone.is-over { border-color: var(--green); background: var(--green-soft); }
.dropzone .icon { color: var(--green-2); margin-bottom: 9px; }
.dropzone p { margin: 0 0 4px; font-size: 14.5px; }
.dropzone .hint { color: var(--text-3); font-size: 12.5px; }
.dropzone input[type="file"] {
    margin-top: 15px;
    max-width: 360px;
    padding: 8px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
    font-size: 13.5px;
}

.spec { margin: 0; padding: 0; list-style: none; font-size: 13.5px; }
.spec li {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}
.spec li:last-child { border-bottom: 0; }
.spec .k { flex: 0 0 200px; color: var(--text-2); }
.spec .v { font-family: var(--mono); font-size: 12.5px; color: var(--text); }

/* ---------------- อื่นๆ ---------------- */

/* แถวเครื่องมือเหนือตาราง: ช่องค้นหา + ปุ่มต่างๆ
   ใช้ stretch เพื่อให้ปุ่มสูงเท่าช่องค้นหาพอดี ไม่ใช่ลอยอยู่กลางแถว */
.tools { display: flex; align-items: stretch; gap: 11px; flex-wrap: wrap; margin-bottom: 17px; }
.tools .btn { border-radius: var(--radius); }

.inline-form { display: inline-flex; align-items: center; gap: 6px; }
.inline-form select {
    padding: 5px 9px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
}
.inline-form input.input-inline {
    width: 152px;
    padding: 5px 9px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
}
.inline-form input.input-inline:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px var(--green-soft);
}

/* ปุ่มกรองในหัวการ์ด (หน้าบันทึกการใช้งาน)
   เป็นลิงก์ไม่ใช่ฟอร์ม เพราะการกรองไม่เปลี่ยนแปลงข้อมูล และแชร์ URL ได้ */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--line-2);
    border-radius: 99px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 500;
}
.chip:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.chip .n { color: var(--text-3); font-family: var(--mono); font-size: 11.5px; }
.chip.is-on { border-color: var(--green-2); background: var(--green); color: #fff; }
.chip.is-on:hover { background: var(--green-2); color: #fff; }
.chip.is-on .n { color: rgba(255, 255, 255, .8); }

/* ค่าก่อน → หลัง ในบันทึกการใช้งาน */
.diff { margin: 0; padding: 0; list-style: none; font-size: 12.5px; }
.diff li {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 5px;
    padding: 1px 0;
}
.diff .f { color: var(--text-2); font-weight: 600; }
.diff .from, .diff .to { font-family: var(--mono); word-break: break-word; }
.diff .from { color: var(--text-3); text-decoration: line-through; }
.diff .to   { color: var(--text); }
.diff .arrow { color: var(--text-3); }

/* บรรทัดรองใต้ค่าหลักในตาราง เช่น IP ใต้ชื่อผู้ใช้ */
.sub-line { font-size: 11.5px; margin-top: 2px; }

.head-note { color: var(--text-3); font-size: 12.5px; font-weight: 400; }
.txt-ok  { color: var(--green-2); font-weight: 600; white-space: nowrap; }
.txt-bad { color: var(--danger); font-weight: 600; white-space: nowrap; }
.muted { color: var(--text-3); }
.mono  { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; }
.dot.on  { background: var(--green); }
.dot.off { background: var(--text-3); }

/* ============================================================
   จอเล็ก
   ============================================================ */

@media (max-width: 1000px) {
    /* sidebar เลื่อนออกนอกจอ เปิดด้วยปุ่มเมนู */
    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-lg);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    .content { margin-left: 0; }
    .menu-btn { display: inline-flex; }
    .topbar { padding: 0 16px; }
    .main { padding: 18px 16px 44px; }
    .footer { padding: 14px 16px 20px; }
    .table-scroll { max-height: none; }
}

@media (max-width: 720px) {
    /* ตารางกลายเป็นการ์ดต่อแถว อ่านบนมือถือได้ */
    table.data thead { display: none; }
    table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
    table.data tr {
        /* ต้องเป็น auto ไม่ใช่ 100% — margin ไม่ถูกนับรวมใน width ไม่ว่าจะตั้ง
           box-sizing แบบไหน การ์ดจึงกว้างเป็น 100% + margin ซ้ายขวา แล้วล้น
           ออกไปทางขวา 10px (ขอบซ้ายยังดูปกติ เห็นเป็นระยะขวาหายไปอย่างเดียว)
           width: auto ปล่อยให้ block หักระยะ margin ให้เอง ได้เท่ากันทั้งสองข้าง */
        width: auto;
        margin: 10px;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: var(--surface);
        box-shadow: var(--shadow);
        overflow: hidden;
    }
    table.data td {
        display: flex;
        justify-content: space-between;
        gap: 14px;
        padding: 9px 13px;
        text-align: right;
    }
    table.data td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--text-2);
        font-size: 12px;
        font-weight: 600;
        text-align: left;
    }
    table.data td:empty { display: none; }
    table.data td.actions { justify-content: flex-end; }

    /* ชิปกรองรวมกันยาวเกินหนึ่งบรรทัดบนจอแคบอยู่แล้ว บังคับให้ลงบรรทัดของตัวเอง
       เต็มความกว้างเสมอ ไม่งั้นบางความกว้างชิปตัวแรกจะไปแปะท้ายชื่อการ์ด
       แล้วที่เหลือตกบรรทัดถัดไป ดูเหมือนจัดเรียงพลาด */
    .card-head .chips { width: 100%; }
    .spec li { flex-direction: column; gap: 2px; }
    .spec .k { flex-basis: auto; }
    .stat .value { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
