/* WebRTC Dialer - Mobile-first PWA CSS */
/* Hebrew RTL UI with blue gradient theme */

:root {
    /* ── Phase 10 brand variable bridges ────────────────────────────────
     * theme.css (served from /api/webrtc/brand/theme.css) sets:
     *   --color-primary, --color-accent, --color-bg, --color-text
     * The var() fallbacks below keep the original default values when
     * no brand profile is active. */
    --primary: var(--color-primary, #2563eb);
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --secondary: var(--color-accent, #64748b);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: var(--color-bg, #f8fafc);
    --surface: #ffffff;
    --surface2: #f1f5f9;
    --text: var(--color-text, #1e293b);
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 24px rgba(37,99,235,0.10);
    --radius: 16px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
    --dialpad-btn-size: 72px;
}

* { box-sizing: border-box; margin: 0; padding: 0; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

html, body {
    height: 100%;
    font-family: 'Heebo', 'Segoe UI', Arial, sans-serif;
    font-size: 17px;
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    overflow: hidden;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ========== APP SHELL ========== */
#app {
    height: 100vh;
    max-width: 420px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    position: relative;
    overflow: hidden;
}

/* ========== SCREENS ========== */
.screen {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.screen.active {
    display: flex;
}

/* ── GPU promotion for animated elements (Phase 1.2) ── */
.sd-ext.sd-scrolling  { will-change: transform; }
.sd-label.sd-scrolling { will-change: transform; }
.screen               { will-change: transform; }

/* ========== STATUS BAR ========== */
.status-bar {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    min-height: 36px;
}
.status-bar .status-conn { display: flex; align-items: center; gap: 6px; }
.status-toolbar { display: flex; align-items: center; gap: 4px; }
.toolbar-toggle-btn { display: none; } /* moved into dialpad as dial-icon-btn */

/* DND / AA icon buttons inside dialpad */
.dial-feature-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: 20px 0 16px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}
.dial-icon-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--surface2);
    border: 2px solid transparent;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    transition: background 0.18s, border-color 0.18s, color 0.18s;
}
.dial-icon-label {
    font-size: 0.48rem;
    font-weight: 700;
    letter-spacing: 0.6px;
    line-height: 1;
}
.dial-icon-btn:active { background: var(--border); }
.dial-icon-btn.dnd-active {
    background: rgba(239,68,68,0.12);
    border-color: var(--danger);
    color: var(--danger);
}
.dial-icon-btn.aa-active {
    background: rgba(249,115,22,0.12);
    border-color: #f97316;
    color: #f97316;
}
.dial-redial-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--surface2);
    border: none;
    cursor: pointer;
    font-size: 1.15rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}
