@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800&display=swap');

/* ══════════════════════════════════════════════════════
   VARIABLES
══════════════════════════════════════════════════════ */
:root {
    --primary:        #00104b;
    --primary-hover:  #001f8a;
    --secondary:      #0058f0;
    --white:          #ffffff;
    --bg:             #f0f4fb;
    --ink:            #101828;
    --muted:          #667085;
    --line:           #e6eaf2;
    --soft:           #f3f7ff;

    --sidebar-w:      260px;
    --topbar-h:       64px;

    --radius-sm:      8px;
    --radius-md:      14px;
    --radius-lg:      20px;

    --fs-xs:  11px;
    --fs-sm:  13px;
    --fs-md:  15px;
    --fs-lg:  17px;
    --fs-xl:  20px;
    --fs-xxl: 26px;

    --fw-sm:       400;
    --fw-md:       500;
    --fw-semibold: 600;
    --fw-lg:       700;

    --shadow-sm: 0 2px 8px rgba(0,16,75,.06);
    --shadow-md: 0 6px 24px rgba(0,16,75,.09);
    --shadow-lg: 0 14px 40px rgba(0,16,75,.13);

    --success: #16a34a;
    --warning: #d97706;
    --danger:  #dc2626;
    --info:    #0891b2;
}

/* ══════════════════════════════════════════════════════
   RESET
══════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Noto Sans Thai', system-ui, sans-serif;
    font-size: var(--fs-md);
    color: var(--ink);
    background: var(--bg);
    line-height: 1.6;
}

a { text-decoration: none; color: var(--secondary); }
a:hover { color: var(--primary); }
img { max-width: 100%; display: block; }

/* ══════════════════════════════════════════════════════
   LOGIN PAGE
══════════════════════════════════════════════════════ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #00104b 0%, #0041c2 100%);
}

.login-card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo h1 {
    font-size: var(--fs-xl);
    font-weight: var(--fw-lg);
    color: var(--primary);
    margin-top: 12px;
}
.login-logo p {
    font-size: var(--fs-sm);
    color: var(--muted);
}

/* ══════════════════════════════════════════════════════
   ADMIN LAYOUT
══════════════════════════════════════════════════════ */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ───────────────────────────────────────── */
.admin-sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform .3s ease;
}

.sidebar-brand {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sidebar-brand .brand-icon {
    width: 38px; height: 38px;
    background: var(--secondary);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sidebar-brand .brand-icon i { font-size: 18px; color: #fff; }

.sidebar-brand .brand-text h2 {
    font-size: var(--fs-md);
    font-weight: var(--fw-lg);
    color: #fff;
    line-height: 1.2;
}
.sidebar-brand .brand-text span {
    font-size: var(--fs-xs);
    color: rgba(255,255,255,.55);
}

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-section-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: rgba(255,255,255,.35);
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 16px 20px 6px;
}

.nav-item { position: relative; }

.nav-link-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: rgba(255,255,255,.72);
    font-size: var(--fs-sm);
    font-weight: var(--fw-md);
    border-radius: 0;
    transition: background .15s, color .15s;
    cursor: pointer;
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.nav-link-item i.nav-icon {
    font-size: 17px;
    width: 20px;
    flex-shrink: 0;
}

.nav-link-item:hover {
    background: rgba(255,255,255,.09);
    color: #fff;
}

.nav-link-item.active {
    background: var(--secondary);
    color: #fff;
}

.nav-link-item .nav-arrow {
    margin-left: auto;
    font-size: 12px;
    transition: transform .25s;
}

.nav-item.open > .nav-link-item .nav-arrow {
    transform: rotate(90deg);
}

/* Sub nav */
.nav-sub {
    display: none;
    background: rgba(0,0,0,.18);
    padding: 4px 0;
}
.nav-item.open .nav-sub { display: block; }

.nav-sub-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px 8px 50px;
    color: rgba(255,255,255,.6);
    font-size: var(--fs-sm);
    text-decoration: none;
    transition: color .15s, background .15s;
}
.nav-sub-link:hover,
.nav-sub-link.active {
    color: #fff;
    background: rgba(255,255,255,.07);
}
.nav-sub-link::before {
    content: "";
    width: 5px; height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user .user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--secondary);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: var(--fs-sm);
    font-weight: var(--fw-lg);
    flex-shrink: 0;
}
.sidebar-user .user-info {
    flex: 1;
    min-width: 0;
}
.sidebar-user .user-info .user-name {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user .user-info .user-role {
    font-size: var(--fs-xs);
    color: rgba(255,255,255,.45);
}
.sidebar-user .btn-logout {
    color: rgba(255,255,255,.45);
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    transition: color .15s;
    flex-shrink: 0;
}
.sidebar-user .btn-logout:hover { color: #f87171; }

/* ─── Main area ─────────────────────────────────────── */
.admin-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ─── Topbar ─────────────────────────────────────────── */
.admin-topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.topbar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--primary);
    cursor: pointer;
    padding: 4px;
}

