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

:root {
  --bg:         #F4F6F9;
  --surface:    #FFFFFF;
  --border:     #E2E8F0;
  --blue:       #1B4F91;
  --blue-l:     #2563EB;
  --blue-dim:   #EFF4FF;
  --red:        #DC2626;
  --red-dim:    rgba(220,38,38,.08);
  --green:      #16A34A;
  --green-dim:  rgba(22,163,74,.08);
  --amber:      #D97706;
  --amber-dim:  rgba(217,119,6,.08);
  --text:       #0F172A;
  --muted:      #64748B;
  --subtle:     #94A3B8;
  --tg:         #2AABEE;
  --nav-h:      64px;
  --safe-top:   env(safe-area-inset-top, 0px);
  --safe-bot:   env(safe-area-inset-bottom, 0px);
  --radius:     16px;
  --shadow:     0 1px 4px rgba(0,0,0,.06), 0 4px 20px rgba(0,0,0,.07);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; background: var(--bg); color: var(--text); direction: rtl; -webkit-font-smoothing: antialiased; overflow: hidden; }

/* ── Screens ── */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: var(--safe-top); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.screen.active { opacity: 1; pointer-events: auto; }

/* ════ LOGIN ════ */
#screen-login { background: var(--surface); align-items: center; justify-content: flex-end; }
.login-bg { position: absolute; inset: 0; background: linear-gradient(160deg,#1B4F91 0%,#2563EB 55%,#1e40af 100%); z-index: 0; }
.login-card { position: relative; z-index: 1; width: 100%; background: var(--surface); border-radius: 28px 28px 0 0; padding: 32px 28px calc(32px + var(--safe-bot)); display: flex; flex-direction: column; gap: 20px; }
.login-hero { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 28px 24px; gap: 12px; text-align: center; }
.brand-logo { width: 72px; height: 72px; background: rgba(255,255,255,.15); border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 36px; backdrop-filter: blur(8px); border: 1.5px solid rgba(255,255,255,.25); margin-bottom: 4px; }
.brand-name { font-size: 26px; font-weight: 800; color: white; letter-spacing: -.5px; }
.brand-sub { font-size: 15px; color: rgba(255,255,255,.75); line-height: 1.5; }
.login-title { font-size: 22px; font-weight: 700; color: var(--text); }
.login-desc { font-size: 15px; color: var(--muted); line-height: 1.6; }
.btn-tg { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 16px; background: var(--tg); color: white; border: none; border-radius: var(--radius); font-size: 17px; font-weight: 700; cursor: pointer; transition: opacity .15s, transform .1s; }
.btn-tg:active { opacity: .85; transform: scale(.98); }
.btn-tg:disabled { opacity: .6; cursor: default; }
.tg-icon { width: 22px; height: 22px; flex-shrink: 0; }
.waiting-card { background: var(--blue-dim); border: 1.5px solid #BFDBFE; border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.waiting-header { display: flex; align-items: center; gap: 12px; }
.waiting-num { width: 28px; height: 28px; border-radius: 50%; background: var(--blue-l); color: white; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.waiting-text { font-size: 15px; font-weight: 600; color: var(--text); }
.waiting-sub  { font-size: 13px; color: var(--muted); }
.btn-open-tg { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px; background: var(--blue); color: white; text-decoration: none; border-radius: 12px; font-size: 15px; font-weight: 600; }
.step-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.step-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--subtle); flex-shrink: 0; animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.2} }
.link-reset { background: none; border: none; color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: underline; padding: 0; }

.login-divider { text-align: center; font-size: 12px; color: var(--subtle); position: relative; }
.login-divider::before, .login-divider::after { content: ''; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border); }
.login-divider::before { right: 0; }
.login-divider::after  { left: 0; }

.btn-copy-link { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 12px; background: none; border: 1.5px solid var(--border); border-radius: 12px; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; transition: all .15s; }
.btn-copy-link:hover { border-color: var(--blue-l); color: var(--blue-l); }
.btn-copy-link.copied { border-color: var(--green); color: var(--green); }

