/* ============================================================
   Air2Call — iOS-Style Dark Theme
   ============================================================ */

/* ---------- Variables ---------- */
:root {
    --bg:           #000000;
    --bg-secondary: #1C1C1E;
    --bg-tertiary:  #2C2C2E;
    --bg-elevated:  #3A3A3C;
    --text:         #FFFFFF;
    --text-secondary: #8E8E93;
    --text-tertiary: #636366;
    --accent:       #007AFF;
    --green:        #34C759;
    --red:          #FF3B30;
    --orange:       #FF9500;
    --separator:    rgba(255,255,255,0.08);
    --dial-btn:     #333333;
    --dial-btn-active: #4a4a4a;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    height: 100%; width: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.overlay { position: fixed; inset: 0; z-index: 100; }
.page { display: none; flex: 1; flex-direction: column; overflow-y: auto; }
.page.active { display: flex; }

/* ============================================================
   LOADING
   ============================================================ */
#loading-screen {
    align-items: center; justify-content: center;
    background: linear-gradient(160deg, #0a0a0a 0%, #111 100%);
    z-index: 200;
    transition: opacity .4s ease;
}
#loading-screen.hide { opacity: 0; pointer-events: none; }
.loading-logo { text-align: center; animation: fadeInUp .8s ease; }
.loading-icon { font-size: 56px; margin-bottom: 12px; }
.loading-logo h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.5px; }

/* ============================================================
   LOGIN
   ============================================================ */
#login-screen {
    align-items: center; justify-content: center;
    background: linear-gradient(180deg, #0d0d0d 0%, #000 100%);
    padding: 24px;
}
.login-wrapper { width: 100%; max-width: 380px; }

.login-header { text-align: center; margin-bottom: 40px; }
.login-icon { font-size: 52px; margin-bottom: 8px; animation: pulse 2.5s ease infinite; }
.login-header h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 6px; }
.login-header p { font-size: 14px; color: var(--text-secondary); }

.login-form { display: flex; flex-direction: column; gap: 14px; }

/* Input Groups */
.input-group {
    display: flex; align-items: center; gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--separator);
    border-radius: 14px;
    padding: 0 16px;
    height: 54px;
    transition: border-color .2s ease;
    cursor: pointer;
}
.input-group:focus-within { border-color: var(--accent); }
.input-group input {
    flex: 1; background: none; border: none; outline: none;
    color: var(--text); font-size: 16px; font-family: var(--font);
    height: 100%;
}
.input-group input::placeholder { color: var(--text-tertiary); }
.input-icon { font-size: 20px; color: var(--text-secondary); display: flex; align-items: center; }
.input-icon svg { stroke: var(--text-secondary); }
.input-prefix {
    font-size: 16px; font-weight: 600; color: var(--text-secondary);
    white-space: nowrap; padding-right: 8px; border-right: 1px solid var(--separator);
}
.input-value { flex: 1; font-size: 16px; color: var(--text); }
.input-chevron { color: var(--text-tertiary); display: flex; }

/* Login Button */
.btn-login {
    height: 54px; border: none; border-radius: 14px;
    background: var(--green);
    color: #fff; font-size: 17px; font-weight: 600; font-family: var(--font);
    cursor: pointer; margin-top: 8px;
    transition: transform .15s ease, opacity .15s ease;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-login:active { transform: scale(0.97); opacity: .85; }
.btn-login:disabled { opacity: .5; cursor: not-allowed; }
.btn-spinner {
    width: 20px; height: 20px;
    border: 2.5px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
.login-error { color: var(--red); font-size: 13px; text-align: center; min-height: 20px; margin-top: 4px; }

/* ============================================================
   APP SHELL
   ============================================================ */
#app-shell { background: var(--bg); }

/* ---------- Page Header ---------- */
.page-header {
    padding: 56px 20px 16px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
}
.page-header h2 { font-size: 32px; font-weight: 700; letter-spacing: -0.5px; }
.header-action {
    background: none; border: none;
    color: var(--accent); font-size: 16px; font-weight: 500;
    font-family: var(--font); cursor: pointer;
    padding: 4px 0; margin-bottom: 4px;
}
.header-action:active { opacity: .5; }

/* ---------- Call Log ---------- */
.call-log-list {
    flex: 1; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(90px + var(--safe-bottom));
}
.call-log-item {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--separator);
    cursor: pointer;
    transition: background .1s ease;
}
.call-log-item:active { background: var(--bg-secondary); }
.call-log-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.call-log-icon.completed { background: rgba(52,199,89,.12); color: var(--green); }
.call-log-icon.failed    { background: rgba(255,59,48,.12); color: var(--red); }
.call-log-icon svg { width: 18px; height: 18px; }
.call-log-info { flex: 1; min-width: 0; }
.call-log-number {
    font-size: 16px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.call-log-number.failed { color: var(--red); }
.call-log-meta {
    font-size: 13px; color: var(--text-secondary); margin-top: 2px;
}
.call-log-time {
    font-size: 13px; color: var(--text-secondary);
    white-space: nowrap; flex-shrink: 0;
}

/* ---------- Empty State ---------- */
.empty-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 40px; text-align: center;
    padding-bottom: 120px;
}
.empty-icon { font-size: 56px; margin-bottom: 16px; opacity: .6; }
.empty-state h3 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.empty-state p { font-size: 14px; color: var(--text-secondary); max-width: 240px; }

/* ============================================================
   DIALER / KEYPAD
   ============================================================ */
#page-keypad {
    justify-content: flex-end;
    padding-bottom: calc(80px + var(--safe-bottom));
}

