/* ==========================================================================
   Wiikto ERP — Design System
   Premium, minimal, white-surface aesthetic.
   Palette: deep navy (brand/interactive) + muted brass (signature accent)
   on near-white canvas, with a refined neutral scale and quiet semantic
   colors. Manrope for headings, Inter for body/data.
   ========================================================================== */

:root {
    /* Brand */
    --primary: #16324F;
    --primary-dark: #0E2438;
    --accent: #0E7C86;
    --gold: #B08D57;
    --gold-soft: rgba(176, 141, 87, .14);

    /* Semantic */
    --success: #12805C;
    --warning: #B7791F;
    --danger: #C0362C;
    --info: #2C6693;

    /* Surfaces */
    --bg-body: #F7F8FA;
    --bg-glass: #FFFFFF;
    --bg-glass-solid: #FFFFFF;
    --border-glass: #E6E8EC;

    /* Text */
    --text-primary: #101828;
    --text-secondary: #64748B;

    /* Elevation */
    --shadow-glass: 0 1px 2px rgba(16,24,40,.04), 0 4px 12px rgba(16,24,40,.05);
    --shadow-raised: 0 4px 10px rgba(16,24,40,.06), 0 12px 28px rgba(16,24,40,.07);

    --sidebar-width: 264px;
    --topbar-height: 72px;
    --radius-lg: 16px;
    --radius-md: 10px;

    --font-display: 'Manrope', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
    --bg-body: #0B1220;
    --bg-glass: #111927;
    --bg-glass-solid: #111927;
    --border-glass: #22293A;
    --text-primary: #F1F3F7;
    --text-secondary: #8B94A7;
    --shadow-glass: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
    --shadow-raised: 0 8px 24px rgba(0,0,0,.4);
    --gold-soft: rgba(176, 141, 87, .18);
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-body);
    font-size: .925rem;
    background: var(--bg-body);
    color: var(--text-primary);
    transition: background .3s ease, color .3s ease;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    letter-spacing: -.01em;
}

/* Bootstrap variable overrides so native .btn/.badge/.alert utilities pick up
   the same palette automatically, without touching any Blade markup. */
:root, [data-bs-theme] {
    --bs-primary: #16324F;
    --bs-primary-rgb: 22, 50, 79;
    --bs-success: #12805C;
    --bs-success-rgb: 18, 128, 92;
    --bs-danger: #C0362C;
    --bs-danger-rgb: 192, 54, 44;
    --bs-warning: #B7791F;
    --bs-warning-rgb: 183, 121, 31;
    --bs-info: #2C6693;
    --bs-info-rgb: 44, 102, 147;
    --bs-border-radius: var(--radius-md);
    --bs-border-color: var(--border-glass);
    --bs-body-font-family: var(--font-body);
    --bs-link-color: var(--primary);
    --bs-link-hover-color: var(--primary-dark);
}

/* Cards — flat white surfaces, hairline border, soft elevation. No blur,
   no gradient wash: the previous glassmorphism/gradient-blob backdrop is
   gone entirely in favor of quiet, confident whitespace. */
.glass-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-glass);
    transition: box-shadow .2s ease, border-color .2s ease;
}

.glass-card:hover {
    box-shadow: var(--shadow-raised);
    border-color: #D8DBE1;
}

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-glass-solid);
    border-right: 1px solid var(--border-glass);
    z-index: 1030;
    overflow-y: auto;
    transition: transform .3s ease, background .3s ease;
}

.sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 1.5rem;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -.01em;
    border-bottom: 1px solid var(--border-glass);
}

.sidebar-brand .logo-dot {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
}

.nav-section-label {
    text-transform: uppercase;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .09em;
    color: var(--text-secondary);
    padding: 1.1rem 1.5rem .4rem;
}

.nav-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    text-transform: uppercase;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .09em;
    color: var(--text-secondary);
    padding: .75rem 1.5rem;
    cursor: pointer;
    transition: color .15s ease;
}

.nav-section-toggle:hover { color: var(--primary); }

.nav-section-toggle .chevron {
    transition: transform .2s ease;
    font-size: .68rem;
}

.nav-section-toggle[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.nav-section-toggle[aria-expanded="true"] {
    color: var(--primary);
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .6rem 1.5rem;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: .87rem;
    border-left: 2px solid transparent;
    transition: all .15s ease;
}

.sidebar .nav-link:hover {
    background: #F3F4F6;
    color: var(--primary);
}

.sidebar .nav-link.active {
    background: linear-gradient(90deg, var(--gold-soft), transparent);
    color: var(--primary);
    border-left-color: var(--gold);
    font-weight: 700;
}

.sidebar .nav-link i { width: 20px; text-align: center; }

.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin .3s ease;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-glass-solid);
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.global-search {
    background: #F3F4F6;
    border: 1px solid var(--border-glass);
    border-radius: 999px;
    padding: .5rem 1.1rem;
    min-width: 320px;
    display: flex;
    align-items: center;
    gap: .6rem;
}

