:root {
  --navy: #15265C; --navy2: #1E3577; --ink: #15265C; --muted: #5B6785; --line: #E1E7F2; --bg: #F3F6FC; --card: #fff;
  --blue: #2F6BFF; --gold: #FFC83D; --goldbg: #FFF4D6; --green: #1E8E5A; --greenbg: #E3F7EE; --red: #C53A5A; --redbg: #FDE8EC;
  --violet: #6B3FD6; --shadow: 0 1px 2px rgba(21,38,92,.06), 0 6px 18px rgba(21,38,92,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* الدخول */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 80% -10%, #DCE8FF, transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 24px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-weight: 600; }
.login-card input { height: 46px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 12px; }
.login-card input:focus { outline: none; border-color: var(--blue); }
.err { color: var(--red); min-height: 1em; margin: 0; font-weight: 600; }

/* الهيكل */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.side { background: var(--navy); color: #fff; display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 18px; }
.brand b { display: block; font-size: 17px; }
.brand small { color: #AFC0E6; font-size: 12px; }
.brand.big b { font-size: 22px; color: var(--ink); }
.brand.big small { color: var(--muted); }
.shield { width: 38px; height: 38px; flex: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 44 44'%3E%3Cpath d='M22 3 38 9v12c0 10-7 17-16 20C13 38 6 31 6 21V9Z' fill='%23FFC83D'/%3E%3Cpath d='m22 13 2.6 5.4 5.9.8-4.3 4.1 1 5.9-5.2-2.8-5.2 2.8 1-5.9-4.3-4.1 5.9-.8Z' fill='%2315265C'/%3E%3C/svg%3E") center/contain no-repeat; }
nav { display: grid; gap: 2px; overflow: auto; }
nav button { all: unset; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; color: #D5DEF5; font-weight: 500; }
nav button:hover { background: rgba(255,255,255,.06); }
nav button[aria-current="page"] { background: rgba(255,255,255,.12); color: #fff; font-weight: 700; }
nav button:focus-visible { outline: 2px solid var(--gold); }
nav .count { margin-inline-start: auto; background: var(--gold); color: var(--navy); border-radius: 999px; padding: 0 8px; font-size: 12px; font-weight: 700; line-height: 20px; }
nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding: 14px 6px 0; display: grid; gap: 6px; }
.me { font-weight: 600; }
.link { all: unset; cursor: pointer; color: #AFC0E6; font-size: 13px; }
.link:hover { color: #fff; }

.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 14px; padding: 18px 28px; background: var(--bg); position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--line); }
.top h1 { margin: 0; font-size: 22px; }
.menu { display: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px; padding: 10px 9px; }
.menu span { display: block; height: 2px; background: var(--ink); margin: 3px 0; border-radius: 2px; }
.live { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.green { background: #22C55E; box-shadow: 0 0 0 3px #22C55E33; }
.dot.gold { background: var(--gold); }
.dot.red { background: #FF4D5E; }
.view { padding: 24px 28px 48px; display: grid; gap: 18px; }

/* مكونات */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.card { background: var(--card); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .val { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1.2; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.gold { background: linear-gradient(135deg, #FFF4D6, #fff); }
.kpi.green { background: linear-gradient(135deg, #E3F7EE, #fff); }
.kpi.navy { background: var(--navy); color: #fff; }
.kpi.navy .label, .kpi.navy .sub { color: #AFC0E6; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.seg { display: inline-flex; background: #E6ECF7; border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.btn { border: 0; border-radius: 10px; padding: 8px 14px; font-weight: 700; font-size: 13px; min-height: 36px; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: #fff; color: var(--red); border: 1.5px solid #F2C4CF; }
.btn:disabled { opacity: .5; cursor: default; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.b-new, .b-pending, .b-requested, .b-open { background: var(--goldbg); color: #8A5A00; }
.b-accepted, .b-active, .b-ringing { background: #E6EEFF; color: var(--blue); }
.b-done, .b-approved, .b-paid, .b-closed { background: var(--greenbg); color: var(--green); }
.b-cancelled, .b-rejected, .b-ended { background: #EEF1F6; color: var(--muted); }
.b-suspended { background: var(--redbg); color: var(--red); }

/* الجداول */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: right; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #FAFBFE; position: sticky; top: 0; }
td { padding: 11px 14px; border-bottom: 1px solid #F0F3F9; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.hl td { background: #FFFBEB; }
td .name { font-weight: 700; }
td .sub { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { height: 38px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 12px; min-width: 220px; background: #fff; }

/* الرسم */
.chart { width: 100%; height: 220px; }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }

/* الإعدادات */
.form { display: grid; gap: 14px; max-width: 560px; }
.form label { display: grid; gap: 6px; font-weight: 600; }
.form input { height: 42px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 12px; }
.form .hint { font-weight: 400; color: var(--muted); font-size: 12px; }

/* نافذة */
dialog { border: 0; border-radius: 20px; padding: 0; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10,18,40,.45); }
dialog form { padding: 22px; display: grid; gap: 12px; }
dialog h3 { margin: 0; font-size: 18px; }
dialog label { display: grid; gap: 6px; font-weight: 600; }
dialog input, dialog select, dialog textarea { border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; }
dialog .acts { display: flex; gap: 10px; justify-content: flex-start; margin-top: 6px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 600; opacity: 0; transition: .25s; pointer-events: none; z-index: 99; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--red); }

.agent-cell { display: flex; align-items: center; gap: 10px; }
.av { width: 34px; height: 34px; border-radius: 50%; background: #E6EEFF; color: var(--blue); display: grid; place-items: center; font-weight: 700; flex: none; }
.stars { color: #E0A100; letter-spacing: 1px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 0 0 auto; width: 260px; z-index: 20; transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: -20px 0 60px rgba(0,0,0,.3); }
  .menu { display: block; }
  .top { padding: 12px 16px; flex-wrap: wrap; }
  .top h1 { font-size: 19px; }
  .live { width: 100%; margin: 0; }
  .view { padding: 16px; }
  .kpi .val { font-size: 22px; }
}
td { white-space: nowrap; }
.seg { max-width: 100%; overflow-x: auto; }
.seg button { white-space: nowrap; flex: none; }