.manual-fallback { background: var(--bg); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.manual-title { font-size: 13px; font-weight: 700; color: var(--text); }
.manual-desc  { font-size: 12px; color: var(--muted); line-height: 1.4; }
.manual-command { font-size: 13px; font-family: 'SF Mono', 'Fira Code', monospace; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: var(--blue); word-break: break-all; margin-top: 4px; }

/* ════ MAIN ════ */
#screen-main { background: var(--bg); padding-bottom: var(--nav-h); }
.app-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.header-brand { font-size: 17px; font-weight: 700; color: var(--blue); letter-spacing: -.3px; }
.header-user { font-size: 13px; color: var(--muted); }
.btn-logout { background: none; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-size: 13px; padding: 6px 12px; cursor: pointer; transition: all .15s; }
.btn-logout:hover { border-color: var(--red); color: var(--red); }
.template-bar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px; flex-shrink: 0; }
.template-label { font-size: 11px; font-weight: 600; color: var(--subtle); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 8px; }
.template-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-btn { padding: 7px 14px; border-radius: 20px; border: 1.5px solid var(--border); background: var(--bg); color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; }
.tab-btn.active { background: var(--blue); border-color: var(--blue); color: white; font-weight: 600; }
.tab-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.tab-panel.hidden { display: none; }

/* Record stage */
.record-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; gap: 0; }
.record-hint { font-size: 16px; color: var(--muted); margin-bottom: 36px; font-weight: 500; transition: color .3s; }
.record-hint.active { color: var(--red); }
.btn-record-wrap { position: relative; width: 200px; height: 200px; display: flex; align-items: center; justify-content: center; }
.ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--red); opacity: 0; }
.recording .ring-1 { animation: ring-out 2s ease-out infinite; }
.recording .ring-2 { animation: ring-out 2s ease-out .6s infinite; }
@keyframes ring-out { 0%{transform:scale(.7);opacity:.5} 100%{transform:scale(1.4);opacity:0} }
.btn-record { width: 140px; height: 140px; border-radius: 50%; border: none; background: var(--surface); box-shadow: var(--shadow), 0 0 0 8px white, 0 0 0 10px var(--border); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform .12s, box-shadow .2s; position: relative; z-index: 1; }
.btn-record:active { transform: scale(.95); }
.btn-record.recording { background: var(--red); box-shadow: 0 8px 40px rgba(220,38,38,.35), 0 0 0 8px white, 0 0 0 10px rgba(220,38,38,.15); }
.mic-icon { width: 48px; height: 48px; color: var(--blue); transition: color .2s; }
.btn-record.recording .mic-icon { display: none; }
.stop-icon { width: 28px; height: 28px; background: white; border-radius: 6px; display: none; }
.btn-record.recording .stop-icon { display: block; }

/* Recording controls (timer + pause) */
.recording-controls { display: flex; flex-direction: column; align-items: center; gap: 16px; margin-top: 28px; }
.record-timer { font-size: 48px; font-weight: 700; color: var(--red); letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.btn-pause { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 24px; color: var(--muted); font-size: 15px; font-weight: 600; padding: 10px 22px; cursor: pointer; transition: all .15s; }
.btn-pause.paused { color: var(--red); border-color: var(--red); }
.btn-pause:hover { border-color: var(--blue-l); color: var(--blue-l); }

/* Upload */
.upload-strip { background: var(--surface); border-top: 1px solid var(--border); padding: 14px 20px; flex-shrink: 0; }
.upload-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 13px; border: 1.5px dashed var(--border); border-radius: 12px; background: none; color: var(--muted); font-size: 15px; cursor: pointer; transition: border-color .15s, color .15s; }
.upload-btn:hover { border-color: var(--blue-l); color: var(--blue-l); }

/* Bottom nav */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + var(--safe-bot)); padding-bottom: var(--safe-bot); background: var(--surface); border-top: 1px solid var(--border); display: flex; z-index: 50; }
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; background: none; border: none; color: var(--subtle); font-size: 12px; font-weight: 500; cursor: pointer; transition: color .15s; }
.nav-btn.active { color: var(--blue); }
.nav-btn.active svg { stroke: var(--blue); }
.nav-btn span { font-size: 11px; font-weight: 600; }