.global-search input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    width: 100%;
    font-size: .88rem;
}

.icon-btn {
    width: 42px; height: 42px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #F3F4F6;
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    position: relative;
    vertical-align: middle;
    transition: all .15s ease;
}

.icon-btn:hover { background: var(--gold-soft); color: var(--primary); border-color: #D8DBE1; }

/* Action buttons in table rows (edit/delete/etc.) always sit inline on one row,
   even when a delete action is wrapped in its own <form> for the CSRF token. */
.table form {
    display: inline-block;
    vertical-align: middle;
    margin: 0;
}

.table {
    --bs-table-hover-bg: #FAFBFC;
    font-size: .885rem;
}

.table thead th {
    font-family: var(--font-body);
    font-weight: 700;
    text-transform: uppercase;
    font-size: .68rem;
    letter-spacing: .06em;
    border-bottom-width: 1px;
    color: var(--text-secondary);
}

.badge-dot {
    position: absolute;
    top: 6px; right: 8px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--bg-glass-solid);
}

.stat-card {
    padding: 1.4rem;
    border-radius: var(--radius-lg);
}

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #fff;
    box-shadow: 0 4px 10px rgba(22,50,79,.18);
}

.content-area { padding: 1.75rem; }

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--bg-body);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    border-radius: 22px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-raised);
}

.form-control, .form-select {
    background: #FFFFFF;
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: .6rem .9rem;
    font-size: .88rem;
}

.form-control:focus, .form-select:focus {
    background: #FFFFFF;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(22,50,79,.1);
    color: var(--text-primary);
}

.form-label { font-weight: 600; font-size: .82rem; color: var(--text-primary); }

.btn {
    font-weight: 600;
    border-radius: var(--radius-md);
    font-size: .875rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    padding: .65rem 1.3rem;
}

.btn-primary.btn-sm { padding: .25rem .5rem; }
.btn-primary.btn-lg { padding: .8rem 1.6rem; }

.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--border-glass);
}

.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-outline-secondary {
    color: var(--text-secondary);
    border-color: var(--border-glass);
}

.btn-outline-secondary:hover {
    background: var(--text-primary);
    border-color: var(--text-primary);
}

/* Badges — quiet tint-on-tint treatment instead of bright saturated fills */
.badge { font-weight: 600; letter-spacing: .01em; font-size: .72rem; }

/* Responsive rules live at the end of this file. */

/* Pagination — explicit sizing so prev/next arrows never render oversized,
   regardless of any icon-font or inherited font-size elsewhere on the page. */
.pagination {
    gap: .25rem;
}

.pagination .page-link {
    font-size: .875rem !important;
    line-height: 1.25 !important;
    padding: .5rem .85rem !important;
    width: auto;
    height: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    background: var(--bg-glass);
}

.pagination .page-link i,
.pagination .page-link svg {
    font-size: 1rem !important;
    width: 1rem !important;
    height: 1rem !important;
    line-height: 1 !important;
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.pagination .page-item.disabled .page-link {
    opacity: .5;
}


/* ==========================================================================
   RESPONSIVE / MOBILE LAYER
   Visual-only. Desktop (>=992px) rendering is unchanged.
   ========================================================================== */

/* Never let one wide child stretch the whole page sideways */
html, body { max-width: 100%; overflow-x: hidden; }
.main-wrapper, .content-area { min-width: 0; max-width: 100%; }
img, svg, canvas, video { max-width: 100%; }
.tbl-scroll { max-width: 100%; }

/* Sidebar backdrop (created by js/responsive.js) */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(16, 24, 40, .45);
    z-index: 1025;
}
body.sidebar-open .sidebar-backdrop { display: block; }
body.sidebar-open { overflow: hidden; }

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: min(300px, 86vw);
        box-shadow: none;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.show { transform: translateX(0); box-shadow: var(--shadow-raised); }
    .main-wrapper { margin-left: 0; }
    .global-search { min-width: 0; }
}

