/* =========================================================================
   Auto Parts Inventory — application shell
   Desktop: fixed left sidebar + topbar. Mobile: off-canvas drawer + bottom nav.
   Theming via Bootstrap's [data-bs-theme].
   ========================================================================= */

:root {
    --brand:        #0f766e;
    --brand-dark:   #115e59;
    --brand-light:  #ccfbf1;
    --sidebar-w:    250px;
    --topbar-h:     58px;
    --bottomnav-h:  60px;
    --app-bg:       #f4f6f8;
    --card-bg:      #ffffff;
    --border:       #e5e7eb;
    --text-muted:   #6b7280;
}

[data-bs-theme="dark"] {
    --app-bg:     #0b1220;
    --card-bg:    #131c2e;
    --border:     #26324a;
    --text-muted: #93a1b5;
}

* { box-sizing: border-box; }

/* User text-size preference: scales every rem-based size (Bootstrap + app). */
:root { --app-font-scale: 1; }
html { font-size: calc(16px * var(--app-font-scale)); }

body {
    margin: 0;
    background: var(--app-bg);
    font-family: "Hind Siliguri", "Segoe UI", system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* --- Appearance preferences (persisted per device) --- */

/* Hide the left sidebar on desktop so the page gets the full width.
   Uses display:none rather than a transform so it is instant and cannot be
   left half-applied if transitions don't run (background tab, reduced-motion). */
@media (min-width: 992px) {
    html.sidebar-hidden .app-sidebar { display: none; }
    html.sidebar-hidden .app-main    { margin-left: 0; }
}

/* Hide navigation icons (sidebar, bottom nav, home grid) — text only. */
html.icons-hidden .app-nav-link i,
html.icons-hidden .app-bottomnav a i,
html.icons-hidden .home-grid a i { display: none; }
html.icons-hidden .home-grid a { padding: 1.1rem .4rem; }

/* Text-size / colour picker in the topbar */
.fc-swatch {
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 2px solid var(--border);
    padding: 0;
    cursor: pointer;
}
.fc-swatch.is-active { outline: 2px solid var(--brand); outline-offset: 2px; }
.fc-swatch--default {
    background: linear-gradient(135deg, #ffffff 0 50%, #212529 50% 100%);
}

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

/* ---------- Sidebar ---------- */
.app-sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 1045;
    transition: transform .25s ease;
}

.app-sidebar__brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 1rem;
    font-weight: 700;
    color: var(--brand);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
}
.app-sidebar__brand i { font-size: 1.4rem; }

.app-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: .5rem;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .8rem;
    border-radius: .5rem;
    color: inherit;
    text-decoration: none;
    font-size: .93rem;
    margin-bottom: 2px;
}
.app-nav-link i { font-size: 1.1rem; width: 1.3rem; text-align: center; color: var(--text-muted); }
.app-nav-link:hover { background: rgba(15,118,110,.08); }
.app-nav-link.is-active { background: var(--brand); color: #fff; }
.app-nav-link.is-active i { color: #fff; }

.app-sidebar__backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1044;
}

/* ---------- Main column ---------- */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: var(--topbar-h);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.app-topbar__title { font-size: 1.1rem; font-weight: 600; margin: 0; flex: 1; }
.app-topbar__actions { display: flex; align-items: center; gap: .25rem; }

.btn-icon {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; background: transparent; border-radius: 50%;
    color: inherit; font-size: 1.15rem;
}
.btn-icon:hover { background: rgba(0,0,0,.06); }
[data-bs-theme="dark"] .btn-icon:hover { background: rgba(255,255,255,.08); }
.lang-pill { font-size: .8rem; font-weight: 700; }

.app-content {
    padding: 1.25rem;
    flex: 1;
}

/* ---------- Bottom nav (mobile) ---------- */
.app-bottomnav {
    position: fixed;
    inset: auto 0 0 0;
    height: var(--bottomnav-h);
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 1040;
    padding-bottom: env(safe-area-inset-bottom);
}
.app-bottomnav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: .68rem;
}
.app-bottomnav a i { font-size: 1.25rem; }
.app-bottomnav a.is-active { color: var(--brand); }

/* ---------- KPI / widget cards ----------
   Fixed layout: 4 per row on desktop, 3 per row on mobile — so each box is
   large and the rows line up predictably. */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);   /* 3 per row — bigger boxes */
    gap: 1.1rem;
}
.kpi-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: .9rem;
    padding: 1.6rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    min-width: 0;                 /* let long amounts shrink instead of overflowing */
}
.kpi-card__icon {
    width: 68px; height: 68px; flex: 0 0 68px;
    border-radius: .8rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; color: #fff;
    background: var(--brand);
}
.kpi-card__label { font-size: 1.25rem; color: var(--text-muted); }
.kpi-card__value { font-size: 2.9rem; font-weight: 700; line-height: 1.15; word-break: break-word; }

.card { background: var(--card-bg); border-color: var(--border); }

/* ---------- Home grid (menu tiles) ----------
   4 per row on desktop, 3 per row on mobile. */
.home-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .85rem;
}
.home-grid a {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: .8rem;
    padding: 1.35rem .5rem;
    text-align: center;
    text-decoration: none;
    color: inherit;
    font-size: .95rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 104px;
}
.home-grid a:hover { border-color: var(--brand); }
.home-grid a i { display: block; font-size: 2rem; margin-bottom: .45rem; color: var(--brand); }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.is-open { transform: translateX(0); }
    .app-sidebar__backdrop.is-open { display: block; }
    .app-main { margin-left: 0; }
    .app-content { padding: 1rem; padding-bottom: calc(var(--bottomnav-h) + 1rem); }

    /* 3 tiles per row on mobile */
    .kpi-grid, .home-grid { grid-template-columns: repeat(3, 1fr); gap: .6rem; }

    /* Stack the KPI card (icon above the text) so it fits the narrower box */
    .kpi-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: .45rem;
        padding: .85rem .45rem;
    }
    .kpi-card__icon { width: 42px; height: 42px; flex: 0 0 42px; font-size: 1.2rem; }
    .kpi-card__label { font-size: .88rem; }
    .kpi-card__value { font-size: 1.4rem; }

    .home-grid a { padding: 1rem .35rem; font-size: .8rem; min-height: 92px; }
    .home-grid a i { font-size: 1.7rem; margin-bottom: .35rem; }
}

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    padding: 1rem;
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card__brand { text-align: center; margin-bottom: 1.5rem; color: var(--brand); }
.login-card__brand i { font-size: 2.5rem; }
