/* NetPulse — design tokens, layout, components, RTL and responsive rules. */

/* ---------- Light theme (default) ---------- */
:root {
  --bg: #f5f7fb;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 60%),
             radial-gradient(900px 500px at 100% 0%, #cffafe 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f1f4fa;
  --text: #161b2e;
  --muted: #64708a;
  --border: #e4e9f2;
  --primary: #5b5ce2;
  --primary-2: #06b6d4;
  --primary-text: #ffffff;
  --success: #12a06a;
  --warning: #d98a17;
  --danger: #dc4a4a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .12);
  --shadow-lg: 0 24px 60px -20px rgba(16, 24, 40, .35);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --sidebar-w: 248px;
  --topbar-h: 62px;
  --hidden-x: -105%;     /* mobile sidebar offscreen position (flipped in RTL) */
  color-scheme: light;
}

/* ---------- Dark theme ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #0b0f1a; --bg-grad: radial-gradient(1000px 500px at 0% -10%, #1e1b4b 0%, transparent 60%), radial-gradient(800px 500px at 100% 0%, #083344 0%, transparent 55%); --surface: #131a2a; --surface-2: #1b2437; --text: #e8ecf8; --muted: #94a0bb; --border: #232d44; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.6); --shadow-lg: 0 30px 70px -20px rgba(0,0,0,.8); color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #0b0f1a; --bg-grad: radial-gradient(1000px 500px at 0% -10%, #1e1b4b 0%, transparent 60%), radial-gradient(800px 500px at 100% 0%, #083344 0%, transparent 55%); --surface: #131a2a; --surface-2: #1b2437; --text: #e8ecf8; --muted: #94a0bb; --border: #232d44; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.6); --shadow-lg: 0 30px 70px -20px rgba(0,0,0,.8); color-scheme: dark; }

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
/* The off-canvas mobile sidebar must never create sideways scrolling (LTR or RTL). */
html { overflow-x: clip; }
body {
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans Arabic", "Tahoma", sans-serif;
  overflow-x: hidden;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
:root[dir="rtl"] body { font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Segoe UI Arabic", system-ui, sans-serif; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { margin: 0; font-size: 1.05rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .88em; }

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; box-shadow: 0 6px 16px -6px rgba(91,92,226,.6); }
.brand-lg { font-size: 1.6rem; justify-content: center; }
.brand-lg .logo { width: 44px; height: 44px; border-radius: 13px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-wrap { width: 100%; max-width: 400px; display: grid; gap: 14px; animation: rise .5s var(--ease); }
.auth-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.auth-tools { display: flex; gap: 8px; }
.auth-card { padding: 26px; }
.auth-card .stack { gap: 14px; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Layout ---------- */
.topbar {
  position: fixed; inset-inline: 0; inset-block-start: 0; height: var(--topbar-h); z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-block-end: 1px solid var(--border);
}
.topbar-right { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.sidebar {
  position: fixed; inset-block-start: var(--topbar-h); inset-block-end: 0; inset-inline-start: 0;
  width: var(--sidebar-w); z-index: 15; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 3px; overflow-y: auto;
  background: var(--surface); border-inline-end: 1px solid var(--border);
  transition: transform .3s var(--ease);
}
.sidebar a {
  display: flex; align-items: center; gap: 12px; color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-weight: 550;
  transition: background .2s, color .2s, transform .2s var(--ease);
}
.sidebar a .ico { width: 22px; text-align: center; opacity: .75; }
.sidebar a:hover { background: var(--surface-2); transform: translateX(-2px); }
:root[dir="rtl"] .sidebar a:hover { transform: translateX(2px); }
.sidebar a.active {
  background: linear-gradient(135deg, var(--primary), #7c7cf0); color: var(--primary-text);
  box-shadow: 0 10px 24px -12px var(--primary);
}
.sidebar a.active .ico { opacity: 1; }
.main {
  margin-inline-start: var(--sidebar-w); padding: calc(var(--topbar-h) + 22px) 24px 48px;
  max-width: 1240px; min-height: 100vh;
  animation: rise .4s var(--ease);
}

/* ---------- Components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
  transition: transform .25s var(--ease), box-shadow .25s var(--ease);
}
.card:hover { box-shadow: var(--shadow-lg); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 16px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 16px; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.7rem; font-weight: 750; margin-top: 2px; letter-spacing: -.02em; }
.stat .sub { color: var(--muted); font-size: .8rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; justify-content: space-between; margin-bottom: 18px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 15px; border-radius: 11px; cursor: pointer; font: inherit; font-weight: 600;
  white-space: nowrap; transition: transform .15s var(--ease), background .2s, box-shadow .2s, filter .2s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--primary), #7c7cf0); border-color: transparent; color: var(--primary-text); box-shadow: 0 10px 22px -12px var(--primary); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 10px; font-size: .84rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600;
  transition: background .2s;
}
.chip:hover { background: var(--surface-2); }
.chip.icon { padding: 6px 10px; }
.icon-btn { background: none; border: 0; font-size: 1.15rem; cursor: pointer; color: var(--text); padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }
.menu-toggle { display: none; }

input, select, textarea {
  width: 100%; margin-top: 5px; padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit;
  transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
label { display: block; font-size: .88rem; color: var(--muted); font-weight: 550; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.ok, .pill.active, .pill.online { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.pill.expired, .pill.unknown { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning); }
.pill.unused { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }
.pill.disabled, .pill.suspended, .pill.offline { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 11px 9px; border-block-end: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 650; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--surface-2); }
td.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

.live { display: inline-flex; align-items: center; gap: 7px; color: var(--success); font-size: .82rem; font-weight: 650; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 0 var(--success); animation: ping 1.8s infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.bar-wrap { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar { width: 0; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 999px; transition: width .6s var(--ease); }
.spark { width: 100%; height: 110px; display: block; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }

.voucher-box { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 14px; border-radius: var(--radius-sm); max-height: 280px; overflow: auto; white-space: pre; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 170px; }
.chart > div { flex: 1; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, var(--primary-2), var(--primary)); min-height: 3px; transition: opacity .2s; }
.chart > div:hover { opacity: .75; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: .95rem; }

/* ---------- Ads (AdSense placeholders) ---------- */
.ad {
  display: grid; place-items: center; text-align: center; color: var(--muted);
  border: 1.5px dashed color-mix(in srgb, var(--muted) 35%, transparent); border-radius: var(--radius);
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 10px, transparent 10px 20px);
  font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; min-height: 70px; margin: 16px 0; padding: 10px;
}
.ad-sidebar { min-height: 220px; margin: auto 4px 4px; }
.ad-banner { min-height: 96px; }
.ad-auth { min-height: 250px; }

/* ---------- Voucher cards (screen preview + print) ----------
   Cards always use fixed light "paper" colours so they print the same in dark mode.
   Layout uses grid areas + logical direction, so the logo sits at the inline start
   (left in English, right in Arabic). */
.vcard {
  display: grid;
  grid-template-columns: 20mm 1fr;
  grid-template-areas: "logo body" "logo creds" "note note";
  gap: 2mm 4mm;
  padding: 4mm;
  border: 1.3px dashed #9aa3b5;
  border-radius: 3mm;
  background: #fff;
  color: #111827;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans Arabic", Tahoma, sans-serif;
  break-inside: avoid;
  page-break-inside: avoid;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.vcard-logo { grid-area: logo; align-self: center; }
.vcard-logo img { display: block; width: 100%; max-height: 20mm; object-fit: contain; }
.vcard-body { grid-area: body; min-width: 0; }
.vcard-cafe { font-weight: 800; font-size: 11pt; line-height: 1.2; overflow-wrap: anywhere; }
.vcard-plan {
  display: inline-block; margin: 1.2mm 0 2mm; padding: .4mm 2.4mm; border-radius: 99px;
  background: #eef2ff; color: #4338ca; font-size: 7.5pt; font-weight: 700; letter-spacing: .04em;
}
/* Label above value. Credentials never wrap: the font shrinks with the text length
   (--chars, set per value) to fit the card's text column (--avail, per layout). */
.vcard { --avail: 26mm; }
.vcard-creds { grid-area: creds; margin: 0; min-width: 0; }
/* Long username/password (> 14 chars): credentials take the full card width under the logo. */
.vcard.vcard--long { grid-template-areas: "logo body" "creds creds" "note note"; --avail: 50mm; }
.vcard-creds dt { color: #6b7280; font-size: 6.5pt; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.vcard-creds dd {
  margin: 0 0 1.2mm; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: min(12pt, calc(var(--avail) / (var(--chars, 10) * 0.68)));
  font-weight: 700; letter-spacing: .05em; line-height: 1.25; white-space: nowrap; text-align: start; unicode-bidi: isolate;
}
.vcard-creds dd:last-child { margin-bottom: 0; }
/* Credentials are LTR text, but in an Arabic card they align with the RTL labels. */
:root[dir="rtl"] .vcard-creds dd, #print-area[dir="rtl"] .vcard-creds dd { text-align: right; }
.vcard-note {
  grid-area: note; margin: 0; padding-top: 2mm; border-top: 1px dashed #d1d5db;
  color: #4b5563; font-size: 7.5pt; text-align: center; line-height: 1.35;
}

/* Designer preview: actual print width of one card. */
.vcard-preview {
  display: grid; place-items: center; padding: 22px 12px; border-radius: var(--radius-sm);
  background: repeating-linear-gradient(45deg, var(--surface-2) 0 12px, transparent 12px 24px);
}
.vcard-preview .vcard { width: min(63mm, 100%); box-shadow: 0 12px 30px -16px rgba(16, 24, 40, .45); }
.vcard-preview.preview-thermal .vcard { width: min(72mm, 100%); grid-template-columns: 15mm 1fr; --avail: 42mm; }

/* Print area: hidden on screen; the only visible thing while printing. */
#print-area { display: none; }
#print-area.print-a4 { grid-template-columns: repeat(3, 1fr); gap: 5mm; }
#print-area.print-thermal { grid-template-columns: 1fr; gap: 4mm; width: 72mm; }
#print-area.print-thermal .vcard { grid-template-columns: 15mm 1fr; border-radius: 0; border-inline: 0; --avail: 42mm; }
#print-area.print-thermal .vcard--long,
.vcard-preview.preview-thermal .vcard--long { --avail: 60mm; }

@media print {
  body.printing { background: #fff !important; }
  body.printing > :not(#print-area) { display: none !important; }
  body.printing #print-area { display: grid !important; }
}

/* ---------- Footer ---------- */
.site-footer {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px;
  margin-top: 8px; padding: 18px 12px; text-align: center;
  color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border);
}
.site-footer strong {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 750;
}
.site-footer .dot { opacity: .5; }

/* ---------- Modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(6, 9, 20, .55); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .2s; }
.modal-card { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 580px; max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: var(--shadow-lg); animation: rise .3s var(--ease); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.toast {
  position: fixed; bottom: 22px; inset-inline-start: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; max-width: 92vw;
  box-shadow: var(--shadow-lg); font-weight: 550; animation: rise .3s var(--ease);
}
:root[dir="rtl"] .toast { transform: translateX(50%); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- RTL ----------
   Layout uses logical properties (inset-inline-start, margin-inline-start, border-inline-end…),
   which flip automatically with dir="rtl". Only physical transforms and LTR-only data need rules here. */
:root[dir="rtl"] { --hidden-x: 105%; }
:root[dir="rtl"] .spark { direction: ltr; }
:root[dir="rtl"] .voucher-box, :root[dir="rtl"] code, :root[dir="rtl"] input[type="email"], :root[dir="rtl"] input[type="password"], :root[dir="rtl"] input[type="number"], :root[dir="rtl"] input[name="host"], :root[dir="rtl"] input[name="username"] { direction: ltr; text-align: start; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .menu-toggle { display: inline-block; }
  .sidebar { transform: translateX(var(--hidden-x)); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-inline-start: 0; margin-inline-end: 0; padding: calc(var(--topbar-h) + 14px) 14px 36px; }
  .ad-sidebar { display: none; }
}
@media (max-width: 560px) {
  .hide-sm { display: none; }
  h1 { font-size: 1.3rem; }
  .stat .value { font-size: 1.4rem; }
  .btn { padding: 8px 12px; }
  .modal-card { padding: 16px; }
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-right { gap: 5px; min-width: 0; }
  /* Compact top bar: logo only, status as a coloured dot, smaller buttons. */
  .topbar .brand span { display: none; }
  #router-status { font-size: 0; padding: 6px; gap: 0; }
  .topbar .chip { padding: 5px 9px; font-size: .8rem; }
  .topbar .btn.ghost { padding: 6px 8px; font-size: .85rem; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
