:root {
  --blue: #0b3c7d;
  --blue-2: #14508f;
  --blue-soft: #e8effa;
  --red: #c8102e;
  --red-soft: #fdecef;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f4f6f9;
  --card: #ffffff;
  --green: #0f7b53;
  --green-soft: #e6f5ee;
  --amber: #b25e00;
  --amber-soft: #fff4e5;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Noto Kufi Arabic", "Tahoma", "Cairo", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- app bar ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-2) 100%);
  color: #fff;
  padding: 14px 16px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 10px rgba(11, 60, 125, 0.18);
}
.brandmark {
  width: 40px; height: 40px; border-radius: 11px; background: rgba(255,255,255,.14);
  display: grid; place-items: center; flex: 0 0 auto; position: relative; overflow: hidden;
}
.brandmark i { display: block; }
.brandmark .bar-red { position: absolute; inset-inline-start: 8px; top: 9px; width: 5px; height: 22px; background: var(--red); border-radius: 2px; }
.brandmark .bar-w { position: absolute; inset-inline-start: 17px; top: 9px; width: 16px; height: 5px; background: #fff; border-radius: 2px; }
.brandmark .bar-w2 { position: absolute; inset-inline-start: 17px; top: 18px; width: 12px; height: 4px; background: #fff; border-radius: 2px; }
.appbar h1 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: 0; }
.appbar .sub { font-size: 11.5px; opacity: .82; margin-top: 1px; }
.appbar .spacer { flex: 1; }
.iconbtn {
  background: rgba(255,255,255,.14); border: 0; color: #fff; width: 38px; height: 38px;
  border-radius: 11px; display: grid; place-items: center; cursor: pointer; font-size: 16px;
}
.iconbtn:active { transform: scale(.96); }

/* ---------- layout ---------- */
.page { max-width: 760px; margin: 0 auto; padding: 16px 14px 24px; }
.page.narrow { max-width: 480px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; border: 1px solid rgba(228,231,236,.7); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 18px 4px 10px; }
.section-title h2 { font-size: 14px; margin: 0; color: var(--muted); font-weight: 700; }
.section-title a, .section-title button { font-size: 13px; font-weight: 600; background: none; border: 0; color: var(--blue); cursor: pointer; padding: 4px; }

/* ---------- nav ---------- */
.nav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  max-width: 760px; margin: 0 auto;
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: #8a94a6; font-size: 10.5px; font-weight: 600; padding-top: 6px;
}
.nav a.on { color: var(--blue); }
.nav a.on svg { color: var(--blue); }
.nav svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  background: var(--blue); color: #fff; font-weight: 700; font-size: 14.5px; cursor: pointer;
  width: 100%; transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.99); }