@media (max-width: 767.98px) {
    :root { --topbar-height: 60px; }

    body { font-size: .9rem; }
    .content-area { padding: 1rem .875rem 1.5rem; }
    .topbar { padding: 0 .875rem; gap: .5rem; }
    .topbar > div { min-width: 0; }
    .topbar .fw-bold { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55vw; }
    .sidebar-brand { padding: 0 1.125rem; }

    /* Dropdowns in the topbar must stay inside the screen */
    #notificationMenu { width: calc(100vw - 1.75rem) !important; max-width: 360px; }
    .topbar .dropdown-menu { max-width: calc(100vw - 1.75rem); }

    /* Headings and page headers */
    h4, .h4 { font-size: 1.15rem; }
    h5, .h5 { font-size: 1.05rem; }
    .content-area > .d-flex.justify-content-between,
    .content-area > .d-flex.align-items-center.justify-content-between,
    .glass-card .d-flex.justify-content-between.align-items-center {
        flex-wrap: wrap;
        gap: .625rem;
    }
    .content-area > .d-flex > .d-flex,
    .content-area > .d-flex > form,
    .content-area > .d-flex > a.btn {
        max-width: 100%;
    }
    /* Action-button rows wrap instead of overflowing */
    .d-flex.gap-1, .d-flex.gap-2, .d-flex.gap-3 { flex-wrap: wrap; }
    .content-area > .d-flex > form .form-select,
    .content-area > .d-flex > form .form-control { width: 100%; }
    .content-area > .d-flex > form { flex: 1 1 100%; }

    /* Cards: tighter padding so content gets the room */
    .glass-card.p-4, .glass-card.p-5 { padding: 1rem !important; }
    .glass-card:hover { box-shadow: var(--shadow-glass); border-color: var(--border-glass); }
    .row { --bs-gutter-x: .875rem; }
    .row.g-4 { --bs-gutter-y: .875rem; --bs-gutter-x: .875rem; }
    .row.g-3 { --bs-gutter-y: .75rem; --bs-gutter-x: .75rem; }
    /* Summary cards sit two-per-row on phones */
    .row > .col-md-3, .row > .col-md-2, .row > .col-lg-3 { flex: 0 0 auto; width: 50%; }
    .stat-card { padding: .875rem !important; }
    .stat-icon { width: 38px; height: 38px; }
    .fs-3 { font-size: 1.35rem !important; }

    /* Tables scroll inside their own card, never the page */
    .tbl-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -.25rem;
        padding: 0 .25rem;
    }
    .tbl-scroll > .table { margin-bottom: 0; min-width: 620px; }
    .tbl-scroll > .table th,
    .tbl-scroll > .table td { white-space: nowrap; }
    .tbl-scroll > .table td .text-wrap,
    .tbl-scroll > .table td.text-wrap { white-space: normal; min-width: 180px; }
    .table { font-size: .82rem; }
    .table > :not(caption) > * > * { padding: .55rem .6rem; }

    /* Forms: comfortable touch targets, no iOS zoom on focus */
    .form-control, .form-select { font-size: 16px; min-height: 42px; }
    .btn { min-height: 38px; }
    .btn-sm { min-height: 34px; }
    [style*="min-width:220px"], [style*="min-width:200px"],
    [style*="min-width:180px"], [style*="min-width:140px"],
    [style*="min-width: 220px"], [style*="min-width: 200px"] { min-width: 0 !important; }
    [style*="width:240px"], [style*="width: 240px"] { width: 100% !important; }

    /* Modals */
    .modal-dialog { margin: .75rem; max-width: none; }
    .modal-footer { flex-wrap: wrap; gap: .5rem; }
    .modal-footer .btn { flex: 1 1 auto; }

    /* Tabs / nav pills scroll sideways */
    .nav-tabs, .nav-pills { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; }

    /* Pagination */
    .pagination { flex-wrap: wrap; justify-content: center; }
    .pagination .page-link { padding: .4rem .65rem !important; }

    /* Global-search results panel if ever shown */
    #globalSearchResults { width: calc(100vw - 1.75rem) !important; }

    /* Auth pages */
    .auth-shell { padding: 1rem; }
    .auth-card { padding: 1.5rem 1.25rem; max-width: 100%; }

    /* Totals block (invoice / quotation / PO show pages) */
    .content-area .totals-block { display: block; max-width: 100% !important; margin: .75rem 0 0 !important; }
    .tbl-scroll.has-totals > .table > tfoot { display: none; }
}

@media (max-width: 400px) {
    .content-area { padding: .875rem .625rem 1.25rem; }
    .btn-sm { padding: .3rem .55rem; font-size: .78rem; }
    .badge { font-size: .68rem; }
}

/* Totals block: mobile-only summary generated from <tfoot> total rows by responsive.js */
.totals-block { display: none; max-width: 380px; margin-left: auto; }
.totals-block .t-row {
    display: flex; justify-content: space-between; gap: 1rem;
    padding: .4rem 0; font-size: .9rem;
    border-bottom: 1px dashed var(--border-glass);
}
.totals-block .t-row:last-child { border-bottom: 0; }
.totals-block .t-row .t-label { color: var(--text-secondary); }
.totals-block .t-row.t-grand {
    border-top: 1px solid var(--border-glass); border-bottom: 0;
    margin-top: .25rem; padding-top: .65rem; font-weight: 700; font-size: 1rem;
}
.totals-block .t-row.t-grand .t-label { color: var(--text-primary); }
