:root {
  --primary: #00a884;
  --primary-dark: #017561;
  --primary-light: #d9f5ee;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #111b21;
  --muted: #667781;
  --border: #e9edef;
  --danger: #e2453c;
  --danger-light: #fde8e7;
  --warn: #d98c00;
  --ok: #00a884;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(11, 20, 26, .08), 0 1px 2px rgba(11, 20, 26, .04);
  --shadow-lg: 0 8px 30px rgba(11, 20, 26, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Rubik", -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-dark); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; background: #0b141a; color: #e9edef;
  display: flex; flex-direction: column; padding: 20px 14px; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px;
  padding: 8px 12px 20px; color: #fff;
}
.sidebar .brand .logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary);
  display: grid; place-items: center; font-size: 18px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
  color: #aebac1; cursor: pointer; font-size: 15px; text-decoration: none; border: none;
  background: none; width: 100%; text-align: right; font-family: inherit;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .ico { font-size: 18px; width: 22px; text-align: center; }
.sidebar .spacer { flex: 1; }
.sidebar .user-box { font-size: 13px; color: #8696a0; padding: 10px 14px; border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--border); padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.content { padding: 28px; max-width: 1200px; width: 100%; margin: 0 auto; }

.page { display: none; }
.page.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Cards & grid ---------- */
.grid { display: grid; gap: 18px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; } .sidebar { width: 70px; } .sidebar .brand span, .nav-item span, .user-box { display: none; } }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; border: 1px solid var(--border);
}
.card h2 { font-size: 16px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: -10px; margin-bottom: 16px; }

.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; border: 1px solid var(--border); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.stat .value.small { font-size: 22px; }
.stat .ico { float: left; width: 42px; height: 42px; border-radius: 11px; background: var(--primary-light); color: var(--primary-dark); display: grid; place-items: center; font-size: 20px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600; background: var(--primary); color: #fff;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #3b4a54; }
input, select, textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 14px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea { resize: vertical; min-height: 90px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:hover { background: #fafbfc; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--primary-light); color: var(--primary-dark); }
.badge.gray { background: #eceff1; color: #667781; }
.badge.red { background: var(--danger-light); color: var(--danger); }
.badge.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Device cards ---------- */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.device {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; background: #fff;
  display: flex; flex-direction: column; gap: 12px;
}
.device .head { display: flex; align-items: center; justify-content: space-between; }
.device .avatar { width: 40px; height: 40px; border-radius: 11px; background: var(--primary-light); color: var(--primary-dark); display: grid; place-items: center; font-size: 20px; }
.device .name { font-weight: 700; }
.device .phone { color: var(--muted); font-size: 13px; direction: ltr; text-align: right; }
.device .actions { display: flex; gap: 8px; margin-top: auto; }

/* ---------- Code / token ---------- */
.token-box, code, pre {
  font-family: "Consolas", "Courier New", monospace; direction: ltr; text-align: left;
}
.token-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #0b141a; color: #7ee6c8; padding: 12px 14px; border-radius: 10px; font-size: 14px;
}
/* Copy/action buttons sitting on a dark token-box need light text (were dark-on-dark) */
.token-box .btn.ghost {
  color: #d7e4dd; border-color: rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .08);
}
.token-box .btn.ghost:hover { background: rgba(255, 255, 255, .18); }

/* ---------- API docs: right-side menu + left detail ---------- */
.api-layout { display: flex; gap: 18px; margin-top: 18px; }
.api-menu { flex: 0 0 210px; display: flex; flex-direction: column; gap: 6px; }
.api-menu-item {
  display: flex; align-items: center; gap: 9px; text-align: right; padding: 12px 14px;
  border-radius: 10px; border: 1px solid var(--border); background: #fff; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--text);
}
.api-menu-item small { color: var(--muted); font-weight: 500; font-family: "Consolas", monospace; direction: ltr; }
.api-menu-item:hover { background: var(--bg); }
.api-menu-item.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.api-menu-item.active small { color: rgba(255, 255, 255, .85); }
.api-detail { flex: 1; min-width: 0; }
.api-detail h3 { font-size: 16px; margin-bottom: 4px; }
.api-detail .method-badges { display: flex; gap: 6px; margin: 10px 0 14px; }
.api-detail .method-badges .badge { font-family: "Consolas", monospace; }
@media (max-width: 820px) { .api-layout { flex-direction: column; } .api-menu { flex-basis: auto; } }
pre.code {
  background: #0b141a; color: #d7e4dd; padding: 16px; border-radius: 10px; overflow-x: auto;
  font-size: 13px; white-space: pre-wrap; word-break: break-all;
}
pre.code .k { color: #7ee6c8; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 10px 16px; cursor: pointer; border: none; background: none; font-family: inherit; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(11,20,26,.5); display: none; place-items: center; z-index: 50; padding: 20px; }
.modal-bg.open { display: grid; }
.modal { background: #fff; border-radius: var(--radius); padding: 26px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); animation: pop .2s ease; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { margin-bottom: 8px; }
.modal .qr-wrap { display: grid; place-items: center; padding: 14px; min-height: 280px; }
.modal .qr-wrap img { width: 260px; height: 260px; border-radius: 10px; }
.modal .close { float: left; cursor: pointer; color: var(--muted); font-size: 22px; line-height: 1; background: none; border: none; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-start; margin-top: 18px; }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast { background: #0b141a; color: #fff; padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; animation: pop .2s ease; max-width: 90vw; }
.toast.ok { background: var(--primary-dark); }
.toast.err { background: var(--danger); }

.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--muted); }
.mono { font-family: "Consolas", monospace; direction: ltr; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.flex { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.hint { font-size: 13px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #00a884 0%, #017561 100%); }
.auth-card { background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); padding: 36px; width: 100%; max-width: 400px; }
.auth-card .brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 8px; font-size: 24px; font-weight: 800; }
.auth-card .brand .logo { width: 42px; height: 42px; border-radius: 11px; background: var(--primary); display: grid; place-items: center; font-size: 22px; color: #fff; }
.auth-card .tagline { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 14px; color: var(--muted); }
.auth-switch a { cursor: pointer; font-weight: 600; }
