/* ==========================================================================
   Savaliya Gas Agency — ERP theme
   Built on Bootstrap 5. Kept deliberately calm: one accent colour, generous
   white space, dense tables, and clear financial typography.
   ========================================================================== */

:root {
    --sga-primary:      #1f5f8b;
    --sga-primary-dark: #16455f;
    --sga-primary-soft: #eaf2f8;
    --sga-accent:       #e07b39;
    --sga-success:      #1f8a5f;
    --sga-danger:       #c0392b;
    --sga-warning:      #d68910;
    --sga-info:         #2874a6;
    --sga-purple:       #6c3f97;

    --sga-bg:      #f4f6f9;
    --sga-surface: #ffffff;
    --sga-border:  #e3e8ef;
    --sga-text:    #1f2937;
    --sga-muted:   #6b7280;

    --sga-sidebar-bg:     #16283d;
    --sga-sidebar-hover:  #1f3a5b;
    --sga-sidebar-active: #1f5f8b;
    --sga-sidebar-text:   #b8c4d4;

    --sga-radius: 10px;
    --sga-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --sga-shadow-lg: 0 4px 12px rgba(16, 24, 40, .08);
    --sidebar-width: 248px;
}

* { -webkit-font-smoothing: antialiased; }

body {
    background: var(--sga-bg);
    color: var(--sga-text);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
}

/* ------------------------------------------------------------ layout ---- */

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

.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--sga-sidebar-bg);
    color: var(--sga-sidebar-text);
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    z-index: 1040;
    transition: transform .2s ease;
}
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.app-content { padding: 20px 24px 48px; flex: 1; }

