@import url('https://fonts.googleapis.com/css2?family=Alexandria:wght@400;500;700;800&family=Poppins:wght@400;500;600&display=swap');

:root {
  --navy: #2E2E63;
  --navy-2: #3a3a75;
  --paper: #F7F4F0;
  --gold: #C49A5A;
  --gold-soft: #f1e7d8;
  --white: #FFFFFF;
  --ink: #2E2E63;
  --muted: #7a7a96;
  --line: #e4ddd3;
  --ok: #2f8f5b;
  --bad: #b8433a;
  --warn: #C49A5A;
  --font-ar: 'Alexandria', system-ui, sans-serif;
  --font-en: 'Poppins', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ar);
  font-size: 14px;
  line-height: 1.6;
}
.en, .num, code, .mono { font-family: var(--font-en); direction: ltr; unicode-bidi: isolate; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--navy);
  color: var(--white);
  display: flex; align-items: center; gap: 32px;
  padding: 0 32px; height: 64px;
  position: sticky; top: 0; z-index: 10;
}
.brand-word { font-family: var(--font-en); font-weight: 600; letter-spacing: .14em; font-size: 15px; direction: ltr; }
.brand-word span { color: var(--gold); font-weight: 400; letter-spacing: .06em; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  text-decoration: none; padding: 8px 14px; color: rgba(255,255,255,.7);
  border-bottom: 2px solid transparent; font-weight: 500;
}
.topbar nav a.active, .topbar nav a:hover { color: var(--white); border-bottom-color: var(--gold); }
.topbar .badge { background: var(--gold); color: var(--navy); }
.link-btn { background: none; border: 0; color: rgba(255,255,255,.7); cursor: pointer; }
.link-btn:hover { color: var(--white); }

main { max-width: 1280px; margin: 0 auto; padding: 40px 32px 80px; }

/* ---------- Headings ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 32px; flex-wrap: wrap; }
.page-head h1 { font-size: 34px; font-weight: 800; margin: 0; line-height: 1.2; }
.page-head .sub { color: var(--muted); margin-top: 6px; }
.eyebrow { color: var(--gold); font-weight: 700; font-size: 13px; margin-bottom: 6px; }
h2 { font-size: 20px; font-weight: 800; margin: 40px 0 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--navy); background: transparent; color: var(--navy);
  padding: 9px 18px; border-radius: 2px; cursor: pointer; font-weight: 500;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--navy); color: var(--white); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--white); }
.btn-gold:hover { background: var(--navy); border-color: var(--navy); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad); color: var(--white); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--navy); border-bottom: 1px solid var(--line); }
.stat { padding: 24px 0 22px; border-inline-start: 1px solid var(--line); padding-inline-start: 24px; }
.stat:first-child { border-inline-start: 0; padding-inline-start: 0; }
.stat .num { font-size: 44px; font-weight: 600; line-height: 1; display: block; text-align: right; }
.stat .num.gold { color: var(--gold); }
.stat .lbl { color: var(--muted); margin-top: 10px; display: block; }

/* ---------- Sites grid ---------- */
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; }
.site-card {
  background: var(--white); border: 1px solid var(--line); padding: 24px;
  cursor: pointer; text-decoration: none; display: block; position: relative;
}
.site-card::before { /* battlement accent, echoing the logo crown */
  content: ''; position: absolute; top: -1px; inset-inline-start: 24px; width: 42px; height: 4px;
  background: linear-gradient(90deg, var(--gold) 0 8px, transparent 8px 17px, var(--gold) 17px 25px, transparent 25px 34px, var(--gold) 34px);
}
.site-card:hover { border-color: var(--navy); }
.site-card h3 { margin: 6px 0 4px; font-size: 20px; font-weight: 800; }
.site-card .meta { color: var(--muted); font-size: 13px; }
.site-card .row { display: flex; gap: 24px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.site-card .row div { display: flex; flex-direction: column; }
.site-card .row .num { font-size: 22px; font-weight: 600; text-align: right; }
.site-card .row small { color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c9c4bc; display: inline-block; flex: none; }
.dot.on { background: var(--ok); }
.dot.blocked { background: var(--bad); }
.badge {
  display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 10px; font-size: 11px;
  font-family: var(--font-en); text-align: center; background: var(--gold-soft); color: var(--navy);
}
.badge.bad { background: var(--bad); color: var(--white); }
.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border: 1px solid var(--gold); color: var(--gold); border-radius: 2px; }
.tag.bad { border-color: var(--bad); color: var(--bad); }