.topbar-title {
    flex: 1;
}
.topbar-title h1 {
    font-size: var(--fs-lg);
    font-weight: var(--fw-lg);
    color: var(--primary);
    line-height: 1.2;
    margin: 0;
}
.topbar-title .breadcrumb-sm {
    font-size: var(--fs-xs);
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 4px;
}
.topbar-title .breadcrumb-sm a { color: var(--secondary); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ─── Content ───────────────────────────────────────── */
.admin-content {
    flex: 1;
    padding: 28px;
}

/* ══════════════════════════════════════════════════════
   COMMON COMPONENTS
══════════════════════════════════════════════════════ */

/* Stat Cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    border: 1px solid var(--line);
    transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-icon {
    width: 46px; height: 46px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-icon.blue   { background: #eff6ff; color: #2563eb; }
.stat-icon.green  { background: #f0fdf4; color: #16a34a; }
.stat-icon.orange { background: #fff7ed; color: #ea580c; }
.stat-icon.red    { background: #fef2f2; color: #dc2626; }
.stat-icon.purple { background: #faf5ff; color: #7c3aed; }
.stat-icon.cyan   { background: #ecfeff; color: #0891b2; }

.stat-body { flex: 1; min-width: 0; }
.stat-label {
    font-size: var(--fs-xs);
    color: var(--muted);
    font-weight: var(--fw-md);
    margin-bottom: 4px;
}
.stat-value {
    font-size: var(--fs-xl);
    font-weight: var(--fw-lg);
    color: var(--primary);
    line-height: 1;
}

/* Cards / Panels */
.panel {
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--line);
    overflow: hidden;
    margin-bottom: 24px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    gap: 12px;
}
.panel-header h2 {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    color: var(--primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.panel-header h2 i { font-size: 18px; color: var(--secondary); }

.panel-body { padding: 20px; }
.panel-body.p-0 { padding: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
}
.data-table thead tr { background: #f8faff; }
.data-table thead th {
    padding: 12px 14px;
    text-align: left;
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--muted);
    letter-spacing: .04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.data-table tbody tr {
    border-bottom: 1px solid #f1f4fb;
    transition: background .12s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: #f8faff; }
.data-table tbody td {
    padding: 12px 14px;
    vertical-align: middle;
    color: var(--ink);
}

/* Badges */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    white-space: nowrap;
}
.badge-status.active   { background: #f0fdf4; color: #16a34a; }
.badge-status.inactive { background: #f9fafb; color: #6b7280; }
.badge-status.warning  { background: #fff7ed; color: #ea580c; }
.badge-status.danger   { background: #fef2f2; color: #dc2626; }
.badge-status.info     { background: #eff6ff; color: #2563eb; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    cursor: pointer;
    border: none;
    transition: background .15s, transform .1s, box-shadow .15s;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

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

.btn-secondary-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}
.btn-secondary-outline:hover { background: var(--primary); color: #fff; }

.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }

.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-warning { background: #d97706; color: #fff; }
.btn-warning:hover { background: #b45309; color: #fff; }

.btn-light {
    background: #f3f7ff;
    color: var(--primary);
    border: 1px solid var(--line);
}
.btn-light:hover { background: var(--line); }

.btn-sm { padding: 6px 12px; font-size: var(--fs-xs); }
.btn-icon {
    width: 32px; height: 32px;
    padding: 0;
    justify-content: center;
    border-radius: var(--radius-sm);
}
.btn-icon.btn-sm { width: 28px; height: 28px; }

/* Forms */
.form-group { margin-bottom: 18px; }
.form-label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--ink);
    margin-bottom: 6px;
}
.form-label .req { color: #dc2626; margin-left: 2px; }

.form-control, .form-select {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    color: var(--ink);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
    line-height: 1.5;
}
.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(0,88,240,.10);
}
.form-control::placeholder { color: #b5bdc9; }
.form-control.is-invalid { border-color: #dc2626; }

.form-hint {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 4px;
}

/* Input with icon */
.input-icon-wrap {
    position: relative;
}
.input-icon-wrap .form-control { padding-left: 40px; }
.input-icon-wrap .input-icon {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 16px;
    pointer-events: none;
}

/* Scan bar */
.scan-bar {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.scan-bar .form-control { flex: 1; }
.scan-bar .btn-scan {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 16px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background .15s;
}
.scan-bar .btn-scan:hover { background: var(--secondary); }

/* Product found card */
.product-found-card {
    background: #f0fdf4;
    border: 1.5px solid #bbf7d0;
    border-radius: var(--radius-md);
    padding: 16px 20px;
    margin-bottom: 20px;
    display: flex;
    gap: 14px;
    align-items: center;
}
.product-found-card .pf-icon {
    width: 42px; height: 42px;
    border-radius: 10px;
    background: #16a34a;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 18px;
    flex-shrink: 0;
}
.product-found-card .pf-info .pf-name {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    color: var(--primary);
}
.product-found-card .pf-info .pf-meta {
    font-size: var(--fs-xs);
    color: var(--muted);
}

/* Product not found */
.product-not-found {
    background: #fef2f2;
    border: 1.5px solid #fecaca;
    border-radius: var(--radius-md);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #dc2626;
    font-size: var(--fs-sm);
    margin-bottom: 16px;
}

/* Lot Table */
.lot-table-wrap {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

/* Expiry badges */
.expiry-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
}
.expiry-badge.expired  { background: #fef2f2; color: #dc2626; }
.expiry-badge.d7       { background: #fef2f2; color: #dc2626; }
.expiry-badge.d15      { background: #fff7ed; color: #ea580c; }
.expiry-badge.d30      { background: #fefce8; color: #ca8a04; }
.expiry-badge.ok       { background: #f0fdf4; color: #16a34a; }

/* Tabs */
.nav-tabs-custom {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--line);
    margin-bottom: 24px;
}
.nav-tabs-custom .tab-btn {
    padding: 10px 18px;
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color .15s, border-color .15s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-tabs-custom .tab-btn:hover { color: var(--primary); }
.nav-tabs-custom .tab-btn.active {
    color: var(--secondary);
    border-bottom-color: var(--secondary);
}

/* Toast / Alert */
.toast-container-custom {
    position: fixed;
    top: 80px; right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast-msg {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: 12px 16px;
    min-width: 280px;
    max-width: 360px;
    animation: toastIn .25s ease;
}
.toast-msg.success { border-left: 4px solid #16a34a; }
.toast-msg.error   { border-left: 4px solid #dc2626; }
.toast-msg.warning { border-left: 4px solid #d97706; }
.toast-msg i { font-size: 18px; flex-shrink: 0; }
.toast-msg.success i { color: #16a34a; }
.toast-msg.error   i { color: #dc2626; }
.toast-msg.warning i { color: #d97706; }
.toast-msg .toast-text { flex: 1; font-size: var(--fs-sm); color: var(--ink); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}
.empty-state i {
    font-size: 48px;
    color: #c9d4eb;
    margin-bottom: 16px;
    display: block;
}
.empty-state h3 {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    color: var(--muted);
    margin-bottom: 6px;
}
.empty-state p { font-size: var(--fs-sm); color: #b5bdc9; }

/* Search/Filter bar */
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.filter-bar .form-control,
.filter-bar .form-select { width: auto; min-width: 160px; }

/* Stock amount highlight */
.stock-num {
    font-weight: var(--fw-lg);
    color: var(--primary);
}
.stock-num.low  { color: #dc2626; }
.stock-num.warn { color: #d97706; }
.stock-num.ok   { color: #16a34a; }

/* Chart container */
.chart-container {
    position: relative;
    height: 280px;
}

/* Modal override */
.modal-header { background: var(--primary); }
.modal-title { color: #fff; font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.btn-close-white { filter: invert(1) grayscale(1) brightness(2); }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ══════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════ */
@media (max-width: 1199px) {
    .stat-cards { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 991px) {
    :root { --sidebar-w: 0px; }

    .admin-sidebar {
        width: 260px;
        transform: translateX(-260px);
    }
    .admin-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 30px rgba(0,0,0,.25);
    }
    .admin-main { margin-left: 0; }
    .topbar-toggle { display: flex; }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.45);
        z-index: 999;
    }
    .sidebar-overlay.show { display: block; }

    .admin-content { padding: 16px; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 576px) {
    .stat-cards { grid-template-columns: 1fr 1fr; }
    .panel-header { flex-wrap: wrap; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .form-control,
    .filter-bar .form-select { width: 100%; }
}
