
:root {
    --bg-dark: #0f1014;
    --bg-panel: #1a1b20;
    --bg-input: #2a2b30;
    --border-color: #383a40;
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --accent-blue: #007aff;
    --accent-red: #ff3b30;
    --accent-green: #34c759;
    --accent-red-hover: #c70000;
    --accent-green-hover: #2aa14a;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-round: 50%;

    --padding-md: 16px;
    --padding-sm: 12px;

    --icon-arrow-down: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 16px;
    direction: rtl;
    text-align: right;
}

body {
    width: 100%;
    min-height: 100vh;
}

h1, h2, h3 {
    font-weight: 600;
    line-height: 1.3;
}

h1 {
    font-size: 1.75rem;
}

h2 {
    font-size: 1.25rem;
    margin-bottom: var(--padding-md);
}

h3 {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

button, input, select {
    font-family: inherit;
    font-size: 1rem;
}

img, video {
    max-width: 100%;
    display: block;
}

.wrap {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--padding-md);
    display: flex;
    flex-direction: column;
    gap: var(--padding-md);
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--padding-md);
    display: flex;
    flex-direction: column;
}

.icon-btn {
    font-size: 1rem;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-round);
    border: none;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;

    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn i {
    line-height: 1;
    color: var(--text-primary);
}

.icon-btn:not(:disabled):hover {
    filter: brightness(1.2);
}

.icon-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#authScreen {
    min-height: 100vh;
    justify-content: center;
}

.auth {
    max-width: 400px;
    margin: 0 auto;
    text-align: center;
    padding: 24px;
}

.auth h2 {
    color: var(--text-primary);
}

.auth input {
    width: 100%;
    margin-bottom: 12px;
    padding: 12px var(--padding-sm);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s;
}

.auth input::placeholder {
    color: var(--text-secondary);
}

.auth input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.3);
}

.auth button {
    width: 100%;
    padding: 12px;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.auth button:hover {
    filter: brightness(1.2);
}

.auth button:active {
    transform: scale(0.98);
}

.or {
    margin: 20px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.or::before, .or::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--padding-md);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--padding-md);
}

.me {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

#you {
    color: var(--text-primary);
    font-weight: 500;
}

#visibility, #callMode {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 8px 12px 8px 36px;
    cursor: pointer;
    background-image: var(--icon-arrow-down);
    background-repeat: no-repeat;
    background-position: left 10px center;
    outline: none;
    min-width: 150px;
}

#visibility:focus, #callMode {
    border-color: var(--accent-blue);
}

#callMode {
    width: 100%;
    margin-block: 10px;
}

#btnLogout {
    background-color: var(--bg-input);
}

#btnLogout i {
    color: var(--accent-red);
}

.list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 40vh;
    overflow-y: auto;
}

.user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: var(--padding-sm);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
}

.user .name {
    flex-grow: 1;
    font-weight: 500;
}

.user .badge {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.user .badge.busy {
    background: var(--accent-red);
    color: white;
}

.user .badge.free {
    background: var(--accent-green);
    color: white;
}

.user .btnCall {
    background: var(--accent-blue);
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
}

.user .btnCall:disabled {
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: not-allowed;
}

.add-friend {
    display: flex;
    gap: 8px;
    margin-top: var(--padding-md);
    border-top: 1px solid var(--border-color);
    padding-top: var(--padding-md);
}

.add-friend input {
    flex-grow: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px var(--padding-sm);
    border-radius: var(--radius-sm);
    outline: none;
}

.add-friend input:focus {
    border-color: var(--accent-blue);
}

#btnAddFriend {
    background-color: var(--accent-blue);
}

#btnAddFriend i {
    color: white;
}

.call .controls {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--padding-md);
    flex-wrap: wrap;
}

#status {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    opacity: 0.8;
}

#toggleVideo, #toggleAudio {
    background-color: var(--bg-input);
    width: 56px;
    height: 56px;
    font-size: 1.2rem;
}

#toggleVideo.active,
#toggleAudio.active {
    background-color: var(--accent-blue);
}

#toggleVideo.active i,
#toggleAudio.active i {
    color: white;
}

#btnHangup {
    background-color: var(--accent-red);
    width: 56px;
    height: 56px;
    font-size: 1.2rem;
}

#btnHangup i {
    color: white;
}

#btnHangup:hover {
    background-color: var(--accent-red-hover);
}

.videos {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

video {
    width: 100%;
    background: #000;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    aspect-ratio: 16/9;
    object-fit: cover;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 340px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

.modal-header {
    padding: var(--padding-sm);
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.modal-header h3 {
    color: var(--accent-blue);
    margin-bottom: 0;
}

.modal-body {
    padding: 24px var(--padding-md);
    text-align: center;
    font-size: 1.1rem;
}

.caller-avatar {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: var(--accent-blue);
    margin: 12px auto 20px;
    box-shadow: 0 0 0 0 rgba(0, 122, 255, 0.7);
    animation: pulse 1.5s infinite;
}

#callerName {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.modal-footer {
    display: flex;
    gap: 16px;
    padding: 0 var(--padding-md) 24px;
    justify-content: space-around;
}

#btnRejectCall, #btnAcceptCall {
    width: 64px;
    height: 64px;
    font-size: 1.5rem;
}

#btnRejectCall {
    background-color: var(--accent-red);
}

