* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;

    background:
        radial-gradient(circle at 50% 15%,
            #18345c 0%,
            #102544 35%,
            #0a172b 72%,
            #080f1d 100%);

    color: #f4f6fa;
    font-family: Arial, Helvetica, sans-serif;
}

body { overscroll-behavior: none; }

button, input { font: inherit; }

button {
    border: 0;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

button:disabled { cursor: default; }

.app { width: 100%; height: 100%; }

.screen { display: none; width: 100%; height: 100%; }

.screen.active { display: flex; }


/* =========================================================
   LOGIN
   ========================================================= */

#loginScreen {
    position: relative;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    padding:
        calc(25px + env(safe-area-inset-top))
        25px
        calc(25px + env(safe-area-inset-bottom));

    background:
        radial-gradient(circle at 50% 35%,
            rgba(86, 27, 48, .55) 0%,
            rgba(24, 52, 92, .4) 30%,
            transparent 65%),
        linear-gradient(145deg, #081426 0%, #102746 52%, #240f1e 100%);
}

.login-content {
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ЛОГОТИП — РОМБ (вместо круга) */

.emblem {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.emblem::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1px solid rgba(160, 38, 66, .8);
    background:
        radial-gradient(circle,
            rgba(42, 76, 119, .9),
            rgba(13, 28, 50, .95));
    box-shadow:
        0 0 35px rgba(124, 28, 55, .4),
        inset 0 0 25px rgba(255, 255, 255, .04);
    z-index: 0;
}

.login-emblem {
    width: 150px;
    height: 150px;
    margin-bottom: 30px;
    padding: 0;
    box-sizing: border-box;
}

.login-emblem img {
    position: relative;
    z-index: 1;
    width: 62%;
    height: 62%;
    object-fit: contain;
    border-radius: 0;
    filter: drop-shadow(0 2px 12px rgba(0, 0, 0, .7));
}


.login-title {
    font-size: 31px;
    font-weight: 800;
    letter-spacing: 7px;
    text-align: center;
    text-shadow: 0 2px 12px rgba(0, 0, 0, .5);
    color: #f5f7fb;
}

.login-subtitle {
    margin-top: 9px;
    color: #a9b4c7;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 2.4px;
    text-align: center;
}

.login-line {
    width: 100%;
    height: 1px;
    margin: 28px 0 25px;
    background: linear-gradient(90deg, transparent, #76253f, #b33a59, #76253f, transparent);
}

.login-box { width: 100%; }

.input-label {
    margin: 13px 0 7px;
    color: #9da9bc;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.7px;
}

.login-box input {
    display: block;
    width: 100%;
    height: 52px;
    padding: 0 16px;
    border: 1px solid #304463;
    border-radius: 7px;
    outline: none;
    background: rgba(5, 15, 29, .72);
    color: #fff;
    font-size: 16px;
    transition: border-color .15s, box-shadow .15s;
}

.login-box input::placeholder { color: #53647c; }

.login-box input:focus {
    border-color: #a43150;
    box-shadow: 0 0 0 1px rgba(164, 49, 80, .25), 0 0 18px rgba(164, 49, 80, .15);
}

.main-button {
    width: 100%;
    height: 54px;
    margin-top: 24px;
    border: 1px solid #a83252;
    border-radius: 7px;
    background: linear-gradient(135deg, #7d2340, #a93253);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 2.5px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, .25);
    transition: transform .08s, filter .15s;
}

.main-button:active { transform: scale(.98); }

.error {
    min-height: 20px;
    margin-top: 13px;
    text-align: center;
    color: #e05b78;
    font-size: 12px;
}


/* =========================================================
   PHONE SCREEN
   ========================================================= */

#phoneScreen {
    position: relative;
    flex-direction: column;
    background:
        radial-gradient(circle at 50% 30%, rgba(27, 62, 104, .42), transparent 55%),
        linear-gradient(150deg, #081426, #102746 55%, #1d0e1a);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-shrink: 0;
    padding:
        calc(12px + env(safe-area-inset-top))
        17px
        11px;
    border-bottom: 1px solid #64213a;
    background: linear-gradient(180deg, rgba(7, 17, 32, .92), rgba(11, 27, 48, .76));
}

.header-left { min-width: 0; }

.main-title {
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 4px;
    color: #f5f7fb;
}

.registration-number {
    margin-top: 5px;
    color: #b8c3d4;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
}

.user-name {
    margin-top: 3px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #71839d;
    font-size: 10px;
    letter-spacing: 1px;
}

.header-status {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding-top: 2px;
}

.status {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1px;
    white-space: nowrap;
}

.status-online { color: #67d59a; }
.status-offline { color: #c05770; }

.status-detail {
    margin-top: 4px;
    color: #71839d;
    font-size: 8px;
    letter-spacing: .8px;
    white-space: nowrap;
}

.phone {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 8px 12px calc(5px + env(safe-area-inset-bottom));
}

.number-area {
    width: 100%;
    min-height: 63px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.number-display {
    width: 100%;
    height: 38px;
    overflow: hidden;
    text-align: center;
    color: #f6f8fb;
    font-size: 29px;
    font-weight: 500;
    line-height: 38px;
    letter-spacing: 4px;
    white-space: nowrap;
}

.call-status {
    height: 14px;
    color: #8292a9;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: 1.7px;
}

.call-duration {
    height: 15px;
    color: #c34a68;
    font-family: monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
}


/* =========================================================
   KEYPAD
   ========================================================= */

.keypad {
    width: 100%;
    max-width: 355px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 7px;
    margin-top: 4px;
}

.keypad button {
    aspect-ratio: 1.18;
    min-height: 42px;
    border: 1px solid #304967;
    border-radius: 6px;
    background: linear-gradient(145deg, rgba(25, 52, 83, .95), rgba(13, 31, 53, .95));
    color: #f4f6fa;
    font-size: 20px;
    font-weight: 500;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.04), 0 3px 8px rgba(0,0,0,.18);
    transition: transform .06s, background .08s, border-color .08s;
}

.keypad button:active {
    transform: scale(.95);
    border-color: #a53655;
    background: linear-gradient(145deg, #64213a, #391827);
}

.keypad-special {
    color: #c15b75 !important;
    border-color: #64233d !important;
}


/* =========================================================
   CALL CONTROLS — 3 кнопки
   ========================================================= */

.call-controls {
    width: 100%;
    max-width: 355px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-top: 9px;
}

.call-button,
.call-video-button,
.hangup-button {
    height: 52px;
    border-radius: 7px;
    font-size: 9px;
    font-weight: 900;
    letter-spacing: 1.3px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    transition: transform .07s, filter .12s, opacity .15s;
}

.call-icon {
    font-size: 16px;
    line-height: 1;
}

.call-button {
    border: 1px solid #3c8d69;
    background: linear-gradient(135deg, #245e49, #307a5b);
    color: #f4fff9;
}

.call-video-button {
    border: 1px solid #4a7bd6;
    background: linear-gradient(135deg, #234a8a, #2d5fb5);
    color: #f0f6ff;
}

.hangup-button {
    border: 1px solid #8f304b;
    background: linear-gradient(135deg, #591d35, #76233f);
    color: #fff;
}

.call-button:active,
.call-video-button:active,
.hangup-button:active {
    transform: scale(.96);
}

.call-button:disabled,
.call-video-button:disabled,
.hangup-button:disabled {
    opacity: .32;
}


/* =========================================================
   FUNCTION ROW
   ========================================================= */

.function-row {
    width: 100%;
    max-width: 355px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-top: 8px;
}

.function-button {
    min-height: 48px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    border: 1px solid #2e4664;
    border-radius: 6px;
    background: rgba(10, 27, 47, .78);
    color: #8ea0b7;
    font-size: 7px;
    font-weight: 800;
    letter-spacing: .7px;
    transition: transform .07s, background .12s, border-color .12s, color .12s;
}

.function-button:active { transform: scale(.96); }

.function-button.active {
    border-color: #a93454;
    background: rgba(100, 28, 53, .6);
    color: #f08aa1;
}

.function-icon {
    font-size: 16px;
    line-height: 17px;
}


/* =========================================================
   BOTTOM AREA
   ========================================================= */

.bottom-area {
    position: relative;
    width: 100%;
    max-width: 355px;
    flex: 1;
    min-height: 70px;
    margin-top: 7px;
    overflow: hidden;
    border-top: 1px solid #67233d;
    border-bottom: 1px solid #67233d;
    background: linear-gradient(180deg, rgba(7, 19, 35, .65), rgba(24, 10, 19, .72));
}

.emblem-area {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* РОМБ вместо круга */
.emblem-area img {
    width: 42px;
    height: 42px;
    object-fit: contain;
    opacity: .6;
    border-radius: 0;
    filter: drop-shadow(0 0 14px rgba(160, 39, 69, .35));
}


.debug {
    position: absolute;
    inset: 0;
    display: none;
    padding: 7px;
    overflow-y: auto;
    background: rgba(4, 12, 23, .97);
    color: #8291a6;
    font-family: monospace;
    font-size: 8px;
    line-height: 1.35;
    z-index: 5;
}

.debug.active { display: block; }

.account-row {
    width: 100%;
    max-width: 355px;
    display: flex;
    justify-content: center;
    padding-top: 6px;
}

.logout-button {
    height: 27px;
    padding: 0 20px;
    border: 1px solid #4d2635;
    border-radius: 5px;
    background: transparent;
    color: #7e6871;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 1.5px;
    transition: color .12s, border-color .12s, background .12s;
}

.logout-button:active {
    color: #ef7c98;
    border-color: #87314c;
    background: rgba(119, 29, 53, .2);
}


/* =========================================================
   INCOMING CALL OVERLAY
   ========================================================= */

#incomingCallOverlay {
    position: fixed;
    inset: 0;
    z-index: 999997;
    display: none;
    align-items: center;
    justify-content: center;
    padding:
        calc(20px + env(safe-area-inset-top))
        20px
        calc(20px + env(safe-area-inset-bottom));
    background: rgba(4, 10, 20, .88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

#incomingCallOverlay.visible { display: flex; }

#incomingCallBox {
    width: min(380px, calc(100vw - 40px));
    padding: 30px 25px 25px;
    border: 1px solid rgba(164, 49, 80, .75);
    border-radius: 14px;
    background:
        radial-gradient(circle at 50% 0%, rgba(30, 61, 99, .55), transparent 55%),
        linear-gradient(145deg, #0a182c, #101f37 55%, #240f1e);
    box-shadow: 0 25px 80px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.05);
    text-align: center;
    color: #fff;
}

/* РОМБ-эмблема во входящем */
.incoming-emblem {
    position: relative;
    width: 110px;
    height: 110px;
    margin: 0 auto 26px;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: visible;
}

.incoming-emblem::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;

    border: 1px solid rgba(164, 49, 80, .85);

    background:
        radial-gradient(circle,
            rgba(42, 76, 119, .9),
            rgba(13, 28, 50, .95));

    box-shadow: 0 0 28px rgba(164, 49, 80, .4);
    z-index: 0;
}

.incoming-emblem img {
    position: relative;
    z-index: 1;
    width: 62%;
    height: 62%;
    object-fit: contain;
    border-radius: 0;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, .5));
}


.incoming-title {
    color: #f5f7fb;
    font-size: 17px;
    font-weight: 900;
    letter-spacing: 3px;
    margin-bottom: 11px;
}

.incoming-type {
    margin-bottom: 8px;
    color: #a9b4c7;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 2.2px;
}

#incomingCaller {
    min-height: 25px;
    margin-bottom: 25px;
    color: #aebbd0;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 1.5px;
    word-break: break-word;
}

.incoming-line {
    width: 100%;
    height: 1px;
    margin: 0 0 22px;
    background: linear-gradient(90deg, transparent, #76253f, #b33a59, #76253f, transparent);
}

.incoming-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
}

.incoming-buttons button {
    height: 52px;
    border-radius: 6px;
    font-size: 9px;
    font-weight: 900;
    letter-spacing: 1.4px;
    transition: transform .07s, filter .12s, opacity .12s;
}

.incoming-buttons button:active { transform: scale(.96); }
.incoming-buttons button:disabled { opacity: .4; }

#incomingRejectButton {
    border: 1px solid #762d45;
    background: linear-gradient(135deg, #381525, #541d32);
    color: #e4a0b0;
}

#incomingAcceptButton {
    border: 1px solid #3c8d69;
    background: linear-gradient(135deg, #245e49, #307a5b);
    color: #f4fff9;
}


/* =========================================================
   VIDEO AREA
   ========================================================= */

.video-area {
    position: fixed;
    inset: 0;
    z-index: 999998;
    display: none;
    background: #000;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.video-area.visible { display: block; }

.remote-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
    z-index: 1;
}

.local-video-wrapper {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top));
    right: 14px;
    width: 28vw;
    max-width: 160px;
    min-width: 100px;
    aspect-ratio: 3 / 4;
    border-radius: 14px;
    overflow: hidden;
    background: #111;
    box-shadow:
        0 8px 24px rgba(0, 0, 0, .7),
        0 0 0 2px rgba(255, 255, 255, .14);
    z-index: 4;
}

.local-video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #111;
    transform: scaleX(-1);
}

.local-video-label {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.2px;
}

.video-status-bar {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top));
    left: 14px;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, .5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .8px;
    display: flex;
    gap: 12px;
    align-items: center;
    z-index: 4;
}

#videoTimerLabel {
    color: #c34a68;
    font-family: monospace;
    font-weight: 800;
}

.video-minimize-btn {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, .5);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    z-index: 5;
}

.video-minimize-btn:active {
    transform: translateX(-50%) scale(.9);
}

.video-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(20px + env(safe-area-inset-bottom));
    padding: 0 12px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    z-index: 5;
    transition: opacity .3s, transform .3s;
}

