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

:root {
  --bg:      #0b0b12;
  --surface: #13131f;
  --border:  #252535;
  --accent:  #6c63ff;
  --acc-h:   #5a52e0;
  --second:  #1e1c40;
  --success: #00d4aa;
  --error:   #ff4d6d;
  --warn:    #f5a623;
  --text:    #e6e6f0;
  --muted:   #7878a0;
  --r:       14px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Login screen ── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, rgba(108,99,255,.12) 0%, transparent 60%);
}

.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-appname {
  text-align: center;
  margin-bottom: 4px;
}
.login-appname .site-app-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.login-org {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.login-org-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.login-org-name {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}
.login-org-contacts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.login-org-contacts .di-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.login-box h2 {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}

.login-sub {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: -6px;
}

/* ── Admin panel ── */
.app > #admin-panel { max-width: 1160px; margin: 0 auto; padding: 24px 20px 48px; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.2px;
}
.logo .site-logo   { flex-shrink: 0; }
.logo .site-app-name { line-height: 1.35; }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #a09fff;
  background: rgba(108,99,255,.1);
  border: 1px solid rgba(108,99,255,.2);
  border-radius: 999px;
  padding: 4px 12px;
}

.lang-switch {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.lang-btn {
  padding: 5px 13px;
  background: none; border: none;
  color: var(--muted); font-size: 12px; font-weight: 700;
  cursor: pointer; transition: all .2s; letter-spacing: .5px;
}
.lang-btn:hover { color: var(--text); background: rgba(255,255,255,.04); }
.lang-btn.active { background: var(--accent); color: #fff; }

/* ── Layout ── */
main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 680px) { main { grid-template-columns: 1fr; } }

/* ── Camera ── */
.camera-card {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.camera-wrap {
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: #000;
}

video {
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}

.oval-guide {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}

.oval {
  width: 52%;
  aspect-ratio: 3/4;
  border: 2.5px solid rgba(108,99,255,.6);
  border-radius: 50%;
  transition: border-color .4s, box-shadow .4s;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.28);
}
.oval.capturing {
  border-color: var(--warn);
  box-shadow: 0 0 22px rgba(245,166,35,.4), 0 0 0 9999px rgba(0,0,0,.28);
  animation: pulse 1.2s ease-in-out infinite;
}
.oval.ok   { border-color: var(--success); box-shadow: 0 0 28px rgba(0,212,170,.5), 0 0 0 9999px rgba(0,0,0,.28); }
.oval.fail { border-color: var(--error);   box-shadow: 0 0 22px rgba(255,77,109,.4), 0 0 0 9999px rgba(0,0,0,.28); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.cam-overlay {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  pointer-events: none;
}
.cam-overlay.active { display: flex; }

.countdown-wrap { display:flex; flex-direction:column; align-items:center; gap:6px; }
.countdown-ring  { transform: rotate(-90deg); }
.ring-bg { fill:none; stroke:rgba(255,255,255,.15); }
.ring-fg { fill:none; stroke:var(--warn); stroke-linecap:round; transition: stroke-dashoffset .15s linear; }
.countdown-num {
  position: absolute;
  font-size: 28px; font-weight: 700; color:#fff;
  text-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.blink-hint {
  font-size: 13px; color:#fff;
  background: rgba(0,0,0,.55);
  padding: 4px 14px; border-radius: 999px;
  backdrop-filter: blur(4px);
}

.cam-hint {
  padding: 10px 14px;
  font-size: 12px; color:var(--muted); text-align:center;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ── Controls ── */
.controls-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.tabs { display:flex; border-bottom: 1px solid var(--border); overflow-x:auto; scrollbar-width:none; }
.tabs::-webkit-scrollbar { display:none; }
.tab-btn {
  flex: 0 0 auto; padding: 13px 16px;
  background:none; border:none;
  border-bottom: 2px solid transparent;
  color:var(--muted); font-size:13px; font-weight:600;
  cursor:pointer; transition: color .2s, border-color .2s;
  margin-bottom: -1px; white-space: nowrap;
}
.tab-btn:hover { color:var(--text); }
.tab-btn.active { color:var(--accent); border-bottom-color:var(--accent); }

.tab-pane { display:none; padding:20px; }
.tab-pane.active { display:flex; flex-direction:column; gap:14px; }

/* Fields */
.field { display:flex; flex-direction:column; gap:5px; }
.field > label {
  font-size:11px; font-weight:700; color:var(--muted);
  letter-spacing:.5px; text-transform:uppercase;
}
input[type="text"], input[type="password"] {
  width:100%; padding:10px 13px;
  background:var(--bg); border:1px solid var(--border);
  border-radius:8px; color:var(--text); font-size:15px;
  outline:none; transition:border-color .2s;
}
input[type="text"]:focus, input[type="password"]:focus { border-color:var(--accent); }
input[type="file"] { font-size:13px; color:var(--muted); }
#file-preview img { margin-top:8px; max-width:100%; max-height:130px; border-radius:8px; object-fit:cover; }

.radio-row { display:flex; gap:8px; }
.radio-btn {
  flex:1; display:flex; align-items:center; justify-content:center; gap:6px;
  padding:8px 12px; background:var(--bg);
  border:1px solid var(--border); border-radius:8px;
  cursor:pointer; font-size:13px; font-weight:600; color:var(--muted);
  transition:all .2s;
}
.radio-btn input { display:none; }
.radio-btn:hover { color:var(--text); }
.radio-btn.active { color:var(--accent); border-color:var(--accent); background:rgba(108,99,255,.07); }

/* Buttons */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  padding:10px 20px; border:none; border-radius:8px;
  font-size:14px; font-weight:600; cursor:pointer;
  transition:all .2s; white-space:nowrap;
}
.btn-primary {
  background:var(--accent); color:#fff;
}
.btn-primary:hover:not(:disabled) { background:var(--acc-h); transform:translateY(-1px); box-shadow:0 4px 16px rgba(108,99,255,.3); }
.btn-primary:active:not(:disabled) { transform:none; }
.btn-primary:disabled { opacity:.4; cursor:not-allowed; }

.btn-secondary {
  background:var(--second); color:#c0bdff;
  border:1px solid rgba(108,99,255,.25);
}
.btn-secondary:hover:not(:disabled) { background:rgba(108,99,255,.2); }
.btn-secondary:disabled { opacity:.4; cursor:not-allowed; }

.btn-ghost {
  background:rgba(255,255,255,.05); color:var(--muted);
  border:1px solid var(--border);
}
.btn-ghost:hover { color:var(--text); background:rgba(255,255,255,.09); }

.btn-danger {
  background:rgba(255,77,109,.12); color:var(--error);
  font-size:12px; padding:5px 11px; border-radius:6px;
}
.btn-danger:hover { background:rgba(255,77,109,.22); }

.btn-full { width:100%; }
.btn-sm   { padding:5px 12px; font-size:12px; }

/* Messages */
.msg {
  padding:11px 14px; border-radius:8px;
  font-size:13px; line-height:1.5; white-space:pre-wrap;
}
.msg.info    { background:rgba(108,99,255,.12); color:#a09fff; border:1px solid rgba(108,99,255,.25); }
.msg.success { background:rgba(0,212,170,.12);  color:var(--success); border:1px solid rgba(0,212,170,.25); }
.msg.error   { background:rgba(255,77,109,.12); color:var(--error);   border:1px solid rgba(255,77,109,.25); }

.hint { font-size:13px; color:var(--muted); line-height:1.55; }

/* Result card */
.result-card {
  padding:20px; border-radius:10px; text-align:center;
  background:rgba(0,212,170,.08); border:1px solid rgba(0,212,170,.25);
}
.result-card .r-icon  { font-size:36px; margin-bottom:8px; }
.result-card .r-name  { font-size:21px; font-weight:700; color:var(--success); }
.result-card .r-sub   { font-size:12px; color:var(--muted); margin-top:4px; }

/* Faces list */
.users-header {
  display:flex; align-items:center; justify-content:space-between;
  font-size:13px; font-weight:600; color:var(--muted);
}
#faces-list { display:flex; flex-direction:column; gap:8px; margin-top:4px; }
.face-row { display:flex; align-items:center; gap:10px; padding:10px 12px; background:var(--bg); border-radius:8px; }
.face-thumb { width:44px; height:44px; border-radius:8px; object-fit:cover; flex-shrink:0; }
.face-thumb-empty { width:44px; height:44px; border-radius:8px; background:var(--surface); flex-shrink:0; }
.update-face-form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px;
}
.verify-photo {
  width: 80px; height: 80px; border-radius: 12px;
  object-fit: cover; margin: 0 auto 8px; display: block;
  border: 2px solid var(--success);
}
.face-row .f-name { font-size:14px; font-weight:500; }
.face-row .f-meta { font-size:11px; color:var(--text); margin-top:1px; opacity:.75; }
.face-row .f-date { font-size:11px; color:var(--muted); margin-top:2px; }
.empty-state { text-align:center; padding:28px 0; color:var(--muted); font-size:13px; }

/* Settings */
.settings-section { display:flex; flex-direction:column; gap:10px; }
.settings-title { font-size:12px; font-weight:700; color:var(--muted); letter-spacing:.5px; text-transform:uppercase; padding-bottom:2px; }
.admin-row {
  display:flex; align-items:center; justify-content:space-between;
  padding:8px 12px; background:var(--bg); border-radius:8px;
}
.admin-row .a-name { font-size:14px; font-weight:500; }
.admin-row .a-you  { font-size:11px; color:var(--accent); margin-left:6px; }

/* API Key rows */
.key-row {
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding:10px 12px; background:var(--bg); border-radius:8px; flex-wrap:wrap;
}
.k-info { display:flex; flex-direction:column; gap:3px; min-width:0; }
.k-name { font-size:13px; font-weight:600; }
.k-val  {
  font-size:11px; font-family:monospace; color:var(--muted);
  word-break:break-all; max-width:240px;
}
.k-actions { display:flex; gap:6px; flex-shrink:0; flex-wrap:wrap; }
.key-config-form {
  padding: 10px 12px; background: var(--bg);
  border-radius: 0 0 8px 8px; border: 1px solid var(--border);
  border-top: none; margin-top: -4px;
}

/* Session expiry toast */
.session-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #2a1a00; border: 1px solid var(--warn);
  border-radius: 10px; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; color: var(--warn);
  z-index: 9999; box-shadow: 0 4px 20px rgba(0,0,0,.4);
  white-space: nowrap;
}

/* Dashboard */
.dash-stats {
  display: grid; grid-template-columns: repeat(4,1fr); gap: 10px;
}
@media(max-width:500px){ .dash-stats { grid-template-columns: repeat(2,1fr); } }
.dash-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; text-align: center;
}
.dash-card-ok   { border-color: rgba(0,212,170,.3); }
.dash-card-fail { border-color: rgba(255,77,109,.3); }
.dash-card-faces{ border-color: rgba(108,99,255,.3); }
.dc-val   { font-size: 28px; font-weight: 800; line-height: 1.1; }
.dc-label { font-size: 11px; color: var(--muted); margin-top: 4px; }
.dash-card-ok   .dc-val { color: var(--success); }
.dash-card-fail .dc-val { color: var(--error); }
.dash-card-faces .dc-val{ color: var(--accent); }
.dash-chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.dash-chart-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: .5px; }
#dash-chart { display: flex; align-items: flex-end; gap: 6px; height: 100px; }
.dc-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.dc-bar-stack { width: 100%; display: flex; flex-direction: column; gap: 2px; }
.dc-bar-ok   { background: var(--success); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.dc-bar-fail { background: var(--error);   border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.dc-bar-label{ font-size: 9px; color: var(--muted); }

/* Audit log */
.audit-search {
  width: 100%; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13px;
  outline: none; transition: border-color .2s;
}
.audit-search:focus { border-color: var(--accent); }
#audit-list, #faces-list {
  max-height: 420px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.log-row {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.log-row:last-child { border-bottom: none; }
.log-icon { font-size: 16px; flex-shrink: 0; margin-top: 2px; }
.log-body { flex: 1; min-width: 0; }
.log-top  { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 13px; }
.log-event  { font-weight: 700; color: var(--text); }
.log-actor  { color: var(--accent); }
.log-sep    { color: var(--muted); }
.log-target { color: var(--text); }
.log-result { font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.log-result-ok  { background: rgba(0,212,170,.12); color: var(--success); }
.log-result-err { background: rgba(255,77,109,.12); color: var(--error); }
.log-meta { display: flex; gap: 12px; font-size: 11px; color: var(--muted); margin-top: 3px; }

.settings-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-input {
  width: 100%; padding: 8px 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 13px; outline: none;
}
.field-input:focus { border-color: var(--accent); }

/* Threshold slider */
.threshold-row {
  display: flex; align-items: center; gap: 10px; margin-top: 8px;
}
.threshold-row input[type=range] { flex: 1; accent-color: var(--accent); }
.threshold-val { font-size: 14px; font-weight: 700; color: var(--accent); min-width: 44px; }
.threshold-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Developer / org info */
.dev-info-box { margin-top: 4px; }
.dev-info-footer {
  max-width: 1160px; margin: 12px auto 0; padding: 0 20px 24px;
}
#dev-info-login .dev-info {
  background: rgba(255,255,255,.04);
  border-color: rgba(255,255,255,.08);
  max-width: 380px;
  margin: 0 auto;
}
.dev-info {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 6px 14px;
  padding: 10px 14px; border-radius: 8px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  font-size: 12px;
}
.dev-info-col { flex-direction: column; gap: 6px; }
.di-contacts { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; }
.di-name-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.di-name { color: var(--muted); font-weight: 600; }
.di-link {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--muted); text-decoration: none;
  transition: color .2s;
}
.di-link:hover { color: var(--accent); }

/* Site logo container */
.site-logo {
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Settings action buttons */
.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.settings-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 18px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  text-align: center;
  letter-spacing: .3px;
  line-height: 1.3;
}
.settings-action-btn:hover {
  color: var(--accent);
  border-color: rgba(108,99,255,.5);
  background: rgba(108,99,255,.06);
}
.settings-action-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(108,99,255,.12);
}

/* Inline settings form */
.settings-inline-form {
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}
.form-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color .2s;
}
.form-close:hover { color: var(--text); }

/* ── Help tab ── */
.help-section {
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 10px;
}
.help-section-title {
  background: var(--second);
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .3px;
  border-bottom: 1px solid var(--border);
}
.help-item {
  border-top: 1px solid var(--border);
}
.help-item:first-of-type { border-top: none; }
.help-q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  gap: 12px;
  transition: background .15s;
  user-select: none;
}
.help-q:hover { background: rgba(108,99,255,.06); }
.help-chevron {
  flex-shrink: 0;
  font-style: normal;
  font-size: 12px;
  color: var(--muted);
  transition: transform .2s;
}
.help-item.open .help-chevron { transform: rotate(180deg); }
.help-a {
  display: none;
  padding: 0 18px 14px 18px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
  white-space: pre-wrap;
}
.help-item.open .help-a { display: block; }
.help-a code {
  background: rgba(108,99,255,.15);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