.btn.secondary { background: #fff; color: var(--blue); border-color: #cfd9e8; }
.btn.ghost { background: transparent; color: var(--blue); border-color: transparent; }
.btn.danger { background: var(--red-soft); color: var(--red); border-color: #f6c9d1; }
.btn.small { min-height: 38px; font-size: 13px; padding: 0 12px; width: auto; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ---------- forms ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: #475467; margin-bottom: 6px; }
.field label .req { color: var(--red); margin-inline-start: 2px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 11px 12px; border: 1px solid #d0d5dd; border-radius: 11px;
  background: #fff; color: var(--ink); outline: none;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(11,60,125,.1); }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- chips & stats ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.chip.draft { background: #f2f4f7; color: #475467; }
.chip.review { background: var(--amber-soft); color: var(--amber); }
.chip.sent { background: var(--blue-soft); color: var(--blue); }
.chip.won { background: var(--green-soft); color: var(--green); }
.chip.lost { background: var(--red-soft); color: var(--red); }
.chip.gray { background: #f2f4f7; color: #475467; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: #fff; border-radius: 14px; padding: 14px; box-shadow: var(--shadow); border: 1px solid rgba(228,231,236,.7); }
.stat .n { font-size: 26px; font-weight: 800; line-height: 1.1; letter-spacing: -.5px; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 600; }
.stat.blue .n { color: var(--blue); }
.stat.green .n { color: var(--green); }
.stat.red .n { color: var(--red); }
.stat.amber .n { color: var(--amber); }

/* ---------- lists ---------- */
.item {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px; background: #fff;
  border-radius: 14px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(16,24,40,.05);
  border: 1px solid rgba(228,231,236,.8); cursor: pointer;
}
.item:active { background: #fafbfc; }
.item .avatar {
  width: 42px; height: 42px; border-radius: 12px; background: var(--blue-soft); color: var(--blue);
  display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: 0 0 auto;
}
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item .end { text-align: end; flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.item .amount { font-weight: 800; font-size: 13.5px; }

.empty { text-align: center; padding: 34px 18px; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; }
.empty p { margin: 6px 0 14px; font-size: 13.5px; }

/* ---------- misc ---------- */
.note { background: var(--blue-soft); color: #123f6d; border-radius: 12px; padding: 11px 13px; font-size: 12.5px; line-height: 1.65; }
.note.amber { background: var(--amber-soft); color: #7a4300; }
.note.red { background: var(--red-soft); color: #8c1122; }
.note.green { background: var(--green-soft); color: #0a5c3e; }
.note b { font-weight: 800; }
.muted { color: var(--muted); font-size: 12.5px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: end; }
.back { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 700; color: var(--blue); background: none; border: 0; padding: 4px 0; cursor: pointer; margin-bottom: 8px; }
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom));
  background: #101828; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 13.5px;
  z-index: 90; box-shadow: 0 10px 30px rgba(0,0,0,.2); max-width: 420px; margin: 0 auto;
  animation: pop .18s ease;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 18px; background: linear-gradient(160deg, #0b3c7d 0%, #123f6d 42%, #f4f6f9 42.1%, #f4f6f9 100%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 20px; padding: 26px 22px; box-shadow: 0 20px 50px rgba(11,60,125,.18); }
.login-card .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-card h2 { font-size: 19px; margin: 0; }
.login-card p.sub { color: var(--muted); font-size: 13px; margin: 2px 0 20px; }

.gaps { margin: 8px 0 0; padding: 0; list-style: none; }
.gaps li { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.gaps li:last-child { border-bottom: 0; }
.gaps .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); margin-top: 8px; flex: 0 0 auto; }

.line-item { border: 1px solid var(--line); border-radius: 14px; padding: 13px; margin-bottom: 12px; background: #fcfdff; }
.line-item .li-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.line-item .li-head b { font-size: 13px; color: var(--blue); }
.total-box { display: flex; justify-content: space-between; align-items: center; background: var(--blue); color: #fff; border-radius: 14px; padding: 14px 16px; font-weight: 800; }
.total-box .v { font-size: 20px; }
.seg { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; }
.seg button { flex: 0 0 auto; border: 1px solid #d0d5dd; background: #fff; color: #475467; border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.wa-box { width: 100%; min-height: 170px; border: 1px solid #d0d5dd; border-radius: 12px; padding: 12px; font-size: 13px; line-height: 1.8; background: #fbfcfe; white-space: pre-wrap; }
.hidden { display: none !important; }
.row-actions { display: flex; gap: 8px; margin-top: 12px; }
.tiny { font-size: 11.5px; color: var(--muted); }

/* ---------- management-office shell ---------- */
.shell { display: block; }
.side { position: fixed; inset-block: 0; inset-inline-start: 0; width: 250px; background: #0a2f63; color: #fff; z-index: 60; display: flex; flex-direction: column; transform: translateX(110%); transition: transform .2s; overflow-y: auto; }
html[dir=rtl] .side { transform: translateX(110%); }
.menu-open .side { transform: none; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; }
.menu-open .scrim { display: block; }
.side-head { display: flex; gap: 10px; align-items: center; padding: 16px 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
.side nav { padding: 8px; flex: 1; }
.side nav a, .side-foot a { display: flex; justify-content: space-between; align-items: center; color: #dbe6f8; padding: 9px 10px; border-radius: 9px; font-size: 14px; }
.side nav a.on { background: #fff; color: var(--blue); font-weight: 800; }
.side nav a.dim { color: #8fa6cc; }
.side nav a:hover { background: rgba(255,255,255,.1); }
.side nav a.on:hover { background: #fff; }
.side em.off { font-style: normal; font-size: 10px; background: rgba(255,255,255,.14); color: #cfdcf3; padding: 1px 7px; border-radius: 8px; }
.side-foot { padding: 8px; border-top: 1px solid rgba(255,255,255,.12); }
.kpis { display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.kpi { flex: 1 0 auto; min-width: 96px; border-radius: 10px; padding: 6px 12px; background: var(--blue-soft); display: flex; flex-direction: column; }
.kpi b { font-size: 18px; line-height: 1.2; }
.kpi span { font-size: 11px; color: var(--muted); }
.kpi.amber { background: var(--amber-soft); } .kpi.red { background: var(--red-soft); } .kpi.green { background: var(--green-soft); }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.chk { display: flex; gap: 6px; align-items: center; font-weight: 600 !important; background: #f2f4f7; padding: 6px 10px; border-radius: 9px; }
.chk input { width: auto !important; min-height: 0 !important; }
@media (min-width: 900px) {
  .shell { padding-inline-start: 250px; }
  .side { transform: none !important; }
  .menubtn, .scrim { display: none !important; }
  body { padding-bottom: 0; }
  .nav { display: none; }
  .page { max-width: 1100px; }
  .appbar { padding-block: 10px; }
}

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 7px 8px; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 700; background: #f8fafc; }
.kpi { min-width: 110px; }

.more-fields { margin: 4px 0 12px; } .more-fields summary { cursor: pointer; padding: 10px 0; color: var(--blue); font-weight: 700; }
.field input, .field select { font-size: 16px; min-height: 52px; }

.printdoc { background: #fff; padding: 18px; border: 1px solid var(--line); border-radius: 12px; }
.pd-head { display: flex; justify-content: space-between; border-bottom: 3px solid var(--blue); padding-bottom: 10px; margin-bottom: 10px; }
.pd-head h1 { margin: 0; color: var(--blue); font-size: 22px; }
.pd-to { margin: 8px 0; }
.pd-tbl td, .pd-tbl th { white-space: normal; border: 1px solid var(--line); }
.pd-tot { max-width: 320px; margin-inline-start: auto; margin-top: 8px; }
.pd-terms { margin-top: 10px; }
@media print {
  .side, .scrim, .appbar, .kpis, .nav, .noprint, #toast { display: none !important; }
  .shell { padding: 0 !important; } body { background: #fff; padding: 0; }
  .page { max-width: none; padding: 0; } .printdoc { border: 0; padding: 0; }
}

.o3-head{background:#0a1f44;border-bottom:3px solid #d4a017;color:#fff;padding:14px 16px;display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap}
.o3-head h1{margin:0;font-size:20px;color:#fff}.o3-head p{margin:2px 0 0;font-size:12px;color:#aebbd3}
.o3-legend{display:flex;gap:12px;font-size:12px;color:#dbe6f5}.o3-lg{display:inline-flex;align-items:center;gap:5px}.o3-lg i{width:10px;height:10px;border-radius:50%;display:inline-block;box-shadow:0 0 6px currentColor}
.o3-wrap{position:relative;border-radius:14px;overflow:hidden;background:#0b1626;border:1px solid #1d3254}
.o3-box{position:relative;width:100%;height:74vh;min-height:420px;overflow:hidden}
.o3-box canvas{width:100%;height:100%}
.o3-zone,.o3-desk{position:absolute;left:0;top:0;pointer-events:none;white-space:nowrap;direction:rtl}
.o3-zone{color:#f0b429;font-weight:800;font-size:13px;text-shadow:0 1px 3px #000}
.o3-desk{pointer-events:auto;cursor:pointer;background:rgba(10,20,38,.88);border:1px solid #2c4468;border-radius:8px;padding:3px 8px;text-align:center;font-size:11px;color:#fff;line-height:1.35}
.o3-desk b{display:block;font-size:12px}.o3-desk span{display:inline-flex;align-items:center;gap:4px;font-size:10px;color:#cdd9ec}
.o3-desk i{width:7px;height:7px;border-radius:50%;background:#8793a6}
.o3-ready i{background:#2ecc71;box-shadow:0 0 6px #2ecc71}.o3-approval i{background:#f0b429;box-shadow:0 0 6px #f0b429}.o3-off{opacity:.75}
.o3-tools{position:absolute;top:8px;left:8px;display:flex;gap:6px}.o3-tools button{background:rgba(10,31,68,.9);color:#fff;border:1px solid #d4a017;border-radius:8px;padding:8px 12px;font-size:13px;min-width:40px}
.o3-hint{position:absolute;bottom:6px;right:10px;font-size:11px;color:#8fa3c4;pointer-events:none}
@media(max-width:600px){.o3-desk{padding:2px 5px;font-size:9px}.o3-desk b{font-size:10px}.o3-desk span{font-size:8px}.o3-zone{font-size:11px}}