.dial-redial-btn:active { background: var(--border); }
.dial-redial-btn:disabled { opacity: 0.3; cursor: default; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.status-dot.connected { background: #4ade80; }
.status-dot.registering { background: var(--warning); }
.status-dot.error { background: var(--danger); }

/* ========== SPLASH SCREEN ========== */
#splash {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    align-items: center;
    justify-content: center;
    gap: 24px;
}
.splash-logo { width: 100px; height: 100px; border-radius: 24px; box-shadow: 0 8px 32px rgba(0,0,0,0.3); }
.splash-name { color: white; font-size: 1.6rem; font-weight: 700; }
.splash-spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== LOGIN SCREEN ========== */
#login {
    background: linear-gradient(160deg, #eff6ff 0%, var(--surface) 60%);
    overflow-y: auto;
}
.login-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 28px 24px 40px;
    text-align: center;
    clip-path: ellipse(120% 100% at 50% 0%);
}
.login-header h1 { font-size: 1.5rem; font-weight: 700; margin-top: 10px; }
.login-header p { opacity: 0.85; font-size: 0.85rem; margin-top: 4px; }
.login-logo { width: 56px; height: 56px; border-radius: 14px; box-shadow: 0 4px 20px rgba(0,0,0,0.25); }
.login-card {
    margin: -24px 24px 24px;
    background: white;
    border-radius: var(--radius);
    padding: 32px 24px;
    box-shadow: var(--shadow);
}
.login-card .form-group { margin-bottom: 16px; }
.login-card label { display: block; font-size: 0.875rem; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.login-card input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    direction: ltr;
    text-align: left;
    transition: border-color var(--transition);
    outline: none;
}
.login-card input:focus { border-color: var(--primary); }
.login-error { color: var(--danger); font-size: 0.85rem; margin-bottom: 12px; display: none; }

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    outline: none;
    text-decoration: none;
    color: inherit;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(37,99,235,0.4);
}
.btn-primary:active { transform: scale(0.98); box-shadow: none; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-icon {
    width: 48px; height: 48px;
    border-radius: 50%;
    padding: 0;
    font-size: 1.25rem;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== 2FA SCREEN ========== */
#login-2fa { overflow-y: auto; }
.twofa-card {
    margin: 48px 24px;
    background: white;
    border-radius: var(--radius);
    padding: 32px 24px;
    box-shadow: var(--shadow);
    text-align: center;
}
.twofa-icon { font-size: 3rem; margin-bottom: 16px; }
.twofa-card h2 { font-size: 1.3rem; margin-bottom: 8px; }
.twofa-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }
.totp-input {
    display: flex;
    gap: 8px;
    justify-content: center;
    direction: ltr;
    margin-bottom: 16px;
}
.totp-input input {
    width: 44px; height: 56px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
}
.totp-input input:focus { border-color: var(--primary); }

/* ========== BOTTOM NAV ========== */
.bottom-nav {
    display: flex;
    background: white;
    border-top: 1px solid var(--border);
    padding: 4px 0 8px;
    flex-shrink: 0;
}
.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-family: inherit;
    transition: color var(--transition);
    position: relative;
}
.nav-btn.active { color: var(--primary); }
.nav-btn i { font-size: 1.2rem; }
.badge {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(8px);
    background: var(--danger);
    color: white;
    font-size: 0.6rem;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}

/* ========== DIAL PAD ========== */
#dialpad {
    overflow: hidden;
    justify-content: flex-end;
}
.dial-display {
    padding: 10px 16px 8px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
/* Manual number input — replaces the old span display */
.dial-input {
    width: 100%;
    font-size: 2rem;
    font-weight: 300;
    letter-spacing: 4px;
    direction: ltr;
    text-align: center;
    border: none;
    border-bottom: 2px solid var(--border);
    background: transparent;
    color: var(--text);
    padding: 6px 8px;
    outline: none;
    caret-color: var(--primary);
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.15s;
}
.dial-input:focus {
    border-bottom-color: var(--primary);
}
.dial-input::placeholder {
    color: var(--text-muted);
    font-size: 1rem;
    letter-spacing: 0;
    font-weight: 400;
    direction: rtl;
}
/* Legacy — no longer used but keep to avoid breakage */
.dial-number { display: none; }
.dial-number .caller-name { display: none; }
.dial-backspace {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
}
.dial-backspace:active { color: var(--danger); }

.dialpad-grid {
    direction: ltr;                    /* phone keypad is always LTR regardless of page RTL */
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 0 24px 8px;
}
.dial-key {
    width: var(--dialpad-btn-size);
    height: var(--dialpad-btn-size);
    border-radius: 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    transition: background var(--transition), transform 0.1s;
    font-family: inherit;
}
.dial-key:active { background: var(--surface2); transform: scale(0.94); }
.dial-key .key-digit { font-size: 1.5rem; font-weight: 500; color: var(--text); }
.dial-key .key-letters { font-size: 0.55rem; color: var(--text-muted); letter-spacing: 1.5px; height: 10px; }
.dial-call-btn {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--success);
    border: none;
    cursor: pointer;
    font-size: 1.4rem;
    color: white;
    margin: 0 auto;
    box-shadow: 0 4px 16px rgba(16,185,129,0.4);
    transition: transform 0.1s;
    display: flex; align-items: center; justify-content: center;
}
.dial-call-btn:active { transform: scale(0.94); }
.dial-action-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 40px 20px;
}

