:root {
    --navy: #2a0f12;
    --navy-2: #42181c;
    --accent: #b3202a;
    --accent-2: #d4a017;
    --bg: #f3f6f9;
    --card: #ffffff;
    --line: #e3e8ee;
    --text: #1d2b3a;
    --muted: #6b7a8a;
    --ok: #198754;
    --warn: #c98a06;
    --bad: #c0392b;
    --sidebar-w: 260px;
    --bs-primary: #b3202a;
    --bs-primary-rgb: 179, 32, 42;
    --bs-body-font-family: "Cairo", system-ui, sans-serif;
}

body { font-family: "Cairo", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: .93rem; }
a { color: var(--accent); }
.btn-primary { --bs-btn-bg: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-hover-bg: #951a22; --bs-btn-hover-border-color: #951a22; --bs-btn-active-bg: #7d151c; }
.btn-outline-primary { --bs-btn-color: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-hover-bg: var(--accent); --bs-btn-hover-border-color: var(--accent); }
.form-control, .form-select { border-color: #d6dde5; }
.form-control:focus, .form-select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 .2rem rgba(212, 160, 23, .2); }
.form-label { font-weight: 600; font-size: .85rem; margin-bottom: .3rem; color: #3b4b5b; }

/* ---------- Shell ---------- */
.sidebar { position: fixed; inset-block: 0; right: 0; width: var(--sidebar-w); background: var(--navy); color: #c9d6e3; display: flex; flex-direction: column; z-index: 1040; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.2rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(135deg, var(--accent-2), var(--accent)); display: grid; place-items: center; font-size: 1.25rem; }
.brand strong { display: block; font-size: 1.1rem; line-height: 1.1; }
.brand small { color: #8fa6bd; font-size: .72rem; }
.side-nav { flex: 1; overflow-y: auto; padding: .8rem .6rem; }
.side-nav a, .nav-group summary { display: flex; align-items: center; gap: .65rem; padding: .5rem .8rem; border-radius: 9px; color: #c9d6e3; text-decoration: none; cursor: pointer; font-weight: 600; }
.side-nav a:hover, .nav-group summary:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.active { background: var(--accent); color: #fff; }
.side-nav i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.nav-caption { display: block; font-size: .72rem; color: #6f88a1; padding: .6rem .8rem .2rem; }
.nav-group { margin: .15rem 0; }
.nav-group summary { list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after { content: "\F282"; font-family: bootstrap-icons; margin-inline-start: auto; font-size: .75rem; transition: transform .2s; }
.nav-group[open] summary::after { transform: rotate(180deg); }
.nav-group a { padding: .38rem 2.6rem .38rem .8rem; font-weight: 400; font-size: .88rem; }
.plan-box { margin: .8rem; padding: .7rem .9rem; border-radius: 10px; background: var(--navy-2); color: #fff; text-decoration: none; display: flex; flex-direction: column; }
.plan-box small { color: #8fa6bd; }
.main { margin-right: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: 1rem; padding: .7rem 1.5rem; background: rgba(255,255,255,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.topbar-title { display: flex; flex-direction: column; line-height: 1.25; }
.topbar-title small { color: var(--muted); font-size: .75rem; }
.topbar-title strong { font-size: 1.05rem; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; width: 38px; height: 38px; display: grid; place-items: center; font-size: 1.3rem; }
.user-chip { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--line); background: #fff; border-radius: 30px; padding: .25rem .4rem .25rem .8rem; line-height: 1.15; }
.user-chip small { color: var(--muted); font-size: .72rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.content { padding: 1.4rem 1.5rem 3rem; }
.overlay { display: none; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(100%); }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-open .overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1030; }
    .main { margin-right: 0; }
    .content { padding: 1rem; }
    .topbar { padding: .6rem 1rem; }
}

/* ---------- Building blocks ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: 1.1rem; }
.page-head h1 { font-size: 1.35rem; font-weight: 800; margin: 0; }
.page-head p { margin: .15rem 0 0; color: var(--muted); }
.card-x { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-x > .card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line); font-weight: 700; }
.card-x > .card-body-x { padding: 1.1rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.filters .form-control, .filters .form-select { min-width: 150px; }
.table-x { margin: 0; }
.table-x thead th { background: #f7f9fb; color: #4a5a6a; font-size: .8rem; font-weight: 700; white-space: nowrap; border-bottom: 1px solid var(--line); padding: .65rem .8rem; }
.table-x td { padding: .6rem .8rem; vertical-align: middle; border-color: #eef2f5; }
.table-x tbody tr:hover { background: #fafcfd; }
.table-x tfoot td { font-weight: 800; background: #f7f9fb; }
.num { text-align: left !important; direction: ltr; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.empty i { font-size: 2.2rem; display: block; margin-bottom: .4rem; color: #b6c2ce; }
.badge-st { font-size: .74rem; padding: .3rem .6rem; border-radius: 20px; font-weight: 700; }
.st-draft { background: #eef1f4; color: #55606b; }
.st-approved { background: #fff4d6; color: #8a6100; }
.st-posted { background: #dcf3e6; color: #12643c; }
.st-cancelled { background: #fbe1df; color: #9b2c22; }
.actions { white-space: nowrap; }
.actions .btn { padding: .2rem .5rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem 1.1rem; display: flex; gap: .9rem; align-items: center; }
.kpi i { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0; }
.kpi small { color: var(--muted); display: block; }
.kpi strong { font-size: 1.25rem; font-weight: 800; direction: ltr; display: inline-block; }
.k-teal i { background: #fbe4e5; color: var(--accent); }
.k-blue i { background: #e1ecfb; color: #2763b8; }
.k-green i { background: #dcf3e6; color: var(--ok); }
.k-amber i { background: #fff1d2; color: var(--warn); }
.k-red i { background: #fbe1df; color: var(--bad); }

.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.quick a { display: flex; flex-direction: column; align-items: center; gap: .35rem; padding: .9rem .5rem; border: 1px dashed #cfd8e1; border-radius: 12px; text-decoration: none; color: var(--text); font-weight: 600; font-size: .86rem; background: #fbfcfd; }
.quick a:hover { border-color: var(--accent); color: var(--accent); background: #f2fafa; }
.quick i { font-size: 1.4rem; color: var(--accent); }

.tree-row td:first-child { white-space: nowrap; }
.lvl-0 { font-weight: 800; background: #f9fbfc; }
.lvl-1 { font-weight: 700; }
.group-row { font-weight: 700; color: #2c3d4e; }

.lines-table td { padding: .3rem; }
.lines-table .form-control, .lines-table .form-select { font-size: .86rem; padding: .3rem .45rem; }
.totals { max-width: 360px; margin-inline-start: auto; }
.totals div { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px dashed var(--line); }
.totals div.grand { font-size: 1.1rem; font-weight: 800; border-bottom: 0; color: var(--accent); }
.form-section { font-weight: 800; font-size: .95rem; color: var(--navy); margin: 1.2rem 0 .7rem; padding-bottom: .4rem; border-bottom: 1px solid var(--line); }

/* ---------- Auth ---------- */
.auth-body { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; background: #fff; }
.auth-side { background: linear-gradient(160deg, var(--navy) 0%, #0c3b5a 55%, var(--accent) 120%); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h2 { font-weight: 800; font-size: 2rem; line-height: 1.5; }
.auth-side ul { list-style: none; padding: 0; margin: 1.5rem 0 0; }
.auth-side li { padding: .45rem 0; color: #d4e3ef; }
.auth-side li i { color: #6fe0e8; margin-left: .5rem; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-card { width: 100%; max-width: 440px; }
.auth-card h1 { font-weight: 800; font-size: 1.6rem; }
.plan-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.plan-pick label { border: 1px solid var(--line); border-radius: 10px; padding: .6rem; text-align: center; cursor: pointer; font-size: .82rem; }
.plan-pick input { display: none; }
.plan-pick input:checked + label { border-color: var(--accent); background: #eef8f8; box-shadow: 0 0 0 2px rgba(14,124,134,.15); }
.plan-pick strong { display: block; font-size: 1rem; }
@media (max-width: 860px) { .auth-body { grid-template-columns: 1fr; } .auth-side { display: none; } }

/* ---------- Print ---------- */
.print-doc { background: #fff; max-width: 900px; margin: 0 auto; padding: 2rem; border: 1px solid var(--line); border-radius: 10px; }
.print-doc .doc-head { display: flex; justify-content: space-between; border-bottom: 2px solid var(--navy); padding-bottom: 1rem; margin-bottom: 1rem; }
.print-doc h2 { font-weight: 800; color: var(--navy); }
.sign-row { display: flex; justify-content: space-around; margin-top: 3rem; text-align: center; }
.sign-row div { border-top: 1px solid #999; padding-top: .4rem; min-width: 150px; }
@media print {
    .sidebar, .topbar, .no-print, .alert, .filters .btn { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    body { background: #fff; }
    .card-x, .print-doc { border: 0; box-shadow: none; }
}

/* ---------- Hyper Quality additions ---------- */
.form-code { font-size: .72rem; font-weight: 700; background: #fff4d6; color: #8a6100; border: 1px solid #f0d89a; border-radius: 6px; padding: .1rem .45rem; vertical-align: middle; direction: ltr; display: inline-block; }
.color-dot { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line); }
.ready { display: inline-block; width: 90px; height: 8px; background: #eef1f4; border-radius: 6px; overflow: hidden; vertical-align: middle; margin-left: .4rem; }
.ready span { display: block; height: 100%; border-radius: 6px; }
.stage-strip { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .2rem; }
.stage-pill { flex: 1 0 auto; min-width: 104px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .5rem .7rem; text-decoration: none; color: var(--text); display: flex; flex-direction: column; align-items: center; }
.stage-pill strong { font-size: 1.2rem; color: var(--accent); }
.stage-pill span { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.stage-pill.empty strong { color: #c3cbd3; }
.stage-pill.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(179, 32, 42, .15); }
.stepper { display: flex; overflow-x: auto; padding: 1rem .6rem; gap: 0; }
.stepper .step { flex: 1 0 86px; position: relative; text-align: center; margin: 0; }
.stepper .step::before { content: ""; position: absolute; top: 15px; right: 50%; width: 100%; height: 3px; background: #e3e8ee; z-index: 0; }
.stepper .step:first-child::before { display: none; }
.stepper .step.done::before, .stepper .step.current::before { background: var(--accent); }
.stepper button { background: none; border: 0; padding: 0; position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: .3rem; width: 100%; color: var(--muted); }
.stepper .dot { width: 32px; height: 32px; border-radius: 50%; background: #fff; border: 3px solid #e3e8ee; display: grid; place-items: center; font-weight: 800; font-size: .8rem; }
.stepper .step.done .dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.stepper .step.current .dot { border-color: var(--accent-2); color: var(--accent); box-shadow: 0 0 0 4px rgba(212, 160, 23, .2); }
.stepper .step.current small { color: var(--text); font-weight: 700; }
.stepper small { font-size: .7rem; line-height: 1.2; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree ul { list-style: none; margin: 0; padding-inline-start: 1.6rem; border-inline-start: 2px dashed #e3e8ee; }
.tree li { margin: .3rem 0; }
.tree-node { display: flex; align-items: center; gap: .6rem; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.tree-node .health { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.h-green { background: var(--ok); } .h-amber { background: var(--warn); } .h-red { background: var(--bad); } .h-gray { background: #c3cbd3; }
.score-ring { --v: 0; width: 86px; height: 86px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) calc(var(--v) * 1%), #eef1f4 0); }
.score-ring span { width: 66px; height: 66px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; }
.bar-row { display: flex; align-items: center; gap: .6rem; margin: .35rem 0; font-size: .85rem; }
.bar-row .bar { flex: 1; height: 10px; background: #eef1f4; border-radius: 6px; overflow: hidden; }
.bar-row .bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar-row .lbl { width: 190px; flex-shrink: 0; }
.bar-row .val { width: 110px; text-align: left; direction: ltr; font-weight: 700; }
