/* ===== Wakil Collector — styles =====
   Mobile-first, RTL-aware, light + dark via prefers-color-scheme.
   Large touch targets, high contrast. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #11161c;
  --muted: #5a6573;
  --border: #d8dee6;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --ok: #16a34a;
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px; /* min touch target */
  --maxw: 720px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #21262d;
    --text: #e6edf3;
    --muted: #9aa7b4;
    --border: #30363d;
    --primary: #3b82f6;
    --danger: #f87171;
    --warn: #fbbf24;
    --warn-bg: #3a2e0a;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

/* Touch polish: kill the 300ms tap delay + grey flash on mobile. */
button, .seg-btn, .btn, .chip, .iconbtn, .record-btn, .qchip, .tier-badge, label {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { user-select: none; -webkit-user-select: none; }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
[hidden] { display: none !important; }

/* ===== Banners ===== */
.banner { padding: 12px 16px; font-size: 0.9rem; text-align: center; }
.banner-danger { background: var(--danger); color: #fff; }
.banner code { background: rgba(0,0,0,.18); padding: 1px 5px; border-radius: 5px; }

/* ===== App bar ===== */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(14px + env(safe-area-inset-left));
  padding-right: calc(14px + env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.appbar-left { display: flex; align-items: baseline; gap: 8px; }
.logo { font-size: 1.4rem; font-weight: 700; }
.logo-sub { color: var(--muted); font-size: 0.85rem; }
.appbar-right { display: flex; align-items: center; gap: 6px; }

.iconbtn {
  width: var(--tap); height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer;
}
.iconbtn:hover { background: var(--surface-2); }

.chip {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 999px; padding: 8px 12px;
  font-size: 0.82rem; cursor: pointer; min-height: 40px;
}
.chip-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; font-weight: 600; }

/* ===== Layout ===== */
#app {
  max-width: var(--maxw); margin: 0 auto; padding: 14px;
  padding-left: calc(14px + env(safe-area-inset-left));
  padding-right: calc(14px + env(safe-area-inset-right));
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
.screen { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 4px; }
h3 { font-size: 0.95rem; margin: 14px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ===== Forms ===== */
.field { display: block; margin: 14px 0; }
.label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.hint { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 5px; }

input[type="text"], textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px;
  min-height: var(--tap);
}
textarea { resize: vertical; min-height: 84px; font-size: 1.15rem; }
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }

/* Segmented control */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn {
  flex: 1 1 auto; min-width: 84px; min-height: var(--tap);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; cursor: pointer; padding: 0 12px;
}
.seg-btn.is-active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }

/* Buttons */
.btn {
  font: inherit; cursor: pointer; min-height: var(--tap);
  padding: 0 18px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
}
.btn:hover { filter: brightness(0.97); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.btn-block { width: 100%; margin-top: 8px; }

/* ===== Setup ===== */
.setup-card { margin-top: 24px; }

/* ===== Progress ===== */
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width .25s ease; }
.progress-row { display: flex; justify-content: space-between; margin-bottom: 12px; }

/* ===== Scenario card ===== */
.scenario-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.tier-badge {
  background: var(--primary); color: var(--primary-text);
  font-weight: 700; font-size: 0.95rem; padding: 5px 12px; border-radius: 999px;
}
.shuffle-toggle { margin-inline-start: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); cursor: pointer; }

.prompt-ar {
  direction: rtl; text-align: right;
  font-size: 1.9rem; line-height: 1.5; font-weight: 600;
  margin: 6px 0; word-break: break-word;
}
.prompt-en { color: var(--muted); font-size: 0.95rem; margin: 4px 0 0; }

.target-row { margin-top: 12px; min-height: 8px; }
.loc-chip {
  display: inline-block; direction: rtl;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 16px; font-size: 1.15rem; font-weight: 600;
}
.neg-hint { color: var(--danger); font-weight: 600; }
.amb-hint { color: var(--warn); font-weight: 600; }

/* ===== Recorder ===== */
.recorder-card { text-align: center; }
.wave {
  width: 100%; height: 80px; display: block;
  background: var(--surface-2); border-radius: var(--radius-sm); margin-bottom: 8px;
}
.rec-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 12px; min-height: 24px; }
.timer { font-size: 1.3rem; font-weight: 600; }
.rec-warn { color: var(--warn); font-size: 0.85rem; font-weight: 600; }

.record-btn {
  width: 100%; min-height: 72px;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  font-size: 1.25rem; font-weight: 700; cursor: pointer;
  background: var(--primary); color: var(--primary-text);
  border: none; border-radius: var(--radius);
}
.record-btn.is-recording { background: var(--danger); }
.record-btn:active { transform: scale(0.99); }
.record-dot { width: 16px; height: 16px; border-radius: 50%; background: currentColor; }
.record-btn.is-recording .record-dot { border-radius: 3px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ===== Review ===== */
.review { margin-top: 16px; text-align: start; }
.player { width: 100%; margin-bottom: 8px; }
.autoplay-toggle, .shuffle-toggle input, .autoplay-toggle input { vertical-align: middle; }
.autoplay-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; cursor: pointer; }

.quick-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.qchip {
  direction: rtl; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 999px; padding: 8px 14px; font-size: 1.05rem; cursor: pointer; min-height: 40px;
}
.qchip:hover { border-color: var(--primary); }

.action-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 14px; }
.action-row .btn-primary { grid-column: 1 / -1; }

@media (min-width: 560px) {
  .action-row { grid-template-columns: auto auto auto 1fr; }
  .action-row .btn-primary { grid-column: auto; }
}

/* ===== Mobile-first hot loop: keep the primary action thumb-reachable ===== *
   On phones a long Arabic prompt would push Record below the fold, forcing a
   scroll on every single take. Pin the recorder card to the bottom so Record
   (and Save, when reviewing) is always in reach; the scenario scrolls above. */
@media (max-width: 559px) {
  .legend { display: none; }            /* no physical keyboard on phones */
  .prompt-ar { font-size: 1.55rem; }    /* a touch smaller -> more room */
  .recorder-card {
    position: sticky;
    bottom: 0;
    z-index: 10;
    margin-bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.18);
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    max-height: 84vh;
    overflow-y: auto;                   /* tall review state scrolls internally */
  }
}

/* ===== Legend ===== */
.legend { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; color: var(--muted); font-size: 0.78rem; padding: 4px 0 20px; }
kbd {
  font-family: ui-monospace, monospace; font-size: 0.75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px;
}

/* ===== Done ===== */
.done-banner { text-align: center; padding: 24px 0; }

/* ===== Coverage overlay ===== */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; overflow-y: auto;
}
.coverage-card { max-width: 560px; width: 100%; margin-top: 24px; }
.coverage-head { display: flex; align-items: center; justify-content: space-between; }
.cov-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 480px) { .cov-grid { grid-template-columns: repeat(3, 1fr); } }
.cov-item {
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px;
}
.cov-item .k { font-size: 0.8rem; color: var(--muted); direction: rtl; text-align: start; }
.cov-item .v { font-size: 1.3rem; font-weight: 700; }
.coverage-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.coverage-actions .btn { flex: 1 1 auto; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 999px; z-index: 100;
  font-size: 0.9rem; box-shadow: 0 6px 24px rgba(0,0,0,.25);
  max-width: 90vw; text-align: center;
}
.toast.toast-err { background: var(--danger); color: #fff; }
.toast.toast-ok { background: var(--ok); color: #fff; }
