/* ========================================
   Xoiton SIP - Финальная версия (v3)
   Защищено © Xoiton OS 2026
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

input, textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

body {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    min-height: 100vh;
    color: #fff;
    overflow-x: hidden;
    touch-action: manipulation;
}

.stars {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.star {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    animation: twinkle 2s infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.container {
    position: relative;
    z-index: 1;
    max-width: 400px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    padding: 15px 20px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
}

.status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #94a3b8;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-dot.connected { background: #4ade80; }
.status-dot.connecting { background: #fbbf24; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.nav {
    display: flex;
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 52px;
    z-index: 40;
}

.nav-btn {
    flex: 1;
    padding: 12px 8px;
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    border-bottom: 2px solid transparent;
}

.nav-btn.active {
    color: #fff;
    border-bottom-color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    padding-bottom: 80px;
}

.tab { display: none; }
.tab.active { display: block; }

.dialer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.display {
    width: 100%;
    padding: 15px;
    background: rgba(30, 41, 59, 0.6);
    border-radius: 12px;
    text-align: center;
    font-size: 28px;
    font-weight: 300;
    letter-spacing: 1px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

#displayNumber {
    flex: 1;
    text-align: center;
}

.clear-btn {
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 14px;
    cursor: pointer;
    margin-left: 10px;
}

.clear-btn:active { background: #dc2626; transform: scale(0.95); }

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

.key {
    aspect-ratio: 1;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 50%;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.key:active {
    background: rgba(59, 130, 246, 0.4);
    transform: scale(0.95);
}

.key span {
    font-size: 9px;
    color: #94a3b8;
    margin-top: 2px;
    letter-spacing: 0.5px;
}

.call-btn {
    grid-column: 2;
    background: #22c55e;
    border-color: #22c55e;
    font-size: 26px;
}

.call-btn:active { background: #16a34a; }

.backspace-btn {
    grid-column: 3;
    background: rgba(239, 68, 68, 0.3);
    border-color: #ef4444;
    font-size: 20px;
}

.backspace-btn:active { background: rgba(239, 68, 68, 0.5); }

.contacts-header { margin-bottom: 12px; }

.add-contact-btn {
    width: 100%;
    padding: 12px;
    background: rgba(59, 130, 246, 0.2);
    border: 1px dashed rgba(59, 130, 246, 0.5);
    border-radius: 10px;
    color: #3b82f6;
    font-size: 14px;
    cursor: pointer;
}

.add-contact-btn:active { background: rgba(59, 130, 246, 0.3); }

.contact-list { display: flex; flex-direction: column; gap: 8px; }

.contact {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(30, 41, 59, 0.6);
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.contact:active { background: rgba(30, 41, 59, 0.8); }

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
}

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-number { color: #94a3b8; font-size: 12px; }
.contact-note { color: #64748b; font-size: 11px; margin-top: 2px; }

.contact-actions { display: flex; gap: 8px; }

.action-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.action-btn:active { transform: scale(0.95); }

.call-action { background: #22c55e; color: #fff; }
.edit-action { background: #f59e0b; color: #fff; }
.delete-action { background: #ef4444; color: #fff; }

.history-header { margin-bottom: 12px; }

.clear-history-btn {
    width: 100%;
    padding: 10px;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: #ef4444;
    font-size: 13px;
    cursor: pointer;
}

.clear-history-btn:active { background: rgba(239, 68, 68, 0.3); }

.call-history { display: flex; flex-direction: column; gap: 8px; }

.call-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(30, 41, 59, 0.6);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.call-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.incoming { background: #22c55e; }
.outgoing { background: #3b82f6; }
.missed { background: #ef4444; }

.call-details { flex: 1; min-width: 0; }
.call-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.call-time { color: #94a3b8; font-size: 11px; }
.call-duration { color: #94a3b8; font-size: 11px; }

.settings { display: flex; flex-direction: column; gap: 15px; }

.setting-group {
    background: rgba(30, 41, 59, 0.6);
    border-radius: 10px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-group h3 {
    margin-bottom: 12px;
    color: #3b82f6;
    font-size: 14px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-item:last-child { border-bottom: none; }

.setting-label { font-size: 13px; color: #cbd5e1; }

.setting-input {
    padding: 8px 10px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 13px;
    width: 150px;
    max-width: 60%;
}

.setting-input:focus {
    outline: none;
    border-color: #3b82f6;
}

.setting-value { color: #4ade80; font-weight: 600; font-size: 13px; }

.toggle {
    width: 44px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
}

.toggle.active { background: #22c55e; }

.toggle::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: all 0.2s;
}

.toggle.active::after { left: 22px; }

.call-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    z-index: 100;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 25px;
    padding: 20px;
}

.call-screen.active { display: flex; }

.call-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    font-weight: 600;
    animation: pulse 2s infinite;
}

.call-info { text-align: center; }
.call-name { font-size: 24px; font-weight: 600; margin-bottom: 8px; }
.call-status { color: #94a3b8; font-size: 14px; }
.call-timer { font-size: 28px; font-weight: 300; color: #4ade80; margin-top: 5px; }

.call-controls {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-top: 30px;
    width: 100%;
    max-width: 280px;
}

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin: 0 auto;
}

.control-btn:active { transform: scale(0.95); }

.mute-btn { background: rgba(255, 255, 255, 0.2); }
.speaker-btn { background: rgba(255, 255, 255, 0.2); }
.hold-btn { background: rgba(255, 255, 255, 0.2); }
.end-call-btn { 
    background: #ef4444; 
    grid-column: span 2;
    width: 80px;
}

.retry-btn {
    background: #3b82f6;
    grid-column: span 2;
    width: 200px;
}

.cancel-btn {
    background: rgba(255, 255, 255, 0.2);
    grid-column: span 2;
    width: 200px;
}

.control-btn.active { background: #3b82f6; }

.wave {
    position: absolute;
    width: 180px;
    height: 180px;
    border: 2px solid rgba(59, 130, 246, 0.3);
    border-radius: 50%;
    animation: wave 2s infinite;
}

@keyframes wave {
    0% { transform: scale(0.5); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active { display: flex; }

.modal-content {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-radius: 14px;
    width: 100%;
    max-width: 360px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 { font-size: 16px; }

.modal-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    cursor: pointer;
    padding: 5px;
}

.modal-body { padding: 20px; }

.form-group { margin-bottom: 15px; }

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: #94a3b8;
    font-size: 12px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: #3b82f6;
}

.modal-footer {
    display: flex;
    gap: 8px;
    padding: 15px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-btn {
    flex: 1;
    padding: 10px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    border: none;
}

.modal-btn:active { transform: scale(0.98); }

.cancel-btn { background: rgba(255, 255, 255, 0.1); color: #fff; }
.save-btn { background: #3b82f6; color: #fff; }

.password-wrapper { position: relative; display: flex; align-items: center; width: 100%; }

.password-toggle {
    position: absolute;
    right: 10px;
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 16px;
    padding: 5px;
    z-index: 10;
}

.debug-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #0f172a;
    border-top: 1px solid #3b82f6;
    max-height: 180px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    font-family: monospace;
    font-size: 11px;
}

.debug-panel.active { display: block; }

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: rgba(59, 130, 246, 0.2);
    cursor: pointer;
    color: #fff;
    font-size: 12px;
}

.debug-header-buttons { display: flex; gap: 5px; }

.debug-header button {
    background: rgba(59, 130, 246, 0.3);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
}

.debug-header button.close { background: #ef4444; }

.debug-log { padding: 8px 10px; color: #94a3b8; }
.debug-log .info { color: #60a5fa; }
.debug-log .error { color: #f87171; }
.debug-log .sip { color: #4ade80; }
.debug-log .warn { color: #fbbf24; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: rgba(15, 23, 42, 0.5); }
::-webkit-scrollbar-thumb { background: rgba(59, 130, 246, 0.5); border-radius: 2px; }

@media (max-width: 360px) {
    .header h1 { font-size: 16px; }
    .keypad { max-width: 260px; gap: 10px; }
    .key { font-size: 20px; }
    .control-btn { width: 55px; height: 55px; font-size: 20px; }
    .call-avatar { width: 90px; height: 90px; font-size: 36px; }
    .call-name { font-size: 22px; }
    .call-timer { font-size: 26px; }
}

/* Fullscreen PWA */
@media all and (display-mode: standalone) {
    .header { padding-top: env(safe-area-inset-top); }
    .nav { top: calc(52px + env(safe-area-inset-top)); }
}