/* Shared styles for the login page and the dashboard (externalized so a strict
   CSP needs no 'unsafe-inline'). */

/* ===== Cairo — self-hosted Arabic UI font (served from /fonts, CSP-safe) ===== */
@font-face { font-family:'Cairo'; font-style:normal; font-weight:400; font-display:swap;
  src:url('/fonts/cairo-arabic-400-normal.woff2') format('woff2');
  unicode-range:U+0600-06FF,U+0750-077F,U+08A0-08FF,U+FB50-FDFF,U+FE70-FEFF,U+200C-200E,U+2010-2011,U+204F,U+2E41; }
@font-face { font-family:'Cairo'; font-style:normal; font-weight:400; font-display:swap;
  src:url('/fonts/cairo-latin-400-normal.woff2') format('woff2');
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:'Cairo'; font-style:normal; font-weight:600; font-display:swap;
  src:url('/fonts/cairo-arabic-600-normal.woff2') format('woff2');
  unicode-range:U+0600-06FF,U+0750-077F,U+08A0-08FF,U+FB50-FDFF,U+FE70-FEFF,U+200C-200E,U+2010-2011,U+204F,U+2E41; }
@font-face { font-family:'Cairo'; font-style:normal; font-weight:600; font-display:swap;
  src:url('/fonts/cairo-latin-600-normal.woff2') format('woff2');
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:'Cairo'; font-style:normal; font-weight:700; font-display:swap;
  src:url('/fonts/cairo-arabic-700-normal.woff2') format('woff2');
  unicode-range:U+0600-06FF,U+0750-077F,U+08A0-08FF,U+FB50-FDFF,U+FE70-FEFF,U+200C-200E,U+2010-2011,U+204F,U+2E41; }
@font-face { font-family:'Cairo'; font-style:normal; font-weight:700; font-display:swap;
  src:url('/fonts/cairo-latin-700-normal.woff2') format('woff2');
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:'Cairo'; font-style:normal; font-weight:800; font-display:swap;
  src:url('/fonts/cairo-arabic-800-normal.woff2') format('woff2');
  unicode-range:U+0600-06FF,U+0750-077F,U+08A0-08FF,U+FB50-FDFF,U+FE70-FEFF,U+200C-200E,U+2010-2011,U+204F,U+2E41; }
@font-face { font-family:'Cairo'; font-style:normal; font-weight:800; font-display:swap;
  src:url('/fonts/cairo-latin-800-normal.woff2') format('woff2');
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2212,U+2215,U+FEFF,U+FFFD; }