/* ========== IN-CALL SCREEN ========== */
#in-call {
    background: linear-gradient(160deg, #0f172a 0%, #1e3a5f 100%);
    color: white;
    align-items: center;
    justify-content: space-between;
    padding: 32px 24px 48px;
}
.incall-avatar {
    width: 100px; height: 100px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex; align-items: center; justify-content: center;
    font-size: 2.5rem;
    margin: 0 auto 16px;
}
.incall-name { font-size: 1.6rem; font-weight: 600; text-align: center; margin-bottom: 6px; }
.incall-number { font-size: 1rem; opacity: 0.7; text-align: center; margin-bottom: 4px; direction: ltr; }
.incall-timer { font-size: 1.2rem; font-weight: 300; text-align: center; opacity: 0.9; font-variant-numeric: tabular-nums; }
.incall-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    width: 100%;
}
.ctrl-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.12);
    border: none;
    border-radius: 16px;
    padding: 16px 8px;
    cursor: pointer;
    color: white;
    font-size: 0.75rem;
    font-family: inherit;
    transition: background var(--transition);
}
.ctrl-btn i { font-size: 1.5rem; }
.ctrl-btn.active { background: rgba(255,255,255,0.3); }
.ctrl-btn:active { background: rgba(255,255,255,0.4); }
.incall-hangup {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--danger);
    border: none;
    cursor: pointer;
    color: white;
    font-size: 1.6rem;
    box-shadow: 0 4px 20px rgba(239,68,68,0.5);
    display: flex; align-items: center; justify-content: center;
    margin: 8px auto 0;
}
.dtmf-display {
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-size: 1.1rem;
    letter-spacing: 4px;
    direction: ltr;
    text-align: center;
    min-height: 40px;
    width: 100%;
}

/* ========== INCOMING CALL ========== */
#incoming {
    background: linear-gradient(160deg, #0f172a 0%, #1e3a5f 100%);
    color: white;
    align-items: center;
    justify-content: center;
    gap: 32px;
    padding: 48px 24px;
}
.incoming-ring {
    width: 120px; height: 120px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex; align-items: center; justify-content: center;
    font-size: 3rem;
    animation: pulse-ring 1.5s ease-in-out infinite;
    position: relative;
}
@keyframes pulse-ring {
    0%,100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.4); }
    50% { box-shadow: 0 0 0 24px rgba(255,255,255,0); }
}
.incoming-name { font-size: 1.8rem; font-weight: 600; text-align: center; }
.incoming-number { font-size: 1rem; opacity: 0.7; direction: ltr; }
.incoming-sub { font-size: 0.85rem; opacity: 0.6; }
.incoming-actions {
    display: flex;
    gap: 48px;
    align-items: center;
}
.inc-answer-swipe {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 160px;
}
.inc-answer {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--success);
    border: none;
    cursor: pointer;
    color: white;
    font-size: 1.6rem;
    box-shadow: 0 4px 20px rgba(16,185,129,0.5);
    display: flex; align-items: center; justify-content: center;
    animation: bounce-ans 1s ease-in-out infinite;
    touch-action: none;
    user-select: none;
    transition: transform 120ms ease;
}
.inc-answer.swiping {
    animation: none;
    transition: none;
}
.answer-swipe-hint {
    font-size: 0.75rem;
    opacity: 0.85;
    text-align: center;
    max-width: 150px;
    line-height: 1.25;
}
@keyframes bounce-ans {
    0%,100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}
.inc-reject {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--danger);
    border: none;
    cursor: pointer;
    color: white;
    font-size: 1.6rem;
    box-shadow: 0 4px 20px rgba(239,68,68,0.5);
    display: flex; align-items: center; justify-content: center;
}

