:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #22c55e;
  --accent-dim: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); }

nav.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

nav.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  height: 32px;
  width: auto;
  border-radius: 4px;
}

nav.topbar .links a {
  color: var(--text-dim);
  text-decoration: none;
  margin-left: 18px;
  font-size: 0.92rem;
}
nav.topbar .links a:hover { color: var(--text); }

@media (max-width: 640px) {
  nav.topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  nav.topbar .links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
  }
  nav.topbar .links a {
    margin-left: 0;
  }
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

h1 { font-size: 1.6rem; margin: 0 0 6px; }
h2 { font-size: 1.2rem; margin: 0 0 14px; }
.subtitle { color: var(--text-dim); margin-bottom: 22px; }

.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.92rem;
}
.flash.error { background: #451a1a; color: #fca5a5; border: 1px solid #7f1d1d; }
.flash.success { background: #14301f; color: #86efac; border: 1px solid #166534; }

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 14px 0 6px;
}

input[type="text"], input[type="password"], select, input[type="file"] {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}

button, .btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.92rem;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--accent-dim); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #31415a; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; }
.badge { padding: 3px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.active { background: #14301f; color: #86efac; }
.badge.inactive { background: #451a1a; color: #fca5a5; }

/* Dashboard grid */
.dash-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20px; }
.present-count { font-size: 1rem; color: var(--text-dim); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
}
.emp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.emp-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
}
.emp-card .name { font-weight: 600; font-size: 0.92rem; }
.emp-card .meta { color: var(--text-dim); font-size: 0.78rem; margin-top: 3px; }
.empty-state { color: var(--text-dim); padding: 40px 0; text-align: center; }

/* Clock kiosk */
.kiosk { text-align: center; padding: 18px 20px; }
.kiosk h2 { font-size: 1.05rem; margin: 0 0 10px; }
/* Many phones deliver the rear camera stream in portrait (taller than wide),
   so html5-qrcode renders a very tall preview to fill the container's width.
   .qr-crop is a fixed-height window that visually clips that excess via
   overflow; #qr-reader itself is deliberately left with no height constraint
   of its own, because the library measures ITS box (not .qr-crop's) to decide
   how large to render the video and the scan target box — constraining
   #qr-reader directly previously shrank the scan box along with it. */
.qr-crop {
  max-width: 380px;
  height: 260px;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  background: #000;
}
#qr-reader {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  transform: translateY(-50%);
}
/* Un-mirrors a front-camera feed; only the video is flipped (not the whole
   #qr-reader box), so the centering/positioning above is unaffected, and the
   shaded overlay's scan box — centered either way — still lines up visually. */
#qr-reader.mirrored video { transform: scaleX(-1); }
#scan-result {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  min-height: 26px;
}
#scan-result.ok { background: #14301f; color: #86efac; border: 1px solid #166534; }
#scan-result.error { background: #451a1a; color: #fca5a5; border: 1px solid #7f1d1d; }
.clock-time { font-size: 1.7rem; font-weight: 700; margin-bottom: 2px; }
.clock-date { color: var(--text-dim); margin-bottom: 14px; font-size: 0.88rem; }

/* Webcam capture */
#webcam-wrap { max-width: 320px; }
#webcam-video, #webcam-canvas, #webcam-preview { width: 100%; border-radius: 8px; border: 1px solid var(--border); }
#webcam-canvas, #webcam-preview { display: none; }
.webcam-actions { display: flex; gap: 10px; margin-top: 10px; }

.station-pick-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 14px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.station-pick-btn:hover { background: #31415a; }
.clock-station { font-size: 1rem; color: var(--text-dim); margin-bottom: 10px; }

.qr-display { text-align: center; }
.qr-display img.qr { width: 260px; height: 260px; margin: 20px auto; display: block; }

/* Employees list — each employee is a row that expands downward in normal
   document flow (not a floating dropdown), so there's never a reason for
   the page to need horizontal scrolling regardless of screen width. */
.emp-row { border-bottom: 1px solid var(--border); padding: 10px 2px; }
.emp-row:last-of-type { border-bottom: none; }
.emp-row summary {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  flex-wrap: wrap;
}
.emp-row summary::-webkit-details-marker { display: none; }
.emp-row-photo { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.emp-row-main { flex: 1 1 120px; min-width: 0; }
.emp-row-name { font-weight: 600; }
.emp-row-code { color: var(--text-dim); font-size: 0.82rem; }
.emp-row-today { flex-shrink: 0; }
.emp-row-caret {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text-dim);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.emp-row[open] .emp-row-caret { transform: rotate(180deg); }
.emp-row-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  font-size: 0.9rem;
}
.emp-row-panel form { margin: 0; }