:root {
  --bg: #0b1120; --surface: #151d30; --surface-2: #1b2540; --surface-raised: #1d2742; --border: #2a3650;
  --text: #e8eefc; --text-2: #c3cee4; --muted: #93a3c0; --faint: #64748b;
  --accent: #3b82f6; --accent-2: #38bdf8; --accent-hover: #2563eb; --focus: #60a5fa;
  --success: #16a34a; --success-hover: #15803d; --danger: #dc2626; --danger-hover: #b91c1c;
  --ok-text: #6ee7b7; --err-text: #fca5a5;
  --r: 10px; --r-lg: 16px;
  --shadow: 0 6px 20px rgba(0,0,0,.28); --shadow-lg: 0 18px 44px rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif; color: var(--text);
  margin: 0; padding: 24px 24px 56px; line-height: 1.6; min-height: 100vh; overflow-x: hidden;
  background:
    radial-gradient(1000px 620px at 100% -8%, rgba(56,189,248,.12), transparent 60%),
    radial-gradient(900px 600px at -5% 0%, rgba(59,130,246,.12), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
/* technical values stay monospaced for legibility (IP / port / SN / token / code) */
code, pre, .srv-row code, .reveal code, .mono { font-family: "Cascadia Code", ui-monospace, Consolas, monospace; }

/* ===== Accessibility: visible keyboard focus (was entirely missing) ===== */
:where(a, button, input, select, textarea, .nav-item, .dtab, .kebab-btn, .modal-x, .tab, .filter-btn, [tabindex]):focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r);
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus);
}
.wrap { max-width: 1000px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; color: #cbd5e1; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #94a3b8; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.admin { background: rgba(59,130,246,.18); color: #bfdbfe; border: 1px solid rgba(59,130,246,.45); }
.badge.viewer { background: rgba(148,163,184,.14); color: #cbd5e1; border: 1px solid rgba(148,163,184,.3); }

.status { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: bold;
  padding: 14px 18px; border-radius: 10px; background: #1e293b; margin-bottom: 16px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--faint); }
.dot.on { background: #22c55e; box-shadow: 0 0 10px #22c55e; }
.dot.off { background: #ef4444; outline: 2px solid #fca5a5; outline-offset: 1px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.cards.stats4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.serverinfo { display: flex; flex-direction: column; gap: 10px; }
.srv-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.srv-label { min-width: 110px; color: #94a3b8; font-size: 14px; }
.srv-row code { background: #020617; color: #6ee7b7; padding: 8px 14px; border-radius: 8px; font-size: 15px;
  direction: ltr; min-width: 160px; max-width: 100%; display: inline-block; word-break: break-all; }
.docs-link { display: inline-block; text-decoration: none; margin-top: 12px; }
.docs-link:hover { text-decoration: none; }

/* small inline status dot for the devices table */
.statusdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; margin-left: 4px; }
.statusdot.on { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.statusdot.off { background: #ef4444; }

/* modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(2,6,23,.7); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; z-index: 60; overflow-y: auto; }
.modal { background: linear-gradient(160deg, var(--surface-2), var(--surface)); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 22px; width: 100%; max-width: 560px; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-x { background: transparent; color: var(--muted); border: 0; font-size: 20px; cursor: pointer; margin: 0; padding: 4px 10px; min-width: 40px; min-height: 40px; }
.modal-x:hover { color: #e2e8f0; background: transparent; }
.modal input[type=text], .modal select { margin-bottom: 4px; }
.modal-lg { max-width: 720px; }
.ctl-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }

/* device detail page: header, tabs, two-column grid */
.dv-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.dv-titlebox { display: flex; flex-direction: column; }
.dv-name { font-size: 20px; font-weight: bold; }
.dtabs { display: flex; gap: 4px; margin: 16px 0 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.dtab { background: transparent; color: #94a3b8; border: 0; border-bottom: 3px solid transparent; padding: 10px 18px;
  cursor: pointer; font-size: 14px; font-family: inherit; margin: 0; border-radius: 0; }
.dtab:hover { color: #e2e8f0; background: transparent; }
.dtab.active { color: #fff; border-bottom-color: var(--accent-2); font-weight: 700; }
.dpane { display: none; } .dpane.active { display: block; }
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
@media (max-width: 760px) { .dgrid { grid-template-columns: 1fr; } }
.lockhint { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: #0b2a4a; border: 1px solid #1d4ed8;
  color: #dbeafe; font-size: 13px; line-height: 1.8; }
.lockhint b { color: #fff; }

/* user row avatar + edit-user dialog */
.unamecell { display: flex; align-items: center; gap: 8px; }
.uavatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #1e293b; flex: 0 0 auto; }
.uavatar-ph { display: inline-flex; align-items: center; justify-content: center; color: #93a4bd; font-weight: bold;
  border: 1px solid #334155; font-size: 14px; }
.ue-grid { display: grid; grid-template-columns: 200px 1fr; gap: 18px; }
@media (max-width: 620px) { .ue-grid { grid-template-columns: 1fr; } }
.ue-photo { text-align: center; }
.ue-photoimg { width: 180px; height: 180px; max-width: 100%; border-radius: 12px; object-fit: cover;
  background: #0f172a; border: 1px solid #334155; display: block; margin: 0 auto; }
.ue-photoph { display: flex; align-items: center; justify-content: center; font-size: 56px; color: #475569; }
.ue-fields .fld { margin-bottom: 10px; }

/* clickable table cell link + device checklist (institution enroll) */
.rowlink { color: #93c5fd; text-decoration: none; font-weight: 600; }
.rowlink:hover { text-decoration: underline; }
.checklist { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto;
  border: 1px solid #334155; border-radius: 8px; padding: 8px; background: #0f172a; }
.checkitem { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; margin: 0; }
.checkitem:hover { background: #1e293b; }
.checkitem input { width: auto; margin: 0; }

/* kebab (⋮) actions menu */
.kebab { position: relative; display: inline-block; }
.kebab-btn { background: var(--border); color: var(--text); border: 0; border-radius: var(--r); padding: 4px 12px;
  font-size: 18px; line-height: 1; cursor: pointer; margin: 0; min-width: 36px; min-height: 36px; }
.kebab-btn:hover { background: #475569; }
/* position:fixed so the dropdown escapes the table's overflow clipping; its
   top/left are set in JS from the button's bounding rect. */
.kebab-menu { position: fixed; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px; min-width: 190px; z-index: 60; box-shadow: var(--shadow-lg); }
.kebab-menu button { display: block; width: 100%; text-align: right; background: transparent; color: #e2e8f0;
  border: 0; padding: 9px 12px; border-radius: 7px; font-size: 13px; cursor: pointer; margin: 0; }
.kebab-menu button:hover { background: #1e293b; }
.kebab-menu button[data-act="remove"] { color: #fca5a5; }
.card { position: relative; overflow: hidden; min-width: 0; background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 20px 18px; text-align: center;
  box-shadow: var(--shadow); transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.card:hover { transform: translateY(-3px); border-color: rgba(56,189,248,.45); box-shadow: var(--shadow-lg); }
.card-ic { width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 13px; display: flex; align-items: center;
  justify-content: center; font-size: 22px; background: rgba(56,189,248,.12); border: 1px solid rgba(56,189,248,.28); }
.card .n { font-size: clamp(22px, 6vw, 34px); line-height: 1.05; font-weight: 800; color: #7dd3fc;
  overflow-wrap: anywhere; background: linear-gradient(90deg, #93c5fd, #38bdf8);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.card .l { font-size: 13px; color: var(--muted); margin-top: 6px; font-weight: 600; }

table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: 13px 14px; text-align: right; border-bottom: 1px solid rgba(42,54,80,.55); font-size: 14px; white-space: nowrap; }
th { background: var(--surface-2); color: var(--text-2); font-weight: 700; font-size: 13px; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: rgba(56,189,248,.05); }
tbody tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); text-align: center; padding: 20px; }
.pill { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.in { background: rgba(16,185,129,.16); color: #6ee7b7; border: 1px solid rgba(16,185,129,.35); }
.out { background: rgba(239,68,68,.16); color: #fca5a5; border: 1px solid rgba(239,68,68,.35); }
.thumb { height: 36px; width: 36px; object-fit: cover; border-radius: 6px; border: 1px solid #334155; vertical-align: middle; }
.muted { color: var(--muted); font-size: 13px; }
.sub { color: var(--muted); font-size: 12px; }

/* margin is 0 by default; vertical spacing is the container's job (gap / .form-actions).
   This removes the need for the dozens of inline style="margin:0" patches. */
button { background: linear-gradient(180deg, var(--accent), var(--accent-hover)); color: #fff; border: 0; border-radius: var(--r);
  padding: 11px 20px; font-size: 15px; font-weight: 600; cursor: pointer; margin: 0;
  box-shadow: 0 4px 12px rgba(37,99,235,.25); transition: transform .1s ease, filter .15s ease, box-shadow .15s ease; }
button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; filter: none; }
.btn-danger { background: linear-gradient(180deg, #ef4444, var(--danger)); box-shadow: 0 4px 12px rgba(220,38,38,.25); }
.btn-green { background: linear-gradient(180deg, #22c55e, var(--success)); box-shadow: 0 4px 12px rgba(22,163,74,.25); }
.btn-gray { background: var(--surface-raised); box-shadow: none; } .btn-gray:hover { background: #2a3650; filter: none; }
.btn-sm { font-size: 13px; padding: 8px 14px; margin: 0; min-height: 34px; box-shadow: none; font-weight: 600; }
/* the bare-button look above is for primary actions — neutralise it on chrome buttons */
.dtab, .modal-x, .kebab-btn, .nav-toggle { box-shadow: none; }
.dtab:hover, .modal-x:hover, .kebab-btn:hover, .nav-toggle:hover { transform: none; filter: none; }
/* spacing for the few buttons that used to rely on the default button margin */
#simBtn { margin-top: 8px; }
.form-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* form validation / status messages — readable error/success colors (were grey .sub) */
.formmsg { font-size: 13px; min-height: 18px; }
.formmsg.err { color: var(--err-text); font-weight: 600; }
.formmsg.ok { color: var(--ok-text); }
.fld input.invalid, .fld select.invalid, input.invalid, select.invalid { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(185,28,28,.35); }
/* isolate latin/technical values inside RTL so bidi doesn't reorder them */
.ltrval { direction: ltr; unicode-bidi: isolate; display: inline-block; }

pre { background: #020617; border-radius: 8px; padding: 12px; font-size: 13px; max-height: 200px; overflow: auto; direction: ltr; text-align: left; }
.tablewrap { overflow-x: auto; }
.panel { background: linear-gradient(160deg, var(--surface-2), var(--surface)); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.fld { font-size: 13px; color: #94a3b8; display: block; margin-bottom: 10px; }
input[type=text], input[type=password], input[type=number], input[type=date], textarea, select {
  width: 100%; background: rgba(2,6,23,.45); color: var(--text); border: 1px solid var(--border); border-radius: var(--r);
  padding: 10px 12px; font-family: inherit; font-size: 14px; margin-top: 4px; direction: rtl;
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: #3a496a; }
/* latin/numeric-only fields read & edit left-to-right even inside the RTL form */
#imSlug, #uePassword, #ueCard, #dvPin, .ltr-input { direction: ltr; text-align: left; }
textarea { resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.hidden { display: none !important; }
.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select { width: auto; display: inline-block; }
.reveal { margin-top: 12px; padding: 12px; border-radius: 8px; background: #052e16; border: 1px solid #16a34a; }
.reveal code { display: block; direction: ltr; text-align: left; background: #020617; padding: 8px; border-radius: 6px;
  margin: 6px 0; font-size: 13px; word-break: break-all; color: #6ee7b7; }
.reveal .warn { color: #fca5a5; font-size: 12px; }
tr.unassigned td { background: #422006; }
.copybtn { font-size: 12px; padding: 6px 12px; margin: 0; min-height: 32px; }
.toast { position: fixed; top: 16px; inset-inline-end: 16px; left: auto; transform: none; background: var(--surface);
  border: 1px solid var(--border); color: var(--text); padding: 12px 18px; border-radius: var(--r); font-size: 14px;
  z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.4); text-align: right; max-width: calc(100vw - 32px); }
.toast.err { border-color: #b91c1c; }
.toast.ok { border-color: #16a34a; }

/* ===== App shell (sidebar layout) ===== */
.app { max-width: 1200px; margin: 0 auto; }
.topbar { background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 14px 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.nav-toggle { display: none; background: var(--surface-raised); margin: 0; padding: 8px 12px; font-size: 18px; border-radius: var(--r); }

.layout { display: flex; gap: 20px; align-items: flex-start; }
.sidebar { width: 232px; flex-shrink: 0; background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 12px; position: sticky; top: 16px; box-shadow: var(--shadow); }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; color: var(--text-2);
  text-decoration: none; font-size: 14px; font-weight: 600; margin-bottom: 4px; transition: background .15s, color .15s; }
.nav-item .ic { font-size: 18px; width: 22px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.05); color: var(--text); }
.nav-item.active { background: linear-gradient(90deg, var(--accent), rgba(56,189,248,.55)); color: #fff;
  font-weight: 700; box-shadow: 0 8px 18px rgba(59,130,246,.35); }

.main { flex: 1; min-width: 0; } /* min-width:0 lets wide tables scroll instead of overflowing */
.page { display: none; }
.page.active { display: block; }
.page-title { font-size: 20px; color: var(--text); font-weight: 700; margin: 0 0 16px; }
.sec { font-size: 15px; color: var(--text-2); margin: 22px 0 10px; }
.panel > .sec:first-child { margin-top: 0; }

/* backdrop behind the mobile sidebar drawer */
.nav-backdrop { display: none; }

@media (max-width: 760px) {
  body { padding: 12px; }
  .nav-toggle { display: inline-block; }
  /* column layout must STRETCH items to full width; flex-start (desktop) would size
     .main to its widest content (a wide table) and overflow the phone. */
  .layout { flex-direction: column; align-items: stretch; }
  .main { width: 100%; }
  /* sidebar slides in as a drawer from the right (RTL) instead of pushing content */
  .sidebar { position: fixed; inset: 0 0 0 auto; right: 0; width: 80%; max-width: 300px;
    transform: translateX(100%); transition: transform .2s ease; display: block; z-index: 70; border-radius: 0; }
  .sidebar.open { transform: translateX(0); box-shadow: -12px 0 40px rgba(0,0,0,.5); }
  .nav-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(2,6,23,.6); z-index: 65; }
  .modal-overlay { padding: 16px 10px; }
  .modal-head { position: sticky; top: 0; background: var(--surface-2); z-index: 1; }
  .modal { padding: 18px 16px; }
  /* tighten dense chrome so nothing overflows a narrow phone */
  .page-title { font-size: 18px; }
  .dtab { padding: 9px 12px; font-size: 13px; }
  .card { padding: 16px 12px; }
  .card-ic { width: 40px; height: 40px; font-size: 20px; margin-bottom: 8px; }
  .card .n { font-size: clamp(20px, 5.4vw, 28px); }
  /* records table: drop the 460px inner scroll on phones (let the page scroll) */
  .dpane[data-pane="logs"] .tablewrap { max-height: none !important; }
}

/* login page */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px;
  width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.login-card h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.login-card .err { color: var(--err-text); font-size: 13px; min-height: 0; margin: 6px 0; text-align: center; }
.login-card .err:not(:empty) { background: #4c1d24; border: 1px solid var(--danger); color: #fecaca;
  padding: 10px 12px; border-radius: var(--r); }
.login-card button { width: 100%; margin-top: 8px; }