/* ---------- Site header ---------- */
.site-facts { display: flex; gap: 40px; flex-wrap: wrap; padding: 18px 0; border-top: 1px solid var(--navy); border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.site-facts div small { display: block; color: var(--muted); font-size: 12px; }
.site-facts div b { font-weight: 500; }

/* ---------- View switch ---------- */
.viewswitch { display: flex; gap: 28px; border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.viewswitch button { background: none; border: 0; padding: 12px 2px; cursor: pointer; color: var(--muted); font-weight: 700; font-size: 15px; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 8px; }
.viewswitch button.active { color: var(--navy); border-bottom-color: var(--gold); }
.viewswitch button:hover { color: var(--navy); }

/* ---------- Toolbar & table ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.tabs { display: flex; border: 1px solid var(--line); background: var(--white); }
.tabs button { border: 0; background: none; padding: 7px 14px; cursor: pointer; color: var(--muted); border-inline-start: 1px solid var(--line); }
.tabs button:first-child { border-inline-start: 0; }
.tabs button.active { background: var(--navy); color: var(--white); }
.search { flex: 1; min-width: 200px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--white); padding: 9px 12px; border-radius: 2px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); }

.table-wrap { background: var(--white); border: 1px solid var(--line); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: right; font-weight: 500; color: var(--muted); font-size: 12px; padding: 12px 16px; border-bottom: 1px solid var(--navy); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: #fbf9f6; }
tbody tr.offline td { color: var(--muted); }
td .name { font-weight: 700; }
td .hint { color: var(--muted); font-size: 12px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

/* ---------- Progress bar (router restart) ---------- */
.progwrap { height: 10px; background: var(--line); border-radius: 6px; overflow: hidden; margin-top: 8px; }
.progbar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--navy)); transition: width .8s ease; }

/* ---------- Sub-tabs (attendance, control) ---------- */
.subtabs { display: flex; gap: 6px; margin-bottom: 18px; }
.subtabs button { border: 1px solid var(--line); background: var(--white); padding: 7px 16px; cursor: pointer; color: var(--muted); border-radius: 2px; font-weight: 500; }
.subtabs button.active { background: var(--navy); color: var(--white); border-color: var(--navy); }

