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

:root {
    --bg: #0a0a0a;
    --bg2: #141414;
    --bg3: #1c1c1c;
    --text: #fff;
    --text2: #999;
    --text3: #555;
    --green: #22c55e;
    --green-dark: #16a34a;
    --red: #ef4444;
    --red-dark: #dc2626;
    --accent: #3b82f6;
    --border: #222;
    --radius: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ===== TABS ===== */
.tab-content {
    display: none;
    flex-direction: column;
    height: calc(100vh - 70px - var(--safe-bottom));
    overflow-y: auto;
    padding: 12px 16px;
    padding-bottom: 20px;
}
.tab-content.active { display: flex; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(70px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 50;
}
.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    background: none;
    border: none;
    color: var(--text3);
    font-size: 11px;
    cursor: pointer;
    transition: color 0.2s;
}
.nav-btn.active { color: var(--green); }
.nav-btn svg { transition: fill 0.2s; }

/* ===== DIALPAD TAB ===== */
.active-account {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg2);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
.active-account:active { background: var(--bg3); }
.acc-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--red);
    flex-shrink: 0;
}
.acc-dot.online { background: var(--green); }
#activeAccountName {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}
.chevron { color: var(--text3); }

.sip-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 4px 0;
    font-size: 12px;
    color: var(--text2);
}
.status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.disconnected { background: var(--text3); }
.status-dot.connecting { background: #f59e0b; animation: pulse 1s infinite; }
.status-dot.registered { background: var(--green); }
.status-dot.error { background: var(--red); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Display */
.display {
    text-align: center;
    padding: 16px 8px 8px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.display-label {
    font-size: 12px;
    color: var(--text3);
    margin-bottom: 4px;
}
.display-number {
    font-size: 30px;
    font-weight: 300;
    letter-spacing: 1px;
    min-height: 38px;
    word-break: break-all;
    line-height: 1.2;
}
.display-number.small { font-size: 22px; }
.call-timer {
    font-size: 16px;
    color: var(--green);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

/* Dialpad grid */
.dialpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 4px 20px;
    max-width: 320px;
    margin: 0 auto;
}
.dkey {
    width: 72px; height: 72px;
    border-radius: 50%;
    border: none;
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    justify-self: center;
    transition: background 0.1s;
}
.dkey:active { background: #333; }
.dnum { font-size: 26px; font-weight: 400; line-height: 1; }
.dsub { font-size: 8px; letter-spacing: 1.5px; color: var(--text3); margin-top: 1px; }

/* Call actions */
.call-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    padding: 12px 0 8px;
}
.btn-call {
    width: 64px; height: 64px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background 0.15s;
}
.btn-call:active { transform: scale(0.95); }
.btn-call.green { background: var(--green); }
.btn-call.green:active { background: var(--green-dark); }
.btn-call.red { background: var(--red); }
.btn-call.red:active { background: var(--red-dark); }

.btn-action {
    width: 48px; height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--bg3);
    color: var(--text2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.btn-action:active { background: #333; }
.btn-action.active { background: #333; color: var(--green); }

/* ===== HISTORY TAB ===== */
.tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.tab-header h2 { font-size: 20px; font-weight: 600; }

.btn-clear-history {
    background: none;
    border: none;
    color: var(--red);
    font-size: 13px;
    cursor: pointer;
}

.history-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.filter-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg2);
    color: var(--text2);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.filter-btn.active {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}

.history-list {
    flex: 1;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}
.history-item:active { background: var(--bg2); }

.history-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.history-icon.outgoing { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.history-icon.incoming { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.history-icon.missed { background: rgba(239, 68, 68, 0.15); color: var(--red); }

.history-info { flex: 1; min-width: 0; }
.history-number {
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-number.missed { color: var(--red); }
.history-meta {
    font-size: 12px;
    color: var(--text3);
    display: flex;
    gap: 8px;
    margin-top: 2px;
}
.history-duration { font-size: 13px; color: var(--text2); text-align: right; white-space: nowrap; }
.history-account-tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bg3);
    color: var(--text2);
}

.empty-state {
    text-align: center;
    color: var(--text3);
    padding: 40px 0;
    font-size: 14px;
}

/* ===== ACCOUNTS TAB ===== */
.btn-add {
    background: var(--green);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-add:active { background: var(--green-dark); }

.accounts-list { flex: 1; }

.acc-card {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.1s;
    border: 2px solid transparent;
}
.acc-card:active { background: var(--bg3); }
.acc-card.active { border-color: var(--green); }

.acc-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
}

.acc-info { flex: 1; min-width: 0; }
.acc-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.acc-server-text {
    font-size: 12px;
    color: var(--text3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.acc-status-tag {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
    display: inline-block;
}
.acc-status-tag.online { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.acc-status-tag.offline { background: rgba(85, 85, 85, 0.3); color: var(--text3); }

.acc-actions {
    display: flex;
    gap: 8px;
}
.acc-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--bg3);
    color: var(--text2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.acc-btn:active { background: #333; }
.acc-btn.delete:active { color: var(--red); }

/* Account form */
.account-form {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 16px;
}
.account-form h3 {
    font-size: 16px;
    margin-bottom: 16px;
}
.form-field {
    margin-bottom: 12px;
}
.form-field label {
    display: block;
    font-size: 11px;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.form-field input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    outline: none;
}
.form-field input:focus { border-color: var(--green); }

.form-buttons {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}
.btn-save {
    flex: 1;
    padding: 12px;
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.btn-save:active { background: var(--green-dark); }
.btn-cancel {
    flex: 1;
    padding: 12px;
    background: var(--bg3);
    color: var(--text2);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

/* ===== INCOMING CALL ===== */
.incoming-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 200;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.incoming-overlay.active { display: flex; }

.incoming-card { text-align: center; }
.incoming-label {
    font-size: 14px;
    color: var(--text2);
    margin-bottom: 8px;
    animation: pulse 2s infinite;
}
.incoming-caller {
    font-size: 28px;
    font-weight: 300;
    margin-bottom: 4px;
}
.incoming-account {
    font-size: 13px;
    color: var(--text3);
    margin-bottom: 40px;
}
.incoming-buttons {
    display: flex;
    gap: 60px;
    justify-content: center;
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }
