:root {
  --bg: #071013;
  --bg-elevated: #0b171b;
  --panel: #101f23;
  --panel-2: #14272c;
  --line: #274047;
  --line-soft: #1b3238;
  --text: #edf7f6;
  --muted: #91aaa9;
  --cyan: #38e8d4;
  --cyan-soft: #173f3e;
  --amber: #ffb454;
  --red: #ff6b73;
  --green: #55e69b;
  --shadow: 0 24px 60px rgba(0, 0, 0, .24);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 86% 8%, rgba(56, 232, 212, .07), transparent 28rem),
    linear-gradient(180deg, #071013 0%, #081216 100%);
  color: var(--text);
  font-family: "SF Arabic", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button, a.button { touch-action: manipulation; }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 20px 20px;
  border-left: 1px solid var(--line-soft);
  background: rgba(7, 16, 19, .92);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.brand strong { display: block; font-size: 1rem; letter-spacing: .01em; }
.brand small { display: block; color: var(--muted); font-size: .78rem; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 1px solid rgba(56, 232, 212, .5); border-radius: 12px;
  background: linear-gradient(145deg, rgba(56, 232, 212, .2), rgba(56, 232, 212, .04));
  box-shadow: inset 0 0 22px rgba(56, 232, 212, .08);
}
.brand-mark span { width: 14px; height: 14px; border: 3px solid var(--cyan); border-radius: 50%; box-shadow: 0 0 16px var(--cyan); }
.nav { display: grid; gap: 7px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border: 1px solid transparent; border-radius: 11px; color: var(--muted); font-weight: 700; }
.nav a:hover { color: var(--text); background: var(--panel); }
.nav a.active { color: var(--text); border-color: var(--line); background: linear-gradient(90deg, rgba(56,232,212,.12), rgba(56,232,212,.03)); }
.nav a.active span { color: var(--cyan); }
.sidebar-foot { margin-top: auto; display: grid; gap: 14px; }
.primary-badge { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid #604928; border-radius: 12px; background: rgba(255, 180, 84, .07); }
.primary-badge small, .primary-badge strong { display: block; }
.primary-badge small { color: var(--amber); font-size: .72rem; }
.primary-badge strong { font-size: .92rem; direction: ltr; text-align: right; }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 5px rgba(255,180,84,.09); }
.logout { width: 100%; padding: 9px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.logout:hover { color: var(--red); }

.main { min-width: 0; padding: 30px clamp(20px, 4vw, 58px) 70px; }
.topbar { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 28px; }
.topbar h1 { margin: 2px 0 0; font-size: clamp(1.75rem, 3vw, 2.45rem); letter-spacing: -.03em; }
.eyebrow { margin: 0; color: var(--cyan); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .74rem; font-weight: 800; letter-spacing: .16em; direction: ltr; text-align: right; }
.topbar-status { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .86rem; }
.status-chip { display: inline-flex; align-items: center; min-height: 29px; padding: 3px 10px; border-radius: 99px; font-size: .78rem; font-weight: 800; }
.status-chip.neutral { border: 1px solid var(--line); background: var(--panel); color: var(--muted); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric { min-height: 146px; padding: 20px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: linear-gradient(145deg, rgba(20,39,44,.95), rgba(12,27,31,.95)); box-shadow: var(--shadow); }
.metric-head { display: flex; justify-content: space-between; color: var(--muted); font-size: .83rem; }
.metric > strong { display: block; margin-top: 20px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: clamp(1.7rem, 3vw, 2.25rem); direction: ltr; text-align: right; }
.metric > small { color: var(--muted); font-size: .78rem; }
.metric.priority-metric { border-color: #5f4a2b; background: linear-gradient(145deg, rgba(65,48,28,.56), rgba(20,31,32,.95)); }
.priority-metric > strong { color: var(--amber); font-size: 1.55rem; }
.priority-rank { color: var(--amber); font-family: ui-monospace, monospace; font-weight: 900; }
.metric-word { font-family: inherit !important; font-size: 1.45rem !important; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 5px rgba(255,107,115,.08); }
.dot.online { background: var(--green); box-shadow: 0 0 0 5px rgba(85,230,155,.08); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr); gap: 14px; margin-bottom: 14px; }
.panel { padding: 22px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: rgba(16,31,35,.88); box-shadow: var(--shadow); }
.panel h2 { margin: 2px 0 0; font-size: 1.18rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 20px; }
.panel-head > strong { font-family: ui-monospace, monospace; font-size: 1.7rem; direction: ltr; }
.panel-note { margin: 14px 0 0; color: var(--muted); font-size: .84rem; }
.storage-track { position: relative; height: 16px; overflow: hidden; border: 1px solid var(--line); border-radius: 99px; background: #071013; direction: ltr; }
.storage-track span { display: block; width: 0; max-width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #20b9ad, var(--cyan)); box-shadow: 0 0 18px rgba(56,232,212,.3); transition: width .4s ease; }
.storage-panel.warning .storage-track span { background: linear-gradient(90deg, #dc832a, var(--amber)); }
.cleanup-mark { position: absolute; left: 90%; top: -5px; width: 2px; height: 24px; background: var(--amber); }
.storage-numbers { display: flex; justify-content: space-between; margin-top: 12px; color: var(--muted); font-size: .84rem; }
.storage-numbers strong { color: var(--text); direction: ltr; display: inline-block; }
.gate-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; padding: 0; list-style: none; }
.gate-list li { display: flex; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--line-soft); border-radius: 11px; background: rgba(7,16,19,.5); }
.gate-list li > span { color: var(--cyan); font-family: ui-monospace, monospace; font-size: .72rem; }
.gate-list strong, .gate-list small { display: block; }
.gate-list strong { direction: ltr; text-align: right; font-size: .83rem; }
.gate-list small { color: var(--muted); font-size: .68rem; }
.table-panel, .events-panel { margin-top: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 14px 12px; border-top: 1px solid var(--line-soft); text-align: right; vertical-align: middle; }
th { padding-top: 8px; border-top: 0; color: var(--muted); font-size: .76rem; font-weight: 700; }
td { font-size: .86rem; }
.primary-row { background: linear-gradient(90deg, rgba(255,180,84,.05), transparent); }
.priority-tag { display: inline-block; margin-right: 7px; padding: 1px 7px; border: 1px solid #72552b; border-radius: 99px; color: var(--amber); font-size: .68rem; }
.priority-number { font-family: ui-monospace, monospace; color: var(--amber); }
.state { display: inline-flex; padding: 3px 9px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: .73rem; font-weight: 800; white-space: nowrap; }
.state-recording, .state-public_live, .state-completed, .state-sent { color: var(--green); border-color: rgba(85,230,155,.35); background: rgba(85,230,155,.06); }
.state-private_or_restricted, .state-error_safe, .state-failed { color: var(--red); border-color: rgba(255,107,115,.35); background: rgba(255,107,115,.06); }
.state-checking, .state-finalizing, .state-starting, .state-pending, .state-preparing, .state-sending { color: var(--cyan); border-color: rgba(56,232,212,.35); background: rgba(56,232,212,.06); }
.lock { color: var(--amber); }
.muted { color: var(--muted); }
.error-text { color: var(--red); display: block; margin-top: 5px; max-width: 240px; }
.actions { display: flex; gap: 7px; justify-content: flex-end; white-space: nowrap; }
.actions form { margin: 0; }
.event-list { margin: 0; padding: 0; list-style: none; }
.event-list li { display: grid; grid-template-columns: 150px 170px 1fr; gap: 16px; padding: 10px 0; border-top: 1px solid var(--line-soft); font-size: .82rem; }
.event-list li:first-child { border-top: 0; }
.event-list time, .event-list span { color: var(--muted); }
.event-list strong { font-family: ui-monospace, monospace; font-size: .75rem; direction: ltr; text-align: right; }

.add-account-panel { display: grid; grid-template-columns: 1fr minmax(360px, .8fr); align-items: center; gap: 28px; margin-bottom: 14px; }
.inline-form { display: flex; gap: 10px; }
input { width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px; outline: 0; background: #081317; color: var(--text); }
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(56,232,212,.1); }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 40px; padding: 8px 14px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 800; font-size: .83rem; white-space: nowrap; }
.button.primary { background: var(--cyan); color: #05201e; box-shadow: 0 8px 24px rgba(56,232,212,.14); }
.button.primary:hover { background: #6ff2e3; }
.button.ghost { border-color: var(--line); background: transparent; color: var(--text); }
.button.ghost:hover { border-color: var(--muted); }
.button.danger { border-color: rgba(255,107,115,.3); background: rgba(255,107,115,.06); color: var(--red); }
.button.protected { border-color: #72552b; background: rgba(255,180,84,.1); color: var(--amber); }
.button.small { min-height: 33px; padding: 5px 10px; font-size: .74rem; }
.button.wide { width: 100%; }
.text-link { color: var(--cyan); font-size: .82rem; font-weight: 800; }
.notice-card { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding: 14px 18px; border: 1px solid #5f4a2b; border-radius: 13px; background: rgba(255,180,84,.06); }
.notice-card > span { color: var(--amber); }
.notice-card p { margin: 0; color: var(--muted); font-size: .86rem; }
.notice-card strong { color: var(--text); }
.empty-state { padding: 46px 20px; border: 1px dashed var(--line); border-radius: 12px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--text); font-size: 1.05rem; }
.empty-state p { margin: 4px 0 0; }
.empty-state.compact { padding: 20px; }
.flash { margin-bottom: 14px; padding: 12px 15px; border-radius: 10px; font-size: .86rem; }
.flash.success { border: 1px solid rgba(85,230,155,.3); background: rgba(85,230,155,.08); color: var(--green); }
.flash.error { border: 1px solid rgba(255,107,115,.3); background: rgba(255,107,115,.08); color: #ff9aa0; }

.login-body { display: grid; place-items: center; padding: 24px; }
.login-body::before { content: ""; position: fixed; inset: 0; pointer-events: none; background-image: linear-gradient(rgba(56,232,212,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(56,232,212,.025) 1px, transparent 1px); background-size: 44px 44px; mask-image: radial-gradient(circle, black, transparent 72%); }
.login-card { position: relative; width: min(100%, 440px); padding: clamp(28px, 6vw, 46px); border: 1px solid var(--line); border-radius: 22px; background: rgba(11,23,27,.94); box-shadow: 0 35px 100px rgba(0,0,0,.45); }
.login-brand { margin-bottom: 28px; }
.login-brand .brand-mark { margin-bottom: 24px; }
.login-brand h1 { margin: 7px 0 4px; font-size: clamp(1.55rem, 5vw, 2rem); }
.login-brand > p:last-child { margin: 0; color: var(--muted); }
.stack-form { display: grid; gap: 16px; }
.stack-form label span { display: block; margin-bottom: 6px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .add-account-panel { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px 16px; border-left: 0; border-bottom: 1px solid var(--line-soft); }
  .brand { padding: 0 0 12px; }
  .brand-mark { width: 36px; height: 36px; }
  .nav { display: flex; overflow-x: auto; }
  .nav a { flex: 0 0 auto; padding: 9px 11px; font-size: .86rem; }
  .sidebar-foot { display: none; }
  .main { padding: 22px 15px 50px; }
  .topbar { align-items: start; }
  .topbar-status { display: none; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric { min-height: 128px; padding: 15px; }
  .metric > strong { margin-top: 15px; font-size: 1.5rem; }
  .panel { padding: 17px; }
  .gate-list { grid-template-columns: 1fr; }
  .inline-form { flex-direction: column; }
  .event-list li { grid-template-columns: 1fr; gap: 3px; }
}

@media (max-width: 440px) {
  .metric-grid { grid-template-columns: 1fr; }
  .storage-numbers { display: grid; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
