/* مركز البدالة — local styles only, no external assets */
:root {
  --bg: #f4f6f8; --card: #fff; --text: #14212b; --muted: #6b7a86; --line: #e3e8ec;
  --brand: #0f766e; --brand-2: #14b8a6; --in: #2563eb; --out: #0f766e; --miss: #dc2626; --warn: #d97706;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1418; --card: #152027; --text: #e6edf1; --muted: #8fa0ab; --line: #24333c; --shadow: none; --in: #60a5fa; --out: #2dd4bf; --miss: #f87171; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
a { color: var(--brand); text-decoration: none; }
small, .muted { color: var(--muted); }
h1, h2 { margin: 0; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { width: 28px; height: 28px; }
.live { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.live.ok .dot { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.2); }
.live.bad .dot { background: var(--miss); }

/* nav: bottom bar on mobile, side on desktop */
.nav { position: fixed; bottom: 0; inset-inline: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; font-size: 12px; color: var(--muted); }
.nav a.on { color: var(--brand); font-weight: 700; }
.nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.main { max-width: 1100px; margin: 0 auto; padding: 16px; }
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-inline-start: 200px; }
  .nav { top: 0; bottom: 0; inset-inline-start: 0; inset-inline-end: auto; width: 200px; flex-direction: column; border-top: 0; border-inline-end: 1px solid var(--line); padding-top: 70px; }
  .nav a { flex: none; flex-direction: row; gap: 10px; padding: 12px 20px; font-size: 15px; }
  .topbar { margin-inline-start: -200px; padding-inline-start: 216px; }
}

