:root {
  color-scheme: light;
  --navy-950: #1b1b1b;
  --navy-900: #242424;
  --navy-800: #353535;
  --emerald-600: #d96c00;
  --emerald-500: #ee7700;
  --emerald-100: #fff0df;
  --amber-500: #f59e0b;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --slate-900: #24201d;
  --slate-700: #544d47;
  --slate-500: #7d746c;
  --slate-300: #d2cbc4;
  --slate-200: #e9e4df;
  --slate-100: #f3efeb;
  --surface: #ffffff;
  --background: #f7f5f2;
  --shadow: 0 12px 30px rgba(35, 27, 20, .09);
  --radius-lg: 20px;
  --radius-md: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--background);
  color: var(--slate-900);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
a { color: inherit; }

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--slate-500);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--slate-200);
  border-top-color: var(--emerald-500);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(380px, 520px);
  background: var(--navy-950);
}

.login-hero {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: clamp(36px, 6vw, 90px);
  color: white;
  background:
    radial-gradient(circle at 15% 15%, rgba(238,119,0,.32), transparent 30%),
    linear-gradient(145deg, #151515, #24211f 65%, #3a2b20);
}

.login-hero::after {
  content: "";
  position: absolute;
  width: 420px;
  height: 420px;
  right: -120px;
  bottom: -140px;
  border: 70px solid rgba(255,255,255,.045);
  border-radius: 50%;
}

.brand {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 13px;
  align-items: center;
  font-weight: 760;
  letter-spacing: -.02em;
}

.company-logo { display: block; width: 88px; height: auto; object-fit: contain; }
.brand-divider { width: 1px; height: 35px; background: currentColor; opacity: .18; }
.brand-copy { line-height: 1.1; }
.brand small { display: block; font-weight: 500; opacity: .64; letter-spacing: 0; }

.hero-copy { position: relative; z-index: 1; max-width: 650px; }
.eyebrow { color: #ffad5c; text-transform: uppercase; font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.hero-copy h1 { margin: 14px 0 18px; font-size: clamp(38px, 5vw, 72px); line-height: .98; letter-spacing: -.055em; }
.hero-copy p { max-width: 570px; margin: 0; color: rgba(255,255,255,.72); font-size: clamp(16px, 1.6vw, 20px); line-height: 1.7; }

.trust-row { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 22px; color: rgba(255,255,255,.68); font-size: 13px; }
.trust-item { display: flex; align-items: center; gap: 8px; }
.trust-dot { width: 8px; height: 8px; border-radius: 50%; background: #ffad5c; }

.login-panel {
  display: grid;
  place-items: center;
  padding: 42px;
  background: white;
}

.login-card { width: min(100%, 390px); }
.login-card h2 { margin: 0 0 8px; font-size: 30px; letter-spacing: -.035em; }
.login-card > p { color: var(--slate-500); line-height: 1.6; margin: 0 0 32px; }

.form-stack { display: grid; gap: 18px; }
.field { display: grid; gap: 7px; }
.field label { color: var(--slate-700); font-size: 13px; font-weight: 700; }
.field input, .field textarea, .field select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--slate-300);
  border-radius: 11px;
  background: white;
  color: var(--slate-900);
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--emerald-500); box-shadow: 0 0 0 4px rgba(238,119,0,.13); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 16px;
  border: 0;
  border-radius: 11px;
  font-weight: 750;
  text-decoration: none;
  transition: transform .15s, filter .15s, background .15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--emerald-600); color: white; box-shadow: 0 9px 18px rgba(217,108,0,.2); }
.btn-primary:hover:not(:disabled) { filter: brightness(.95); }
.btn-dark { background: var(--navy-950); color: white; }
.btn-soft { background: var(--slate-100); color: var(--navy-950); }
.btn-danger { background: var(--red-100); color: var(--red-600); }
.btn-outline { border: 1px solid var(--slate-300); background: white; color: var(--slate-700); }
.btn-block { width: 100%; }
.btn-small { min-height: 35px; padding: 7px 11px; font-size: 12px; border-radius: 9px; }
.btn svg { width: 18px; height: 18px; }

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: calc(72px + var(--safe-top));
  padding: var(--safe-top) clamp(18px, 4vw, 56px) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid rgba(203,213,223,.72);
  backdrop-filter: blur(18px);
}