.dialer-display {
    padding: 20px 24px 8px;
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dialer-number {
    font-size: 36px;
    font-weight: 300;
    letter-spacing: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    transition: font-size .15s ease;
}
.dialer-number.small { font-size: 26px; }

/* Dialpad Grid */
.dialpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 12px 32px;
    max-width: 360px;
    margin: 0 auto;
    width: 100%;
}
.dial-btn {
    aspect-ratio: 1;
    max-height: 80px;
    border-radius: 50%;
    border: none;
    background: var(--dial-btn);
    color: var(--text);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    cursor: pointer;
    transition: background .1s ease, transform .1s ease;
    -webkit-tap-highlight-color: transparent;
}
.dial-btn:active {
    background: var(--dial-btn-active);
    transform: scale(0.93);
}
.dial-btn .digit {
    font-size: 30px;
    font-weight: 400;
    line-height: 1;
}
.dial-btn .letters {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
    margin-top: 2px;
    text-transform: uppercase;
}

/* Dialer Action Row */
.dialer-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 36px;
    padding: 12px 32px 8px;
    max-width: 360px;
    margin: 0 auto;
    width: 100%;
}
.action-spacer { width: 56px; }
.btn-call {
    width: 68px; height: 68px;
    border-radius: 50%; border: none;
    background: var(--green);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: transform .1s ease, box-shadow .2s ease;
    box-shadow: 0 4px 20px rgba(52,199,89,.35);
}
.btn-call:active { transform: scale(0.9); }
.btn-backspace {
    width: 56px; height: 56px;
    border: none; background: none;
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: opacity .15s ease;
}
.btn-backspace:active { opacity: .5; }

/* ============================================================
   BOTTOM NAV
   ============================================================ */
#bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(70px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(28,28,30,.92);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--separator);
    display: flex; align-items: flex-start; justify-content: space-around;
    padding-top: 6px;
    z-index: 50;
}
.nav-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; gap: 3px;
    background: none; border: none;
    color: var(--text-tertiary);
    font-size: 10px; font-family: var(--font); font-weight: 500;
    cursor: pointer; padding: 4px 0;
    transition: color .2s ease;
}
.nav-item svg { stroke: var(--text-tertiary); transition: stroke .2s ease; }
.nav-item.active { color: var(--accent); }
.nav-item.active svg { stroke: var(--accent); }

/* Center Keypad Button */
.nav-center { position: relative; }
.nav-center-btn {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    margin-top: -16px;
    box-shadow: 0 4px 16px rgba(0,122,255,.4);
    transition: transform .15s ease, box-shadow .15s ease;
}
.nav-center:active .nav-center-btn { transform: scale(0.9); }
.nav-center span { display: none; }

/* ============================================================
   ACCOUNT PAGE
   ============================================================ */
#page-account {
    padding-bottom: calc(100px + var(--safe-bottom));
}
.account-content {
    padding: 0 20px;
    display: flex; flex-direction: column; align-items: center;
}
.account-avatar {
    width: 88px; height: 88px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #5856D6);
    display: flex; align-items: center; justify-content: center;
    font-size: 36px; font-weight: 600; color: #fff;
    margin-bottom: 8px;
}
.account-phone {
    font-size: 15px; color: var(--text-secondary); margin-bottom: 28px;
}

.settings-section {
    width: 100%;
    background: var(--bg-secondary);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 14px;
}
.settings-label {
    font-size: 12px; font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 10px;
}
.settings-row {
    display: flex; gap: 10px; align-items: center;
}
.settings-input {
    flex: 1; background: var(--bg-tertiary);
    border: 1px solid var(--separator); border-radius: 10px;
    padding: 10px 14px; font-size: 15px; font-family: var(--font);
    color: var(--text); outline: none;
}
.settings-input:focus { border-color: var(--accent); }
.btn-save {
    padding: 10px 20px; border: none; border-radius: 10px;
    background: var(--accent); color: #fff;
    font-size: 14px; font-weight: 600; font-family: var(--font);
    cursor: pointer; white-space: nowrap;
    transition: opacity .15s ease;
}
.btn-save:active { opacity: .7; }

