/* ============================================================
   Dashboard Design Tokens
   Palette: steel-slate sidebar + warehouse amber accent + steel-blue info
   Type: Kanit (display/แบรนด์) + Sarabun (เนื้อหา) + JetBrains Mono (ตัวเลข KPI)
   Signature: กราฟกึ่งเกจ + เส้นแบ่ง "pipeline" จุดไข่ปลาแทนสาย valve เชื่อมโมดูล
   ============================================================ */

:root {
    --color-bg: #F5F6F8;
    --color-surface: #FFFFFF;
    --color-border: #E3E6EB;
    --color-text: #1C2333;
    --color-text-muted: #6B7280;
    --color-sidebar-bg: #0C367F;
    --color-sidebar-bg-deep: #082554;
    --color-sidebar-text: #A9BEDD;
    --color-sidebar-text-active: #FFFFFF;
    --color-accent: #E8912B;
    --color-accent-soft: #FDF1E1;
    --color-info: #319BD0;
    --color-info-soft: #E7F3FA;
    --color-success: #009788;
    --color-success-soft: #E1F5F2;
    --color-danger: #AD2547;
    --color-danger-soft: #FBEAEE;
    --font-display: 'Kanit', 'Sarabun', sans-serif;
    --font-body: 'Sarabun', 'Noto Sans Thai', sans-serif;
    --font-mono: 'JetBrains Mono', 'Roboto Mono', monospace;
}

* { box-sizing: border-box; }

body.dashboard-body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
}

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

/* ---------- Sidebar ---------- */
.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--color-sidebar-bg);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width 0.18s ease;
    overflow: hidden;
}
html.sidebar-collapsed .sidebar { width: 72px; }

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
html.sidebar-collapsed .sidebar-brand { flex-direction: column; padding: 16px 10px; gap: 12px; }

.sidebar-brand .brand-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
html.sidebar-collapsed .sidebar-brand .brand-identity { flex-direction: column; }

.sidebar-brand .logo-plate {
    background: #fff;
    border-radius: 8px;
    padding: 7px 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-brand .logo-plate img { display: block; height: 30px; width: auto; }
html.sidebar-collapsed .sidebar-brand .logo-plate img { height: 22px; }
.sidebar-brand small { font-size: 11px; color: var(--color-sidebar-text); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.sidebar-collapsed .sidebar-brand small { display: none; }

.sidebar-toggle-btn {
    background: rgba(255,255,255,0.08);
    border: none; color: #fff;
    width: 26px; height: 26px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0; padding: 0;
}
.sidebar-toggle-btn:hover { background: rgba(255,255,255,0.18); }
.sidebar-toggle-btn .icon { width: 15px; height: 15px; transition: transform 0.18s ease; }
html.sidebar-collapsed .sidebar-toggle-btn .icon { transform: rotate(180deg); }

.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; overflow-x: hidden; }
.nav-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.35);
    padding: 16px 12px 6px;
    white-space: nowrap;
}
html.sidebar-collapsed .nav-section-label {
    height: 1px; padding: 0; margin: 12px 10px; background: rgba(255,255,255,0.1);
    font-size: 0; overflow: hidden; color: transparent;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--color-sidebar-text);
    text-decoration: none;
    font-size: 14px;
    margin-bottom: 2px;
    border-left: 3px solid transparent;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}