.topbar .company-logo { width: 69px; }
.topbar .brand-divider { height: 30px; }
.topbar .brand { color: var(--navy-950); }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.profile-chip { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; border: 0; border-radius: 999px; background: var(--slate-100); }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--navy-950); color: white; font-weight: 800; font-size: 12px; }
.profile-chip strong { display: block; font-size: 12px; }
.profile-chip small { display: block; color: var(--slate-500); font-size: 10px; }

.main { width: min(1440px, 100%); margin: 0 auto; padding: 34px clamp(18px, 4vw, 56px) calc(50px + var(--safe-bottom)); }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-heading h1 { margin: 0 0 7px; font-size: clamp(27px, 3vw, 40px); letter-spacing: -.045em; }
.page-heading p { margin: 0; color: var(--slate-500); }
.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.status-line { display: flex; align-items: center; gap: 8px; color: var(--slate-500); font-size: 12px; }
.status-indicator { width: 8px; height: 8px; border-radius: 50%; background: var(--emerald-500); box-shadow: 0 0 0 4px var(--emerald-100); }
.status-indicator.offline { background: var(--red-600); box-shadow: 0 0 0 4px var(--red-100); }

.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card { padding: 19px; border: 1px solid var(--slate-200); border-radius: var(--radius-md); background: var(--surface); box-shadow: 0 5px 16px rgba(60,40,24,.04); }
.stat-label { color: var(--slate-500); font-size: 12px; font-weight: 700; }
.stat-value { margin-top: 10px; color: var(--navy-950); font-size: 30px; line-height: 1; font-weight: 830; letter-spacing: -.04em; }
.stat-meta { margin-top: 10px; color: var(--slate-500); font-size: 11px; }

.panel { border: 1px solid var(--slate-200); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 19px 22px; border-bottom: 1px solid var(--slate-200); }
.panel-header h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.panel-header p { margin: 3px 0 0; color: var(--slate-500); font-size: 12px; }
.panel-body { padding: 22px; }

.tabs { display: flex; gap: 4px; padding: 5px; margin-bottom: 20px; border-radius: 12px; background: var(--slate-100); width: fit-content; }
.tab { padding: 9px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--slate-500); font-weight: 750; font-size: 13px; }
.tab.active { background: white; color: var(--navy-950); box-shadow: 0 3px 9px rgba(60,40,24,.08); }