.settings-value {
    font-size: 17px; font-weight: 500;
    display: flex; align-items: center; gap: 6px;
}
.rate-amount { color: var(--green); font-weight: 700; font-size: 22px; }
.rate-unit { color: var(--text-secondary); font-size: 14px; }

.sip-dot {
    width: 10px; height: 10px; border-radius: 50%;
    display: inline-block;
    background: var(--red);
    transition: background .3s ease;
}
.sip-dot.connected { background: var(--green); }
.sip-dot.connecting { background: var(--orange); animation: blink 1s ease infinite; }

.btn-clear-cache {
    width: 100%; height: 50px; border: none; border-radius: 14px;
    background: rgba(255,149,0,.12);
    color: var(--orange); font-size: 16px; font-weight: 600; font-family: var(--font);
    cursor: pointer; margin-top: 12px;
    transition: background .15s ease;
}
.btn-clear-cache:active { background: rgba(255,149,0,.22); }

.btn-logout {
    width: 100%; height: 50px; border: none; border-radius: 14px;
    background: rgba(255,59,48,.12);
    color: var(--red); font-size: 16px; font-weight: 600; font-family: var(--font);
    cursor: pointer; margin-top: 12px;
    transition: background .15s ease;
}
.btn-logout:active { background: rgba(255,59,48,.22); }

/* ============================================================
   CALL SCREEN
   ============================================================ */
#call-screen {
    background: linear-gradient(180deg, #1a1a2e 0%, #0d0d0d 100%);
    display: flex; flex-direction: column;
    align-items: center; justify-content: space-between;
    padding: 100px 24px calc(80px + var(--safe-bottom));
    z-index: 110;
    animation: fadeIn .3s ease;
}
.call-info { text-align: center; }
.call-number {
    font-size: 34px; font-weight: 300; letter-spacing: 1.5px;
    margin-bottom: 12px;
}
.call-status {
    font-size: 16px; color: var(--text-secondary);
    animation: blink 1.5s ease infinite;
}
.call-timer {
    font-size: 20px; font-weight: 500; color: var(--green);
    margin-top: 8px; font-variant-numeric: tabular-nums;
}