/* History */
.history-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.history-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); font-size: 15px; }
.history-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; align-items: center; gap: 14px; cursor: pointer; transition: box-shadow .15s; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.history-card:hover { box-shadow: var(--shadow); }
.history-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--blue-dim); display: flex; align-items: center; justify-content: center; color: var(--blue); flex-shrink: 0; }
.history-info { flex: 1; min-width: 0; }
.history-title { font-size: 15px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.history-arrow { color: var(--subtle); font-size: 18px; flex-shrink: 0; }

/* Processing */
.processing-overlay { position: absolute; inset: 0; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; z-index: 100; }
.progress-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px 32px; width: calc(100% - 48px); max-width: 340px; box-shadow: var(--shadow); }
.progress-title { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 20px; text-align: center; }
.progress-steps { display: flex; flex-direction: column; gap: 10px; }
.prog-step { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--subtle); transition: color .3s; }
.prog-step.done { color: var(--text); }
.prog-step.active { color: var(--blue-l); font-weight: 600; }
.prog-icon { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0; transition: all .3s; }
.prog-step.done .prog-icon { background: var(--green); border-color: var(--green); color: white; }
.prog-step.active .prog-icon { border-color: var(--blue-l); animation: spin .8s linear infinite; border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ════ REVIEW ════ */
#screen-review { background: var(--bg); }
.review-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.btn-text-small { background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; padding: 4px 8px; }
.review-progress { font-size: 15px; font-weight: 700; color: var(--text); }
.btn-vapi { display: flex; align-items: center; gap: 6px; background: var(--blue); border: none; border-radius: 20px; color: white; font-size: 13px; font-weight: 600; padding: 8px 14px; cursor: pointer; transition: opacity .15s; }
.btn-vapi.active { background: var(--red); animation: pulse-btn 1.5s ease-in-out infinite; }
@keyframes pulse-btn { 0%,100%{opacity:1} 50%{opacity:.7} }

/* Card stage */
.card-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px 20px 10px; position: relative; overflow: hidden; }
.section-ctx { font-size: 12px; font-weight: 700; color: var(--blue); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px; background: var(--blue-dim); border-radius: 20px; padding: 5px 14px; }

.review-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px; padding: 24px; box-shadow: var(--shadow); position: relative; touch-action: pan-y; user-select: none; transition: transform .15s, box-shadow .15s; min-height: 200px; }
.review-card.swiping { transition: none; }

.swipe-hint { position: absolute; top: 20px; font-size: 18px; font-weight: 800; opacity: 0; transition: opacity .15s; pointer-events: none; padding: 6px 16px; border-radius: 20px; }
.swipe-hint.accept { left: 20px; color: var(--green); background: var(--green-dim); border: 2px solid var(--green); }
.swipe-hint.reject { right: 20px; color: var(--red); background: var(--red-dim); border: 2px solid var(--red); }

.card-number { font-size: 11px; font-weight: 700; color: var(--subtle); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.card-topic { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.4; margin-bottom: 14px; }
.card-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.card-badge { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 5px 10px; }
.badge-label { font-size: 10px; font-weight: 700; color: var(--subtle); text-transform: uppercase; letter-spacing: .3px; }
.card-notes { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted); line-height: 1.5; }
.card-edit-mode { margin-top: 16px; }
.edit-input { width: 100%; border: 1.5px solid var(--blue-l); border-radius: 12px; padding: 12px; font-size: 16px; font-family: inherit; color: var(--text); resize: none; outline: none; background: var(--bg); }
.edit-actions { display: flex; gap: 10px; margin-top: 10px; }
.btn-edit-cancel { flex: 1; padding: 12px; border: 1.5px solid var(--border); border-radius: 12px; background: none; color: var(--muted); font-size: 15px; font-weight: 600; cursor: pointer; }
.btn-edit-save   { flex: 2; padding: 12px; border: none; border-radius: 12px; background: var(--blue); color: white; font-size: 15px; font-weight: 700; cursor: pointer; }