/* ---------- Cameras ---------- */
.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.cam-card { background: var(--white); border: 1px solid var(--line); }
.cam-view { position: relative; aspect-ratio: 16/9; background: #11111a; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cam-view img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; z-index: 1; }
.cam-view img.nosig { display: none; }
.cam-off { color: #888; font-size: 13px; z-index: 0; }
.cam-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.cam-bar b { flex: 1; }

/* ---------- Events ---------- */
.events { background: var(--white); border: 1px solid var(--line); }
.event { display: grid; grid-template-columns: 10px 1fr auto; gap: 14px; align-items: baseline; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.event:last-child { border-bottom: 0; }
.event .dot { transform: translateY(-1px); }
.event.alert .dot { background: var(--gold); }
.event.unread { background: #fcf8f1; }
.event .site { color: var(--gold); font-size: 12px; margin-inline-end: 8px; }
.event time { color: var(--muted); font-size: 12px; }

/* ---------- Drawer / modal ---------- */
.scrim { position: fixed; inset: 0; background: rgba(46,46,99,.35); z-index: 20; }
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(520px, 100%);
  background: var(--paper); z-index: 21; overflow-y: auto; border-inline-start: 1px solid var(--navy);
}
.drawer-head { background: var(--navy); color: var(--white); padding: 24px 28px; }
.drawer-head h2 { margin: 0; color: var(--white); }
.drawer-head .sub { color: rgba(255,255,255,.7); font-size: 13px; }
.drawer-body { padding: 24px 28px 40px; }
.close-x { float: left; background: none; border: 0; color: var(--white); font-size: 22px; cursor: pointer; line-height: 1; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 16px; margin-bottom: 24px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.section-title { font-weight: 800; margin: 28px 0 12px; padding-top: 18px; border-top: 1px solid var(--line); }
label { display: block; margin-bottom: 14px; font-weight: 500; }
label input, label select, label textarea { margin-top: 6px; font-weight: 400; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--gold); margin: 0; }

.modal {
  position: fixed; z-index: 21; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto;
  background: var(--paper); border-top: 4px solid var(--gold); padding: 28px;
}
.modal h2 { margin-top: 0; }

pre.output {
  background: var(--navy); color: #e8e6f5; padding: 14px 16px; font-size: 12px; overflow-x: auto;
  white-space: pre-wrap; direction: ltr; text-align: left; margin: 10px 0 0; font-family: Consolas, monospace;
}
.ports { width: 100%; border: 1px solid var(--line); background: var(--white); }
.ports td, .ports th { padding: 8px 12px; }
.copy-box { display: flex; gap: 8px; align-items: stretch; margin: 8px 0 16px; }
.copy-box code { flex: 1; background: var(--white); border: 1px solid var(--line); padding: 10px 12px; word-break: break-all; font-size: 12px; text-align: left; }

.speed { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); background: var(--white); margin-top: 12px; }
.speed div { padding: 16px; border-inline-start: 1px solid var(--line); }
.speed div:first-child { border-inline-start: 0; }
.speed .num { font-size: 28px; font-weight: 600; color: var(--gold); display: block; text-align: right; }
.speed small { color: var(--muted); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--navy); color: var(--white); padding: 12px 22px; border-inline-start: 4px solid var(--gold);
}
.toast.err { border-inline-start-color: var(--bad); }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; background: var(--navy); padding: 16px; }
.login-card { background: var(--paper); width: min(400px, 100%); padding: 40px 36px; border-top: 4px solid var(--gold); }
.login-card .brand-word { color: var(--navy); margin-bottom: 28px; }
.login-card h1 { font-size: 26px; font-weight: 800; margin: 0 0 24px; }
.login-card .btn { width: 100%; margin-top: 8px; padding: 12px; }
.form-msg { color: var(--bad); margin: 0 0 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 800px) {
  .topbar { padding: 0 16px; gap: 16px; }
  .topbar nav a { padding: 8px 8px; }
  main { padding: 24px 16px 60px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-inline-start: 0; padding-inline-start: 0; }
  .stat .num { font-size: 34px; }
  .page-head h1 { font-size: 26px; }
  .hide-sm { display: none; }
  .site-facts { gap: 20px; }
}

/* ---------- v2: network-assets vault + fingerprint panel + polish ---------- */
.zkpanel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 2px 10px rgba(46, 46, 99, .05);
}
.zkpanel table { margin: 0; }
.zkpanel .btn-sm { margin-inline-start: 4px; }
.pw { letter-spacing: 2px; color: var(--navy); font-family: var(--font-en); }
.link-btn { background: none; border: 0; cursor: pointer; font-size: 15px; padding: 0 4px; line-height: 1; }
.link-btn:hover { opacity: .7; }
/* smoother interactive feel across the dashboard */
.viewswitch button, .subtabs button, .btn, .tabs button { transition: background .15s ease, color .15s ease, border-color .15s ease; }
.btn:hover { filter: brightness(.97); }
.table-wrap { border-radius: 12px; overflow: hidden; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #faf7f2; }
.tag { padding: 1px 8px; border-radius: 999px; font-size: 11px; background: var(--gold-soft); color: var(--navy); }
.tag.bad { background: #f6dcd9; color: var(--bad); }

/* ---------- IP map (IPAM) ---------- */
.ipm-sum { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 6px; }
.ipm-chip { padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid transparent; }
.ipm-badge { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.ipm-used { background: #e4f4ea; color: #1d7a45; border-color: #bfe6cd; }
.ipm-off  { background: #eceef4; color: #5a5f73; border-color: #d8dbe6; }
.ipm-res  { background: var(--gold-soft); color: #8a6a2e; border-color: #e7d4b2; }
.ipm-free { background: #f7f6f3; color: var(--muted); border-color: #eceae6; }