.call-actions, .call-controls { 
    width: 100%;
    display: flex; justify-content: center;
    margin-top: auto;
}
.control-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px 24px;
    width: 100%;
    max-width: 320px;
}
.call-btn {
    background: none; border: none;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    color: #fff; cursor: pointer;
    font-family: var(--font);
}
.call-btn-icon {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    transition: all .2s ease;
}
.call-btn:active .call-btn-icon {
    background: rgba(255,255,255,0.3);
    transform: scale(0.92);
}
.call-btn.active .call-btn-icon {
    background: #fff;
    color: #000;
}
.call-btn span {
    font-size: 14px; font-weight: 400; opacity: 0.9;
}
.call-btn-icon.end-icon {
    background: var(--red);
    box-shadow: 0 4px 16px rgba(255,59,48,0.4);
    backdrop-filter: none; -webkit-backdrop-filter: none;
}
.btn-end-call:active .end-icon {
    background: #d92b1f;
}
[data-theme="light"] .call-btn { color: #000; }
[data-theme="light"] .call-btn-icon { background: rgba(0,0,0,0.06); color: #000; }
[data-theme="light"] .call-btn:active .call-btn-icon { background: rgba(0,0,0,0.12); }
[data-theme="light"] .call-btn.active .call-btn-icon { background: #000; color: #fff; }
[data-theme="light"] .call-btn-icon.end-icon { background: var(--red); color: #fff; }

/* In-call Keypad */
.incall-keypad {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(13,13,13,0.95);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    display: flex; flex-direction: column;
    z-index: 120;
    padding-top: calc(60px + var(--safe-top));
    padding-bottom: calc(40px + var(--safe-bottom));
}
[data-theme="light"] .incall-keypad { background: rgba(245,245,250,0.95); }
.incall-display {
    height: 60px; font-size: 32px; font-weight: 300;
    text-align: center; color: #fff;
    display: flex; align-items: center; justify-content: center;
    letter-spacing: 2px; margin-bottom: 20px;
}
[data-theme="light"] .incall-display { color: #000; }
.btn-hide-keypad {
    background: none; border: none;
    color: #fff; font-size: 18px; padding: 20px;
    cursor: pointer;
}
[data-theme="light"] .btn-hide-keypad { color: #000; }

/* ============================================================
   COUNTRY MODAL
   ============================================================ */
#country-modal {
    background: rgba(0,0,0,.55);
    display: flex; align-items: flex-end;
    z-index: 120;
    animation: fadeIn .2s ease;
}
.modal-sheet {
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 85vh;
    display: flex; flex-direction: column;
    animation: slideUp .35s cubic-bezier(.16,1,.3,1);
}
.modal-handle {
    width: 36px; height: 5px;
    background: var(--bg-elevated);
    border-radius: 3px;
    margin: 10px auto 0;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px 8px;
}
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: none; color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.modal-search {
    padding: 8px 20px 12px;
}
.modal-search input {
    width: 100%; height: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--separator); border-radius: 10px;
    padding: 0 14px; font-size: 15px; font-family: var(--font);
    color: var(--text); outline: none;
}
.modal-search input:focus { border-color: var(--accent); }
.modal-search input::placeholder { color: var(--text-tertiary); }

.modal-list {
    flex: 1; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.country-row {
    display: flex; align-items: center; gap: 14px;
    padding: 13px 20px;
    cursor: pointer;
    transition: background .1s ease;
    border-bottom: 1px solid var(--separator);
}
.country-row:active { background: var(--bg-tertiary); }
.country-flag { font-size: 26px; line-height: 1; }
.country-name { flex: 1; font-size: 15px; }
.country-code { font-size: 14px; color: var(--text-secondary); font-weight: 500; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
    from { opacity: 0; } to { opacity: 1; }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: .4; }
}

/* ============================================================
   LIGHT THEME
   ============================================================ */
[data-theme="light"] {
    --bg:           #FFFFFF;
    --bg-secondary: #F2F2F7;
    --bg-tertiary:  #E5E5EA;
    --bg-elevated:  #D1D1D6;
    --text:         #000000;
    --text-secondary: #8E8E93;
    --text-tertiary: #AEAEB2;
    --separator:    rgba(0,0,0,0.08);
    --dial-btn:     #E0E0E2;
    --dial-btn-active: #C8C8CC;
}
[data-theme="light"] #loading-screen {
    background: linear-gradient(160deg, #f5f5f5 0%, #fff 100%);
}
[data-theme="light"] #login-screen {
    background: linear-gradient(180deg, #f0f0f5 0%, #fff 100%);
}
[data-theme="light"] #bottom-nav {
    background: rgba(242,242,247,.92);
    border-top-color: rgba(0,0,0,.08);
}
[data-theme="light"] #call-screen {
    background: linear-gradient(180deg, #e8e8f0 0%, #f5f5fa 100%);
}
[data-theme="light"] #country-modal {
    background: rgba(0,0,0,.3);
}
[data-theme="light"] .btn-login {
    box-shadow: 0 4px 16px rgba(52,199,89,.25);
}
[data-theme="light"] .btn-call {
    box-shadow: 0 4px 16px rgba(52,199,89,.25);
}
[data-theme="light"] .nav-center-btn {
    box-shadow: 0 4px 12px rgba(0,122,255,.25);
}
[data-theme="light"] .btn-end-call {
    box-shadow: 0 4px 16px rgba(255,59,48,.25);
}
[data-theme="light"] .call-number,
[data-theme="light"] .call-status {
    color: #000;
}

/* ---------- iOS Toggle Switch ---------- */
.toggle-switch {
    position: relative;
    width: 51px; height: 31px;
    display: inline-block; flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--bg-elevated);
    border-radius: 31px; cursor: pointer;
    transition: background .3s ease;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 27px; height: 27px;
    left: 2px; bottom: 2px;
    background: #fff; border-radius: 50%;
    transition: transform .3s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--green);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ============================================================
   RESPONSIVE (very small screens)
   ============================================================ */
@media (max-height: 640px) {
    .dialpad { gap: 10px; padding: 8px 24px; }
    .dial-btn .digit { font-size: 24px; }
    .dialer-number { font-size: 28px; }
    .dialer-display { padding: 12px 20px 4px; }
    .btn-call { width: 58px; height: 58px; }
}
@media (max-height: 560px) {
    .dialpad { gap: 6px; padding: 4px 20px; }
    .dial-btn { max-height: 60px; }
    .dial-btn .digit { font-size: 22px; }
    .dial-btn .letters { display: none; }
    .dialer-display { padding: 8px 16px 2px; min-height: 40px; }
    .dialer-number { font-size: 24px; }
    .dialer-actions { padding: 6px 20px 4px; gap: 24px; }
    .btn-call { width: 52px; height: 52px; }
}

