:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #2b2620;
  --muted: #7a7265;
  --line: #e3ddd2;
  --accent: #8a4b2f;       /* ochre/earth red */
  --accent-dark: #6e3a23;
  --accent-soft: #f3e7df;
  --good: #3c7a4e;
  --warn: #a3622a;
  --danger: #a33a2a;
  --radius: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

/* ---- App shell: compact header + persistent sidebar + content ---- */
#appbar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.55rem 1.1rem;
  background: var(--panel);
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
#nav-toggle { font-size: 1.1rem; padding: 0.25rem 0.6rem; display: none; }
#appbar .user-menu { margin-left: auto; }

#shell { display: flex; min-height: calc(100vh - 52px); }
#shell.no-nav #sidebar, #shell.no-nav #sidebar-backdrop { display: none !important; }

#sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 0.9rem 0.7rem 2rem;
  overflow-y: auto;
  position: sticky;
  top: 52px;
  align-self: flex-start;
  max-height: calc(100vh - 52px);
}
.nav-context { display: flex; flex-direction: column; gap: 0.45rem; margin-bottom: 0.9rem; }
.nav-context label {
  display: flex; flex-direction: column; gap: 0.15rem;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted);
}
.nav-context select, .nav-context .context-fixed {
  font: inherit; font-size: 0.92rem; font-weight: 600; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  padding: 0.35rem 0.5rem; width: 100%;
}
.nav-context .context-fixed { border-color: transparent; background: transparent; padding-left: 0.1rem; }
.nav-section { margin-top: 1rem; }
.nav-section h3 {
  margin: 0 0 0.25rem; padding: 0 0.55rem;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
#sidebar a {
  display: block;
  text-decoration: none;
  color: var(--ink);
  padding: 0.42rem 0.55rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.95rem;
}
#sidebar a[aria-current="page"] { background: var(--accent); color: #fff; }
#sidebar a:hover:not([aria-current="page"]) { background: var(--accent-soft); }
#sidebar a:focus-visible, #appbar button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
#sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 19;
}

@media (max-width: 900px) {
  #nav-toggle { display: inline-block; }
  /* The app bar wraps taller than 52px on narrow screens, so the drawer
     overlays from the very top (above the bar, z-index over its 30) — the
     Organization context at its head must never hide under the bar. */
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    max-height: none; height: auto;
    box-shadow: 4px 0 18px rgba(0,0,0,0.15);
    transform: translateX(-105%);
    transition: transform 0.18s ease;
  }
  #sidebar-backdrop { z-index: 39; }
  #shell.nav-open #sidebar { transform: translateX(0); }
  #sidebar a { padding: 0.6rem 0.7rem; } /* touch targets */
  /* Keep the bar itself to one compact row. */
  #appbar { gap: 0.5rem; padding: 0.55rem 0.7rem; }
  .brand { font-size: 0.95rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  #appbar .user-menu button { white-space: nowrap; }
}
@media (min-width: 901px) {
  #sidebar-backdrop { display: none !important; }
}

.user-menu { position: relative; }
.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  min-width: 180px;
  overflow: hidden;
}
.dropdown button {
  background: none;
  border: none;
  color: var(--ink);
  font-weight: 500;
  text-align: left;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
}
.dropdown button:hover { background: var(--accent-soft); }

