:root {
  --bg: #0b1020;
  --bg-2: #121a30;
  --card: #161f38;
  --card-2: #1c2745;
  --line: #26314f;
  --text: #e7ecf6;
  --muted: #8b98b8;
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --crit: #ef4444;
  --info: #38bdf8;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", Tahoma, system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1b2547 0%, var(--bg) 55%);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  display: grid; place-items: center; min-height: 100vh; padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 36px 30px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 26px; margin-bottom: 6px; }
.login-card .logo {
  width: 56px; height: 56px; border-radius: 14px; margin-bottom: 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-size: 26px;
}
.login-card p.sub { color: var(--muted); margin-bottom: 24px; font-size: 14px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 13px; font-size: 14px; font-family: inherit;
  transition: border 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
textarea { resize: vertical; min-height: 90px; }

.btn {
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  border: none; border-radius: 10px; padding: 11px 18px; font-size: 14px; font-weight: 600;
  transition: transform 0.1s, filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; margin-top: 20px; }
.btn.ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.btn.ok { background: linear-gradient(135deg, #16a34a, #22c55e); }

.error-msg { color: var(--crit); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg)); border-left: 1px solid var(--line);
  padding: 22px 16px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 20px; }
.brand .mark {
  width: 40px; height: 40px; border-radius: 11px; background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-size: 20px;
}
.brand b { font-size: 18px; }
.brand small { display: block; color: var(--muted); font-size: 11px; }

.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 11px;
  color: var(--muted); font-size: 14.5px; font-weight: 500; transition: all 0.15s;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--card-2); color: #fff; }
.nav-item .ic { font-size: 17px; width: 22px; text-align: center; }
.nav-item .badge {
  margin-inline-start: auto; background: var(--crit); color: #fff; font-size: 11px;
  border-radius: 20px; padding: 1px 7px; font-weight: 700;
}
.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }

.main { padding: 26px 30px; overflow-x: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.topbar h2 { font-size: 22px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------- Stat cards ---------- */
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; position: relative; overflow: hidden;
}
.stat::after {
  content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px;
  background: var(--brand);
}
.stat.ok::after { background: var(--ok); }
.stat.warn::after { background: var(--warn); }
.stat.crit::after { background: var(--crit); }
.stat.info::after { background: var(--info); }
.stat .k { color: var(--muted); font-size: 13px; margin-bottom: 8px; display: flex; gap: 7px; align-items: center; }
.stat .v { font-size: 28px; font-weight: 800; }
.stat .v small { font-size: 14px; font-weight: 500; color: var(--muted); }

/* ---------- Cards / sections ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-head h3 { font-size: 16px; }
.card-head .tools { display: flex; gap: 8px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 12px 12px; text-align: right; white-space: nowrap; }
thead th { color: var(--muted); font-weight: 600; font-size: 12.5px; border-bottom: 1px solid var(--line); }
tbody tr { border-bottom: 1px solid var(--line); transition: background 0.12s; }
tbody tr:hover { background: var(--card-2); }
td .mono { font-family: "Consolas", monospace; font-size: 12.5px; color: var(--info); }

/* ---------- Badges ---------- */
.badge-s { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.b-ok { background: rgba(34,197,94,0.15); color: #4ade80; }
.b-warn { background: rgba(245,158,11,0.15); color: #fbbf24; }
.b-crit { background: rgba(239,68,68,0.15); color: #f87171; }
.b-mut { background: rgba(139,152,184,0.15); color: var(--muted); }
.b-info { background: rgba(56,189,248,0.15); color: #38bdf8; }

.pill { padding: 3px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; }

/* ---------- Capacity bar ---------- */
.cap { display: flex; align-items: center; gap: 9px; min-width: 130px; }
.cap-bar { flex: 1; height: 8px; background: var(--bg-2); border-radius: 20px; overflow: hidden; }
.cap-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 20px; }
.cap-fill.full { background: linear-gradient(90deg, #ef4444, #f97316); }
.cap small { color: var(--muted); font-size: 12px; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(5,8,18,0.7); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 17px; }
.modal-head .x { background: none; border: none; color: var(--muted); font-size: 22px; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-start; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- WhatsApp ---------- */
.wa-status { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ready { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.dot.qr, .dot.authenticating { background: var(--warn); }
.dot.error { background: var(--crit); }
.qr-box { display: grid; place-items: center; padding: 24px; background: #fff; border-radius: 14px; width: fit-content; margin: 16px auto; }
.qr-box img { display: block; }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 40px; font-size: 14px; }
.toast-wrap { position: fixed; bottom: 20px; left: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 13px 18px;
  font-size: 14px; box-shadow: var(--shadow); animation: slide 0.25s; max-width: 340px;
}
.toast.ok { border-inline-start: 3px solid var(--ok); }
.toast.err { border-inline-start: 3px solid var(--crit); }
@keyframes slide { from { transform: translateX(-20px); opacity: 0; } to { transform: none; opacity: 1; } }

.hint { background: var(--card-2); border: 1px dashed var(--line); border-radius: 12px; padding: 14px 16px; font-size: 13px; color: var(--muted); line-height: 1.7; margin-bottom: 16px; }
.hint b { color: var(--text); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input, .filters select { width: auto; min-width: 160px; }

/* ---------- Global Search ---------- */
.global-search { position: relative; margin-bottom: 20px; }
.global-search .gs-ic { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); font-size: 15px; opacity: 0.7; }
.global-search input { padding-inline-start: 40px; height: 46px; font-size: 14.5px; background: var(--card); }
.gs-results {
  position: absolute; top: 52px; inset-inline: 0; z-index: 60; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto; padding: 8px;
}
.gs-group { padding: 6px 10px 4px; color: var(--muted); font-size: 11.5px; font-weight: 700; }
.gs-item { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px; cursor: pointer; font-size: 13.5px; }
.gs-item:hover { background: var(--card-2); }
.gs-item .gs-sub { color: var(--muted); font-size: 12px; margin-inline-start: auto; }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-inline-start: 22px; margin-top: 8px; }
.timeline::before { content: ''; position: absolute; inset-inline-start: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 18px; }
.tl-item::before {
  content: ''; position: absolute; inset-inline-start: -20px; top: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--brand); border: 2px solid var(--card);
}
.tl-item.t-created::before { background: var(--info); }
.tl-item.t-paid::before, .tl-item.t-renewed::before { background: var(--ok); }
.tl-item.t-expired::before { background: var(--crit); }
.tl-item.t-code::before { background: #fbbf24; }
.tl-item.t-message::before { background: var(--brand-2); }
.tl-item .tl-head { font-size: 13.5px; font-weight: 600; }
.tl-item .tl-meta { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* ---------- Health cards ---------- */
.hcard { display: flex; align-items: center; gap: 12px; }
.hdot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.hdot.up { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.hdot.idle { background: var(--warn); }
.hdot.down { background: var(--crit); box-shadow: 0 0 8px var(--crit); }
.hcard .hname { font-weight: 700; font-size: 14px; }
.hcard .hmeta { color: var(--muted); font-size: 12px; }

/* ---------- Device card ---------- */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 13px; }
.kv .k2 { color: var(--muted); }
.checkbox-cell { width: 34px; text-align: center; }

/* live pulse */
.live-pulse { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ok); }
.live-pulse::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: none; }
  .row2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