.admin-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .7fr); gap: 22px; align-items: start; }
.live-list { display: grid; }
.live-item { display: grid; grid-template-columns: 72px minmax(130px, .75fr) 1fr 110px 84px; gap: 14px; align-items: center; padding: 13px 18px; border-bottom: 1px solid var(--slate-200); }
.live-item:last-child { border-bottom: 0; }
.live-photo { width: 58px; height: 48px; border-radius: 9px; object-fit: cover; background: var(--slate-100); }
.photo-expired { display: grid; place-items: center; padding: 4px; color: var(--slate-500); font-size: 9px; font-weight: 700; text-align: center; border: 1px dashed var(--slate-300); }
.live-item strong { display: block; font-size: 13px; }
.live-item small { display: block; margin-top: 3px; color: var(--slate-500); font-size: 11px; }
.distance-badge { display: inline-flex; align-items: center; width: fit-content; padding: 5px 8px; border-radius: 999px; background: var(--emerald-100); color: #b45309; font-size: 11px; font-weight: 800; }

.empty-state { display: grid; justify-items: center; padding: 54px 24px; text-align: center; color: var(--slate-500); }
.empty-icon { width: 52px; height: 52px; margin-bottom: 14px; display: grid; place-items: center; border-radius: 16px; background: var(--slate-100); color: var(--slate-700); }
.empty-state strong { color: var(--slate-900); }
.empty-state p { max-width: 420px; margin: 8px 0 0; line-height: 1.55; font-size: 13px; }

.quick-card { padding: 18px; border-radius: var(--radius-md); background: linear-gradient(145deg, var(--navy-950), #3b2b20); color: white; }
.quick-card h3 { margin: 0 0 7px; font-size: 17px; }
.quick-card p { margin: 0 0 18px; color: rgba(255,255,255,.66); font-size: 12px; line-height: 1.5; }
.quick-list { display: grid; gap: 10px; margin-top: 18px; }
.quick-row { display: flex; align-items: center; justify-content: space-between; font-size: 12px; }
.quick-row span { color: rgba(255,255,255,.65); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 14px; background: var(--slate-100); color: var(--slate-500); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
td { padding: 13px 14px; border-bottom: 1px solid var(--slate-200); font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.actions-cell { display: flex; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.badge-success { background: var(--emerald-100); color: #b45309; }
.badge-muted { background: var(--slate-100); color: var(--slate-500); }

.guard-summary {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 20px;
  margin-bottom: 26px;
}
.patrol-hero { position: relative; padding: 28px; border-radius: var(--radius-lg); overflow: hidden; color: white; background: linear-gradient(135deg, var(--navy-950), #4a3020); box-shadow: var(--shadow); }
.patrol-hero::after { content: ""; position: absolute; width: 190px; height: 190px; right: -50px; top: -70px; border: 40px solid rgba(255,255,255,.055); border-radius: 50%; }
.patrol-hero h2 { margin: 0 0 8px; font-size: 23px; letter-spacing: -.035em; }
.patrol-hero p { max-width: 540px; margin: 0 0 23px; color: rgba(255,255,255,.7); line-height: 1.55; font-size: 13px; }
.progress-card { padding: 23px; border: 1px solid var(--slate-200); border-radius: var(--radius-lg); background: white; box-shadow: var(--shadow); }
.progress-head { display: flex; align-items: end; justify-content: space-between; margin-bottom: 15px; }
.progress-head strong { font-size: 29px; letter-spacing: -.04em; }
.progress-head span { color: var(--slate-500); font-size: 12px; }
.progress-track { height: 9px; overflow: hidden; border-radius: 999px; background: var(--slate-100); }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--emerald-600), #ff9a33); transition: width .35s; }
.progress-note { margin-top: 14px; color: var(--slate-500); font-size: 12px; }

.checkpoint-heading { display: flex; justify-content: space-between; align-items: center; margin: 0 0 15px; }
.checkpoint-heading h2 { margin: 0; font-size: 19px; }
.checkpoint-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.checkpoint-card { display: grid; gap: 15px; padding: 19px; border: 1px solid var(--slate-200); border-radius: var(--radius-md); background: white; transition: border-color .2s, transform .2s, box-shadow .2s; }
.checkpoint-card:hover { border-color: #e4a66a; transform: translateY(-2px); box-shadow: 0 12px 24px rgba(63,40,19,.08); }
.checkpoint-card.done { background: #fffaf4; border-color: #ffd1a3; }
.checkpoint-top { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.checkpoint-code { color: var(--emerald-600); font-size: 11px; font-weight: 850; letter-spacing: .08em; }
.checkpoint-card h3 { margin: 4px 0 0; font-size: 17px; letter-spacing: -.02em; }
.checkpoint-card p { min-height: 38px; margin: 0; color: var(--slate-500); font-size: 12px; line-height: 1.55; }
.checkpoint-meta { display: flex; gap: 13px; color: var(--slate-500); font-size: 11px; }
.checkpoint-meta span { display: flex; align-items: center; gap: 5px; }
.checkpoint-meta svg { width: 14px; height: 14px; }

.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(2,20,31,.72); backdrop-filter: blur(8px); }
.modal { width: min(100%, 620px); max-height: min(92vh, 860px); overflow: auto; border-radius: 20px; background: white; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--slate-200); }
.modal-header h2 { margin: 0; font-size: 18px; }
.icon-btn { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 10px; background: var(--slate-100); color: var(--slate-700); }
.modal-body { padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--slate-200); }

.camera-modal { width: min(100%, 780px); background: #171411; color: white; }
.camera-modal .modal-header { border-color: rgba(255,255,255,.1); }
.camera-modal .icon-btn { background: rgba(255,255,255,.1); color: white; }
.camera-stage { position: relative; min-height: 340px; background: #080706; overflow: hidden; }
.camera-stage video { display: block; width: 100%; max-height: 62vh; object-fit: cover; }
.camera-overlay { position: absolute; inset: 0; pointer-events: none; border: 2px solid rgba(255,255,255,.18); }
.camera-overlay::before, .camera-overlay::after { content: ""; position: absolute; width: 42px; height: 42px; border-color: #ffad5c; border-style: solid; }
.camera-overlay::before { left: 18px; top: 18px; border-width: 3px 0 0 3px; }
.camera-overlay::after { right: 18px; bottom: 18px; border-width: 0 3px 3px 0; }
.camera-status { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 13px; background: #28221d; }
.camera-metric { padding: 10px; border-radius: 10px; background: rgba(255,255,255,.07); text-align: center; }
.camera-metric span { display: block; margin-bottom: 4px; color: rgba(255,255,255,.55); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.camera-metric strong { font-size: 13px; }
.camera-message { padding: 12px 16px; color: #fde68a; background: rgba(245,158,11,.1); font-size: 12px; text-align: center; }
.camera-actions { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 18px; padding-bottom: calc(18px + var(--safe-bottom)); }
.shutter { width: 68px; height: 68px; border: 5px solid rgba(255,255,255,.8); border-radius: 50%; background: white; box-shadow: inset 0 0 0 5px #171411; }

.toast-stack { position: fixed; z-index: 200; right: 18px; bottom: calc(18px + var(--safe-bottom)); display: grid; gap: 9px; width: min(390px, calc(100vw - 36px)); }
.toast { display: flex; gap: 11px; align-items: start; padding: 14px 15px; border: 1px solid var(--slate-200); border-radius: 13px; background: white; box-shadow: 0 16px 45px rgba(60,40,24,.2); animation: toast-in .23s ease-out; }
.toast::before { content: ""; width: 9px; height: 9px; margin-top: 4px; flex: 0 0 auto; border-radius: 50%; background: var(--emerald-500); }
.toast.error::before { background: var(--red-600); }
.toast.warning::before { background: var(--amber-500); }
.toast strong { display: block; font-size: 13px; }
.toast p { margin: 4px 0 0; color: var(--slate-500); font-size: 12px; line-height: 1.45; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.error-box { padding: 11px 13px; border-radius: 10px; background: var(--red-100); color: #991b1b; font-size: 12px; line-height: 1.45; }
.helper { color: var(--slate-500); font-size: 11px; line-height: 1.45; }
.hidden { display: none !important; }
.text-right { text-align: right; }
.muted { color: var(--slate-500); }
.mt-14 { margin-top: 14px; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .checkpoint-grid { grid-template-columns: repeat(2, 1fr); }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .login-shell { grid-template-columns: 1fr; background: white; }
  .login-hero { min-height: 290px; padding: 28px; }
  .hero-copy h1 { font-size: 42px; }
  .hero-copy p { font-size: 15px; }
  .trust-row { display: none; }
  .login-panel { padding: 35px 24px 50px; }
  .topbar { min-height: calc(64px + var(--safe-top)); }
  .profile-chip > div:last-child { display: none; }
  .main { padding-top: 24px; }
  .page-heading { align-items: start; flex-direction: column; }
  .guard-summary { grid-template-columns: 1fr; }
  .live-item { grid-template-columns: 62px 1fr auto; }
  .live-item > :nth-child(3) { grid-column: 2 / 4; }
  .live-item > :nth-child(4) { grid-column: 2; }
  .live-item > :nth-child(5) { grid-column: 3; grid-row: 1; }
}

@media (max-width: 600px) {
  .topbar .brand small { display: none; }
  .topbar .brand-divider { display: none; }
  .topbar .company-logo { width: 62px; }
  .topbar .btn .desktop-label { display: none; }
  .main { padding-left: 14px; padding-right: 14px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 15px; }
  .stat-value { font-size: 26px; }
  .checkpoint-grid { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr; }
  .panel-header, .panel-body { padding-left: 16px; padding-right: 16px; }
  .tabs { width: 100%; overflow-x: auto; }
  .tab { flex: 1 0 auto; }
  .camera-status { grid-template-columns: 1fr 1fr; }
  .camera-metric:last-child { grid-column: 1 / 3; }
}