.video-controls.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.vc-btn {
    flex: 0 0 auto;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .25);
    background: rgba(20, 30, 50, .78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    transition: transform .1s, background .2s, border-color .2s;
}

.vc-btn:active { transform: scale(.92); }

.vc-icon { font-size: 22px; line-height: 1; }

.vc-label {
    font-size: 6.5px;
    font-weight: 800;
    letter-spacing: .7px;
    opacity: .9;
}

.vc-btn.active {
    background: rgba(164, 49, 80, .9);
    border-color: rgba(255, 120, 150, .55);
}

.vc-btn.vc-hangup {
    background: rgba(180, 30, 55, .92);
    border-color: rgba(255, 100, 130, .5);
}

@media (max-width: 380px) {
    .local-video-wrapper {
        width: 34vw;
        max-width: 130px;
        min-width: 90px;
        top: calc(10px + env(safe-area-inset-top));
        right: 10px;
    }

    .vc-btn { width: 58px; height: 58px; }
    .vc-icon { font-size: 19px; }
    .video-controls { gap: 7px; padding: 0 8px; }
}

@media (orientation: landscape) and (max-height: 500px) {
    .local-video-wrapper { width: 18vh; max-width: 140px; }
    .vc-btn { width: 54px; height: 54px; }
}


/* =========================================================
   DESKTOP
   ========================================================= */

