:root {
  --bg: #f3efe6;
  --bg-deep: #e4ddd0;
  --ink: #14212b;
  --muted: #5c6b76;
  --line: #c9c0b0;
  --panel: rgba(255, 252, 246, 0.92);
  --accent: #c45c26;
  --accent-2: #0f4c5c;
  --ok: #1f7a4c;
  --danger: #9b2c2c;
  --shadow: 0 18px 40px rgba(20, 33, 43, 0.08);
  --radius: 14px;
  --font: "DM Sans", sans-serif;
  --mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(196, 92, 38, 0.12), transparent 32%),
    radial-gradient(circle at 88% 0%, rgba(15, 76, 92, 0.14), transparent 28%),
    linear-gradient(180deg, #f7f3eb 0%, var(--bg) 45%, #ebe4d7 100%);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
code { font-family: var(--mono); font-size: 0.86em; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.9rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.75rem; min-width: 220px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background:
    linear-gradient(135deg, var(--accent-2), #1a6b7c 55%, var(--accent));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25);
}
.brand-name { font-weight: 700; font-size: 0.95rem; line-height: 1.1; }
.brand-sub { color: var(--muted); font-size: 0.75rem; }

.nav { display: flex; gap: 0.35rem; flex: 1; flex-wrap: wrap; }
.nav a {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
}
.nav a:hover, .nav a.active {
  background: rgba(15, 76, 92, 0.1);
  color: var(--accent-2);
}

.userbox { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.9rem; }

.main { padding: 1.5rem clamp(1rem, 3vw, 2.2rem) 3rem; max-width: 1280px; margin: 0 auto; }
.main-login { max-width: none; padding: 0; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap;
}
.page-head h1, h1, h2 { margin: 0 0 0.25rem; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.tiny { font-size: 0.78rem; }
.mt { margin-top: 1.5rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.btn-ghost { background: transparent; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.35rem; }
.stat-value { font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; }
.stat-value.accent { color: var(--accent); }

.split {
  display: grid;
  grid-template-columns: 1.7fr 0.9fr;
  gap: 1.25rem;
}
.table-wrap, aside, .form, .filters {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem 0.9rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: rgba(228, 221, 208, 0.45); }
.clamp { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

aside { padding: 1rem 1.1rem; }
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.55rem 0; border-bottom: 1px dashed var(--line);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-in { background: rgba(196, 92, 38, 0.15); color: var(--accent); }
.badge-out { background: rgba(31, 122, 76, 0.15); color: var(--ok); }

.form { padding: 1.2rem; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-grid .full { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 500; }
label span { font-size: 0.88rem; color: var(--muted); }
input, select, textarea {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(15, 76, 92, 0.25);
  border-color: var(--accent-2);
}
.form-actions { display: flex; gap: 0.75rem; align-items: center; }

.filters {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end;
  padding: 0.9rem; margin-bottom: 1rem;
}
.filters input, .filters select { min-width: 140px; }
.inline { display: flex; flex-direction: column; gap: 0.3rem; }

.flash-wrap { margin-bottom: 1rem; display: grid; gap: 0.5rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}
.flash-success { border-color: rgba(31,122,76,0.35); background: rgba(31,122,76,0.08); color: var(--ok); }
.flash-error { border-color: rgba(155,44,44,0.35); background: rgba(155,44,44,0.08); color: var(--danger); }

.empty { color: var(--muted); padding: 1rem; }

.login-stage {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
}
.login-visual {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(160deg, rgba(15,76,92,0.92), rgba(20,33,43,0.75)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cpath fill='none' stroke='rgba(255,255,255,0.08)' stroke-width='1' d='M0 40h160M0 80h160M0 120h160M40 0v160M80 0v160M120 0v160'/%3E%3C/svg%3E");
  color: #f7f3eb;
  display: flex;
  align-items: flex-end;
  padding: clamp(2rem, 5vw, 4rem);
}
.login-visual-copy { max-width: 28rem; position: relative; z-index: 1; }
.login-visual .eyebrow {
  text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.75rem; opacity: 0.8;
}
.login-visual h1 {
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.05;
  margin: 0.4rem 0 0.8rem;
}
.login-visual p { font-size: 1.05rem; opacity: 0.9; }
.login-panel {
  display: flex; flex-direction: column; justify-content: center;
  padding: clamp(1.5rem, 4vw, 3rem);
  background: rgba(255,252,246,0.95);
}
.login-panel h2 { font-size: 1.8rem; margin-bottom: 0.2rem; }
.hint { margin-top: 1.2rem; color: var(--muted); font-size: 0.85rem; }

.site-footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.75rem 1rem 1.25rem;
}

.main-menu { align-items: center; }
.menu-drop { position: relative; }
.menu-btn {
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}
.menu-btn:hover, .menu-drop.open .menu-btn {
  background: rgba(15, 76, 92, 0.1);
  color: var(--accent-2);
}
.menu-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.4rem;
  z-index: 40;
}
.menu-drop:hover .menu-panel, .menu-drop.open .menu-panel { display: grid; }
.menu-panel a {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 500;
}
.menu-panel a:hover { background: rgba(15, 76, 92, 0.08); }
.menu-quit {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  font-weight: 700;
  color: var(--danger) !important;
}
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.check { flex-direction: row !important; align-items: center; gap: 0.5rem !important; font-weight: 500; }
.photo-capture { margin-top: 0.5rem; }
.field-label { display:block; font-size: 0.88rem; color: var(--muted); margin-bottom: 0.35rem; font-weight: 500; }
.photo-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}
.inline-field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.88rem; color: var(--muted); }
.inline-field select { font: inherit; color: var(--ink); padding: 0.45rem 0.55rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.file-capture {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,0.55);
  font-size: 0.9rem;
  color: var(--muted);
}
.file-capture input[type="file"] { font: inherit; max-width: 100%; }
#cam_status.cam-error { color: var(--danger); font-weight: 600; }
.photo-row { display:flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-start; }
.photo-row video, .photo-row img, .photo-row canvas {
  width: 220px; max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: #111;
}
.tiny { font-size: 0.82rem; }
.typeahead-row { display: flex; gap: 0.45rem; align-items: stretch; }
.typeahead-row input { flex: 1; }
.btn-add {
  min-width: 2.4rem;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.35rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f4c5c;
  color: #fff;
  cursor: pointer;
}
.btn-add:hover { filter: brightness(1.08); }
.suggest-box {
  margin-top: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  max-height: 220px;
  overflow: auto;
  box-shadow: var(--shadow);
}
.suggest-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:hover { background: #f3efe6; }
.visitor-name-wrap { position: relative; }
.util-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}
.util-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.chart-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  margin-bottom: 1.4rem;
}

@media (max-width: 960px) {
  .stat-row, .split, .form-grid, .login-stage { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .login-visual { min-height: 280px; }
  .menu-panel { position: static; box-shadow: none; border: none; }
}