/* ========== RECENTS SCREEN ========== */
#recents { overflow-y: auto; }
.screen-header {
    padding: 16px 20px;
    background: var(--primary);
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.call-list { flex: 1; overflow-y: auto; }
.call-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}
.call-item:active { background: var(--surface2); }
.call-info { flex: 1; }
.call-name { font-weight: 600; font-size: 0.95rem; }
.call-number { font-size: 0.8rem; color: var(--text-muted); direction: ltr; display: inline-block; }
.call-meta { text-align: left; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.call-time { font-size: 0.75rem; color: var(--text-muted); }
.call-duration { font-size: 0.75rem; color: var(--text-muted); }
/* Direction+status arrow icon (MicroSIP-style) */
.call-dir-icon {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}
.call-dir-icon.ci-answered  { color: var(--success); }
.call-dir-icon.ci-unanswered { color: var(--danger); }
.call-dir-icon.ci-elsewhere  { color: var(--warning); }
/* Outbound (→)  rotated -45° = ↗ upper-right */
.call-dir-icon.ci-out i { display: inline-block; transform: rotate(-45deg); }
/* Inbound  (→)  rotated 135° = ↙ lower-left  */
.call-dir-icon.ci-in  i { display: inline-block; transform: rotate(135deg); }

/* Add-to-speed-dial star button on call history rows */
.call-add-sd-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text-muted);
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.call-add-sd-btn:active,
.call-add-sd-btn:hover {
    background: rgba(20,184,166,0.12);
    color: #0d9488;
    border-color: rgba(20,184,166,0.4);
}

/* Inline action buttons (call / SMS) on call-history rows (v2.3.0) */
.ci-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface2);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.ci-btn-call { color: #16a34a; }
.ci-btn-call:hover { background: rgba(22,163,74,0.12); border-color: rgba(22,163,74,0.4); }
.ci-btn-sms  { color: var(--primary); }
.ci-btn-sms:hover  { background: rgba(20,184,166,0.12); border-color: rgba(20,184,166,0.4); }

/* ========== SMS SCREENS ========== */
#sms, #sms-thread { overflow-hidden; }
.sms-list { flex: 1; overflow-y: auto; }
.sms-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}
.sms-item:active { background: var(--surface2); }
.sms-item.unread .sms-preview { font-weight: 700; color: var(--text); }
.sms-preview { font-size: 0.85rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sms-thread-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-break: break-word;
}
.msg-bubble.incoming {
    background: var(--surface2);
    color: var(--text);
    align-self: flex-start;
    border-bottom-right-radius: 4px;
}
.msg-bubble.outgoing {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-left-radius: 4px;
}
.msg-time { font-size: 0.7rem; opacity: 0.65; margin-top: 4px; text-align: left; }

.sms-compose {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.sms-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 80px;
    direction: rtl;
}
.sms-input:focus { border-color: var(--primary); }
.sms-send-btn {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
}