@media (min-width: 700px) {

    body {
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .app {
        width: 430px;
        height: 850px;
        max-height: 95vh;
        overflow: hidden;
        border: 1px solid #472238;
        border-radius: 24px;
        box-shadow: 0 25px 80px rgba(0,0,0,.55);
    }

    .video-area {
        width: 100vw !important;
        height: 100vh !important;
        inset: 0 !important;
    }
}

@media (max-height: 700px) {
    .header {
        padding-top: calc(7px + env(safe-area-inset-top));
        padding-bottom: 7px;
    }
    .main-title { font-size: 17px; }
    .registration-number { margin-top: 3px; }
    .number-area { min-height: 51px; }
    .number-display { height: 31px; font-size: 25px; line-height: 31px; }
    .keypad { gap: 5px; margin-top: 2px; }
    .keypad button { min-height: 36px; font-size: 18px; }
    .call-controls { margin-top: 6px; }
    .call-button, .call-video-button, .hangup-button { height: 42px; }
    .function-row { margin-top: 5px; }
    .function-button { min-height: 40px; }
    .bottom-area { min-height: 48px; margin-top: 5px; }
    .emblem-area img { width: 36px; height: 36px; }
    .account-row { padding-top: 3px; }
}

@media (max-width: 380px) {
    .header { padding-left: 11px; padding-right: 11px; }
    .main-title { font-size: 17px; letter-spacing: 3px; }
    .status, .status-detail { font-size: 7px; }
    .phone { padding-left: 7px; padding-right: 7px; }
    .keypad, .call-controls, .function-row, .bottom-area, .account-row { max-width: 340px; }
    .keypad { gap: 5px; }
    .keypad button { font-size: 18px; }
}


/* =========================================================
   INCOMING PULSE — простое расширяющееся кольцо
   ========================================================= */

.incoming-emblem::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(220, 80, 110, .7);
    z-index: 0;
    pointer-events: none;
    animation: incomingPulseRing 1.6s ease-out infinite;
}

@keyframes incomingPulseRing {
    0% {
        transform: scale(1);
        opacity: 0.9;
    }
    100% {
        transform: scale(1.9);
        opacity: 0;
    }
}