.page-title { font-size: 22px; margin: 4px 0 12px; }
.page-title small { font-size: 14px; font-weight: 400; margin-inline-start: 6px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.panel h2 { font-size: 16px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.panel h2 .more { font-size: 13px; font-weight: 400; }
.grid2 { display: grid; gap: 14px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; margin-bottom: 14px; } .grid2 > .panel { margin-bottom: 0; } }

/* range chips */
.range { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chip { white-space: nowrap; padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: 14px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.custom { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.custom input { padding: 5px 8px; }

/* forms */
input, select, button { font: inherit; color: inherit; }
input, select { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; color: var(--text); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 12px; font-size: 14px; }
.form label, .auth-card label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
.form input, .form select { width: 100%; color: var(--text); }
.inline { display: inline; }
.alert { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; }
.ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; }
@media (prefers-color-scheme: dark) { .alert { background: #3b1414; color: #fecaca; border-color: #7f1d1d; } .ok { background: #0f2e1c; color: #bbf7d0; border-color: #166534; } }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.filters input[type=search] { grid-column: 1 / -1; }
.filters .check { display: flex; align-items: center; gap: 6px; font-size: 14px; }
@media (min-width: 900px) { .filters { grid-template-columns: 2fr repeat(4, 1fr) auto auto auto; } .filters input[type=search] { grid-column: auto; } }

/* stat cards */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 700px) { .cards { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .cards { grid-template-columns: repeat(6, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); border-top: 3px solid var(--line); }
.stat span { display: block; font-size: 13px; color: var(--muted); }
.stat b { display: block; font-size: 26px; line-height: 1.2; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat small { font-size: 12px; }
.stat.in { border-top-color: var(--in); } .stat.out { border-top-color: var(--out); } .stat.missed { border-top-color: var(--miss); }
.stat.missed b { color: var(--miss); } .stat.total { border-top-color: var(--brand); } .stat.wait { border-top-color: var(--warn); }

/* status strip */
.status-strip { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; scrollbar-width: none; }
.pill { display: flex; align-items: center; gap: 6px; white-space: nowrap; padding: 6px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; font-size: 13px; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.up i { background: #16a34a; } .pill.down i { background: var(--miss); } .pill.busy i { background: var(--warn); }
.pill.down { color: var(--muted); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: start; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 13px; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.dim { opacity: .5; }
.red { color: var(--miss); font-weight: 700; }
.tbl details { display: inline-block; } .tbl details form { display: flex; gap: 6px; margin-top: 6px; }
summary { list-style: none; } summary::-webkit-details-marker { display: none; }

/* hourly bars */
.bars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; height: 130px; align-items: end; }
.bar { display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar .stack { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar .stack i { display: block; width: 100%; }
.bar span { font-size: 10px; color: var(--muted); height: 14px; }
i.i { background: var(--in); } i.o { background: var(--out); }
.legend { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 4px; vertical-align: -1px; }

/* call cards */
.count { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.day { font-weight: 700; margin: 14px 2px 6px; } .day small { font-weight: 400; margin-inline-start: 6px; }
.call { position: relative; display: grid; grid-template-columns: 40px 1fr; gap: 0 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.panel .call { box-shadow: none; }
.dicon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--bg); }
.dicon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.dicon.in { color: var(--in); } .dicon.out { color: var(--out); } .dicon.internal { color: var(--muted); }
.dicon.missed, .dicon.no_answer, .dicon.busy, .dicon.failed { color: var(--miss); }
.call-body { color: inherit; min-width: 0; }
.call-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.call-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-top time { flex-shrink: 0; font-size: 12px; color: var(--muted); }
.call-sub { font-size: 13px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.call-meta { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding-inline-end: 56px; }
.call-meta i { font-style: normal; opacity: .6; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: rgba(15,118,110,.12); color: var(--brand); }
.st { font-weight: 600; } .st.answered { color: #16a34a; } .st.missed, .st.no_answer, .st.busy, .st.failed { color: var(--miss); }
.rec { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.rec audio { flex: 1; height: 36px; min-width: 0; }
.rec .dl { width: 36px; height: 36px; flex-shrink: 0; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.rec .dl svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.callback { position: absolute; inset-inline-end: 12px; bottom: 10px; font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--brand); color: #fff; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 14px 0; color: var(--muted); }

/* detail */
.back { display: inline-block; margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; border-inline-start: 2px solid var(--line); }
.timeline li { position: relative; padding: 6px 14px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.timeline li.answered::before { background: #16a34a; } .timeline li.failed::before, .timeline li.no_answer::before { background: var(--miss); }
.timeline time { color: var(--muted); margin-inline-end: 8px; font-size: 13px; }

/* lines page */
.lines-full { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.lcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.lcard b { display: block; font-size: 17px; }
.lcard .state { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-top: 6px; }
.lcard .state i { width: 10px; height: 10px; border-radius: 50%; background: var(--miss); }
.lcard.up .state i { background: #16a34a; } .lcard.busy .state i { background: var(--warn); }
.lcard small { display: block; margin-top: 4px; }
.lines-head { grid-column: 1 / -1; font-weight: 700; margin-top: 6px; }

/* auth */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); text-align: center; }
.auth-card label { text-align: start; }
.auth-card input { width: 100%; color: var(--text); }
.auth-card .btn { width: 100%; margin-top: 6px; }
.auth-logo { width: 56px; height: 56px; }
.auth-card h1 { font-size: 20px; margin: 8px 0 4px; }
.auth-card p { margin: 0 0 16px; font-size: 14px; }

/* delete */
.btn.danger { background: transparent; border-color: var(--miss); color: var(--miss); }
.panel.danger { border-color: rgba(220,38,38,.35); }
.panel.danger .row { display: flex; gap: 8px; flex-wrap: wrap; }
.panel.danger p { margin: 0 0 10px; font-size: 14px; }

/* ---- tap feedback + loading (web app) ---- */
html { -webkit-tap-highlight-color: transparent; }
a, button, .btn, .chip, select, label.check { touch-action: manipulation; }
.btn, .chip, .nav a, .call-body, .dl, .callback, .more, .pager a { transition: transform .08s ease, opacity .08s ease, background-color .12s ease; }
.btn:active, .chip:active, .dl:active, .callback:active { transform: scale(.95); opacity: .8; }
.nav a:active { transform: scale(.9); }
.call:has(.call-body:active) { background: var(--bg); transform: scale(.99); }
.call { transition: transform .08s ease, background-color .12s ease; }
.tapped { opacity: .6 !important; }
button[disabled], .btn[disabled] { opacity: .6; pointer-events: none; }
.btn .spin { width: 14px; height: 14px; border-width: 2px; }

#pbx-bar { position: fixed; top: 0; inset-inline: 0; height: 3px; z-index: 100; pointer-events: none; opacity: 0; transition: opacity .2s; }
#pbx-bar::after { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 40%; background: var(--brand-2); border-radius: 3px; animation: pbxbar 1s ease-in-out infinite; }
#pbx-bar.on { opacity: 1; }
@keyframes pbxbar { 0% { transform: translateX(160%); } 100% { transform: translateX(-260%); } }

#pbx-loading { position: fixed; inset: 0; z-index: 99; display: grid; place-items: center; background: rgba(0,0,0,.18); opacity: 0; visibility: hidden; transition: opacity .15s; }
#pbx-loading.on { opacity: 1; visibility: visible; }
#pbx-loading .box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 22px; border-radius: 16px; background: var(--card); box-shadow: 0 8px 30px rgba(0,0,0,.2); font-size: 14px; color: var(--muted); }
.spin { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: pbxspin .7s linear infinite; display: inline-block; }
@keyframes pbxspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #pbx-bar::after, .spin { animation-duration: 2s; } }
