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

:root {
  --yellow: #ffc92e;
  --yellow-dim: rgba(255,201,46,.15);
  --green: #3fb950;
  --green-dim: rgba(63,185,80,.15);
  --red: #f85149;
  --red-dim: rgba(248,81,73,.15);
  --orange: #d29922;
  --orange-dim: rgba(210,153,34,.15);

  --bg: #0b0d0f;
  --sidebar-bg: #0f1114;
  --card: #161b22;
  --card-hover: #1c2129;
  --border: rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);

  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #484f58;

  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 220px;
  --bottom-nav-h: 62px;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, a { touch-action: manipulation; }

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-icon {
  width: 36px; height: 36px;
  background: var(--yellow);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand span { color: var(--yellow); font-size: 15px; font-weight: 900; letter-spacing: .3px; text-transform: uppercase; }
.brand strong { color: var(--text-muted); font-size: 11px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; }

.sidebar nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 2px;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.sidebar nav a .nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar nav a:hover { background: rgba(255,255,255,.05); color: var(--text); }
.sidebar nav a.active { background: var(--yellow-dim); color: var(--yellow); }

.sidebar-footer {
  padding: 12px 10px 18px;
  border-top: 1px solid var(--border);
}
.sidebar-footer form button {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s, color .15s, border-color .15s;
}
.sidebar-footer form button:hover { background: rgba(255,255,255,.06); color: var(--text); border-color: var(--border-strong); }

/* ── MAIN APP ─────────────────────────────────────────────── */
.app {
  margin-left: var(--sidebar-w);
  padding: 32px 36px;
  min-height: 100vh;
}

/* ── LOGIN PAGE ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 60% 40% at 20% 20%, rgba(255,201,46,.08), transparent),
    radial-gradient(ellipse 50% 60% at 80% 80%, rgba(63,185,80,.05), transparent),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: 0 40px 100px rgba(0,0,0,.5);
}
.login-logo {
  width: 56px; height: 56px;
  background: var(--yellow);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  margin-bottom: 24px;
}
.login-card .eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.login-card h1 {
  font-size: 28px;
  font-weight: 900;
  color: var(--text);
  margin-bottom: 28px;
  line-height: 1.1;
}
.hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 14px;
  line-height: 1.5;
}

/* ── FORMS ────────────────────────────────────────────────── */
.stack { display: grid; gap: 16px; }

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 13px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(255,201,46,.5);
  box-shadow: 0 0 0 3px rgba(255,201,46,.1);
}
input::placeholder { color: var(--text-dim); }
textarea { min-height: 80px; resize: vertical; }
select { color-scheme: dark; }

/* ── BUTTONS ──────────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  min-height: 42px;
  padding: 0 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
button:active { transform: scale(.97); }

button.primary, .primary { background: var(--yellow); color: #111; }
button.primary:hover { box-shadow: 0 0 0 3px rgba(255,201,46,.25); }
button.danger, .danger { background: var(--red); color: #fff; }
button.danger:hover { box-shadow: 0 0 0 3px rgba(248,81,73,.25); }
button.ghost, .ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}
button.ghost:hover { background: rgba(255,255,255,.06); color: var(--text); }
button.muted {
  background: rgba(255,255,255,.06);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
button.muted:hover { background: rgba(255,255,255,.1); color: var(--text); }

/* ── FLASH ────────────────────────────────────────────────── */
.flash {
  margin-bottom: 20px;
  padding: 12px 16px;
  background: rgba(255,201,46,.1);
  border: 1px solid rgba(255,201,46,.25);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--yellow);
}

/* ── PAGE HEADER ──────────────────────────────────────────── */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.page-head h1 {
  font-size: 28px;
  font-weight: 900;
  color: var(--text);
  line-height: 1.1;
}
.user-pill {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border-strong);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── EMPLOYEE DASHBOARD ───────────────────────────────────── */
.employee-home {
  min-height: calc(100vh - 160px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 20px 0 40px;
}

/* Status bar */
.alarm-current {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.alarm-current span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.alarm-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .3px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  transition: background .3s, color .3s, border-color .3s;
}
.alarm-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background .3s;
}
.alarm-current strong {
  display: contents;
  font-size: 15px;
  font-weight: 800;
}
.alarm-current em {
  font-style: normal;
  font-size: 12px;
  color: var(--text-dim);
}

