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

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --accent: #b91c1c;
  --accent-soft: #fef2f2;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --fail: #dc2626;
  --info-soft: #eff6ff;
  --info: #1d4ed8;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.07);
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ---- Top bar ---- */

#topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tb-brand { font-weight: 700; font-size: 16px; }
.tb-logo { height: 26px; width: auto; display: block; }
.tb-nav { display: flex; gap: 4px; flex: 1; }
.tb-nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 8px 12px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  font-size: 15px;
}
.tb-nav a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.tb-right { display: flex; align-items: center; gap: 8px; }
.tb-user { color: var(--muted); font-size: 14px; padding-inline: 4px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 40px;
  color: var(--text);
  font-size: 14px;
}

/* ---- Layout & cards ---- */

.page { max-width: 560px; margin: 0 auto; padding: 16px 14px 48px; }
.page-wide { max-width: 1200px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h2 { font-size: 18px; margin-bottom: 6px; }
.card .hint { color: var(--muted); font-size: 14px; line-height: 1.6; margin-bottom: 12px; }

/* ---- Forms ---- */

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: 48px;
  font-size: 16px;
  background: var(--card);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.input-big { font-size: 22px; text-align: center; letter-spacing: 1px; font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  min-height: 50px;
  padding: 12px 18px;
  font-size: 17px;
  font-weight: 600;
  width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { background: #e2b3b3; cursor: default; }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn-ghost { background: none; border: none; color: var(--info); width: auto; min-height: 44px; font-size: 15px; }
.btn-row { display: flex; gap: 10px; }
.btn:active { transform: scale(0.98); }

/* ---- Login ---- */

.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; text-align: center; }
.login-card .logo { font-size: 44px; margin-bottom: 8px; }
.login-card .logo-img { width: 100%; max-width: 240px; height: auto; margin: 0 auto 16px; display: block; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .tagline { color: var(--muted); font-size: 14px; line-height: 1.7; margin-bottom: 20px; }
.login-card form { text-align: start; }
.login-lang { margin-top: 14px; }

/* ---- Banners / badges ---- */

.banner { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.banner-info { background: var(--info-soft); color: var(--info); }
.banner-ok { background: var(--ok-soft); color: var(--ok); }
.banner-warn { background: var(--accent-soft); color: var(--accent); }

.badge {
  display: inline-block;
  font-size: 12px;
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--bg);
  color: var(--muted);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--accent-soft); color: var(--accent); }

/* ---- Capture: recorder ---- */

.rec-area { text-align: center; padding: 8px 0 4px; }
.rec-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 40px;
  box-shadow: 0 6px 18px rgba(185, 28, 28, 0.35);
}
.rec-btn.recording { animation: pulse 1.2s infinite; background: #7f1d1d; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(185, 28, 28, 0.45); }
  70% { box-shadow: 0 0 0 22px rgba(185, 28, 28, 0); }
  100% { box-shadow: 0 0 0 0 rgba(185, 28, 28, 0); }
}
.rec-btn:disabled { background: #cbd5e1; box-shadow: none; }
.rec-state { margin-top: 10px; color: var(--muted); font-size: 15px; }
.rec-timer { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 6px; direction: ltr; }
.rec-timer.low { color: var(--fail); }

.clip-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.clip {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.clip .clip-name { font-size: 14px; white-space: nowrap; }
.clip audio { flex: 1; min-width: 0; height: 40px; }
.clip .clip-x {
  background: none;
  border: none;
  color: var(--fail);
  font-size: 20px;
  min-width: 44px;
  min-height: 44px;
}

/* ---- Capture: photos ---- */

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .clip-x {
  position: absolute;
  top: 2px;
  inset-inline-end: 2px;
  background: rgba(15, 23, 42, 0.7);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 18px;
}

/* ---- Capture: done ---- */

.done-shell { text-align: center; padding: 40px 0; }
.done-check {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  font-size: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.done-shell h2 { font-size: 22px; margin-bottom: 6px; }
.done-shell p { color: var(--muted); margin-bottom: 22px; }

.upload-progress { text-align: center; color: var(--muted); padding: 8px 0; font-size: 15px; }

/* ---- Recent list / search results ---- */

.rec-list { display: flex; flex-direction: column; gap: 8px; }
.rec-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--card);
  cursor: pointer;
  text-align: start;
  width: 100%;
}
.rec-item:hover { border-color: var(--accent); }
.rec-item.selected { border-color: var(--accent); background: var(--accent-soft); }
.rec-item .jo { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.rec-item .meta { color: var(--muted); font-size: 13px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; overflow-wrap: anywhere; }

/* ---- Search layout ---- */

.search-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.search-filters .full { grid-column: 1 / -1; }
/* Very narrow phones: stack the filters so nothing runs off-screen. */
@media (max-width: 360px) {
  .search-filters { grid-template-columns: 1fr; }
}
.search-layout { display: grid; gap: 14px; margin-top: 14px; }
#detail-pane { display: none; }
#detail-pane.open { display: block; }
.back-row { margin-bottom: 8px; }

@media (min-width: 900px) {
  .search-layout { grid-template-columns: 400px 1fr; align-items: start; }
  #results-pane { max-height: calc(100vh - 220px); overflow-y: auto; }
  #detail-pane { display: block; }
  .back-row { display: none; }
}

/* ---- Detail ---- */

.det-header .jo { font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.det-meta { color: var(--muted); font-size: 14px; margin-top: 6px; line-height: 1.8; overflow-wrap: anywhere; }
.att-audio { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.att-audio audio { width: 100%; height: 42px; margin-top: 6px; }
.att-meta { color: var(--muted); font-size: 13px; }
.transcript { margin-top: 8px; background: var(--bg); border-radius: 8px; padding: 10px; }
.transcript .tr-tag { font-size: 12px; color: var(--accent); display: block; margin-bottom: 6px; }
.transcript .tr-text { font-size: 15px; line-height: 1.7; white-space: pre-wrap; }
.transcript textarea { width: 100%; min-height: 90px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-top: 6px; }
.det-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.det-photos .photo-thumb { cursor: zoom-in; }
.photo-cell { display: flex; flex-direction: column; gap: 4px; }
.photo-cap { font-size: 11px; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.det-header .btn-ghost { margin-top: 8px; padding-inline: 0; }

/* ---- Lightbox ---- */

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#lightbox.open { display: flex; }
#lightbox img { max-width: 94vw; max-height: 88vh; object-fit: contain; }
#lightbox .lb-close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 46px;
  height: 46px;
  font-size: 20px;
}
#lightbox .lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 46px;
  height: 64px;
  font-size: 24px;
}
#lightbox .lb-prev { inset-inline-start: 10px; }
#lightbox .lb-next { inset-inline-end: 10px; }
#lightbox .lb-count { position: absolute; bottom: 16px; color: #cbd5e1; font-size: 14px; }

/* ---- Admin ---- */

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  min-height: 46px;
  font-size: 15px;
  color: var(--muted);
}
.tabs button.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.row-list { display: flex; flex-direction: column; gap: 8px; }
.row-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  flex-wrap: wrap;
}
.row-item .grow { flex: 1; min-width: 140px; }
.row-item .title { font-weight: 600; overflow-wrap: anywhere; }
.row-item .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row-actions { display: flex; gap: 6px; }
.row-actions .tb-btn { min-height: 44px; }

/* ---- Modal ---- */

#modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 90;
}
#modal.open { display: flex; }
#modal .modal-card {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 560px;
  padding: 18px 16px 24px;
  animation: slideup 0.25s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0.5; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) {
  #modal { align-items: center; }
  #modal .modal-card { border-radius: 16px; }
}

/* ---- Toasts ---- */

#toasts {
  position: fixed;
  top: 12px;
  inset-inline: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: #fff;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  max-width: 92vw;
  opacity: 0;
  transform: translateY(-8px);
  transition: all 0.25s ease-out;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--fail); }
.toast-ok { background: var(--ok); }

/* ---- Misc ---- */

/* iOS: small viewport units avoid layout jumps when the URL bar hides. */
@supports (min-height: 100svh) {
  body, .login-shell, .splash { min-height: 100svh; }
}

.center { text-align: center; }
.muted { color: var(--muted); }
.mt { margin-top: 12px; }
.splash {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
}