.sidebar-brand {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    display: flex; align-items: center; gap: 11px;
}
.sidebar-brand .brand-mark {
    width: 36px; height: 36px; border-radius: 9px;
    background: linear-gradient(135deg, var(--sga-accent), #c2611f);
    display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: 15px; flex: 0 0 36px;
}
.sidebar-brand .brand-name { color: #fff; font-weight: 600; font-size: 14.5px; line-height: 1.2; }
.sidebar-brand .brand-sub  { font-size: 11px; color: #7d8fa6; }

.sidebar-nav { padding: 10px 10px 30px; }
.sidebar-heading {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
    color: #63758d; padding: 14px 10px 6px; font-weight: 600;
}
.sidebar-link {
    display: flex; align-items: center; gap: 10px;
    padding: 8.5px 11px; border-radius: 8px;
    color: var(--sga-sidebar-text); text-decoration: none;
    font-size: 13.5px; font-weight: 500;
    margin-bottom: 1px;
}
.sidebar-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sidebar-link.active { background: var(--sga-sidebar-active); color: #fff; }
.sidebar-link .nav-ico { width: 18px; text-align: center; opacity: .9; flex: 0 0 18px; }
.sidebar-link .nav-badge {
    margin-left: auto; background: var(--sga-danger); color: #fff;
    border-radius: 20px; padding: 1px 7px; font-size: 10.5px; font-weight: 600;
}
.sidebar-link .nav-badge.warn { background: var(--sga-warning); }

.app-topbar {
    background: var(--sga-surface);
    border-bottom: 1px solid var(--sga-border);
    padding: 11px 24px;
    display: flex; align-items: center; gap: 14px;
    position: sticky; top: 0; z-index: 1020;
}
.app-topbar h1 { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.topbar-meta { font-size: 12px; color: var(--sga-muted); }

.sidebar-toggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    body.sidebar-open .app-sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop {
        display: block; position: fixed; inset: 0;
        background: rgba(15, 23, 42, .45); z-index: 1035;
    }
    .app-main { margin-left: 0; }
    .app-content { padding: 16px 14px 40px; }
    .sidebar-toggle { display: inline-flex; }
    .app-topbar { padding: 10px 14px; }
}

/* ------------------------------------------------------------- cards ---- */

.card {
    border: 1px solid var(--sga-border);
    border-radius: var(--sga-radius);
    box-shadow: var(--sga-shadow);
    background: var(--sga-surface);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--sga-border);
    padding: 13px 16px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    flex-wrap: wrap;
}
.card-header h2, .card-header h3, .card-title {
    font-size: 14px; font-weight: 650; margin: 0; letter-spacing: -.005em;
}
.card-header .card-sub { font-size: 12px; color: var(--sga-muted); font-weight: 400; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

/* --------------------------------------------------------- KPI cards ---- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
    /* A flex item defaults to min-width:auto, which would stop this grid
       shrinking below the sum of its tracks and push the page sideways on a
       phone. Allow it to shrink so auto-fit can drop to fewer columns. */
    min-width: 0;
}
.kpi-card {
    min-width: 0;
    background: var(--sga-surface);
    border: 1px solid var(--sga-border);
    border-radius: var(--sga-radius);
    padding: 14px 15px;
    box-shadow: var(--sga-shadow);
    position: relative;
    overflow: hidden;
    display: block; text-decoration: none; color: inherit;
}
a.kpi-card:hover { box-shadow: var(--sga-shadow-lg); border-color: #cfd8e3; color: inherit; }
.kpi-card::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
    background: var(--sga-primary);
}
.kpi-card.tone-success::before { background: var(--sga-success); }
.kpi-card.tone-danger::before  { background: var(--sga-danger); }
.kpi-card.tone-warning::before { background: var(--sga-warning); }
.kpi-card.tone-info::before    { background: var(--sga-info); }
.kpi-card.tone-purple::before  { background: var(--sga-purple); }

.kpi-label {
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--sga-muted); font-weight: 600; margin-bottom: 5px;
    display: flex; align-items: center; gap: 6px;
    overflow-wrap: anywhere;
}
.kpi-value { font-size: 21px; font-weight: 680; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.kpi-value.sm { font-size: 18px; }
.kpi-meta { font-size: 11.5px; color: var(--sga-muted); margin-top: 5px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.trend { font-weight: 600; font-size: 11.5px; white-space: nowrap; }

@media (max-width: 575.98px) {
    /* Two compact KPI cards per row reads better than one wide one. */
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(142px, 1fr)); gap: 9px; margin-bottom: 14px; }
    .kpi-value { font-size: 17.5px; }
    .kpi-value.sm { font-size: 15.5px; }
    .kpi-label { font-size: 10.5px; letter-spacing: .03em; }
    .kpi-card { padding: 11px 12px; }
}

.trend-up   { color: var(--sga-success); }
.trend-down { color: var(--sga-danger); }
.trend-flat { color: var(--sga-muted); }

/* ------------------------------------------------------------ tables ---- */

.table { font-size: 13.2px; margin-bottom: 0; color: var(--sga-text); }
.table > :not(caption) > * > * { padding: 9px 12px; }
.table thead th {
    background: #f8fafc;
    font-size: 11px; text-transform: uppercase; letter-spacing: .045em;
    color: #5a6b80; font-weight: 650; border-bottom: 1px solid var(--sga-border);
    white-space: nowrap;
}
.table tbody tr:hover { background: #fafbfd; }
.table td, .table th { border-color: #eef1f6; vertical-align: middle; }
.table-sticky thead th { position: sticky; top: 0; z-index: 5; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num-strong { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.money-pos { color: var(--sga-success); font-weight: 600; }
.money-neg { color: var(--sga-danger); font-weight: 600; }
.text-muted-sm { font-size: 11.5px; color: var(--sga-muted); }
.cell-title { font-weight: 570; color: var(--sga-text); text-decoration: none; }
.cell-title:hover { color: var(--sga-primary); text-decoration: underline; }

.table-wrap { overflow-x: auto; }
.table-wrap.scroll-y { max-height: 460px; overflow-y: auto; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--sga-muted); }
.empty-state .empty-ico { font-size: 30px; opacity: .35; margin-bottom: 8px; }
.empty-state p { margin: 0 0 4px; font-size: 13.5px; }

/* ------------------------------------------------------------ badges ---- */

.badge { font-weight: 600; font-size: 10.8px; padding: 3.5px 8px; border-radius: 20px; letter-spacing: .02em; }
.badge-soft-success { background: #e4f5ec; color: #14684a; }
.badge-soft-danger  { background: #fdeceb; color: #a5281c; }
.badge-soft-warning { background: #fdf2e0; color: #9a6208; }
.badge-soft-info    { background: #e6f1f9; color: #1a5a83; }
.badge-soft-primary { background: var(--sga-primary-soft); color: var(--sga-primary-dark); }
.badge-soft-purple  { background: #f0eaf8; color: #52307a; }
.badge-soft-secondary { background: #eef1f5; color: #4b5563; }

/* ------------------------------------------------------------- forms ---- */

.form-label { font-size: 12.5px; font-weight: 600; color: #414d5f; margin-bottom: 4px; }
.form-control, .form-select {
    font-size: 13.5px; border-color: #d7dde6; border-radius: 8px; padding: 7px 11px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--sga-primary);
    box-shadow: 0 0 0 3px rgba(31, 95, 139, .12);
}
.form-control-lg { font-size: 15px; padding: 10px 13px; }
.form-text { font-size: 11.5px; }
.input-group-text { background: #f5f7fa; border-color: #d7dde6; font-size: 13px; color: var(--sga-muted); }

.btn { font-size: 13.5px; font-weight: 550; border-radius: 8px; padding: 7px 14px; }
.btn-sm { font-size: 12.5px; padding: 4.5px 10px; }
.btn-primary { background: var(--sga-primary); border-color: var(--sga-primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--sga-primary-dark); border-color: var(--sga-primary-dark); }
.btn-outline-primary { color: var(--sga-primary); border-color: #b9cddc; }
.btn-outline-primary:hover { background: var(--sga-primary); border-color: var(--sga-primary); }
.btn-accent { background: var(--sga-accent); border-color: var(--sga-accent); color: #fff; }
.btn-accent:hover { background: #c2611f; border-color: #c2611f; color: #fff; }

.filter-bar {
    background: var(--sga-surface); border: 1px solid var(--sga-border);
    border-radius: var(--sga-radius); padding: 12px 14px; margin-bottom: 14px;
    box-shadow: var(--sga-shadow);
}
.filter-bar .row { --bs-gutter-x: .65rem; --bs-gutter-y: .6rem; }

/* ------------------------------------------------------------ charts ---- */

.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }
.chart-box.lg { height: 310px; }

/* --------------------------------------------------------- entry grid --- */

.entry-table { font-size: 13px; }
.entry-table th { font-size: 11px; }
.entry-table td { padding: 5px 6px; }
.entry-table .form-control, .entry-table .form-select { padding: 5px 8px; font-size: 13px; }
.entry-table input[readonly] { background: #f6f8fa; }

/* ---------------------------------------------------------------------
   Sale / purchase entry on a phone.
   A dense grid is right on a counter PC but unusable on a 375px screen, so
   each line becomes a stacked card with full-width, labelled inputs. No
   horizontal scrolling, no 40px-wide price boxes.
   --------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .entry-table thead { display: none; }
    .entry-table, .entry-table tbody, .entry-table tr, .entry-table td { display: block; width: 100%; }

    .entry-table tr.item-row {
        border: 1px solid var(--sga-border);
        border-radius: 10px;
        padding: 10px 12px 6px;
        margin-bottom: 10px;
        background: #fff;
        position: relative;
    }
    .entry-table td {
        display: flex; align-items: center; justify-content: space-between;
        gap: 12px; border: 0; padding: 5px 0;
    }
    .entry-table td::before {
        content: attr(data-label);
        font-size: 12px; font-weight: 600; color: var(--sga-muted);
        flex: 0 0 auto;
    }
    /* the product name cell spans the full width and needs no label */
    .entry-table td.cell-product { display: block; padding-bottom: 8px; }
    .entry-table td.cell-product::before { content: none; }

    .entry-table td .form-control {
        max-width: 58%; min-height: 40px; font-size: 15px; text-align: right;
    }
    .entry-table td.cell-remove { justify-content: flex-end; padding-top: 8px; }
    .entry-table td.cell-remove::before { content: none; }
    .entry-table td.cell-remove .btn { min-height: 38px; padding-inline: 16px; }

    /* totals read as a value, not an input */
    .entry-table td.cell-total, .entry-table td.cell-profit { font-size: 15px; }

    /* the wrapper no longer needs to scroll sideways */
    .entry-table-wrap { overflow-x: visible; }
}

/* Comfortable touch targets on phones and tablets. */
@media (max-width: 767.98px) {
    .btn { min-height: 40px; padding: 9px 16px; }
    .btn-sm { min-height: 34px; padding: 6px 12px; }
    .form-control, .form-select { min-height: 42px; font-size: 15px; }
    .form-control-sm, .form-select-sm { min-height: 36px; }
    .form-check-input { width: 1.25em; height: 1.25em; }
    .form-switch .form-check-input { width: 2.4em; height: 1.25em; }
    .nav-tabs .nav-link { padding: 10px 14px; }
    .page-actions .btn { flex: 1 1 auto; }
}

.product-search-wrap { position: relative; }
.product-results {
    position: absolute; z-index: 1060; top: calc(100% + 3px); left: 0; right: 0;
    background: #fff; border: 1px solid var(--sga-border); border-radius: 9px;
    box-shadow: var(--sga-shadow-lg); max-height: 340px; overflow-y: auto; display: none;
}
.product-results.show { display: block; }
.product-result {
    padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f1f4f8;
    display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.product-result:last-child { border-bottom: 0; }
.product-result:hover, .product-result.active { background: var(--sga-primary-soft); }
.product-result .pr-name { font-weight: 570; font-size: 13.2px; }
.product-result .pr-meta { font-size: 11.5px; color: var(--sga-muted); }
.product-result .pr-stock { font-size: 11.5px; text-align: right; white-space: nowrap; }

.totals-panel { background: #f8fafc; border-radius: 9px; padding: 13px 15px; border: 1px solid var(--sga-border); }
.totals-row { display: flex; justify-content: space-between; padding: 3.5px 0; font-size: 13.2px; }
.totals-row.grand {
    border-top: 1.5px solid #d7dde6; margin-top: 7px; padding-top: 9px;
    font-size: 16px; font-weight: 680;
}

.profit-panel { border-radius: 9px; padding: 12px 14px; font-size: 13px; border: 1px solid; }
.profit-panel.is-profit { background: #eefaf3; border-color: #b8e6cd; }
.profit-panel.is-loss   { background: #fdeeec; border-color: #f3c2bc; }

.warn-list { margin: 0; padding-left: 17px; font-size: 12.5px; }
.warn-list li { margin-bottom: 3px; }

/* ------------------------------------------------------------- misc ----- */

.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section-title { font-size: 13px; font-weight: 650; color: #414d5f; text-transform: uppercase; letter-spacing: .04em; margin: 20px 0 10px; }
.stat-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed #eef1f6; font-size: 13px; }
.stat-line:last-child { border-bottom: 0; }
.stat-line .sl-label { color: var(--sga-muted); }
.stat-line .sl-value { font-weight: 600; font-variant-numeric: tabular-nums; }

.progress { height: 6px; background: #eef1f6; border-radius: 20px; }
.progress-bar { background: var(--sga-primary); }

.insight-item {
    display: flex; gap: 10px; padding: 10px 12px; border-radius: 8px;
    margin-bottom: 7px; font-size: 13px; border: 1px solid;
}
.insight-item.type-warning { background: #fdf8ec; border-color: #f2e0b8; }
.insight-item.type-danger  { background: #fdeeec; border-color: #f3c9c3; }
.insight-item.type-success { background: #eefaf3; border-color: #c2e8d5; }
.insight-item.type-info    { background: #eef4fa; border-color: #cddeee; }

.alert { border-radius: 9px; font-size: 13.5px; border-width: 1px; padding: 11px 14px; }
.flash-stack { position: fixed; top: 14px; right: 14px; z-index: 1080; max-width: 400px; }
.flash-stack .alert { box-shadow: var(--sga-shadow-lg); }

.nav-tabs { border-bottom-color: var(--sga-border); }
.nav-tabs .nav-link {
    font-size: 13.3px; font-weight: 550; color: var(--sga-muted);
    border: 0; border-bottom: 2px solid transparent; padding: 8px 14px;
}
.nav-tabs .nav-link.active { color: var(--sga-primary); border-bottom-color: var(--sga-primary); background: transparent; }

.pagination { margin: 0; }
.page-link { font-size: 13px; color: var(--sga-primary); border-color: var(--sga-border); }
.page-item.active .page-link { background: var(--sga-primary); border-color: var(--sga-primary); }

.login-shell {
    min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: linear-gradient(140deg, #16283d 0%, #1f5f8b 100%);
}
.login-card {
    width: 100%; max-width: 400px; background: #fff;
    border-radius: 14px; box-shadow: 0 18px 40px rgba(9, 20, 34, .28); padding: 30px 28px;
}

.required::after { content: ' *'; color: var(--sga-danger); }

@media print {
    .app-sidebar, .app-topbar, .no-print, .flash-stack { display: none !important; }
    .app-main { margin-left: 0; }
    .app-content { padding: 0; }
    body { background: #fff; font-size: 12px; }
    .card { box-shadow: none; border: 1px solid #ccc; }
    a { text-decoration: none; color: inherit; }
}