/* Armed states */
.employee-home.armed_total .alarm-status-pill,
.employee-home.armed_night .alarm-status-pill {
  background: var(--green-dim);
  border-color: rgba(63,185,80,.3);
  color: var(--green);
}
.employee-home.armed_total .alarm-status-dot,
.employee-home.armed_night .alarm-status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }

.employee-home.panic_pending .alarm-status-pill {
  background: var(--red-dim);
  border-color: rgba(248,81,73,.3);
  color: var(--red);
}
.employee-home.panic_pending .alarm-status-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }

/* Big round toggle button */
.big-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
}
.big-toggle button {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: transparent;
  border: 4px solid var(--yellow);
  box-shadow: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: box-shadow .25s, border-color .25s, background .25s, transform .15s;
  padding: 0;
  min-height: unset;
}
.big-toggle button:hover {
  background: rgba(255,201,46,.06);
  box-shadow: 0 0 40px rgba(255,201,46,.2), 0 0 80px rgba(255,201,46,.08);
  transform: scale(1.03);
}
.big-toggle button:active { transform: scale(.97); }

.btn-emoji { font-size: 52px; line-height: 1; display: block; }
.btn-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--yellow);
  display: block;
}

.arm-button { border-color: var(--yellow); }
.arm-button .btn-label { color: var(--yellow); }

.disarm-button { border-color: var(--green); }
.disarm-button .btn-label { color: var(--green); }
.disarm-button:hover { background: rgba(63,185,80,.06) !important; box-shadow: 0 0 40px rgba(63,185,80,.2), 0 0 80px rgba(63,185,80,.08) !important; }

.employee-home.panic_pending .big-toggle button {
  border-color: var(--red);
  box-shadow: 0 0 30px rgba(248,81,73,.2);
}
.employee-home.panic_pending .big-toggle button .btn-label { color: var(--red); }

/* Divider */
.employee-divider {
  width: 60px;
  height: 1px;
  background: var(--border-strong);
}

/* Secondary actions */
.employee-secondary {
  display: flex;
  gap: 10px;
}
.employee-secondary form { display: flex; }
.employee-secondary button {
  min-height: 38px;
  padding: 0 20px;
  font-size: 13px;
  border-radius: 999px;
}

/* ── ADMIN DASHBOARD ──────────────────────────────────────── */
.status-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.status-band > div {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.status-band span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.status-band strong {
  font-size: 20px;
  font-weight: 900;
  color: var(--text);
  text-transform: uppercase;
}
.status-band.armed_total strong,
.status-band.armed_night strong { color: var(--green); }
.status-band.panic_pending strong { color: var(--red); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.actions form button {
  border-radius: 999px;
  font-size: 13px;
  min-height: 38px;
  padding: 0 18px;
}

/* ── GRID / PANELS ────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 16px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
}
.panel h2 {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 16px;
}

.rules {
  padding-left: 18px;
  display: grid;
  gap: 8px;
}
.rules li {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── EVENTS ───────────────────────────────────────────────── */
.event {
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.025);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-dim);
  margin-bottom: 8px;
  transition: background .15s;
}
.event:hover { background: rgba(255,255,255,.04); }
.event strong { font-size: 13px; font-weight: 700; color: var(--text); }
.event span, .event small { font-size: 12px; color: var(--text-muted); }
.event.warning { border-left-color: var(--orange); }
.event.warning strong { color: var(--orange); }
.event.critical { border-left-color: var(--red); }
.event.critical strong { color: var(--red); }
.event.info { border-left-color: var(--green); }
.event.info strong { color: var(--green); }
.event.row { grid-template-columns: 200px 1fr 180px; align-items: center; }