html.sidebar-collapsed .nav-item { justify-content: center; padding: 10px 6px; }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; }
html.sidebar-collapsed .nav-item .nav-label { display: none; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active {
    background: rgba(232,145,43,0.14);
    color: var(--color-sidebar-text-active);
    border-left-color: var(--color-accent);
    font-weight: 500;
}
html.sidebar-collapsed .nav-item.active { border-left-color: transparent; box-shadow: inset 0 0 0 1.5px var(--color-accent); }

.sidebar-footer {
    padding: 14px 16px 18px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 13px;
}
html.sidebar-collapsed .sidebar-footer { padding: 14px 8px 18px; }
.sidebar-footer .user-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
html.sidebar-collapsed .sidebar-footer .user-row { justify-content: center; margin-bottom: 12px; }
.sidebar-footer .user-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--color-info);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display); font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.sidebar-footer .user-text { min-width: 0; }
html.sidebar-collapsed .sidebar-footer .user-text { display: none; }
.sidebar-footer .user-name { color: #fff; font-weight: 500; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .user-role { color: rgba(255,255,255,0.45); font-size: 11px; }
.sidebar-footer a.logout-link {
    display: flex; align-items: center; gap: 8px;
    color: var(--color-sidebar-text); text-decoration: none; font-size: 13px;
    padding: 6px 2px;
    white-space: nowrap;
}
html.sidebar-collapsed .sidebar-footer a.logout-link { justify-content: center; padding: 6px; }
html.sidebar-collapsed .sidebar-footer a.logout-link .nav-label { display: none; }
.sidebar-footer a.logout-link:hover { color: #fff; }
.sidebar-footer .icon { width: 16px; height: 16px; }

/* ---------- Main area ---------- */
.main-area { flex: 1; min-width: 0; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 22px 32px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.topbar h1 {
    font-family: var(--font-display);
    font-size: 21px; font-weight: 600; margin: 0;
    letter-spacing: -0.01em;
}
.topbar .topbar-sub { font-size: 13px; color: var(--color-text-muted); margin-top: 2px; }
.topbar-meta { text-align: right; font-size: 13px; color: var(--color-text-muted); }
.topbar-meta strong { color: var(--color-text); font-family: var(--font-mono); }

.dashboard-content { padding: 28px 32px 48px; max-width: 1280px; }

/* ---------- Pending approval banner ---------- */
.pending-banner {
    background: var(--color-accent-soft);
    border: 1px solid #F3D6A8;
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 22px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.pending-banner .icon { width: 20px; height: 20px; color: var(--color-accent); flex-shrink: 0; margin-top: 2px; }
.pending-banner strong { font-family: var(--font-display); font-size: 14px; }
.pending-banner ul { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.pending-banner li a {
    display: inline-block; background: #fff; border: 1px solid #F3D6A8; border-radius: 6px;
    padding: 5px 10px; font-size: 12.5px; color: var(--color-text); text-decoration: none;
}
.pending-banner li a:hover { border-color: var(--color-accent); }

/* ---------- KPI Grid (signature: gauge-plate cards) ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
}
.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-border);
    border-radius: 10px;
    padding: 16px 18px;
    position: relative;
}
.kpi-card.tone-amber { border-left-color: var(--color-accent); }
.kpi-card.tone-blue { border-left-color: var(--color-info); }
.kpi-card.tone-green { border-left-color: var(--color-success); }
.kpi-card.tone-red { border-left-color: var(--color-danger); }
.kpi-card .kpi-label {
    font-size: 12.5px; color: var(--color-text-muted);
    display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
}
.kpi-card .kpi-label .icon { width: 15px; height: 15px; }
.kpi-card .kpi-value {
    font-family: var(--font-mono); font-size: 26px; font-weight: 600;
    line-height: 1.1; color: var(--color-text);
}
.kpi-card .kpi-value .kpi-unit { font-size: 13px; font-weight: 500; color: var(--color-text-muted); margin-left: 4px; }
.kpi-card .kpi-foot { font-size: 11.5px; color: var(--color-text-muted); margin-top: 6px; }

/* ---------- Pipeline divider (signature flourish) ---------- */
.pipeline-divider {
    display: flex; align-items: center; gap: 6px;
    margin: 26px 0 22px;
}
.pipeline-divider .line {
    flex: 1; height: 2px;
    background-image: linear-gradient(to right, var(--color-border) 55%, transparent 0%);
    background-size: 9px 2px; background-repeat: repeat-x;
}
.pipeline-divider .node {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-soft);
    flex-shrink: 0;
}
.pipeline-divider .label {
    font-family: var(--font-display); font-size: 12.5px; font-weight: 500;
    color: var(--color-text-muted); white-space: nowrap; padding: 0 4px;
}

/* ---------- Panels / two-column layout ---------- */
.dashboard-columns {
    display: grid;
    grid-template-columns: 1.1fr 1.4fr;
    gap: 18px;
    align-items: start;
}
@media (max-width: 900px) { .dashboard-columns { grid-template-columns: 1fr; } }

.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 18px 20px;
}
.panel h2 {
    font-family: var(--font-display); font-size: 15px; font-weight: 600;
    margin: 0 0 14px; display: flex; align-items: center; gap: 8px;
}
.panel h2 .icon { width: 17px; height: 17px; color: var(--color-accent); }

.quick-actions { display: flex; flex-direction: column; gap: 8px; }
.quick-action {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 12px; border-radius: 8px;
    border: 1px solid var(--color-border);
    text-decoration: none; color: var(--color-text); font-size: 13.5px;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.quick-action .icon { width: 17px; height: 17px; color: var(--color-info); flex-shrink: 0; }
.quick-action:hover { border-color: var(--color-info); background: var(--color-info-soft); }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li {
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 0; border-bottom: 1px solid var(--color-border); font-size: 13px;
}
.mini-list li:last-child { border-bottom: none; }
.mini-list .mini-name { color: var(--color-text); }
.mini-list .mini-code { color: var(--color-text-muted); font-size: 11.5px; font-family: var(--font-mono); }
.mini-list .mini-qty { font-family: var(--font-mono); font-weight: 600; }

.activity-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.activity-table th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--color-text-muted); padding: 0 10px 8px; border-bottom: 1px solid var(--color-border);
}
.activity-table td { padding: 9px 10px; border-bottom: 1px solid var(--color-border); }
.activity-table tr:last-child td { border-bottom: none; }
.activity-table .qty-in { color: var(--color-success); font-family: var(--font-mono); font-weight: 600; }
.activity-table .qty-out { color: var(--color-danger); font-family: var(--font-mono); font-weight: 600; }
.trans-type-chip {
    font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 500;
    background: var(--color-info-soft); color: var(--color-info);
}
.empty-panel { color: var(--color-text-muted); font-size: 13px; text-align: center; padding: 24px 0; }

/* ---------- Signature Pad (ลายเซ็นดิจิทัลผ่าน Tablet) ---------- */
.signature-box {
    border: 1.5px dashed var(--color-border);
    border-radius: 10px;
    background: #FBFCFD;
    padding: 4px;
}
.signature-canvas {
    width: 100%; height: 160px; display: block;
    touch-action: none; cursor: crosshair;
    background: #fff; border-radius: 7px;
}
.signature-canvas.has-signature { border-color: var(--color-success); }
.signature-hint { font-size: 12px; color: var(--color-text-muted); text-align: center; margin-top: 6px; }
.signature-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.signature-name { font-family: var(--font-display); font-size: 13px; color: var(--color-text); }

/* ---------- Barcode Scan (คลังยิงบาร์โค้ดจับคู่รายการเบิก) ---------- */
.scan-input-row { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; }
.scan-input-row input[type="text"] {
    flex: 1; padding: 13px 14px; font-size: 16px; font-family: var(--font-mono);
    border: 2px solid var(--color-info); border-radius: 8px;
}
.scan-input-row input[type="text"]:focus { outline: none; box-shadow: 0 0 0 3px var(--color-info-soft); }
.scan-progress {
    display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
    font-size: 13px; color: var(--color-text-muted);
}
.scan-progress-bar { flex: 1; height: 8px; background: var(--color-border); border-radius: 4px; overflow: hidden; }
.scan-progress-bar-fill { height: 100%; background: var(--color-success); width: 0%; transition: width 0.2s ease; }
.scan-row { transition: background 0.2s ease; }
.scan-row.matched { background: var(--color-success-soft); }
.scan-row .scan-status { font-size: 12px; font-weight: 500; }
.scan-row.matched .scan-status { color: var(--color-success); }
.scan-feedback {
    padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 14px; display: none;
}
.scan-feedback.show-ok { display: block; background: var(--color-success-soft); color: var(--color-success); }
.scan-feedback.show-err { display: block; background: var(--color-danger-soft); color: var(--color-danger); }
.stock-check-badge { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; font-weight: 500; margin-left: 6px; }
.stock-check-badge.ok { background: var(--color-success-soft); color: var(--color-success); }
.stock-check-badge.low { background: var(--color-danger-soft); color: var(--color-danger); }
.stock-check-badge.loading { background: var(--color-bg); color: var(--color-text-muted); }
