/* =====================================================================
   Quotation Management System - Design System
   ===================================================================== */
:root {
    --qms-sidebar-w: 260px;
    --qms-sidebar-collapsed-w: 72px;
    --qms-primary: #1f4e79;
    --qms-primary-2: #2e6da4;
    --qms-accent: #0d6efd;
    --qms-sidebar-bg: #152238;
    --qms-sidebar-hover: #1e2f4d;
    --qms-topbar-h: 56px;
    --qms-radius: .5rem;
    --qms-zebra: #f6f9fc;
    --qms-hover: #eaf2fb;
    --qms-border: #dee2e6;
    --qms-font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

html, body { height: 100%; }
body {
    font-family: var(--qms-font);
    font-size: .9rem;
    background: #f2f5f9;
    overflow-x: hidden;
}

/* ---------------------------------------------------------------------
   Sidebar
   --------------------------------------------------------------------- */
.qms-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--qms-sidebar-w);
    background: linear-gradient(180deg, var(--qms-sidebar-bg) 0%, #101a2b 100%);
    color: #cfd8e6;
    z-index: 1040;
    transition: width .2s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.qms-sidebar .brand {
    display: flex; align-items: center; gap: .65rem;
    height: var(--qms-topbar-h);
    padding: 0 1rem;
    color: #fff;
    font-weight: 600;
    letter-spacing: .3px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    white-space: nowrap;
}
.qms-sidebar .brand img { max-height: 30px; max-width: 34px; object-fit: contain; }
.qms-sidebar .brand .brand-icon {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, var(--qms-accent), #4f9cf9);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; flex: 0 0 32px;
}
.qms-sidebar .nav-section {
    padding: .9rem 1.1rem .25rem;
    font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
    color: #7d8ea8;
}
.qms-sidebar .nav-link {
    display: flex; align-items: center; gap: .7rem;
    color: #c3cede; padding: .52rem 1.1rem;
    border-radius: 0; text-decoration: none;
    white-space: nowrap; font-size: .875rem;
    border-left: 3px solid transparent;
}
.qms-sidebar .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .9; }
.qms-sidebar .nav-link:hover { background: var(--qms-sidebar-hover); color: #fff; }
.qms-sidebar .nav-link.active {
    background: rgba(13,110,253,.18); color: #fff;
    border-left-color: #4f9cf9;
}
.qms-sidebar .badge-count { margin-left: auto; font-size: .68rem; }
.qms-sidebar .sub-link { padding-left: 3rem; font-size: .83rem; }
.qms-sidebar .nav-link .chevron { margin-left: auto; transition: transform .2s; }
.qms-sidebar .nav-link[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.qms-sidebar-scroll { overflow-y: auto; flex: 1; padding-bottom: 1rem; }
.qms-sidebar-scroll::-webkit-scrollbar { width: 6px; }
.qms-sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

body.sidebar-collapsed .qms-sidebar { width: var(--qms-sidebar-collapsed-w); }
body.sidebar-collapsed .qms-sidebar .brand span,
body.sidebar-collapsed .qms-sidebar .nav-link span,
body.sidebar-collapsed .qms-sidebar .nav-section,
body.sidebar-collapsed .qms-sidebar .chevron,
body.sidebar-collapsed .qms-sidebar .badge-count { display: none; }
body.sidebar-collapsed .qms-sidebar .nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .qms-sidebar .brand { justify-content: center; padding: 0; }

/* ---------------------------------------------------------------------
   Topbar + content
   --------------------------------------------------------------------- */
.qms-main {
    margin-left: var(--qms-sidebar-w);
    min-height: 100vh;
    transition: margin-left .2s ease;
    display: flex; flex-direction: column;
}
body.sidebar-collapsed .qms-main { margin-left: var(--qms-sidebar-collapsed-w); }

.qms-topbar {
    height: var(--qms-topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--qms-border);
    display: flex; align-items: center;
    padding: 0 1rem;
    position: sticky; top: 0; z-index: 1030;
}
.qms-topbar .btn-icon {
    width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 8px; color: #495057; background: transparent; border: 0;
}
.qms-topbar .btn-icon:hover { background: #eef3f8; }
.qms-content { padding: 1rem 1.1rem 2rem; flex: 1; }

.breadcrumb-qms { font-size: .8rem; }
.breadcrumb-qms a { text-decoration: none; }

/* ---------------------------------------------------------------------
   Cards & stats
   --------------------------------------------------------------------- */
.card { border: 0; box-shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1); border-radius: var(--qms-radius); }
.card-qms { border-radius: var(--qms-radius); }
.stat-card { border-radius: var(--qms-radius); border: 0; overflow: hidden; }
.stat-card .stat-body { padding: 1rem 1.1rem; display: flex; align-items: center; gap: .9rem; }
.stat-card .stat-icon {
    width: 46px; height: 46px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.stat-card .stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.1; color: #1f2937; }
.stat-card .stat-label { font-size: .76rem; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }

/* ---------------------------------------------------------------------
   Tables (zebra + compact)
   --------------------------------------------------------------------- */
.table-qms { --bs-table-striped-bg: var(--qms-zebra); }
.table-qms thead th {
    background: #1f4e79; color: #fff; font-weight: 600; font-size: .78rem;
    text-transform: uppercase; letter-spacing: .04em;
    border-bottom: 0; padding: .55rem .6rem; vertical-align: middle;
    white-space: nowrap;
}
.table-qms tbody td { padding: .42rem .6rem; vertical-align: middle; font-size: .86rem; }
.table-qms.table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-accent-bg: var(--qms-zebra); color: inherit; }
.table-qms tbody tr:hover > * { background-color: var(--qms-hover) !important; }
.table-qms .text-end, .text-money { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.table-qms .text-center { text-align: center; }
.table-sm td, .table-sm th { padding: .35rem .5rem; }

table.dataTable { font-size: .86rem; }
table.dataTable thead th { background: #1f4e79 !important; color: #fff !important; }
table.dataTable tbody td { padding: .4rem .55rem; }
table.dataTable.dt-type-numeric { font-variant-numeric: tabular-nums; }
table.dataTable > tbody > tr.odd > * { background-color: #f6f9fc !important; }
table.dataTable > tbody > tr.even > * { background-color: #ffffff !important; }
table.dataTable > tbody > tr:hover > * { background-color: #eaf2fb !important; }
table.dataTable thead .dt-scroll-head { background: #1f4e79; }

.dt-column-filters input, .dt-column-filters select {
    width: 100%; font-size: .75rem; padding: .18rem .35rem;
    border: 1px solid rgba(255,255,255,.35); border-radius: 4px;
    background: rgba(255,255,255,.12); color: #fff;
}
.dt-column-filters input::placeholder { color: rgba(255,255,255,.7); }
.dt-column-filters input:focus, .dt-column-filters select:focus {
    background: #fff; color: #212529; border-color: #86b7fe; outline: none;
}
.dt-column-filters select option { color: #212529; }
table.dataTable > thead > tr > th.dt-head-sortable { cursor: pointer; }
table.dataTable thead th.dt-orderable-asc, table.dataTable thead th.dt-orderable-desc { cursor: pointer; }

/* column resize handle */
.dt-col-resize {
    position: absolute; top: 0; right: -3px; width: 6px; height: 100%;
    cursor: col-resize; z-index: 5; user-select: none;
}
.dt-col-resize:hover, .dt-col-resize.resizing { background: rgba(13,110,253,.55); }
table.dataTable th { position: relative; }
.table-qms thead th, .items-table thead th, .qms-resizable thead th { position: relative; }

/* datatables buttons */
.dt-buttons .btn { font-size: .78rem; padding: .28rem .6rem; }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */
.form-label { font-size: .8rem; font-weight: 600; color: #374151; margin-bottom: .25rem; }
.form-control, .form-select { font-size: .875rem; border-radius: .4rem; }
.form-control:focus, .form-select:focus { box-shadow: 0 0 0 .18rem rgba(31,78,121,.15); border-color: var(--qms-primary-2); }
.input-group-text { font-size: .85rem; background: #f1f5f9; }
.form-section { border: 1px solid var(--qms-border); border-radius: var(--qms-radius); padding: 1rem; background: #fff; }
.form-section > .form-section-title {
    font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--qms-primary); margin-bottom: .8rem;
    border-bottom: 1px dashed var(--qms-border); padding-bottom: .45rem;
}
.req::after { content: " *"; color: #dc3545; }

/* quotation item editor */
.items-table { --bs-table-bg: transparent; table-layout: fixed; min-width: 1120px; }
.items-table thead th {
    background: #e8eef6; color: #1f4e79; font-size: .74rem; text-transform: uppercase;
    border-bottom: 2px solid #c9d7e8; padding: .4rem .45rem;
}
.items-table tbody td { padding: .3rem .35rem; border-bottom: 1px solid #eef2f7; }
.items-table tbody tr:hover { background: #f2f7fd; }
.items-table input, .items-table select { font-size: .83rem; padding: .3rem .4rem; }
.items-table .row-num { width: 34px; text-align: center; font-weight: 600; color: #64748b; }
.items-table .line-total { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items-table .drag-handle { cursor: grab; color: #94a3b8; }
.items-table tr.item-row.dragging { opacity: .5; }

.summary-box { background: #f8fafc; border: 1px solid var(--qms-border); border-radius: var(--qms-radius); padding: .9rem; }
.summary-line { display: flex; justify-content: space-between; padding: .28rem 0; font-size: .88rem; }
.summary-line.total { border-top: 2px solid var(--qms-primary); margin-top: .35rem; padding-top: .5rem; font-size: 1.05rem; font-weight: 700; color: var(--qms-primary); }
.summary-line .lbl { color: #475569; }
.summary-line .val { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------
   Misc UI
   --------------------------------------------------------------------- */
.page-title { font-size: 1.05rem; font-weight: 700; color: #1f2937; margin: 0; }
.btn { font-size: .85rem; }
.btn-qms { background: var(--qms-primary); border-color: var(--qms-primary); color: #fff; }
.btn-qms:hover { background: var(--qms-primary-2); border-color: var(--qms-primary-2); color: #fff; }
.card-header-qms {
    background: #fff; border-bottom: 1px solid var(--qms-border);
    padding: .7rem 1rem; font-weight: 600; font-size: .92rem;
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    border-radius: var(--qms-radius) var(--qms-radius) 0 0 !important;
}
.empty-state { text-align: center; padding: 2.2rem 1rem; color: #8a97a8; }
.empty-state i { font-size: 2.4rem; display: block; margin-bottom: .5rem; }
.autocomplete-list {
    position: absolute; z-index: 1050; max-height: 260px; overflow-y: auto;
    background: #fff; border: 1px solid var(--qms-border); border-radius: .4rem;
    box-shadow: 0 8px 22px rgba(16,24,40,.12); width: 100%;
}
.autocomplete-list .item { padding: .45rem .7rem; cursor: pointer; font-size: .85rem; border-bottom: 1px solid #f1f5f9; }
.autocomplete-list .item:hover, .autocomplete-list .item.active { background: #eaf2fb; }
.autocomplete-list .item .sub { display: block; color: #8792a3; font-size: .74rem; }
.autocomplete-wrap { position: relative; }

.badge-status { font-size: .72rem; font-weight: 600; padding: .32em .6em; }

.toast-container { z-index: 2000; }
.loading-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,.65); z-index: 2050;
    display: none; align-items: center; justify-content: center;
}
.loading-overlay.show { display: flex; }
.spinner-box { background: #fff; border-radius: .8rem; padding: 1.2rem 1.6rem; box-shadow: 0 10px 30px rgba(0,0,0,.12); text-align: center; font-size: .85rem; }

.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, var(--qms-primary), var(--qms-accent));
    color: #fff; display: inline-flex; align-items: center; justify-content: center;
    font-size: .8rem; font-weight: 600;
}

.dropdown-menu { font-size: .85rem; box-shadow: 0 8px 22px rgba(16,24,40,.12); border: 0; }

.quick-expire { border-left: 3px solid #f59e0b; }

/* ---------------------------------------------------------------------
   Print document (A4) - shared with the on screen preview
   --------------------------------------------------------------------- */
.qms-doc { background: #fff; color: #111; font-size: 12px; line-height: 1.45; }
.qms-doc .doc-header { border-bottom: 3px double var(--qms-primary); padding-bottom: 8px; margin-bottom: 14px; }
.qms-doc .doc-header.quote-header { border-bottom: 0; margin-bottom: 0; }
.qms-doc .quote-header-rule { border-top: 3px double var(--qms-primary); margin-bottom: 14px; }
.qms-doc .quote-header.left + .quote-header-rule { margin-left: 21px; }
.qms-doc .doc-header.center { text-align: center; }
.qms-doc .doc-header.right { text-align: right; }
.qms-doc .doc-header .company-name { font-size: 20px; font-weight: 800; color: var(--qms-primary); letter-spacing: .5px; }
.qms-doc .doc-header .company-sub { font-size: 10.5px; color: #444; }
.qms-doc .doc-title { font-size: 18px; font-weight: 800; letter-spacing: 6px; text-align: center; margin: 10px 0 14px; }
.qms-doc table { width: 100%; border-collapse: collapse; }
.qms-doc table.doc-table th { background: var(--qms-primary); color: #fff; font-size: 10.5px; padding: 5px 6px; text-align: left; border: 1px solid var(--qms-primary); }
.qms-doc table.doc-table td { padding: 3px 6px; border: 1px solid #cfd6e0; font-size: 11px; line-height: 1.2; vertical-align: top; }
.qms-doc table.doc-table td > div { line-height: 1.15; }
.qms-doc table.doc-table tr:nth-child(even) td { background: #f5f8fc; }
.qms-doc .money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.qms-doc .doc-footer { page-break-inside: avoid; break-inside: avoid; }
.qms-doc .doc-footer-page { display: table; width: 100%; height: 280mm; page-break-before: always; break-before: page; }
.qms-doc .doc-footer-page > .doc-footer-cell { display: table-cell; vertical-align: bottom; }
.qms-doc .info-table td { border: 0; padding: 1px 2px; font-size: 11px; }
.qms-doc .totals td { border: 0; padding: 2.5px 6px; font-size: 11.5px; }
.qms-doc .totals .grand td { border-top: 1.5px solid #111; font-weight: 800; font-size: 12.5px; padding-top: 6px; }
.qms-doc .box { border: 1px solid #cfd6e0; padding: 8px 10px; }
.qms-doc .sign-area { margin-top: 26px; }
.qms-doc .sign-area .sign-image { height: 56px; line-height: 0; }
.qms-doc .sign-area .sign-image img { max-height: 56px; max-width: 190px; width: auto; height: auto; }
.qms-doc .sign-area .sign-name { margin-top: 4px; font-weight: 700; text-decoration: underline; }
.qms-doc .footer-doc { margin-top: 14px; border-top: 1px solid #cfd6e0; padding-top: 6px; font-size: 9.5px; color: #555; }
.qms-doc .doc-watermark-cell { width: 21px; padding: 0; border: 0; vertical-align: top; text-align: left; overflow: visible; position: relative; }
.qms-doc .doc-watermark { position: absolute; left: 0; top: 0; display: inline-block; transform: rotate(90deg) translateY(-100%); transform-origin: top left; white-space: nowrap; font-size: 9.5px; line-height: 1.2; color: #888; opacity: .5; }
.qms-doc .doc-header.left + .quote-header-rule + .doc-body { padding-left: 21px; }

@media print {
    .qms-sidebar, .qms-topbar, .no-print, .toast-container, .loading-overlay { display: none !important; }
    .qms-main { margin-left: 0 !important; }
    .qms-content { padding: 0 !important; }
    body { background: #fff; }
    .qms-doc { padding: 0; }
    @page { size: A4 portrait; margin: 14mm 12mm 14mm 12mm; }
}

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 991.98px) {
    .qms-sidebar { transform: translateX(-100%); }
    body.sidebar-open .qms-sidebar { transform: translateX(0); }
    .qms-main, body.sidebar-collapsed .qms-main { margin-left: 0; }
    .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1035; display: none; }
    body.sidebar-open .sidebar-backdrop { display: block; }
}
@media (min-width: 992px) {
    .sidebar-backdrop { display: none !important; }
}

/* Print preview frame */
.print-preview-wrap { background: #525659; padding: 1rem; border-radius: .5rem; }
.print-preview-page {
    background: #fff; width: 100%; max-width: 210mm; min-height: 297mm; box-sizing: border-box;
    margin: 0 auto; padding: 5mm;
    box-shadow: 0 6px 24px rgba(0,0,0,.35);
}

/* Column chooser (checkbox list) */
.qms-colvis-menu { min-width: 190px; max-height: 320px; overflow-y: auto; padding: .35rem 0; }
.qms-colvis-item { display: flex; align-items: center; gap: .45rem; padding: .3rem .9rem; margin: 0; cursor: pointer; white-space: nowrap; }
.qms-colvis-item:hover { background: #f1f5fb; }
.qms-colvis-item input { margin: 0; flex: 0 0 auto; }

/* Quotation list: expandable item breakdown (tree toggle) */
.qms-tree-toggle { display: inline-flex; align-items: center; gap: .35rem; color: var(--qms-primary); vertical-align: baseline; }
.qms-tree-toggle:hover { color: var(--qms-primary); }
.qms-tree-caret { display: inline-block; font-size: .7rem; color: #6c757d; transition: transform .15s ease; flex: 0 0 auto; }
.qms-tree-caret.is-open { transform: rotate(90deg); }
.qms-items-panel { padding: .55rem .65rem .65rem 2rem; background: #f7f9fc; border-left: 3px solid var(--qms-primary); }
.qms-items-title { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #6c757d; margin: 0 0 .4rem; }
.qms-items-table { background: #fff; }
.qms-items-table thead th { background: #e8eef7; color: #1f4e79; font-size: .76rem; white-space: nowrap; }
.qms-items-table tbody td { font-size: .82rem; }


