/* ==========================================================================
   Scrap Trading & Godam Management System
   Professional business UI built on Bootstrap 5
   ========================================================================== */

/* --------------------------------------------------------------------------
   One light palette drives the whole system - screen, print and PDF - so every
   surface uses the same small set of tints rather than its own colours.
   -------------------------------------------------------------------------- */

:root {
    /* Brand */
    --sc-primary: #3b82f6;
    --sc-primary-dark: #2563eb;
    --sc-primary-soft: #eef4ff;
    --sc-primary-border: #cfe0fd;

    /* Surfaces */
    --sc-body-bg: #f7f9fc;
    --sc-surface: #ffffff;
    --sc-surface-alt: #fbfcfe;
    --sc-card-border: #e8edf4;
    --sc-line: #eef2f7;

    /* Text */
    --sc-text: #3c4759;
    --sc-text-strong: #2b3648;
    --sc-muted: #8794a8;

    /* Sidebar - original sleek dark black theme */
    --sc-sidebar-bg: #0f172a;
    --sc-sidebar-border: #1e293b;
    --sc-sidebar-text: #cbd5e1;
    --sc-sidebar-hover: #1e293b;
    --sc-sidebar-active-bg: #2563eb;
    --sc-sidebar-active-text: #ffffff;
    --sc-sidebar-heading: #64748b;

    /* Status - softened so nothing shouts on a light background */
    --sc-positive: #10905f;
    --sc-positive-soft: #e9f8f1;
    --sc-negative: #d1495b;
    --sc-negative-soft: #fdeef0;
    --sc-warning: #c08217;
    --sc-warning-soft: #fdf6e7;
    --sc-info: #2b7fb8;
    --sc-info-soft: #eaf5fb;
    --sc-neutral: #6b788c;
    --sc-neutral-soft: #f1f4f8;

    /* Document ink, shared by printed pages and PDFs */
    --sc-doc-ink: #46536a;
    --sc-doc-rule: #d7deea;
    --sc-doc-head-bg: #eef2f8;

    --sc-sidebar-width: 262px;
    --sc-topbar-height: 62px;
    --sc-radius: 10px;
}

/* ---------------------------------------------------------------- base --- */

body {
    background: var(--sc-body-bg);
    color: var(--sc-text);
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.9rem;
}

a { text-decoration: none; }

.text-positive { color: var(--sc-positive) !important; }
.text-negative { color: var(--sc-negative) !important; }

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------------------- sidebar --- */

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sc-sidebar-width);
    background: var(--sc-sidebar-bg);
    border-right: 1px solid var(--sc-sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .2s ease;
}

.app-brand {
    height: var(--sc-topbar-height);
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 0 1.15rem;
    border-bottom: 1px solid var(--sc-sidebar-border);
    background: #090d16;
    flex-shrink: 0;
}

.app-brand .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.app-brand .brand-text {
    color: #f8fafc;
    font-weight: 600;
    font-size: .92rem;
    line-height: 1.15;
    overflow: hidden;
}

.app-brand .brand-text small {
    display: block;
    color: #94a3b8;
    font-size: .68rem;
    font-weight: 400;
}

.app-nav {
    flex: 1;
    overflow-y: auto;
    padding: .75rem .6rem 2rem;
}

.app-nav::-webkit-scrollbar { width: 6px; }
.app-nav::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.nav-heading {
    color: var(--sc-sidebar-heading);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 1rem .75rem .35rem;
}

.app-nav .nav-link {
    color: var(--sc-sidebar-text);
    padding: .5rem .75rem;
    border-radius: 7px;
    display: flex;
    align-items: center;
    gap: .7rem;
    font-size: .85rem;
    margin-bottom: 1px;
    transition: all 0.15s ease;
}

