/* ============================================================
   VORADAR — Parent Dashboard
   LTR (English), dark theme, no build step.
   ============================================================ */

:root {
  --bg:            #0b0f18;
  --bg-soft:       #111827;
  --panel:         #151c2b;
  --panel-2:       #1b2434;
  --border:        #263149;
  --text:          #e8edf7;
  --text-dim:      #93a1bd;
  --text-faint:    #64748b;
  --accent:        #4f8cff;
  --accent-soft:   rgba(79, 140, 255, .14);
  --ok:            #34d399;
  --warn:          #fbbf24;
  --danger:        #f87171;
  --radius:        14px;
  --radius-sm:     10px;
  --shadow:        0 10px 30px rgba(0, 0, 0, .35);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Author display rules (e.g. .modal, #app-view) must not defeat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .4rem; line-height: 1.3; }
p  { margin: 0 0 .6rem; }
.muted { color: var(--text-dim); font-size: .88rem; }
.faint { color: var(--text-faint); font-size: .8rem; }

/* ------------------------------------------------------ buttons & inputs */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .55rem 1.05rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, transform .08s ease;
  color: var(--text);
  background: var(--panel-2);
}
.btn:hover { background: #24304a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #3d7bf5; }
.btn-danger  { background: rgba(248, 113, 113, .14); color: var(--danger); border-color: rgba(248, 113, 113, .3); }
.btn-danger:hover { background: rgba(248, 113, 113, .24); }
.btn-ghost   { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-block   { width: 100%; justify-content: center; }
.btn-sm      { padding: .35rem .75rem; font-size: .84rem; }

input[type=text], input[type=email], input[type=password], select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .6rem .8rem;
  font: inherit;
  outline: none;
  transition: border-color .15s ease;
}
input:focus, select:focus { border-color: var(--accent); }
select { cursor: pointer; }

.switch { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; font-size: .87rem; color: var(--text-dim); }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* ------------------------------------------------------------ auth screen */

.auth-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(79, 140, 255, .18), transparent 60%),
    radial-gradient(700px 500px at 10% 110%, rgba(52, 211, 153, .10), transparent 60%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.9rem;
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.4rem; }
.brand-mark { font-size: 2rem; line-height: 1; }
.auth-brand h1 { font-size: 1.4rem; margin: 0; letter-spacing: .3px; }
.auth-brand p { margin: 0; color: var(--text-dim); font-size: .85rem; }

.auth-tabs { display: flex; gap: .4rem; background: var(--bg-soft); padding: .3rem; border-radius: var(--radius-sm); margin-bottom: 1.2rem; }
.auth-tab {
  flex: 1; border: 0; background: transparent; color: var(--text-dim);
  padding: .5rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
.auth-tab.is-active { background: var(--accent); color: #fff; }

.field { display: block; margin-bottom: .95rem; }
.field > span { display: block; margin-bottom: .35rem; font-size: .85rem; color: var(--text-dim); font-weight: 600; }

.auth-error {
  background: rgba(248, 113, 113, .12);
  border: 1px solid rgba(248, 113, 113, .3);
  color: #fca5a5;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  margin-bottom: .9rem;
}
.auth-note { margin: 1.1rem 0 0; font-size: .78rem; color: var(--text-faint); text-align: center; }

/* -------------------------------------------------------------- app shell */

#app-view { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .7rem 1.1rem;
  background: var(--panel); border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.topbar-brand { display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: .9rem; }
.who { color: var(--text-dim); font-size: .87rem; }

.conn { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--text-dim); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.conn.is-live .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .16); }
.conn.is-down .dot { background: var(--danger); }

.layout { display: grid; grid-template-columns: 280px 1fr; flex: 1 1 auto; min-height: 0; }

/* -------------------------------------------------------------- sidebar */

.sidebar {
  background: var(--panel);
  border-inline-end: 1px solid var(--border);
  padding: 1rem .9rem;
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.sidebar-head h2 { font-size: 1rem; margin: 0; }
.sidebar-hint { margin-top: auto; padding-top: 1rem; font-size: .76rem; color: var(--text-faint); line-height: 1.5; }

.device-list { display: flex; flex-direction: column; gap: .45rem; }
.device-card {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .65rem .75rem;
  cursor: pointer; transition: border-color .15s ease, background .15s ease;
}
.device-card:hover { border-color: var(--accent); }
.device-card.is-active { border-color: var(--accent); background: var(--accent-soft); }
.device-card .row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.device-card .name { font-weight: 600; font-size: .92rem; }
.device-card .sub { font-size: .75rem; color: var(--text-faint); }
.device-card .status { font-size: .72rem; display: inline-flex; align-items: center; gap: .3rem; }
.device-card .status i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.device-card.is-online .status i { background: var(--ok); }
.device-card.is-offline .status i { background: var(--danger); }
.batt { font-size: .74rem; color: var(--text-dim); }

/* --------------------------------------------------------------- content */

.content { overflow-y: auto; padding: 1.2rem 1.4rem 3rem; min-width: 0; }
.device-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.device-head h1 { font-size: 1.3rem; margin: 0; }
.device-head-actions { display: flex; gap: .5rem; }

.tabs { display: flex; gap: .35rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: 1.1rem; border-bottom: 1px solid var(--border); }
.tab {
  border: 0; background: transparent; color: var(--text-dim);
  padding: .5rem .85rem; border-radius: 8px; font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; font-size: .9rem;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); }

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

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.panel-head h3 { font-size: 1rem; margin: 0; }
.panel-head select { width: auto; min-width: 140px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card h3 { font-size: .95rem; color: var(--text-dim); font-weight: 600; margin-bottom: .9rem; }

/* ----------------------------------------------------------- stat cards */

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .85rem 1rem;
}
.stat .label { font-size: .78rem; color: var(--text-dim); margin-bottom: .3rem; }
.stat .value { font-size: 1.45rem; font-weight: 700; line-height: 1.2; }
.stat .hint  { font-size: .74rem; color: var(--text-faint); margin-top: .15rem; }
.stat.accent .value { color: var(--accent); }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }

/* ------------------------------------------------------------------ map */

.map-wrap {
  position: relative; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; background: var(--panel);
}
#map { height: 62vh; min-height: 380px; width: 100%; }
.map-tools {
  position: absolute; top: 10px; inset-inline-end: 10px; z-index: 500;
  display: flex; flex-direction: column; gap: .4rem;
  background: rgba(17, 24, 39, .92); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .6rem .7rem;
  backdrop-filter: blur(6px);
}
.map-tools select { width: auto; }
.leaflet-container { background: #0e1420; font-family: var(--font); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
}
.leaflet-popup-content-wrapper { border-radius: 12px; }
.map-popup h4 { margin: 0 0 .3rem; font-size: .95rem; }
.map-popup .row { display: flex; justify-content: space-between; gap: 1rem; font-size: .82rem; color: var(--text-dim); }

/* ----------------------------------------------------------- bar charts */

.bar-list { display: flex; flex-direction: column; gap: .6rem; }
.bar-item { display: grid; grid-template-columns: minmax(120px, 210px) 1fr auto; align-items: center; gap: .8rem; }
.bar-item .name { font-size: .87rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-item .name small { display: block; color: var(--text-faint); font-size: .7rem; text-align: left; }
.bar-track { background: var(--bg-soft); border-radius: 999px; height: 9px; overflow: hidden; }
.bar-fill { background: linear-gradient(90deg, var(--accent), #7aa8ff); height: 100%; border-radius: 999px; }
.bar-item .val { font-size: .8rem; color: var(--text-dim); min-width: 62px; text-align: right; }

/* ---------------------------------------------------------------- lists */

.list { display: flex; flex-direction: column; gap: .5rem; }
.row-item {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .7rem .85rem;
  display: flex; align-items: flex-start; gap: .7rem;
}
.row-item .icon {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 1rem;
  background: var(--panel-2);
}
.row-item .body { flex: 1 1 auto; min-width: 0; }
.row-item .title { font-weight: 600; font-size: .9rem; }
.row-item .sub { font-size: .8rem; color: var(--text-dim); overflow-wrap: anywhere; }
.row-item .when { font-size: .75rem; color: var(--text-faint); white-space: nowrap; }
.tag {
  font-size: .7rem; padding: .1rem .45rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim); background: var(--bg-soft);
}
.tag.in  { color: var(--ok);   border-color: rgba(52, 211, 153, .35); }
.tag.out { color: var(--accent); border-color: rgba(79, 140, 255, .35); }
.tag.miss { color: var(--danger); border-color: rgba(248, 113, 113, .35); }

/* --------------------------------------------------------------- media */

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; }
.media-item {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; cursor: pointer;
  transition: transform .15s ease, border-color .15s ease;
}
.media-item:hover { transform: translateY(-2px); border-color: var(--accent); }
.media-item img { width: 100%; height: 190px; object-fit: cover; display: block; background: var(--bg-soft); }
.media-item .cap { padding: .45rem .6rem; font-size: .76rem; color: var(--text-dim); display: flex; justify-content: space-between; gap: .5rem; }

/* --------------------------------------------------------------- modal */

.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(3, 6, 12, .72);
  display: grid; place-items: center; padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 1.6rem; width: 100%; max-width: 380px;
  box-shadow: var(--shadow); text-align: center;
}
.modal-card h2 { font-size: 1.15rem; }
.code-box {
  font-size: 2.1rem; font-weight: 800; letter-spacing: .35em;
  margin: 1.1rem 0 .5rem; padding: .9rem;
  background: var(--bg-soft); border: 1px dashed var(--accent);
  border-radius: var(--radius-sm); color: var(--accent);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.code-meta { display: flex; align-items: center; justify-content: space-between; font-size: .8rem; color: var(--text-faint); margin-bottom: 1.1rem; }

.modal-card { max-height: calc(100vh - 2rem); overflow-y: auto; }
.btn-link {
  display: block; width: 100%; margin-top: .7rem; padding: .3rem;
  background: none; border: 0; color: var(--accent); font: inherit; font-size: .82rem; cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

/* App download dialog: the QR code needs a light background to be scannable. */
a.btn { text-decoration: none; }
.app-qr {
  width: 208px; height: 208px; margin: 1rem auto; padding: 8px;
  background: #fff; border-radius: var(--radius-sm); line-height: 0;
}
.app-qr svg { width: 100%; height: 100%; display: block; }
.app-qr.is-empty { display: none; }
.app-meta { margin: .7rem 0 0; font-size: .76rem; color: var(--text-faint); word-break: break-all; }
.app-steps { text-align: start; margin: 1rem 0; padding-inline-start: 1.2rem; font-size: .82rem; color: var(--text-dim); display: grid; gap: .35rem; }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed; bottom: 1.2rem; inset-inline-start: 1.2rem; z-index: 3000;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: .7rem 1.1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: .88rem; max-width: 320px;
}
.toast.err { border-color: rgba(248, 113, 113, .45); color: #fca5a5; }
.toast.ok  { border-color: rgba(52, 211, 153, .45); color: #6ee7b7; }

/* ------------------------------------------------------------ empty state */

.empty { text-align: center; color: var(--text-faint); padding: 2.4rem 1rem; font-size: .9rem; }
.empty .big { font-size: 2rem; display: block; margin-bottom: .5rem; opacity: .6; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    border-inline-end: 0; border-bottom: 1px solid var(--border);
    max-height: 240px;
  }
  .sidebar-hint { display: none; }
  .content { padding: 1rem; }
  .bar-item { grid-template-columns: 1fr; gap: .25rem; }
  .bar-item .val { text-align: left; }
}

@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .who { display: none; }
  .device-head-actions { width: 100%; }
}