/* ========== LOADING / EMPTY STATES ========== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 24px;
    color: var(--text-muted);
    text-align: center;
}
.empty-state i { font-size: 3rem; opacity: 0.3; }
.empty-state p { font-size: 0.9rem; }

.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 24px auto;
}

/* ========== TOAST ========== */
#toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: 90%;
    max-width: 380px;
}
.toast {
    background: #1e293b;
    color: white;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 0.875rem;
    animation: slide-up 0.3s ease forwards;
    opacity: 0;
    text-align: center;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ========== SETTINGS SCREEN ========== */
#settings { overflow-y: auto; }
.settings-body { padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.settings-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--primary);
    margin-bottom: 2px;
}
/* ── Accordion sections ─── */
.settings-accordion-item { display: flex; flex-direction: column; }
.settings-accordion-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    cursor: pointer;
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    text-align: right;
    transition: background 0.15s;
}
.settings-accordion-btn:active { background: var(--border); }
.settings-accordion-label {
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-chevron {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.22s ease;
}
.settings-accordion-btn.open .settings-chevron { transform: rotate(180deg); }
.settings-accordion-content {
    overflow: hidden;
    max-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: max-height 0.28s ease, padding-top 0.28s ease;
    padding-top: 0;
}
.settings-accordion-content.open {
    max-height: 900px;
    padding-top: 6px;
}
/* SIP connection toggle row */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    border-radius: 10px;
    background: var(--surface);
    border: 1.5px solid var(--border);
}
.settings-row-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
}
.settings-row-label i { color: var(--primary); width: 16px; text-align: center; }
.sip-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 8px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    transition: background var(--transition), color var(--transition);
}
.sip-toggle-btn.sip-toggle-on  { background: #d1fae5; color: #065f46; }
.sip-toggle-btn.sip-toggle-off { background: #fee2e2; color: #991b1b; }
.sip-toggle-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background var(--transition);
}
.sip-toggle-btn.sip-toggle-on  .sip-toggle-dot { background: #10b981; }
.sip-toggle-btn.sip-toggle-off .sip-toggle-dot { background: #ef4444; }
.ringtone-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}
.ringtone-select {
    flex: 1;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.84rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition);
    appearance: auto;
}
.ringtone-select:focus { border-color: var(--primary); }
.ring-preview-btn {
    background: none;
    border: 1.5px solid var(--border);
    color: var(--text-muted);
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: 0.72rem;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    flex-shrink: 0;
}
.ring-preview-btn:hover, .ring-preview-btn:active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ========== SPEED DIAL RIBBON (Phase 8.5) ========== */
.sd-ribbon {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow: visible;
    min-height: 0;
    flex-shrink: 0;
    flex-wrap: nowrap;
    width: 100%;
    box-sizing: border-box;
}
.sd-btn {
    position: relative;
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    height: 58px;
    border-radius: 9px;
    background: var(--surface2);
    border: 1px solid var(--border);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2px 4px;
    transition: background var(--transition), border-color var(--transition);
    overflow: hidden;
}
.sd-btn:active { background: var(--border); }
.sd-empty-hint { opacity: 0.55; border-style: dashed; }
/* Always-visible + add button */
.sd-add-btn {
    flex: 0 0 44px;
    min-width: 44px;
    max-width: 44px;
    border-style: dashed;
    color: var(--primary);
    border-color: rgba(37,99,235,0.35);
    opacity: 0.85;
}
.sd-add-btn:active { background: rgba(37,99,235,0.08); }
.sd-more-btn { flex: 0 0 36px; min-width: 36px; max-width: 36px; }
/* Speed dial (non-BLF) button — teal tint, no availability dot */
.sd-btn-speeddial {
    background: rgba(20,184,166,0.10);
    border-color: rgba(20,184,166,0.4);
}
.sd-btn-speeddial:active { background: rgba(20,184,166,0.22); }
.sd-btn-speeddial .sd-ext { color: #0d9488; }
.sd-dropdown-row-speeddial { border-inline-start: 3px solid rgba(20,184,166,0.55); }
.sd-ext {
    font-weight: 700;
    font-size: 0.82rem;
    line-height: 1.1;
    direction: ltr;
    max-width: 100%;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: -0.02em;
    text-align: center;
}
.sd-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1;
}

/* BLF indicator dot */
.sd-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    right: 4px;
    background: var(--text-muted);
    opacity: 0.4;
}
.sd-dot.idle    { background: var(--success); opacity: 1; }
.sd-dot.busy    { background: var(--danger);  opacity: 1; }
.sd-dot.ringing { background: var(--danger);  opacity: 1; animation: sd-blink 0.55s infinite; }
.sd-dot.hold    { background: var(--warning); opacity: 1; }
.sd-dot.unknown { background: var(--text-muted); opacity: 0.35; } /* not yet confirmed by Asterisk */
.sd-dot.offline { background: #94a3b8; opacity: 0.7; }            /* extension not registered on PBX */
.sd-dot-off     { opacity: 0 !important; }
@keyframes sd-blink { 0%,100%{opacity:1} 50%{opacity:0.15} }

/* Marquee: scroll overflowing text in BLF buttons */
.sd-ext.sd-scrolling,
.sd-label.sd-scrolling {
    overflow: visible;
    text-overflow: clip;
    animation: sd-text-scroll 5s ease-in-out infinite;
}
@keyframes sd-text-scroll {
    0%, 20%   { transform: translateX(0); }
    50%, 70%  { transform: translateX(var(--sd-scroll, 0px)); }
    100%      { transform: translateX(0); }
}

/* More / dropdown */
.sd-more-wrap { position: relative; flex: 0 0 36px; }
.sd-dropdown {
    position: fixed;
    min-width: 240px;
    max-width: 320px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    z-index: 9999;
    overflow: hidden;
    max-height: 70vh;
    overflow-y: auto;
}
.sd-dropdown-inner { display: flex; flex-direction: column; }
.sd-dropdown-add {
    padding: 9px 14px;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 600;
    color: var(--primary);
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    text-align: right;
}
.sd-dropdown-add:active { background: var(--surface2); }
.sd-dropdown-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}
.sd-dropdown-row:last-child { border-bottom: none; }
.sd-dropdown-row:active { background: var(--surface2); }
.sd-dropdown-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.sd-dropdown-ext { font-weight: 700; font-size: 0.85rem; direction: ltr; }
.sd-dropdown-lbl { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sd-dropdown-actions { display: flex; gap: 4px; flex-shrink: 0; }
.sd-icon-btn {
    width: 26px; height: 26px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    font-family: inherit;
}
.sd-icon-btn:active { background: var(--border); }
.sd-icon-btn.sd-del { color: var(--danger); border-color: rgba(239,68,68,0.25); }

/* Speed dial edit modal */
.sd-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.sd-modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 380px;
    max-height: 90vh;
    overflow-y: auto;
}
.sd-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 0.95rem;
}
.sd-modal-close {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--surface2);
    border: none;
    cursor: pointer;
    font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
}
.sd-modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sd-modal-field { display: flex; flex-direction: column; gap: 4px; }
.sd-modal-field label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.sd-modal-field input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}
.sd-modal-field input:focus { border-color: var(--primary); }
.sd-check-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    cursor: pointer;
}
.sd-check-label input[type=checkbox] {
    width: 17px; height: 17px;
    accent-color: var(--primary);
    cursor: pointer;
}
.sd-check-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    cursor: pointer;
}
.sd-check-label input[type=checkbox] {
    width: 17px; height: 17px;
    accent-color: var(--primary);
    cursor: pointer;
}
/* Type selector segmented control */
.sd-type-selector {
    display: flex;
    gap: 8px;
}
.sd-type-opt {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 9px 6px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: var(--surface2);
    cursor: pointer;
    font-size: 0.82rem;
    font-family: inherit;
    text-align: center;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
    user-select: none;
}
.sd-type-opt input[type="radio"] { display: none; }
.sd-type-opt.active {
    border-color: var(--primary);
    background: rgba(37,99,235,0.09);
    color: var(--primary);
    font-weight: 700;
}
/* Speed dial type option — active state uses teal */
#sd-type-speed-lbl.active {
    border-color: #0d9488;
    background: rgba(20,184,166,0.10);
    color: #0d9488;
}
.sd-modal-footer {
    display: flex;
    gap: 10px;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--border);
}
.sd-modal-btn {
    flex: 1;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), opacity var(--transition);
}
.sd-modal-btn-cancel { background: var(--surface2); color: var(--text); }
.sd-modal-btn-save   { background: var(--primary);  color: white; }
.sd-modal-btn:active { opacity: 0.8; }

