/* CafeStock - warm cafe theme */
:root {
    --coffee-900: #2b1d14;
    --coffee-800: #3b271a;
    --coffee-700: #4e3524;
    --coffee-500: #8b5e3c;
    --coffee-300: #c9a37a;
    --cream-50:   #fbf6ee;
    --cream-100:  #f5ecdc;
    --cream-200:  #ecdfc8;
    --accent:     #c97a3c;
    --accent-hover:#b3672e;
    --success-bg: #e7f6ec;
    --danger-bg:  #fbecec;
    --info-bg:    #e8f1fb;
    --warn-bg:    #fff5e0;
    --border:     #e3d8c4;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--cream-50);
    color: var(--coffee-900);
    font-size: 1rem;       /* 16px base */
    line-height: 1.5;
}
.small, small { font-size: 0.85rem; }   /* ~13.6px */

/* ============= GLOBAL THIN SCROLLBARS ============= */
/* Applies to page body, modals, tables, and any overflowing element */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 94, 60, 0.35) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: rgba(0,0,0,0.04); }
*::-webkit-scrollbar-thumb {
    background: rgba(139, 94, 60, 0.35);
    border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(139, 94, 60, 0.6); }

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

/* ============= SIDEBAR ============= */
.sidebar {
    width: 240px;
    background: var(--coffee-800);
    color: #f4e7d6;
    padding: 20px 0 0;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Brand at top */
.sidebar .brand {
    flex-shrink: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
    padding: 0 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar .brand i { color: var(--accent); }

/* Scrollable nav area in the middle.
   IMPORTANT: plain block layout, NOT flex. Bootstrap's .nav class was
   forcing horizontal layout on some browsers / cached states. */
.sidebar-nav {
    flex: 1 1 auto;
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0 12px;
    margin: 0;
    min-height: 0;
    /* Firefox thin scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}
/* Chrome / Edge / Safari thin scrollbar */
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }

/* Section labels inside nav */
.sidebar .side-section {
    display: block;
    width: 100%;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.5);
    padding: 16px 20px 6px;
}

/* Nav links inside nav — full-width blocks, never wrap */
.sidebar .side-link {
    display: block;
    width: 100%;
    padding: 10px 20px;
    color: #e9d9be;
    font-size: 1rem;
    text-decoration: none;
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar .side-link i {
    display: inline-block;
    width: 18px;
    margin-right: 8px;
    text-align: center;
}
.sidebar .side-link:hover {
    background: rgba(255,255,255,0.05);
    color: #fff;
}
.sidebar .side-link.active {
    background: var(--coffee-900);
    color: #fff;
    border-left-color: var(--accent);
    font-weight: 500;
}

/* Footer pinned at the bottom */
.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 12px 16px 14px;
    background: var(--coffee-900);
}
.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 4px 10px;
}
.sidebar-footer .user-info i {
    font-size: 1.7rem;
    color: var(--accent);
    flex-shrink: 0;
}
.sidebar-footer .user-meta { line-height: 1.2; min-width: 0; }
.sidebar-footer .user-name {
    font-weight: 600;
    color: #fff;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-footer .user-role {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.55);
    text-transform: capitalize;
    letter-spacing: 0.3px;
}
.sidebar-footer .logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    background: rgba(214,70,58,0.15);
    color: #ffb3ad;
    border: 1px solid rgba(214,70,58,0.3);
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s;
}
.sidebar-footer .logout-btn:hover {
    background: #d6463a;
    color: #fff;
    border-color: #d6463a;
}
.sidebar-footer .logout-btn i { font-size: 1rem; }

/* ============= MAIN ============= */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.topbar {
    background: #fff;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.page-title {
    font-size: 1.5rem;        /* 24px */
    margin: 0;
    color: var(--coffee-900);
    font-weight: 600;
}
.page-body {
    padding: 24px;
}