.app-nav .nav-link i { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0; color: #64748b; }

.app-nav .nav-link:hover {
    background: var(--sc-sidebar-hover);
    color: #ffffff;
}

.app-nav .nav-link:hover i { color: #38bdf8; }

.app-nav .nav-link.active {
    background: var(--sc-sidebar-active-bg);
    color: var(--sc-sidebar-active-text);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.app-nav .nav-link.active i { color: #ffffff; }

.app-nav .nav-link .chev { margin-left: auto; font-size: .75rem; transition: transform .15s; }
.app-nav .nav-link[aria-expanded="true"] .chev { transform: rotate(90deg); }

.app-nav .nav-sub { padding-left: 2.35rem; }

.app-nav .nav-sub .nav-link {
    padding: .38rem .75rem;
    font-size: .82rem;
    position: relative;
}

.app-nav .nav-sub .nav-link::before {
    content: "";
    position: absolute;
    left: -.85rem;
    top: 50%;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #cbd5e3;
    transform: translateY(-50%);
}

.app-nav .nav-sub .nav-link.active::before { background: var(--sc-primary); }

/* Sub-items already carry a dot marker, so they skip the inset accent bar. */
.app-nav .nav-sub .nav-link.active { box-shadow: none; }

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

.app-main {
    margin-left: var(--sc-sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: var(--sc-topbar-height);
    background: var(--sc-surface);
    border-bottom: 1px solid var(--sc-card-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

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

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1.1rem;
}

.page-head h1 {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: .55rem;
}

.page-head .breadcrumb { margin: .15rem 0 0; font-size: .8rem; }

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

.card {
    border: 1px solid var(--sc-card-border);
    border-radius: var(--sc-radius);
    box-shadow: 0 1px 2px rgba(64, 84, 120, .04);
    background: var(--sc-surface);
}

.card-header {
    background: var(--sc-surface);
    border-bottom: 1px solid var(--sc-card-border);
    color: var(--sc-text-strong);
    font-weight: 600;
    padding: .8rem 1rem;
    border-radius: var(--sc-radius) var(--sc-radius) 0 0 !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
}

.card-header .card-title { margin: 0; font-size: .95rem; font-weight: 600; }

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

.stat-card {
    background: var(--sc-surface);
    border: 1px solid var(--sc-card-border);
    border-radius: var(--sc-radius);
    padding: .95rem 1rem;
    height: 100%;
    display: flex;
    align-items: flex-start;
    gap: .85rem;
    box-shadow: 0 1px 2px rgba(64, 84, 120, .04);
}

.stat-card .stat-value { color: var(--sc-text-strong); }

.stat-card .stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.stat-card .stat-label {
    color: var(--sc-muted);
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    margin-bottom: .15rem;
}

.stat-card .stat-value { font-size: 1.12rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-sub { font-size: .75rem; color: var(--sc-muted); margin-top: .1rem; }

/* Soft accent tints - the single source of colour for icons, chips and pills */
.bg-soft-primary { background: var(--sc-primary-soft); color: var(--sc-primary-dark); }
.bg-soft-success { background: var(--sc-positive-soft); color: var(--sc-positive); }
.bg-soft-danger  { background: var(--sc-negative-soft); color: var(--sc-negative); }
.bg-soft-warning { background: var(--sc-warning-soft); color: var(--sc-warning); }
.bg-soft-info    { background: var(--sc-info-soft); color: var(--sc-info); }
.bg-soft-purple  { background: #f2eefb; color: #7757c4; }
.bg-soft-dark    { background: var(--sc-neutral-soft); color: var(--sc-neutral); }

/* Bootstrap's solid badges are too saturated for a light interface, so the
   variants used across the system are restated as quiet tinted chips. */
.badge.bg-primary   { background: var(--sc-primary-soft) !important; color: var(--sc-primary-dark) !important; }
.badge.bg-success   { background: var(--sc-positive-soft) !important; color: var(--sc-positive) !important; }
.badge.bg-danger    { background: var(--sc-negative-soft) !important; color: var(--sc-negative) !important; }
.badge.bg-warning   { background: var(--sc-warning-soft) !important; color: var(--sc-warning) !important; }
.badge.bg-info      { background: var(--sc-info-soft) !important; color: var(--sc-info) !important; }
.badge.bg-secondary { background: var(--sc-neutral-soft) !important; color: var(--sc-neutral) !important; }
.badge.bg-dark      { background: #e7ebf2 !important; color: #4d5a70 !important; }
.badge.bg-light     { background: var(--sc-neutral-soft) !important; color: var(--sc-neutral) !important; }

.badge[class*="bg-soft-"] { font-weight: 600; }

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

.table {
    margin-bottom: 0;
    font-size: .85rem;
}

.table > thead > tr > th {
    background: var(--sc-surface-alt);
    border-bottom: 1px solid var(--sc-card-border);
    color: var(--sc-muted);
    font-weight: 600;
    font-size: .74rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
    padding: .6rem .7rem;
}

.table > tbody > tr > td {
    padding: .55rem .7rem;
    vertical-align: middle;
    border-color: var(--sc-line);
}

.table > tbody > tr:hover { background: var(--sc-primary-soft); }

.table tfoot td {
    font-weight: 700;
    background: var(--sc-surface-alt);
    border-top: 2px solid var(--sc-card-border);
    color: var(--sc-text-strong);
}

.table-empty { padding: 2.5rem 1rem; text-align: center; color: var(--sc-muted); }
.table-empty i { font-size: 2rem; display: block; margin-bottom: .5rem; opacity: .45; }

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

.form-label { font-weight: 600; font-size: .8rem; margin-bottom: .28rem; color: #374151; }
.form-label .req { color: #dc2626; }

.form-control, .form-select { font-size: .87rem; }
.form-control:focus, .form-select:focus {
    border-color: #93b4f8;
    box-shadow: 0 0 0 .18rem rgba(37, 99, 235, .12);
}

.filter-bar {
    background: #fff;
    border: 1px solid var(--sc-card-border);
    border-radius: var(--sc-radius);
    padding: .85rem 1rem;
    margin-bottom: 1rem;
}

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

.badge { font-weight: 600; font-size: .7rem; padding: .34em .6em; }

.balance-pill {
    display: inline-flex;
    flex-direction: column;
    line-height: 1.2;
}
.balance-pill .balance-tag { font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; }

/* ------------------------------------------------------------- buttons --- */

.btn { font-size: .85rem; }
.btn-sm { font-size: .78rem; }
.btn-icon { width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center; }

/* -------------------------------------------------------- item builder --- */

.item-row td { padding: .35rem .4rem; }
.item-row .form-control { font-size: .85rem; }
.line-amount { font-weight: 600; }

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

.chart-box { position: relative; height: 280px; }

/* ---------------------------------------------------------- responsive --- */

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 1035;
    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; }
    .app-main { margin-left: 0; }
}

/* ------------------------------------------------------- print / A4 doc --- */

@media print {
    .app-sidebar,
    .app-topbar,
    .no-print,
    .sidebar-backdrop { display: none !important; }

    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; }
    body { background: #fff; font-size: 12px; }
    .card { border: none !important; box-shadow: none !important; }
    a[href]::after { content: none !important; }
}

/* Printable document shell (bills, invoices, receipts, statements) */

.doc-sheet {
    background: var(--sc-surface);
    max-width: 210mm;
    margin: 0 auto;
    padding: 8mm 10mm;
    border: 1px solid var(--sc-card-border);
    border-radius: var(--sc-radius);
    color: var(--sc-doc-ink);
}

.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    border-bottom: 2px solid var(--sc-doc-rule);
    padding-bottom: .4rem;
    margin-bottom: .45rem;
}

.doc-company-name { font-size: 1.15rem; font-weight: 700; margin-bottom: .1rem; color: var(--sc-text-strong); line-height: 1.2; }
.doc-company-meta { font-size: .72rem; color: var(--sc-muted); line-height: 1.3; }
.doc-logo { max-height: 48px; max-width: 150px; object-fit: contain; }
.doc-heading-title { font-size: .98rem; font-weight: 700; color: var(--sc-text-strong); }
.doc-heading-meta { font-size: .78rem; line-height: 1.3; }
.doc-heading-badge { font-size: .72rem; }

.doc-title {
    text-align: center;
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    margin: .4rem 0 .6rem;
    padding: .3rem;
    background: var(--sc-doc-head-bg);
    color: var(--sc-text-strong);
    border-radius: 4px;
}

.doc-parties { display: flex; gap: .6rem; margin-bottom: .45rem; flex-wrap: nowrap; }
.doc-party { flex: 1 1 50%; border: 1px solid #e5e7eb; border-radius: 4px; padding: .35rem .55rem; background: #fdfdfd; }
.doc-party h6 {
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #6b7280;
    margin-bottom: .15rem;
    font-weight: 700;
}
.doc-party .party-name { font-weight: 700; font-size: .84rem; line-height: 1.25; margin-bottom: .1rem; }
.doc-party div, .doc-party .party-meta-line { font-size: .73rem; line-height: 1.3; color: #374151; }
.party-adv-badge {
    margin-top: .2rem;
    padding: .12rem .3rem;
    background: #eef8f3;
    border: 1px solid #bbf7d0;
    border-radius: 3px;
    font-size: .68rem;
    color: #15803d;
    display: inline-block;
}

.doc-table { width: 100%; border-collapse: collapse; font-size: .73rem; line-height: 1.25; border: 1px solid #94a3b8; }
.doc-table th {
    background: #1e293b;
    color: #ffffff;
    padding: .35rem .45rem;
    text-align: left;
    font-weight: 700;
    font-size: .80rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    border: 1px solid #1e293b;
    border-bottom: 2px solid #0f172a;
}
.doc-table td { padding: .22rem .45rem; border: 1px solid #cbd5e1; vertical-align: middle; }
.doc-table tbody tr:nth-child(even) { background: #f8fafc; }
.doc-table tfoot td {
    font-weight: 700;
    background: #e2e8f0;
    border: 1px solid #94a3b8;
    border-top: 2px solid #0f172a;
    border-bottom: 1px solid #94a3b8;
    color: #0f172a;
    padding: .3rem .45rem;
    font-size: .76rem;
}

.doc-totals { margin-left: auto; width: 270px; font-size: .74rem; margin-top: .35rem; border-collapse: collapse; border: 1px solid #cbd5e1; }
.doc-totals tr td { padding: .18rem .35rem; line-height: 1.25; border: 1px solid #e2e8f0; }
.doc-totals tr td:last-child { text-align: right; font-weight: 600; }
.doc-totals tr.grand td {
    border-top: 2px solid #0f172a;
    font-size: .84rem;
    font-weight: 700;
    padding-top: .25rem;
    background: #f1f5f9;
    color: var(--sc-text-strong);
}

.doc-signatures { display: flex; justify-content: space-between; gap: 1.5rem; margin-top: 1.1rem; }
.doc-signatures div {
    flex: 1;
    border-top: 1px solid #9ca3af;
    padding-top: .2rem;
    text-align: center;
    font-size: .70rem;
    color: #4b5563;
}

.doc-footer-note {
    margin-top: .4rem;
    font-size: .67rem;
    color: #6b7280;
    text-align: center;
    border-top: 1px solid #e5e7eb;
    padding-top: .25rem;
}

/* Developer credit, printed at the foot of every document */
.doc-credit {
    margin-top: .2rem;
    padding-top: .2rem;
    border-top: 1px dashed #d1d5db;
    text-align: center;
    font-size: .65rem;
    color: #6b7280;
    letter-spacing: .02em;
}

.doc-credit strong { color: #374151; }

/* Same credit on normal screens (app footer, report pages) */
.app-credit {
    font-size: .72rem;
    color: #94a3b8;
}

.app-credit strong { color: #64748b; }

@media print {
    .doc-sheet { max-width: none; margin: 0; padding: 0; border: none; }
    @page { size: A4 portrait; margin: 6mm 8mm 6mm 8mm; }
    .doc-header { padding-bottom: 2px !important; margin-bottom: 4px !important; }
    .doc-parties { margin-bottom: 4px !important; gap: 6px !important; }
    .doc-party { padding: 3px 6px !important; }
    .doc-party h6 { font-size: 6.5pt !important; margin-bottom: 1px !important; }
    .doc-party .party-name { font-size: 8pt !important; }
    .doc-party div, .doc-party .party-meta-line { font-size: 7pt !important; line-height: 1.25 !important; }
    .doc-table { border: 1px solid #94a3b8 !important; }
    .doc-table th { padding: 3px 5px !important; font-size: 8.5pt !important; font-weight: bold !important; background: #1e293b !important; color: #ffffff !important; border: 1px solid #1e293b !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .doc-table td { padding: 2.2px 4px !important; font-size: 7.4pt !important; border: 1px solid #cbd5e1 !important; line-height: 1.2 !important; }
    .doc-table tbody tr:nth-child(even) { background: #f8fafc !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .doc-table tfoot td { padding: 3px 5px !important; font-size: 7.8pt !important; font-weight: bold !important; background: #e2e8f0 !important; color: #0f172a !important; border: 1px solid #94a3b8 !important; border-top: 2px solid #0f172a !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .doc-totals { font-size: 7.4pt !important; width: 260px !important; margin-top: 3px !important; border: 1px solid #cbd5e1 !important; }
    .doc-totals tr td { padding: 2px 4px !important; line-height: 1.2 !important; border: 1px solid #e2e8f0 !important; }
    .doc-totals tr.grand td { background: #f1f5f9 !important; font-weight: bold !important; border-top: 2px solid #0f172a !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .doc-signatures { margin-top: 8px !important; }
    .doc-signatures div { font-size: 6.8pt !important; padding-top: 2px !important; }
    .doc-footer-note { margin-top: 3px !important; padding-top: 2px !important; font-size: 6.5pt !important; }
    .doc-credit { margin-top: 2px !important; padding-top: 2px !important; font-size: 6pt !important; }
}

/* Receipt is a narrower document */
.doc-sheet.receipt { max-width: 148mm; }

/* A report with many columns needs landscape A4 to stay readable */
.doc-sheet-wide { max-width: 297mm; }
.doc-sheet-wide .doc-table { font-size: .74rem; }
.doc-sheet-wide .doc-table th,
.doc-sheet-wide .doc-table td { padding: .35rem .4rem; }

@media print {
    .doc-sheet-wide { max-width: none; }
}

/* Summary tiles above a printed report share the party-block styling */
.doc-parties .doc-party { min-width: 0; }

/* ------------------------------------------------ Searchable Select Widget */
.scrap-search-wrapper {
    position: relative;
    width: 100%;
}
.scrap-search-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%236c757d' class='bi bi-search' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    background-size: 13px 13px;
    padding-right: 1.8rem !important;
}
.scrap-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 9999;
    max-height: 250px;
    min-width: 260px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid #94a3b8;
    border-radius: 6px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.18);
    display: none;
}
.scrap-search-results.show {
    display: block;
}
.scrap-search-item {
    padding: 0.55rem 0.85rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    color: var(--sc-text);
}
.scrap-search-item:last-child {
    border-bottom: none;
}
.scrap-search-item:hover, .scrap-search-item.active {
    background-color: var(--sc-primary-soft);
    color: var(--sc-primary-dark);
}
.scrap-search-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f9fafb;
}

/* Ensure items table in transaction forms doesn't clip search dropdowns */
.table-responsive:has(#itemsTable),
.table-responsive:has(#items-table),
.items-table-container {
    overflow: visible;
    min-height: 280px;
}