/* ========== HEADER SETTINGS ICON ========== */
.header-icon-btn {
    background: rgba(255,255,255,0.18);
    border: none;
    color: white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    flex-shrink: 0;
}
.header-icon-btn:hover { background: rgba(255,255,255,0.3); }
.header-icon-btn:active { background: rgba(255,255,255,0.4); }

/* ========== TOGGLE SWITCH (dial prefix) ========== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #d1d5db;
    border-radius: 26px;
    transition: background 0.2s;
}
.toggle-slider:before {
    position: absolute;
    content: '';
    height: 20px;
    width: 20px;
    right: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(-20px); }

/* ========== DIAL PREFIX INPUT ========== */
.prefix-input {
    width: 80px;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    text-align: center;
    background: var(--bg-card, #fff);
    color: var(--text-primary, #111);
    direction: ltr;
    font-family: inherit;
}
.prefix-input:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary);
}

/* ========== RESPONSIVE ========== */
@media (min-width: 421px) {
    #app {
        box-shadow: 0 0 60px rgba(0,0,0,0.2);
        border-radius: 24px;
        margin: 20px auto;
        height: calc(100vh - 40px);
    }
}

/* Small screens — scale down dialpad to fit without clipping */
@media (max-height: 700px) {
    :root { --dialpad-btn-size: 60px; }

    .sd-btn { height: 48px; }

    .dial-display { padding: 6px 16px 4px; }
    .dial-input { font-size: 1.7rem; }

    .dialpad-grid { gap: 2px; padding: 0 16px 4px; }

    .dial-feature-row { padding: 10px 0 8px; margin-top: 4px; gap: 28px; }
    .dial-icon-btn { width: 50px; height: 50px; }

    .dial-action-row { padding: 2px 40px 12px; }
    .dial-call-btn { width: 56px; height: 56px; font-size: 1.2rem; }
}