/* Review action buttons — big for driving */
.review-actions { display: flex; gap: 12px; padding: 16px 20px calc(20px + var(--safe-bot)); background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0; }
.review-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 18px 0; border: none; border-radius: 18px; font-size: 15px; font-weight: 700; cursor: pointer; transition: opacity .12s, transform .1s; }
.review-btn:active { opacity: .8; transform: scale(.96); }
.review-btn.reject { background: var(--red-dim); color: var(--red); }
.review-btn.edit   { background: var(--amber-dim); color: var(--amber); }
.review-btn.accept { background: var(--green-dim); color: var(--green); }
.review-btn.reject svg { stroke: var(--red); }
.review-btn.edit   svg { stroke: var(--amber); }
.review-btn.accept svg { stroke: var(--green); }

/* Vapi overlay */
.vapi-overlay { position: absolute; inset: 0; background: rgba(15,23,42,.75); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; z-index: 200; }
.vapi-card { background: var(--surface); border-radius: 24px; padding: 36px 28px; width: calc(100% - 48px); max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 20px; text-align: center; }
.vapi-pulse { width: 72px; height: 72px; border-radius: 50%; background: var(--blue); display: flex; align-items: center; justify-content: center; animation: vapi-pulse 1.5s ease-in-out infinite; }
@keyframes vapi-pulse { 0%,100%{box-shadow:0 0 0 0 rgba(37,99,235,.5)} 50%{box-shadow:0 0 0 18px rgba(37,99,235,0)} }
.vapi-status { font-size: 16px; font-weight: 600; color: var(--text); }
.vapi-item { font-size: 15px; color: var(--muted); line-height: 1.5; min-height: 44px; }
.btn-vapi-end { background: var(--red-dim); border: 1.5px solid var(--red); border-radius: 20px; color: var(--red); font-size: 15px; font-weight: 700; padding: 12px 28px; cursor: pointer; }

/* ════ RESULTS ════ */
#screen-results { background: var(--bg); overflow-y: auto; overflow-x: hidden; }
.results-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 20px; display: flex; align-items: center; gap: 14px; flex-shrink: 0; position: sticky; top: 0; z-index: 10; }
.btn-back { background: none; border: 1px solid var(--border); border-radius: 10px; color: var(--muted); font-size: 18px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.result-title-text { flex: 1; font-size: 16px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-dl { background: var(--blue); border: none; border-radius: 10px; color: white; font-size: 13px; font-weight: 600; padding: 8px 14px; display: flex; align-items: center; gap: 6px; cursor: pointer; flex-shrink: 0; transition: opacity .15s; }
.btn-dl:hover { opacity: .88; }
.result-meta-strip { padding: 16px 16px 8px; display: flex; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.meta-pill { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 6px 14px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.meta-pill b { color: var(--text); font-weight: 600; }

/* Review summary bar */
.review-summary-bar { padding: 10px 16px; display: flex; gap: 8px; background: var(--surface); border-bottom: 1px solid var(--border); }
.rsb-chip { font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 20px; }
.rsb-chip.accepted { background: var(--green-dim); color: var(--green); }
.rsb-chip.rejected { background: var(--red-dim); color: var(--red); text-decoration: line-through; }
.rsb-chip.edited   { background: var(--amber-dim); color: var(--amber); }

.result-section-header { padding: 16px 16px 8px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; flex-shrink: 0; }
.result-cards { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }
.action-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.action-card.is-section { background: var(--blue-dim); border-color: #BFDBFE; }
.action-card.is-rejected { opacity: .45; }
.action-card.is-edited { border-color: var(--amber); }
.card-num { font-size: 11px; font-weight: 700; color: var(--subtle); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.card-topic-result { font-size: 16px; font-weight: 600; color: var(--text); line-height: 1.4; margin-bottom: 10px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--blue); }
.card-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.card-badge-result { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 4px 10px; }
.notes-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted); line-height: 1.5; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.accepted { background: var(--green); }
.status-dot.rejected { background: var(--red); }
.status-dot.edited   { background: var(--amber); }

/* Email button */
.email-strip { padding: 16px 16px calc(24px + var(--safe-bot)); }
.btn-email { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 16px; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 16px; font-weight: 600; cursor: pointer; transition: border-color .15s, color .15s; }
.btn-email:hover { border-color: var(--blue-l); color: var(--blue-l); }
.btn-email svg { stroke: var(--blue); }

.hidden { display: none !important; }