/* ---- Layout ---- */
main {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}
/* Entries tabs (All | Words | Phrases) */
.seg-tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--panel); }
.seg-tabs button {
  border: none; background: none; padding: 0.3rem 0.9rem; font: inherit;
  font-size: 0.9rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg-tabs button.active { background: var(--accent); color: #fff; }
/* Home stat tiles */
/* ---- Master search + Home sections (master-search spec) ---- */
.master-search { display: flex; gap: 0.6rem; margin: 0.4rem 0 1.2rem; }
.master-search input[type="search"] {
  flex: 1;
  width: auto;
  font-size: 1.05rem;
  padding: 0.7rem 0.9rem;
}
.home-section { margin: 1.4rem 0; }
.home-section-title { margin: 1rem 0 0; }
.home-section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: 1px solid var(--line); padding-bottom: 0.3rem; margin-bottom: 0.4rem;
}
.home-section-head h2 { margin: 0; font-size: 1.05rem; }
.home-row {
  display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; align-items: baseline;
  padding: 0.5rem 0.2rem; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit;
}
a.home-row:hover { background: var(--panel); }
.home-row > span:first-child, .home-row > a:first-of-type { min-width: 10rem; }
.home-row-meta { color: var(--muted); font-size: 0.85rem; margin-left: auto; text-align: right; }
.home-snippet { flex-basis: 100%; color: var(--muted); font-size: 0.9rem; }
.home-snippet mark { background: #f3e3c2; color: inherit; padding: 0 2px; border-radius: 3px; }
.home-row-recording { align-items: center; }
.home-row-recording audio { max-width: 220px; height: 34px; }
.home-empty { color: var(--muted); padding: 0.4rem 0.2rem; }
.home-more { color: var(--muted); font-size: 0.85rem; margin: 0.4rem 0 0; }
.muted { color: var(--muted); }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.8rem; margin: 1rem 0; }
.stat-tiles a { text-decoration: none; color: inherit; }
.stat-tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; }
.stat-tile .num { font-size: 1.6rem; font-weight: 700; }
.stat-tile .lbl { color: var(--muted); font-size: 0.85rem; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-context { color: var(--muted); font-size: 0.95rem; font-weight: 500; }
.head-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

/* ---- Forms ---- */
label.field { display: block; margin-bottom: 0.9rem; }
label.field > span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="search"], textarea, select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; min-height: 4.5rem; }
.dene { font-size: 1.15rem; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

button, .btn {
  font: inherit;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { background: var(--accent-dark); }
button.secondary, .btn.secondary {
  background: var(--accent-soft);
  color: var(--accent-dark);
}
button.secondary:hover { background: #e9d8cc; }
button.ghost {
  background: none;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 500;
}
button.ghost:hover { background: var(--accent-soft); }
button.danger { background: var(--danger); }
button.danger:hover { background: #87291b; }
button.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row > label.field { flex: 1; min-width: 200px; }
.form-actions { display: flex; gap: 0.6rem; align-items: center; margin-top: 0.5rem; }

.error-msg { color: var(--danger); font-weight: 500; margin: 0.5rem 0; }

/* ---- Small form hints ---- */
.palette-hint { font-size: 0.78rem; color: var(--muted); margin: 0.1rem 0 0.3rem; }

/* ---- Translation requests / jobs ---- */
.request-wrap { max-width: 560px; margin: 5vh auto 0; }
tr.job-row { cursor: pointer; }
tr.job-row:hover td { background: var(--accent-soft); }
.job-field { margin-bottom: 0.9rem; }
.job-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 0.25rem; }
.job-details {
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.8rem 1rem;
}

/* ---- Login ---- */
.login-wrap {
  max-width: 400px;
  margin: 8vh auto 0;
}
.login-wrap .brand-big,
.request-wrap .brand-big {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}
.login-note { font-size: 0.85rem; color: var(--muted); text-align: center; margin-top: 1rem; }

/* ---- Entries list ---- */
.filters {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.filters input[type="search"] { flex: 2; min-width: 220px; width: auto; }
.filters select { flex: 1; min-width: 130px; width: auto; }
.smart-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}
.smart-toggle input { width: auto; }

.entry-list { display: flex; flex-direction: column; gap: 0.6rem; }
.entry-row {
  display: block;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 1.1rem;
  text-decoration: none;
  color: inherit;
}
.entry-row:hover { border-color: var(--accent); }
.entry-row .dene { font-size: 1.15rem; font-weight: 600; }
.entry-row .english { color: var(--muted); }
.entry-meta {
  display: flex;
  gap: 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.3rem;
  flex-wrap: wrap;
}
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.audio { background: #e3efe6; color: var(--good); }
.badge.status-reviewed { background: #fdf0dd; color: var(--warn); }
.badge.status-verified { background: #e3efe6; color: var(--good); }
.badge.incomplete { background: #fae3da; color: var(--danger); }
.entry-row .placeholder { color: var(--muted); font-style: italic; font-weight: 400; }
.form-hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.8rem; }

.pager { display: flex; gap: 0.6rem; align-items: center; justify-content: center; margin-top: 1rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 0; }

/* ---- Entry detail ---- */
.entry-texts { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .entry-texts { grid-template-columns: 1fr; } }

.audio-item {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-top: 1px solid var(--line);
  padding: 0.9rem 0;
}
.audio-item audio { width: 100%; }
.audio-item-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: baseline; }
.audio-item-head .fname { font-weight: 600; }
.audio-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---- Microphone recorder ---- */
.audio-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 720px) { .audio-slots { grid-template-columns: 1fr; } }
.audio-slot {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.audio-slot audio { width: 100%; }
.slot-head {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-dark);
}
.slot-empty { color: var(--muted); font-size: 0.9rem; }
.slot-meta { color: var(--muted); font-size: 0.82rem; }
.slot-controls {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  min-height: 2.3rem;
}
.rec-btn {
  background: var(--danger);
  font-size: 1rem;
  padding: 0.6rem 1.3rem;
}
.rec-btn:hover { background: #87291b; }
.rec-live { font-weight: 600; display: inline-flex; align-items: center; gap: 0.5rem; }
.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* ---- Translator view ---- */
.translator-home { text-align: center; padding: 4rem 0; }
.translator-home h1 { margin-bottom: 0.2rem; }
.translator-project { color: var(--muted); margin-top: 0; }
.queue-count { font-size: 1.05rem; margin: 1.5rem 0; }
.big-action { font-size: 1.25rem; padding: 1rem 2.2rem; border-radius: 14px; }

.rec-session { max-width: 700px; margin: 0 auto; }
.rec-progress {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.8rem;
}
.rec-card { text-align: center; padding: 2.2rem 1.5rem 1.2rem; }
.rec-dene { font-size: 2.3rem; font-weight: 700; line-height: 1.3; }
.rec-english { font-size: 1rem; margin-top: 0.5rem; }
.rec-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin: 1.8rem 0;
  min-height: 3.5rem;
}
.rec-stage audio { flex: 1; min-width: 240px; max-width: 420px; }
.rec-meta {
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
  color: var(--muted);
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: center;
}
.rec-actions {
  display: flex;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 1.2rem;
  flex-wrap: wrap;
}
.rec-actions button { font-size: 1.05rem; padding: 0.7rem 1.5rem; }

/* ---- Compensation ---- */
.rate-field { display: inline-flex; align-items: center; gap: 0.2rem; }
.rate-field input { width: 6rem; }
.earnings-line { margin-top: 2rem; color: var(--muted); font-size: 0.95rem; }

/* ---- Dashboard ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.project-card h2 { margin: 0 0 0.1rem; font-size: 1.15rem; }
.project-card .dialect { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.7rem; }
.stat-numbers { display: flex; gap: 1.5rem; margin: 0.6rem 0; }
.stat-numbers .num { font-size: 1.5rem; font-weight: 700; }
.stat-numbers .lbl { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.progress {
  height: 8px;
  background: var(--accent-soft);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.4rem 0 0.2rem;
}
.progress > div { height: 100%; background: var(--accent); }
.progress-label { font-size: 0.78rem; color: var(--muted); }
.card-actions { display: flex; gap: 0.5rem; margin-top: 0.9rem; flex-wrap: wrap; }

.recent-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.recent-list li { padding: 0.4rem 0; border-top: 1px solid var(--line); font-size: 0.9rem; }
.recent-list .when { color: var(--muted); font-size: 0.8rem; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
/* Wide admin tables scroll within their card on narrow screens instead of
   stretching the whole page past the viewport. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 520px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 20, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 1rem;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 460px;
  max-height: 84vh; /* tall modals (import wizard preview) scroll inside */
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal h2 { margin-top: 0; }

/* ---- Toast ---- */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
#toast.error { background: var(--danger); }

/* Mic preflight (#8b) */
.preflight { max-width: 460px; margin: 2rem auto; text-align: center; }
.preflight-device { color: var(--muted); font-size: 0.9rem; }
.preflight-meter { height: 14px; background: var(--accent-soft); border-radius: 7px; overflow: hidden; margin: 0.8rem 0; }
.preflight-level { height: 100%; width: 0; background: var(--accent); transition: width 0.06s linear; }
.preflight-hint { min-height: 1.2em; font-size: 0.9rem; }

/* Recording version history (#8b) */
.audio-versions { margin-top: 0.5rem; padding-left: 0.5rem; border-left: 2px solid var(--line); }
.versions-head { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }
.version-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; font-size: 0.85rem; color: var(--muted); padding: 0.25rem 0; }
.empty.small { padding: 0.4rem; font-size: 0.85rem; }