#btnAcceptCall {
    background-color: var(--accent-green);
}

#btnRejectCall i, #btnAcceptCall i {
    color: white;
}

#btnRejectCall:hover {
    background-color: var(--accent-red-hover);
}

#btnAcceptCall:hover {
    background-color: var(--accent-green-hover);
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    animation: toastFade 3s forwards;
    border: 1px solid var(--border-color);
}

.toast.error {
    background: var(--accent-red);
    color: white;
}

.toast.info {
    background: var(--accent-blue);
    color: white;
}

@keyframes toastFade {
    0%, 100% {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    15%, 85% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 122, 255, 0.7);
    }
    70% {
        box-shadow: 0 0 0 20px rgba(0, 122, 255, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 122, 255, 0);
    }
}

@media (min-width: 768px) {
    .wrap {
        padding: 24px;
    }

    header {
        flex-wrap: nowrap;
    }

    main {
        display: grid;
        grid-template-columns: 350px 1fr;
        gap: 20px;
        align-items: start;
    }

    .videos {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }

    .list {
        max-height: 60vh;
    }

    #status {
        position: relative;
        top: auto;
        right: auto;
        background: none;
        padding: 0;
        margin-right: auto;
    }
}

@media (max-width: 767px) {
    body:has(#btnHangup:not(:disabled)) header,
    body:has(#btnHangup:not(:disabled)) main section:not(.call) {
        display: none;
    }

    body:has(#btnHangup:not(:disabled)) .wrap {
        padding: 0;
    }

    body:has(#btnHangup:not(:disabled)) .panel.call {
        height: 100vh;
        border-radius: 0;
        border: none;
        justify-content: space-between;
        background: transparent;
    }

    body:has(#btnHangup:not(:disabled)) .videos {
        flex-grow: 1;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        gap: 0;
    }

    body:has(#btnHangup:not(:disabled)) .videos > div {
        height: 100%;
    }

    body:has(#btnHangup:not(:disabled)) video {
        height: 100%;
        border-radius: 0;
        border: none;
    }

    body:has(#btnHangup:not(:disabled)) .videos div:has(#localVideo) h3,
    body:has(#btnHangup:not(:disabled)) .videos div:has(#remoteVideo) h3 {
        display: none;
    }

    body:has(#btnHangup:not(:disabled)) .videos div:has(#localVideo) {
        position: absolute;
        bottom: 120px;
        left: 20px;
        width: 30%;
        height: auto;
        max-width: 130px;
        z-index: 10;
        border: 2px solid var(--border-color);
        border-radius: var(--radius-md);
        overflow: hidden;
    }

    body:has(#btnHangup:not(:disabled)) .panel.call .controls {
        position: absolute;
        bottom: 24px;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 20;
        margin-bottom: 0;
        padding: 0 var(--padding-md);
        background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
    }

    body:has(#btnHangup:not(:disabled)) #status {
        display: none;
    }
}

.secret-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-blue);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    font-size: 0.95rem;
    max-width: 90%;
    animation: slideDown 0.4s ease;
}

.secret-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.secret-content strong {
    font-family: monospace;
    font-size: 1.1rem;
    letter-spacing: 1px;
}

.copy-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

#showSecretBtn {
    background-color: var(--bg-input);
}

#showSecretBtn i {
    color: #ffd60a;
}

.toast.secret-toast {
    height: fit-content;
}

#btnNotifications {
    position: relative;
    background-color: var(--bg-input);
}

#notificationBadge {
    position: absolute;
    top: -6px;
    right: -6px;
    font-size: 0.65rem;
    min-width: 18px;
    height: 18px;
    background: var(--accent-red);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.notification-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: var(--padding-sm);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
}

.notification-item .content {
    flex-grow: 1;
}

.notification-item .type {
    font-weight: 600;
    color: var(--accent-blue);
    margin-bottom: 4px;
}

.notification-item .message {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.notification-item .actions {
    display: flex;
    gap: 8px;
}

.notification-item .actions button {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
}

.notification-item .accept {
    background: var(--accent-green);
    color: white;
}

.notification-item .reject,
.notification-item .delete {
    background: var(--accent-red);
    color: white;
}

.notification-item .accept:hover {
    background: var(--accent-green-hover);
}

.notification-item .reject:hover,
.notification-item .delete:hover {
    background: var(--accent-red-hover);
}

.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.chat-messages {
    flex-grow: 1;
    padding: 12px;
    overflow-y: auto;
}

.chat-msg {
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 12px;
    max-width: 80%;
    word-wrap: break-word;
}

.chat-msg.me {
    background: var(--accent-blue);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-msg.other {
    background: var(--bg-input);
    border-bottom-left-radius: 4px;
}

.chat-input {
    display: flex;
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

#chatInput {
    flex-grow: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    color: var(--text-primary);
}

#sendChat {
    background: var(--accent-blue);
    color: white;
    border: none;
    width: 44px;
    margin-left: 8px;
}

.sent-request {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.status-pending {
    color: #ffa500;
}

.status-offline {
    color: var(--text-secondary);
}

.status-accepted {
    color: var(--accent-green);
}

.status-rejected {
    color: var(--accent-red);
}

#switchMode {
    background: var(--bg-input);
}

#switchMode i {
    color: var(--accent-blue);
}