/* ============= CARDS ============= */
.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 18px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
    height: 100%;
}
.stat-card .label {
    font-size: 0.85rem;       /* 13.6px */
    color: #7a6a55;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.stat-card .value {
    font-size: 2rem;          /* 32px */
    font-weight: 700;
    color: var(--coffee-900);
    line-height: 1.1;
}
.value-suffix {
    font-size: 0.45em;        /* relative — sits at ~14.4px when value is 32px */
    font-weight: 500;
    color: var(--coffee-500);
    margin-left: 6px;
    text-transform: lowercase;
    letter-spacing: 0.3px;
    vertical-align: 0.25em;
}
.stat-card .sub {
    font-size: 0.85rem;       /* 13.6px */
    color: #9b8a73;
    margin-top: 6px;
}
.stat-card.input  { border-top: 3px solid #2e9e57; }
.stat-card.output { border-top: 3px solid #2e6cd6; }
.stat-card.consumption { border-top: 3px solid #18a2b8; }
.stat-card.wastage { border-top: 3px solid #d6463a; }
.stat-card.remaining { border-top: 3px solid var(--accent); }

.content-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.content-card .card-title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.content-card h2 {
    font-size: 1.15rem;       /* 18.4px */
    margin: 0;
    font-weight: 600;
    color: var(--coffee-800);
}

/* ============= TABLES ============= */
.table {
    font-size: 0.95rem;       /* 15.2px - readable but slightly tighter than body */
    margin-bottom: 0;
}
.table thead th {
    background: var(--cream-100);
    color: var(--coffee-800);
    font-size: 0.8rem;        /* 12.8px - headers stay small */
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 2px solid var(--border) !important;
    padding: 12px;
    font-weight: 600;
}
.table tbody td { padding: 12px; vertical-align: middle; }
.table tbody tr:hover { background: var(--cream-50); }

/* Sortable column headers */
.table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
    padding-right: 22px;
    position: relative;
}
.table thead th.sortable:hover { background: var(--cream-200); }
.table thead th .sort-arrow {
    margin-left: 4px;
    opacity: 0.4;
    font-size: 0.85em;
    display: inline-block;
    transition: opacity 0.15s;
}
.table thead th.sortable:hover .sort-arrow { opacity: 0.75; }
.table thead th.sort-asc, .table thead th.sort-desc { background: var(--cream-200); color: var(--coffee-900); }
.table thead th.sort-asc .sort-arrow, .table thead th.sort-desc .sort-arrow {
    opacity: 1;
    color: var(--accent);
}

/* Tom Select - cafe theme override */
.ts-wrapper .ts-control {
    border-color: var(--border) !important;
    font-size: 1rem;
    padding: 7px 12px;
    min-height: 40px;
}
.ts-wrapper.focus .ts-control,
.ts-wrapper .ts-control:focus-within {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 0.18rem rgba(201,122,60,0.18) !important;
}
.ts-dropdown { border-color: var(--border) !important; }
.ts-dropdown .active { background: var(--accent) !important; color: #fff !important; }
.ts-dropdown .option { padding: 8px 12px; font-size: 0.95rem; }
.ts-wrapper.single .ts-control { background: #fff !important; }
.table-responsive {
    border: 1px solid var(--border);
    border-radius: 8px;
    /* Bootstrap's .table-responsive already sets overflow-x: auto; we just style the scrollbar */
    -webkit-overflow-scrolling: touch;
}
.table-responsive::-webkit-scrollbar { height: 8px; }
.table-responsive::-webkit-scrollbar-thumb { background: var(--coffee-300); border-radius: 4px; }
.table-responsive::-webkit-scrollbar-track  { background: var(--cream-100); }
/* Sticky first column on mobile so item name stays visible while scrolling */
@media (max-width: 768px) {
    .table-sticky-first thead th:first-child,
    .table-sticky-first tbody td:first-child {
        position: sticky;
        left: 0;
        background: #fff;
        z-index: 2;
        box-shadow: 2px 0 4px rgba(0,0,0,0.04);
        min-width: 130px;
    }
    .table-sticky-first thead th:first-child { background: var(--cream-100); }
    .table-sticky-first tbody tr:hover td:first-child { background: var(--cream-50); }
}

/* ============= BADGES / PILLS ============= */
.badge-type {
    padding: 4px 10px;
    font-size: 0.78rem;       /* 12.5px */
    border-radius: 12px;
    font-weight: 500;
    letter-spacing: 0.3px;
}
.badge-INPUT       { background: var(--success-bg); color: #1e7c43; }
.badge-OUTPUT      { background: var(--info-bg);    color: #1f55ab; }
.badge-CONSUMPTION { background: #d8f0f3;           color: #0e7484; }
.badge-WASTAGE     { background: var(--danger-bg);  color: #a3322a; }
.badge-ADJUSTMENT  { background: var(--warn-bg);    color: #8a5b00; }

.stock-warn { color: #d6463a; font-weight: 600; }
.stock-ok   { color: #2e9e57; font-weight: 600; }

/* ============= FORMS ============= */
.form-label { font-weight: 500; color: var(--coffee-800); font-size: 0.95rem; margin-bottom: 6px; }
.form-control, .form-select {
    border-color: var(--border);
    font-size: 1rem;          /* 16px - prevents iOS Safari auto-zoom on focus */
    padding: 9px 12px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 0.18rem rgba(201,122,60,0.18);
}
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}
.btn-outline-secondary { color: var(--coffee-700); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--cream-100); color: var(--coffee-900); border-color: var(--coffee-300); }

/* ============= MODALS ============= */
.modal-header { background: var(--cream-100); border-bottom: 1px solid var(--border); }
.modal-title { color: var(--coffee-900); font-weight: 600; }

/* ============= RESPONSIVE ============= */

/* Sidebar backdrop (mobile drawer overlay) */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1040;
}
.sidebar-backdrop.show { display: block; }

/* Tablet (≤1024px) */
@media (max-width: 1024px) {
    .page-title { font-size: 1.35rem; }       /* 21.6px */
    .stat-card .value { font-size: 1.75rem; } /* 28px */
    .table { font-size: 0.9rem; }             /* 14.4px */
    .page-body { padding: 18px; }
}

/* Mobile (≤768px) - keep base 16px to prevent iOS input auto-zoom */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        width: 260px;
        transition: left 0.25s ease;
        z-index: 1050;
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    }
    .sidebar.open { left: 0; }

    .topbar { padding: 12px 14px; gap: 10px; }
    .page-title { font-size: 1.2rem; }        /* 19.2px */
    .page-body { padding: 14px; }

    .stat-card { padding: 14px; }
    .stat-card .value { font-size: 1.5rem; }  /* 24px */
    .stat-card .label { font-size: 0.78rem; }

    .content-card { padding: 14px; }
    .content-card h2 { font-size: 1.05rem; }
    .card-title-bar { flex-wrap: wrap; gap: 8px; }

    .table { font-size: 0.9rem; }             /* 14.4px */
    .table thead th, .table tbody td { padding: 10px 8px; white-space: nowrap; }

    /* Keep form inputs at 16px - prevents iOS Safari auto-zoom */
    .form-control, .form-select { font-size: 1rem; }
}

/* Small phones (≤480px) */
@media (max-width: 480px) {
    .stat-card .value { font-size: 1.4rem; }
    .page-title { font-size: 1.1rem; }
    .page-body { padding: 10px; }
    .content-card { padding: 12px; }
    .topbar { padding: 10px 12px; }
}

/* Very small / min support: 360px */
@media (max-width: 380px) {
    html { font-size: 15px; }
    .stat-card { padding: 12px; }
    .stat-card .value { font-size: 1.25rem; }
    .stat-card .sub { font-size: 0.8rem; }
    .table thead th, .table tbody td { padding: 8px 6px; }
    .btn { padding: 6px 10px; }
}

/* Helpers */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: #9b8a73;
}
.empty-state i { font-size: 2.5rem; opacity: 0.4; display: block; margin-bottom: 10px; }
