:root {
  --p: #880290;
  --p2: #a51cb0;
  --o: #ff751f;
  --ink: #1d1520;
  --mut: #7b7286;
  --bg: #f6f4f8;
  --line: #e8e2ec;
  --ok: #12855a;
  --err: #c62828;
  --warn: #b26a00;
  --r: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Cairo, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--p); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 800; letter-spacing: -.2px; }
h1 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: .95rem; color: var(--mut); margin-top: 1.25rem; }
.muted { color: var(--mut); font-size: .88rem; }
.dim { color: #c9c2d0; }
.empty { text-align: center; color: var(--mut); padding: 1.6rem 0 !important; }

/* ---------------- shell ---------------- */
.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.side {
  background: linear-gradient(170deg, #2a0a33, #4b0b57 60%, #6a1078);
  color: #f6e9f8; display: flex; flex-direction: column; padding: 1.1rem .8rem;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: .6rem; align-items: center; padding: .3rem .4rem 1rem; color: #fff; }
.brand:hover { text-decoration: none; }
.logo {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--p2), var(--o)); font-weight: 800; font-size: 1.1rem; color: #fff;
}
.brand-t { display: flex; flex-direction: column; line-height: 1.2; }
.brand-t b { font-size: 1rem; }
.brand-t small { color: #d7b9de; font-size: .72rem; }
.side nav { display: flex; flex-direction: column; gap: .15rem; overflow-y: auto; flex: 1; }
.nav {
  display: flex; gap: .6rem; align-items: center; padding: .6rem .7rem; border-radius: 10px;
  color: #ecdcf0; font-size: .92rem; font-weight: 600;
}
.nav:hover { background: rgba(255, 255, 255, .09); text-decoration: none; color: #fff; }
.nav.on { background: rgba(255, 255, 255, .16); color: #fff; box-shadow: inset 3px 0 0 var(--o); }
.nav i { font-style: normal; width: 18px; text-align: center; opacity: .85; }
.side-f { border-top: 1px solid rgba(255, 255, 255, .14); padding-top: .7rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.who { display: flex; flex-direction: column; line-height: 1.2; }
.who b { font-size: .85rem; }
.who small { color: #d7b9de; font-size: .72rem; }
.out { color: #ffd9c2; font-size: .8rem; }
.main { display: flex; flex-direction: column; min-width: 0; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.6rem; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.top-r { display: flex; align-items: center; gap: .6rem; }
.cur { background: #f3ebf5; color: var(--p); font-weight: 700; font-size: .8rem; padding: .25rem .6rem; border-radius: 8px; }
.switch select { border: 1px solid var(--line); border-radius: 8px; padding: .35rem .5rem; font-family: inherit; }
.wrap { padding: 1.2rem 1.6rem 3rem; }

/* ---------------- panels ---------------- */
.panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  padding: 1.1rem 1.2rem; margin-bottom: 1.1rem;
  box-shadow: 0 1px 2px rgba(30, 12, 40, .04);
}
.panel h3 { display: flex; align-items: center; justify-content: space-between; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

/* ---------------- kpis ---------------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.1rem; }
.kpis.sm { grid-template-columns: repeat(3, 1fr); margin-bottom: 1rem; }
@media (max-width: 900px) { .kpis, .kpis.sm { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: .9rem 1rem;
  display: flex; flex-direction: column; gap: .15rem;
}
.kpi span { color: var(--mut); font-size: .8rem; font-weight: 600; }
.kpi b { font-size: 1.35rem; letter-spacing: -.5px; }
.kpi b.warn { color: var(--warn); }
.kpi small { color: var(--mut); font-size: .75rem; }

/* ---------------- toolbar ---------------- */
.bar { display: flex; justify-content: space-between; gap: .8rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.search { display: flex; gap: .4rem; }
.search input, .search select {
  border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; font-family: inherit; background: #fff;
}
.search input { min-width: 190px; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: #fff;
  color: var(--ink); padding: .5rem .9rem; border-radius: 10px; font: inherit; font-weight: 700; font-size: .88rem;
  cursor: pointer;
}
.btn:hover { background: #faf7fc; text-decoration: none; }
.btn.primary { background: linear-gradient(140deg, var(--p), var(--p2)); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--err); border-color: #f3cfcf; }
.mini {
  display: inline-block; border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: .14rem .45rem; font-size: .76rem; font-weight: 700; cursor: pointer; font-family: inherit; color: var(--ink);
}
.mini:hover { text-decoration: none; background: #faf7fc; }
.mini.danger { color: var(--err); border-color: #f3cfcf; }
.inline { display: inline-flex; gap: .35rem; align-items: center; }
.inline input { border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; font-family: inherit; width: 120px; }

/* ---------------- tables ---------------- */
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th {
  text-align: right; font-size: .76rem; color: var(--mut); text-transform: uppercase;
  letter-spacing: .3px; padding: .5rem .6rem; border-bottom: 1px solid var(--line);
}
.tbl td { padding: .55rem .6rem; border-bottom: 1px solid #f4f0f6; vertical-align: middle; }
.tbl tbody tr:hover { background: #fcfafd; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.row-act { display: flex; gap: .35rem; align-items: center; justify-content: flex-end; }
.row-act form { display: inline; }
.lines input, .lines select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; font-family: inherit;
}
.lines .lineTotal { font-weight: 700; white-space: nowrap; }
.lines-f { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-top: .8rem; flex-wrap: wrap; }
.totals { min-width: 230px; }
.totals > div { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; font-size: .9rem; }
.totals .grand { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .4rem; font-size: 1.05rem; }
.totals .grand b { color: var(--p); }

/* ---------------- forms ---------------- */
.form label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 700; color: #4b4254; }
.form input, .form select, .form textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .65rem; font-family: inherit; font-size: .92rem;
  background: #fff; font-weight: 500; color: var(--ink);
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid #e7c9ec; border-color: var(--p2); }
.form input:disabled, .form textarea:disabled { background: #f8f6f9; color: var(--mut); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .85rem 1rem; }
@media (max-width: 780px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.wide { grid-column: 1 / -1; }
.actions { display: flex; gap: .5rem; align-items: center; padding-top: .4rem; }
.chk { flex-direction: row !important; align-items: center; gap: .5rem; margin-top: .8rem; font-weight: 600; }
.perm { width: 100%; border-collapse: collapse; font-size: .82rem; }
.perm th, .perm td { border-bottom: 1px solid #f1ecf4; padding: .3rem .35rem; text-align: center; }
.perm th:first-child, .perm td:first-child { text-align: right; }
.perm input { width: 16px; height: 16px; accent-color: var(--p); }

/* ---------------- badges / flash ---------------- */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; background: #eee7f1; color: #574a60; }
.badge.ok { background: #e3f6ec; color: var(--ok); }
.badge.r { background: #fdeaea; color: var(--err); }
.badge.o { background: #fff2e3; color: var(--warn); }
.badge.b { background: #e9efff; color: #2b4bb5; }
.badge.g { background: #eee7f1; color: #574a60; }
.flash { border-radius: 10px; padding: .6rem .9rem; margin-bottom: .9rem; font-weight: 700; font-size: .88rem; }
.flash.ok { background: #e3f6ec; color: #0d6b48; }
.flash.err { background: #fdeaea; color: var(--err); }

/* ---------------- chart ---------------- */
.chart { display: flex; flex-direction: column; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: 72px 1fr 130px; align-items: center; gap: .6rem; font-size: .82rem; }
.bar-l { color: var(--mut); }
.bar-t { background: #f3edf6; border-radius: 6px; height: 14px; overflow: hidden; }
.bar-t i { display: block; height: 100%; background: linear-gradient(90deg, var(--p), var(--o)); border-radius: 6px; }
.bar-row b { text-align: left; }

/* ---------------- auth ---------------- */
body.auth { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(160deg, #f7f1f9, #efe6f4 60%, #fdf1e8); padding: 1.5rem; }
body.auth .card {
  background: #fff; border-radius: 20px; padding: 1.8rem; width: 100%; max-width: 430px;
  box-shadow: 0 18px 50px rgba(60, 15, 80, .13);
}
.auth-brand { display: flex; align-items: center; gap: .55rem; margin-bottom: 1rem; }
.auth-brand b { font-size: 1.05rem; }
body.auth h2 { font-size: 1.2rem; }
body.auth .form { display: flex; flex-direction: column; gap: .8rem; }
body.auth .form label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 700; color: #4b4254; }
body.auth .form input {
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; font-family: inherit; font-size: .95rem;
}
body.auth .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
body.auth hr { border: 0; border-top: 1px solid var(--line); margin: .4rem 0; }
body.auth .btn { justify-content: center; margin-top: .4rem; }

/* ---------------- document ---------------- */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 1.6rem; max-width: 900px; }
.doc-h { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; border-bottom: 2px solid var(--p); padding-bottom: .9rem; }
.doc-h h2 { font-size: 1.2rem; color: var(--p); }
.doc-meta { text-align: left; display: flex; flex-direction: column; gap: .15rem; }
.doc-meta > div { display: flex; gap: .5rem; justify-content: space-between; font-size: .84rem; }
.doc-meta span { color: var(--mut); }
.doc-cust { margin: 1rem 0; display: flex; flex-direction: column; }
.doc-tbl { margin-top: .5rem; }
.doc-tot { margin-top: .9rem; margin-right: auto; width: 300px; max-width: 100%; }
.doc-tot > div { display: flex; justify-content: space-between; padding: .22rem 0; font-size: .9rem; }
.doc-tot .grand { border-top: 1px solid var(--line); padding-top: .4rem; font-weight: 800; }
.doc-tot .grand b { color: var(--p); }
.doc-notes { margin-top: 1rem; font-size: .85rem; border-top: 1px dashed var(--line); padding-top: .7rem; }
.doc-act { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------------- print ---------------- */
@media print {
  .side, .top, .doc-act, .no-print { display: none !important; }
  body { background: #fff; }
  .shell { display: block; }
  .wrap { padding: 0; }
  .doc { border: 0; max-width: none; padding: 0; }
  @page { size: A4; margin: 14mm; }
}