/* Very small screens (e.g. 360×640) — further reduction */
@media (max-height: 620px) {
    :root { --dialpad-btn-size: 52px; }

    .status-bar { padding: 5px 16px; min-height: 30px; }
    .sd-btn { height: 40px; }
    .sd-ribbon { padding: 3px 0 2px; }

    .dial-display { padding: 4px 16px 2px; }
    .dial-input { font-size: 1.5rem; padding: 4px 8px; }

    .dialpad-grid { gap: 1px; padding: 0 12px 2px; }
    .dial-key .key-digit { font-size: 1.25rem; }
    .dial-key .key-letters { font-size: 0.48rem; }

    .dial-feature-row { padding: 7px 0 6px; margin-top: 2px; gap: 24px; }
    .dial-icon-btn { width: 44px; height: 44px; font-size: 1rem; }

    .dial-action-row { padding: 2px 32px 8px; }
    .dial-call-btn { width: 50px; height: 50px; font-size: 1.1rem; }
    .dial-redial-btn { width: 40px; height: 40px; }

    .bottom-nav { padding: 2px 0 4px; }
    .nav-btn { padding: 5px 4px; font-size: 0.65rem; }
    .nav-btn i { font-size: 1.1rem; }
}

/* ========== MINI BAR (minimized mode) ========== */
.mini-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    max-width: 420px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
    color: white;
    z-index: 9999;
    font-family: 'Heebo', 'Segoe UI', Arial, sans-serif;
    direction: rtl;
    user-select: none;
    -webkit-user-select: none;
}
.mini-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
}
.mini-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-height: 28px;
}
.mini-reg-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
}
.mini-reg-label {
    opacity: 0.85;
    white-space: nowrap;
}
.mini-user-label {
    font-size: 0.72rem;
    opacity: 0.7;
    flex: 1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mini-top-actions {
    display: flex;
    gap: 4px;
}
.mini-top-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    border: none;
    cursor: pointer;
    color: white;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.mini-top-btn:hover { background: rgba(255,255,255,0.25); }
.mini-top-btn:active { background: rgba(255,255,255,0.35); }
.mini-top-btn.pinned { color: #fbbf24; }

.mini-ctrl-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 4px 0 6px;
}
.mini-ctrl-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    width: 50px;
    height: 50px;
    border-radius: 12px;
    background: rgba(255,255,255,0.12);
    border: none;
    cursor: pointer;
    color: white;
    font-size: 0.58rem;
    font-family: inherit;
    transition: background 0.15s;
}
.mini-ctrl-btn i { font-size: 1.15rem; margin-top: 6px; }
.mini-ctrl-btn span { line-height: 1; }
.mini-ctrl-btn:hover { background: rgba(255,255,255,0.22); }
.mini-ctrl-btn:active { background: rgba(255,255,255,0.35); }
.mini-ctrl-btn.active { background: rgba(255,255,255,0.3); }
.mini-ctrl-btn.dnd-active { background: rgba(239,68,68,0.25); color: #fca5a5; }
.mini-ctrl-btn.aa-active  { background: rgba(249,115,22,0.25); color: #fdba74; }
.mini-answer-btn { background: rgba(16,185,129,0.35) !important; }
.mini-answer-btn:hover { background: rgba(16,185,129,0.55) !important; }
.mini-hangup-btn { background: rgba(239,68,68,0.35) !important; }
.mini-hangup-btn:hover { background: rgba(239,68,68,0.55) !important; }

.mini-call-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
.mini-incall-name {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mini-incall-timer {
    font-size: 0.78rem;
    opacity: 0.8;
    font-variant-numeric: tabular-nums;
    direction: ltr;
    text-align: right;
}
.mini-incoming-info {
    font-size: 0.72rem;
    opacity: 0.8;
    text-align: center;
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
