/* Chagharzai Printing Press UI - built on Bootstrap 5.3. No build step required. */

:root {
    --ps-ink: #0f172a;
    --ps-ink-2: #1e293b;
    --ps-primary: #3b5bdb;
    --ps-primary-rgb: 59, 91, 219;
    --ps-bg: #f3f5fa;
    --ps-border: #e3e8f0;
    --ps-muted: #64748b;
    --ps-cyan: #0ea5e9;
    --ps-magenta: #db2777;
    --ps-yellow: #facc15;
    --ps-sidebar-w: 248px;
    --bs-primary: var(--ps-primary);
    --bs-primary-rgb: var(--ps-primary-rgb);
    --bs-link-color: var(--ps-primary);
    --bs-link-color-rgb: var(--ps-primary-rgb);
    --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --bs-border-color: var(--ps-border);
}

body { background: var(--ps-bg); color: #1f2937; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.btn-primary { --bs-btn-bg: var(--ps-primary); --bs-btn-border-color: var(--ps-primary); --bs-btn-hover-bg: #2f4bc0; --bs-btn-hover-border-color: #2f4bc0; --bs-btn-active-bg: #2a43ad; }
.btn-outline-primary { --bs-btn-color: var(--ps-primary); --bs-btn-border-color: var(--ps-primary); --bs-btn-hover-bg: var(--ps-primary); --bs-btn-hover-border-color: var(--ps-primary); }
.text-primary { color: var(--ps-primary) !important; }
.bg-primary { background-color: var(--ps-primary) !important; }
:focus-visible { outline: 3px solid rgba(var(--ps-primary-rgb), .45); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 2000; background: #fff; padding: 8px 14px; border-radius: 6px; }
.skip-link:focus { left: 8px; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: .65rem; color: #fff; font-weight: 700; letter-spacing: .2px; }
.brand:hover { text-decoration: none; color: #fff; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; flex: 0 0 auto; box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.brand-mark span:nth-child(1) { background: var(--ps-cyan); }
.brand-mark span:nth-child(2) { background: var(--ps-magenta); }
.brand-mark span:nth-child(3) { background: var(--ps-yellow); }
.brand-mark span:nth-child(4) { background: #111827; }
.brand small { display: block; font-weight: 400; font-size: .72rem; color: #94a3b8; letter-spacing: 0; }

/* ---------- Layout ---------- */
.app-shell { min-height: 100vh; }
/* Bootstrap's .offcanvas-lg forces a transparent background at >= lg; keep the dark sidebar. */
.sidebar, .sidebar.offcanvas-lg { background-color: var(--ps-ink) !important; color: #cbd5e1; }
.sidebar .offcanvas-header { border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-nav { padding: .75rem .6rem 2rem; }
.sidebar-nav .nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 1rem .75rem .35rem; font-weight: 600; }
.sidebar-nav .nav-link { color: #cbd5e1; border-radius: 8px; padding: .5rem .75rem; display: flex; align-items: center; gap: .7rem; font-size: .925rem; }
.sidebar-nav .nav-link i { font-size: 1.05rem; opacity: .85; width: 1.2rem; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar-nav .nav-link.active { background: rgba(var(--ps-primary-rgb), .9); color: #fff; box-shadow: 0 4px 14px rgba(var(--ps-primary-rgb), .35); }
.sidebar-nav .nav-link .badge { margin-left: auto; }

@media (min-width: 992px) {
    .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--ps-sidebar-w); overflow-y: auto; z-index: 1030; }
    .main-area { margin-left: var(--ps-sidebar-w); }
    .sidebar .offcanvas-header { display: flex !important; padding: 1.1rem 1.1rem; }
}
@media (max-width: 991.98px) {
    .sidebar.offcanvas-lg { width: 270px; }
}

.topbar { position: sticky; top: 0; z-index: 1020; background: rgba(255,255,255,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--ps-border); }
.topbar .page-title { font-size: 1.05rem; font-weight: 600; margin: 0; color: var(--ps-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content { padding: 1.25rem; max-width: 1500px; }
@media (min-width: 768px) { .content { padding: 1.5rem 1.75rem; } }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(var(--ps-primary-rgb), .12); color: var(--ps-primary); display: inline-grid; place-items: center; font-weight: 700; font-size: .85rem; }

/* ---------- Components ---------- */
.card { border: 1px solid var(--ps-border); border-radius: 12px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.card-header { background: #fff; border-bottom: 1px solid var(--ps-border); padding: .85rem 1.1rem; border-radius: 12px 12px 0 0 !important; }
.card-header h2, .card-header .h6 { font-size: .95rem; font-weight: 600; margin: 0; }
.card-body { padding: 1.1rem; }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; }
.page-head h1 { font-size: 1.35rem; font-weight: 700; margin: 0; color: var(--ps-ink); }
.page-head .subtitle { color: var(--ps-muted); font-size: .9rem; }

.kpi { position: relative; overflow: hidden; height: 100%; }
.kpi .card-body { display: flex; flex-direction: column; gap: .2rem; padding-right: 3.6rem; }
.kpi .kpi-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ps-muted); font-weight: 600; }
.kpi .kpi-value { font-size: 1.45rem; font-weight: 700; color: var(--ps-ink); line-height: 1.2; }
.kpi .kpi-note { font-size: .8rem; color: var(--ps-muted); }
.kpi .kpi-icon { position: absolute; right: 14px; top: 14px; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-size: 1.15rem; }
.kpi-blue .kpi-icon { background: #e7ecff; color: var(--ps-primary); }
.kpi-green .kpi-icon { background: #dcfce7; color: #15803d; }
.kpi-amber .kpi-icon { background: #fef3c7; color: #b45309; }
.kpi-red .kpi-icon { background: #fee2e2; color: #b91c1c; }
.kpi-cyan .kpi-icon { background: #e0f2fe; color: #0369a1; }
.kpi-violet .kpi-icon { background: #f3e8ff; color: #7e22ce; }
a.kpi-link { color: inherit; display: block; height: 100%; }
a.kpi-link:hover { text-decoration: none; }
a.kpi-link:hover .card { border-color: rgba(var(--ps-primary-rgb), .45); }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .65rem .75rem; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ps-muted); font-weight: 600; background: #f8fafc; border-bottom: 1px solid var(--ps-border); white-space: nowrap; }
.table-hover tbody tr:hover { --bs-table-hover-bg: #f6f8ff; }
.table td.num, .table th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tfoot td, .table tfoot th { font-weight: 700; background: #f8fafc; }
.table .row-muted td { color: #94a3b8; text-decoration: line-through; }
.num { font-variant-numeric: tabular-nums; }
.status-badge { font-weight: 600; font-size: .74rem; padding: .38em .6em; border-radius: 6px; }
.text-bg-light.status-badge { border: 1px solid var(--ps-border); }

.filters { background: #fff; border: 1px solid var(--ps-border); border-radius: 12px; padding: .85rem; margin-bottom: 1rem; }
.filters .form-label { font-size: .75rem; color: var(--ps-muted); margin-bottom: .2rem; font-weight: 600; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--ps-muted); }
.empty-state i { font-size: 2.4rem; color: #cbd5e1; display: block; margin-bottom: .6rem; }
.empty-state h3 { font-size: 1.05rem; color: var(--ps-ink-2); font-weight: 600; }

.form-label { font-weight: 500; font-size: .9rem; }
.form-text { font-size: .8rem; }
.required::after { content: " *"; color: #dc2626; }
.form-section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ps-muted); font-weight: 700; margin: 1.25rem 0 .6rem; }
.dl-grid { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.dl-grid dt { color: var(--ps-muted); font-weight: 500; font-size: .875rem; }
.dl-grid dd { margin: 0; font-size: .925rem; }
.money-big { font-size: 1.6rem; font-weight: 700; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.4rem; border-left: 2px solid var(--ps-border); margin-left: .4rem; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--ps-primary); }
.timeline .meta { font-size: .78rem; color: var(--ps-muted); }

.status-flow { display: flex; flex-wrap: wrap; gap: .4rem; }
.status-flow .btn { font-size: .8rem; }

/* Items editor */
.item-row { border: 1px solid var(--ps-border); border-radius: 10px; padding: .85rem; margin-bottom: .75rem; background: #fcfdff; }
.item-row .item-index { width: 26px; height: 26px; border-radius: 50%; background: rgba(var(--ps-primary-rgb), .1); color: var(--ps-primary); display: inline-grid; place-items: center; font-weight: 700; font-size: .8rem; }
.item-row .line-total { font-weight: 700; font-size: 1.05rem; }
.item-row .spec-grid:empty { display: none; }
.totals-box { background: #fff; border: 1px solid var(--ps-border); border-radius: 12px; padding: 1rem; }
.totals-box .row-line { display: flex; justify-content: space-between; padding: .25rem 0; }
.totals-box .grand { border-top: 2px solid var(--ps-ink); margin-top: .4rem; padding-top: .5rem; font-size: 1.15rem; font-weight: 700; }

.alert { border-radius: 10px; }
.check-ok { color: #15803d; }
.check-bad { color: #b91c1c; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(1200px 600px at 10% -10%, #dfe6ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #fde2f0 0%, transparent 55%), var(--ps-bg); }
.login-card { width: 100%; max-width: 420px; }
.login-card .brand { color: var(--ps-ink); }
.login-card .brand small { color: var(--ps-muted); }

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

/* Simple-mode helpers */
.step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ps-primary); color: #fff; font-size: .8rem; font-weight: 700; margin-right: .4rem; vertical-align: 1px; }
.step-heading { font-weight: 600; font-size: .95rem; margin: 0 0 .5rem .1rem; color: var(--ps-ink); }
.glance-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ps-muted); font-weight: 600; }
.glance-value { font-size: 1.3rem; font-weight: 700; color: var(--ps-ink); }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "\25BE"; float: right; color: var(--ps-muted); }
.quick-actions .qa { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem; padding: 1rem .5rem; border-radius: 12px; border: 1px solid var(--ps-border); background: #fff; color: var(--ps-ink); font-weight: 600; text-align: center; height: 100%; transition: border-color .15s, box-shadow .15s; }
.quick-actions .qa i { font-size: 1.6rem; color: var(--ps-primary); }
.quick-actions .qa:hover { text-decoration: none; border-color: rgba(var(--ps-primary-rgb), .5); box-shadow: 0 4px 14px rgba(var(--ps-primary-rgb), .12); }
.quick-actions .qa small { font-weight: 400; color: var(--ps-muted); font-size: .75rem; }
.help-steps li { margin-bottom: .45rem; }
.accordion-button:not(.collapsed) { background: #f6f8ff; color: var(--ps-ink); }
.searchable-filter { margin-bottom: .35rem; }

/* ---------- Mobile tweaks ---------- */
.table td > a.fw-semibold:first-child { white-space: nowrap; }
@media (max-width: 575.98px) {
    .table { font-size: .84rem; }
    .page-head h1 { font-size: 1.15rem; }
    .kpi .kpi-value { font-size: 1.2rem; }
    .content { padding: 1rem .75rem; }
    .table > :not(caption) > * > * { padding: .55rem .5rem; }
    .btn-toolbar-mobile .btn { flex: 1 1 auto; }
}

/* ---------- Print (documents & reports) ---------- */
.print-toolbar { position: sticky; top: 0; z-index: 10; background: var(--ps-ink); color: #fff; padding: .6rem 1rem; display: flex; gap: .5rem; align-items: center; justify-content: space-between; }
.print-body { background: #e5e7eb; min-height: 100vh; padding: 1.25rem 0 2.5rem; }
.sheet { background: #fff; width: 210mm; min-height: 297mm; margin: 0 auto; padding: 14mm 14mm 16mm; box-shadow: 0 6px 24px rgba(0,0,0,.12); color: #111827; font-size: 10.5pt; }
.sheet.report { width: auto; max-width: 297mm; min-height: auto; }
@media (max-width: 820px) { .sheet { width: 100%; min-height: auto; padding: 6mm; } }
.doc-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 3px solid #111827; padding-bottom: 10px; margin-bottom: 14px; }
.doc-head .shop-name { font-size: 18pt; font-weight: 800; letter-spacing: .3px; line-height: 1.1; }
.doc-head .shop-meta { font-size: 9pt; color: #374151; line-height: 1.45; }
.doc-head .doc-logo { max-height: 64px; max-width: 160px; object-fit: contain; }
.doc-title { text-align: right; }
.doc-title h1 { font-size: 20pt; font-weight: 800; letter-spacing: 2px; margin: 0; color: #111827; }
.doc-title .doc-no { font-size: 11pt; font-weight: 700; }
.cmyk-bar { display: flex; height: 4px; margin: -12px 0 12px; }
.cmyk-bar span { flex: 1; }
.cmyk-bar span:nth-child(1) { background: var(--ps-cyan); } .cmyk-bar span:nth-child(2) { background: var(--ps-magenta); }
.cmyk-bar span:nth-child(3) { background: var(--ps-yellow); } .cmyk-bar span:nth-child(4) { background: #111827; }
.doc-parties { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 12px; font-size: 9.5pt; }
.doc-parties .box { border: 1px solid #d1d5db; border-radius: 6px; padding: 8px 10px; flex: 1; }
.doc-parties .box h6 { font-size: 8pt; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; margin: 0 0 4px; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
.doc-table th { background: #111827; color: #fff; font-weight: 600; padding: 6px 7px; text-align: left; font-size: 8.5pt; text-transform: uppercase; letter-spacing: .04em; }
.doc-table td { border-bottom: 1px solid #e5e7eb; padding: 6px 7px; vertical-align: top; }
.doc-table .num { text-align: right; white-space: nowrap; }
.doc-table .spec { color: #4b5563; font-size: 8.5pt; }
.doc-table tr { page-break-inside: avoid; }
.doc-summary { display: flex; justify-content: space-between; gap: 1.5rem; margin-top: 12px; page-break-inside: avoid; }
.doc-summary .words { flex: 1; font-size: 9pt; }
.doc-summary table { min-width: 260px; font-size: 10pt; border-collapse: collapse; }
.doc-summary td { padding: 4px 6px; }
.doc-summary td:last-child { text-align: right; white-space: nowrap; }
.doc-summary .grand td { border-top: 2px solid #111827; font-weight: 800; font-size: 12pt; }
.doc-summary .due td { background: #111827; color: #fff; font-weight: 800; }
.doc-foot { margin-top: 22px; font-size: 8.5pt; color: #374151; page-break-inside: avoid; }
.doc-sign { display: flex; justify-content: space-between; margin-top: 38px; font-size: 9pt; }
.doc-sign div { border-top: 1px solid #6b7280; padding-top: 4px; width: 42%; text-align: center; }
.stamp { display: inline-block; border: 3px solid; border-radius: 8px; padding: 2px 10px; font-weight: 800; letter-spacing: 2px; transform: rotate(-6deg); font-size: 14pt; }
.stamp.paid { color: #15803d; } .stamp.unpaid { color: #b91c1c; } .stamp.partial { color: #b45309; } .stamp.cancelled { color: #6b7280; }
.report-table { width: 100%; border-collapse: collapse; font-size: 9pt; }
.report-table th, .report-table td { border: 1px solid #d1d5db; padding: 4px 6px; }
.report-table th { background: #f3f4f6; }

@page { size: A4; margin: 10mm; }
@media print {
    body, .print-body { background: #fff !important; padding: 0 !important; }
    .no-print, .print-toolbar, .sidebar, .topbar, .btn, .filters, .alert-dismissible .btn-close { display: none !important; }
    .sheet { box-shadow: none; margin: 0; width: auto; min-height: auto; padding: 0; }
    .main-area { margin-left: 0 !important; }
    .content { padding: 0 !important; max-width: none; }
    .card { border: none; box-shadow: none; }
    a { color: inherit !important; text-decoration: none !important; }
    .doc-table th, .doc-summary .due td, .cmyk-bar span { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .table thead th { background: #f3f4f6 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