/* ── CAMERAS ──────────────────────────────────────────────── */
.camera-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.camera-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.camera-frame {
  aspect-ratio: 704 / 576;
  background: #060809;
  overflow: hidden;
  position: relative;
}
.camera-frame img, .camera-frame video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-info {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.camera-card strong { font-size: 14px; font-weight: 800; color: var(--text); }
.camera-card span { font-size: 12px; color: var(--text-muted); font-weight: 600; }

/* ── DEVICES ──────────────────────────────────────────────── */
.devices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.device-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.device-form { display: grid; gap: 12px; }
.device-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.device-top strong {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: rgba(255,255,255,.05);
  padding: 4px 10px;
  border-radius: 6px;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.badge.pending { background: rgba(210,153,34,.15); color: var(--orange); }
.badge.connected { background: var(--green-dim); color: var(--green); }
.badge.offline, .badge.fault { background: var(--red-dim); color: var(--red); }

.two, .role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.role-grid article {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
}
.role-grid article h3 {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
}
.role-grid article p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── PANIC MODAL ──────────────────────────────────────────── */
.panic-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: none;
  place-items: center;
  padding: 24px;
}
.panic-overlay.open { display: grid; }
.panic-modal-inner {
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 36px;
  width: min(560px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  display: grid;
  gap: 20px;
  text-align: center;
}
.panic-modal-inner h2 { font-size: 22px; font-weight: 900; color: var(--red); }
.panic-modal-inner p { font-size: 14px; color: var(--text-muted); line-height: 1.6; }
.panic-modal-actions { display: flex; gap: 10px; }
.panic-modal-actions button { flex: 1; }

/* ── PANIC CAM GRID ───────────────────────────────────────── */
.panic-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.panic-cam-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.panic-cam { display: grid; gap: 4px; }
.panic-cam video {
  width: 100%;
  aspect-ratio: 16/9;
  background: #060809;
  border-radius: 6px;
  display: block;
  object-fit: cover;
}
.panic-cam-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

/* ── FLOATING NOTIFICATION BUTTON (mobile) ────────────────── */
#notif-float {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 12px);
  right: 12px;
  z-index: 300;
  background: rgba(255,201,46,.95);
  color: #111;
  border-radius: 999px;
  min-height: 44px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 800;
  display: none;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 20px rgba(255,201,46,.4);
}

/* ── RESPONSIVE DESKTOP MEDIUM ────────────────────────────── */
@media (max-width: 1024px) {
  .app { padding: 24px; }
}

/* ── RESPONSIVE MOBILE (bottom navigation) ────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    top: auto;
    width: 100%;
    height: var(--bottom-nav-h);
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 0;
    overflow: hidden;
    z-index: 200;
  }
  .brand { display: none; }
  .sidebar nav {
    flex: 1;
    flex-direction: row;
    padding: 0;
    gap: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav a {
    flex: 1;
    min-width: 52px;
    height: var(--bottom-nav-h);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 4px 4px 6px;
    font-size: 10px;
    font-weight: 700;
    border-radius: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sidebar nav a .nav-icon { font-size: 20px; width: auto; }
  .sidebar nav a.active {
    background: transparent;
    box-shadow: inset 0 2px 0 var(--yellow);
    color: var(--yellow);
  }
  .sidebar nav a:hover { background: rgba(255,255,255,.04); }
  .sidebar-footer {
    flex-shrink: 0;
    width: 56px;
    height: var(--bottom-nav-h);
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .sidebar-footer form button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
    font-size: 0;
    border: 1px solid var(--border-strong);
  }
  .sidebar-footer form button span { font-size: 20px; }
  #notif-btn-wrapper { display: none; }
  #notif-float { display: flex; }

  .app {
    margin-left: 0;
    padding: 14px 14px calc(var(--bottom-nav-h) + 16px);
  }

  .employee-home {
    min-height: calc(100dvh - var(--bottom-nav-h) - 60px);
    gap: 24px;
    padding: 20px 0 20px;
  }
  .big-toggle button {
    width: 160px;
    height: 160px;
  }
  .btn-emoji { font-size: 40px; }
  .btn-label { font-size: 11px; }

  .status-band, .grid, .camera-grid, .devices, .two, .role-grid, .event.row {
    grid-template-columns: 1fr;
  }
  .page-head { flex-direction: column; }
  .login-card { padding: 28px 20px; border-radius: 16px; }
  .panel { padding: 16px; }
  .actions { padding: 12px; }
}

/* ── PANIC MODAL BOTTOM SHEET (small mobile) ──────────────── */
@media (max-width: 600px) {
  .panic-overlay { padding: 0; align-items: flex-end; }
  .panic-modal-inner {
    width: 100%;
    max-height: 95dvh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding: 28px 20px 32px;
  }
  .panic-modal-actions { flex-direction: column; }
}
