:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #eef2fb;
  --text: #0f1a2b;
  --muted: #58667e;
  --primary: #0f3d6e;
  --primary-600: #174e8a;
  --primary-50: #e7eefa;
  --secondary: #d7deea;
  --success: #0f8a4f;
  --wa: #25d366;
  --mail: #e2732c;
  --danger: #b2283e;
  --border: #d7deea;
  --shadow: 0 2px 10px rgba(15, 26, 43, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1220;
    --surface: #131c31;
    --surface-2: #1b2742;
    --text: #eef2fb;
    --muted: #95a2bd;
    --primary: #5a9ee0;
    --primary-600: #4a87c2;
    --primary-50: #1b2a44;
    --secondary: #27344f;
    --border: #26314b;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.brand { margin: 0; font-size: 18px; font-weight: 700; color: var(--primary); }
.sub { color: var(--muted); font-size: 13px; margin-left: 8px; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }

/* Container */
.container { max-width: 860px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 18px; }

/* Hero / Record */
.hero {
  background: linear-gradient(135deg, var(--primary-50), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.stt-status { color: var(--muted); font-size: 14px; }
.record-btn {
  appearance: none; border: 0; cursor: pointer;
  width: min(76vw, 200px); height: min(76vw, 200px);
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  box-shadow: 0 10px 30px rgba(15, 61, 110, 0.35), inset 0 -4px 0 rgba(0,0,0,0.15);
  transition: transform .08s ease, background .2s ease;
  font-size: 18px; font-weight: 600;
}
.record-btn:hover { background: var(--primary-600); }
.record-btn:active { transform: scale(0.97); }
.record-btn[aria-pressed="true"] {
  background: var(--danger);
  animation: pulse 1.4s infinite;
}
.record-icon { font-size: 30px; line-height: 1; }
.hero-hint { color: var(--muted); font-size: 12px; }
.stt-lang-row { width: 100%; max-width: 420px; }
.stt-lang-row select {
  width: 100%; text-align: center; text-align-last: center;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
}
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(178, 40, 62, 0.5); }
  50% { box-shadow: 0 0 0 18px rgba(178, 40, 62, 0); }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 600; font-size: 14px; color: var(--text);
  margin-bottom: 6px;
}
.label-right { font-weight: 500; }
.linklike {
  appearance: none; background: none; border: 0; padding: 0;
  color: var(--primary); cursor: pointer; font-size: 13px; text-decoration: underline;
}

textarea, input[type="text"], input[type="password"], input[type="email"], input[type="tel"], input[type="number"], input[type="date"], select {
  width: 100%;
  padding: 10px 12px;
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 160px; }
textarea:focus, input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 61, 110, 0.15);
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.primary-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.draft-saved { color: var(--muted); font-size: 13px; }

/* Buttons */
.btn {
  appearance: none; border: 0; cursor: pointer;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font: inherit; font-weight: 600;
  transition: background .15s ease, transform .06s ease, box-shadow .15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; padding: 14px 20px; font-size: 16px; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--primary-600); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary { background: var(--secondary); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-wa { background: var(--wa); color: #0b2e17; }
.btn-wa:hover { filter: brightness(0.95); }
.btn-mail { background: var(--mail); color: #fff; }
.btn-mail:hover { filter: brightness(0.95); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }

/* Summary output */
.summary-output {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 0;
  white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 15px;
  max-height: 60vh; overflow: auto;
}
.share-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.translate-row { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); }
.translate-row > legend { font-weight: 600; color: var(--text); padding: 0 4px; font-size: 13px; }
.muted { color: var(--muted); }
.install-banner {
  background: color-mix(in srgb, var(--surface) 92%, #8b5cf6 8%);
  border: 1px solid color-mix(in srgb, #8b5cf6 55%, var(--border));
  margin-bottom: 12px;
}
.install-banner p { margin: 6px 0 10px; font-size: 13px; }
.install-banner strong { font-size: 14px; }
.install-banner[hidden] { display: none; }
.status { font-size: 13px; color: var(--muted); min-height: 18px; }
.status.ok { color: var(--success); }
.status.err { color: var(--danger); }

.tool-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0 4px; }
.diagnosis {
  margin-top: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, #0ea5e9 8%);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}
.diagnosis h4 { margin: 0 0 4px; font-size: 14px; color: var(--danger); }
.diagnosis.ok { background: color-mix(in srgb, var(--surface) 92%, #22c55e 8%); }
.diagnosis.ok h4 { color: var(--success); }
.diagnosis p { margin: 0 0 6px; }
.diagnosis ul { margin: 6px 0 0 18px; padding: 0; }
.diagnosis li { margin: 2px 0; }
.diagnosis code {
  font-size: 12px; padding: 1px 4px;
  background: rgba(0,0,0,0.05); border-radius: 4px;
}
.diagnosis[hidden] { display: none; }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(6, 10, 20, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-panel {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 640px; width: 100%;
  max-height: 92vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.modal-head, .modal-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-foot { border-bottom: 0; border-top: 1px solid var(--border); gap: 10px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 14px 18px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
legend { padding: 0 6px; font-weight: 600; color: var(--primary); }
.hint { margin: 2px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }
.hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  z-index: 40; max-width: 90vw;
}

/* RTL support for Arabic content areas */
[dir="rtl"] .summary-output, [dir="rtl"] #transcript { text-align: right; }
