/* =========================================================
   THEME VARIABLES
========================================================= */

[data-theme="dark"] {
    --bg-base: #090d16;
    --bg-card: #111827;
    --bg-input: #030712;
    --border-color: #1f293d;
    --border-focus: #3b82f6;

    --text-main: #f3f4f6;
    --text-muted: #9ca3af;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    --success: #10b981;

    --danger: #ef4444;

    --dot-color: rgba(255, 255, 255, 0.08);

    --card-shadow:
        0 20px 25px -5px rgba(0, 0, 0, 0.5),
        0 8px 10px -6px rgba(0, 0, 0, 0.5);

    --modal-overlay: rgba(0, 0, 0, 0.72);
}


[data-theme="light"] {
    --bg-base: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    --border-color: #cbd5e1;
    --border-focus: #2563eb;

    --text-main: #0f172a;
    --text-muted: #64748b;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    --success: #059669;

    --danger: #ef4444;

    --dot-color: rgba(0, 0, 0, 0.08);

    --card-shadow:
        0 10px 25px -5px rgba(0, 0, 0, 0.05),
        0 8px 10px -6px rgba(0, 0, 0, 0.03);

    --modal-overlay: rgba(15, 23, 42, 0.45);
}


/* =========================================================
   GLOBAL RESET
========================================================= */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}


html,
body {
    width: 100%;
    min-height: 100%;
}


body {
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;

    background-color: var(--bg-base);
    color: var(--text-main);

    min-height: 100vh;

    display: flex;
    justify-content: center;
    align-items: center;

    padding: 20px;

    transition:
        background-color 0.3s ease,
        color 0.3s ease;

    background-image:
        radial-gradient(
            var(--dot-color) 1px,
            transparent 1px
        );

    background-size: 24px 24px;
}


/* =========================================================
   MAIN APPLICATION CONTAINER
========================================================= */

.app-container {
    width: 100%;
    max-width: 760px;

    height: 88vh;
    min-height: 560px;

    display: flex;
    flex-direction: column;

    background: var(--bg-card);

    border: 1px solid var(--border-color);
    border-radius: 16px;

    box-shadow: var(--card-shadow);

    overflow: hidden;

    position: relative;
}


/* =========================================================
   TOP BAR
========================================================= */

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;

    gap: 10px;

    padding: 12px 16px 0 16px;

    min-height: 44px;
}


.top-controls-left {
    display: flex;
    align-items: center;
    gap: 8px;

    min-width: 0;
}


/* =========================================================
   USERNAME CONTROLS
========================================================= */

.username-controls {
    margin-left: auto;

    display: flex;
    align-items: center;

    gap: 7px;

    min-width: 0;
}


.username-display {
    display: inline-flex;
    align-items: center;

    gap: 5px;

    max-width: 180px;

    padding: 5px 9px;

    background: var(--bg-input);

    border: 1px solid var(--border-color);

    border-radius: 7px;

    color: var(--text-main);

    font-size: 11px;
    font-weight: 500;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


#current-username {
    overflow: hidden;
    text-overflow: ellipsis;
}


#change-username-btn {
    white-space: nowrap;
}


/* =========================================================
   SMALL SELECT
========================================================= */

.select-sm {
    background: var(--bg-input);

    border: 1px solid var(--border-color);

    color: var(--text-main);

    padding: 4px 8px;

    border-radius: 6px;

    font-size: 11px;

    outline: none;

    cursor: pointer;
}


.select-sm:focus {
    border-color: var(--border-focus);
}


/* =========================================================
   SMALL BUTTON
========================================================= */

.btn-xs {
    padding: 4px 8px;

    font-size: 11px;

    border-radius: 6px;
}


/* =========================================================
   THEME TOGGLE
========================================================= */

.theme-toggle {
    background: transparent;

    border: 1px solid var(--border-color);

    border-radius: 50%;

    width: 32px;
    height: 32px;

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;

    cursor: pointer;

    font-size: 14px;

    transition:
        background-color 0.2s ease,
        transform 0.2s ease;
}


.theme-toggle:hover {
    background: var(--border-color);
    transform: rotate(10deg);
}


.theme-toggle:active {
    transform: scale(0.94);
}


/* =========================================================
   HEADER
========================================================= */

.app-header {
    padding: 10px 20px 20px 20px;

    display: flex;
    flex-direction: column;
    align-items: center;

    text-align: center;

    border-bottom: 1px solid var(--border-color);
}


.logo-circle {
    width: 52px;
    height: 52px;

    background: rgba(37, 99, 235, 0.1);

    border: 1px solid var(--accent);

    border-radius: 16px;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 24px;

    margin-bottom: 10px;
}


.app-header h1 {
    font-size: 20px;

    font-weight: 700;

    margin-bottom: 4px;
}


.subtitle {
    font-size: 13px;

    color: var(--text-muted);

    margin-bottom: 12px;
}


/* =========================================================
   CONNECTION STATUS
========================================================= */

.status-pill {
    display: inline-flex;

    align-items: center;

    gap: 6px;

    padding: 4px 12px;

    border-radius: 9999px;

    font-size: 12px;

    font-weight: 500;

    border: 1px solid var(--border-color);
}


.status-pill .dot {
    width: 6px;
    height: 6px;

    border-radius: 50%;

    flex-shrink: 0;
}


.status-pill.offline {
    background: rgba(239, 68, 68, 0.1);

    color: #ef4444;
}


.status-pill.offline .dot {
    background: #ef4444;
}


.status-pill.connected {
    background: rgba(16, 185, 129, 0.1);

    color: var(--success);
}


.status-pill.connected .dot {
    background: var(--success);

    box-shadow:
        0 0 0 3px rgba(16, 185, 129, 0.08);
}


/* =========================================================
   SETUP CARD
========================================================= */

.card {
    padding: 24px;

    overflow-y: auto;

    display: flex;
    flex-direction: column;

    gap: 20px;

    flex: 1;
}


.step-group h3 {
    font-size: 14px;

    font-weight: 600;

    margin-bottom: 4px;
}


.instruction {
    font-size: 13px;

    color: var(--text-muted);

    margin-bottom: 12px;

    line-height: 1.5;
}


.action-row {
    display: flex;

    gap: 8px;
}


.divider {
    display: flex;

    align-items: center;

    text-align: center;

    color: var(--text-muted);

    font-size: 11px;

    font-weight: 600;
}


.divider::before,
.divider::after {
    content: '';

    flex: 1;

    border-bottom: 1px solid var(--border-color);
}


.divider span {
    padding: 0 10px;
}


/* =========================================================
   INPUT STACKS
========================================================= */

.input-stack {
    display: flex;

    flex-direction: column;

    gap: 6px;
}


.label-row {
    display: flex;

    justify-content: space-between;

    align-items: center;

    gap: 8px;
}


.input-stack label {
    font-size: 12px;

    color: var(--text-muted);
}


/* =========================================================
   FORM ELEMENTS
========================================================= */

input,
select,
textarea {
    background: var(--bg-input);

    border: 1px solid var(--border-color);

    color: var(--text-main);

    padding: 10px 12px;

    border-radius: 8px;

    font-size: 13px;

    font-family: inherit;

    outline: none;

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}


input::placeholder,
textarea::placeholder {
    color: var(--text-muted);

    opacity: 0.7;
}


input:focus,
textarea:focus,
select:focus {
    border-color: var(--border-focus);

    box-shadow:
        0 0 0 2px rgba(37, 99, 235, 0.08);
}


textarea {
    resize: vertical;

    height: 110px;

    font-family:
        ui-monospace,
        SFMono-Regular,
        Menlo,
        Monaco,
        Consolas,
        monospace;

    font-size: 11px;
}


/* =========================================================
   COPY BUTTON
========================================================= */

.btn-text {
    background: transparent;

    border: none;

    color: var(--accent);

    font-size: 11px;

    font-weight: 500;

    cursor: pointer;

    padding: 2px 6px;

    border-radius: 4px;

    transition:
        background-color 0.2s ease;
}


.btn-text:hover {
    background: rgba(37, 99, 235, 0.1);
}


/* =========================================================
   CONNECT ROW
========================================================= */

.connect-row {
    display: flex;

    gap: 8px;
}


.connect-row input {
    flex: 1;

    min-width: 0;
}


/* =========================================================
   BUTTONS
========================================================= */

.btn {
    padding: 9px 16px;

    border-radius: 8px;

    font-size: 13px;

    font-weight: 500;

    cursor: pointer;

    border: none;

    display: inline-flex;

    align-items: center;

    justify-content: center;

    gap: 6px;

    transition:
        background-color 0.2s ease,
        transform 0.1s ease,
        border-color 0.2s ease;
}


.btn:active {
    transform: scale(0.98);
}


.btn.primary {
    background: var(--accent);

    color: white;
}


.btn.primary:hover {
    background: var(--accent-hover);
}


.btn.secondary {
    background: var(--bg-input);

    color: var(--text-main);

    border: 1px solid var(--border-color);
}


.btn.secondary:hover {
    background: var(--border-color);
}


.icon-btn {
    height: 42px;
    width: 42px;

    padding: 0;

    font-size: 16px;

    flex-shrink: 0;
}


/* =========================================================
   CHAT WORKSPACE
========================================================= */

.chat-workspace {
    display: flex;

    flex-direction: column;

    flex: 1;

    overflow: hidden;
}


.chat-window {
    flex: 1;

    padding: 20px;

    overflow-y: auto;

    display: flex;

    flex-direction: column;

    gap: 12px;

    background: var(--bg-input);

    scroll-behavior: smooth;
}


/* =========================================================
   CHAT MESSAGES
========================================================= */

.message {
    padding: 10px 14px;

    border-radius: 8px;

    max-width: 65%;

    word-break: break-word;

    font-size: 13px;

    line-height: 1.4;

    position: relative;

    animation: fadeIn 0.2s ease-out;
}


@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


.message.sent {
    background: var(--accent);

    color: white;

    align-self: flex-end;

    border-bottom-right-radius: 2px;

    cursor: default;
}


.message.received {
    background: var(--bg-card);

    border: 1px solid var(--border-color);

    color: var(--text-main);

    align-self: flex-start;

    border-bottom-left-radius: 2px;
}


/* =========================================================
   MESSAGE USERNAME
========================================================= */

.message-username {
    display: block;

    font-size: 10px;

    font-weight: 700;

    margin-bottom: 4px;

    opacity: 0.85;

    letter-spacing: 0.1px;
}


.message.sent .message-username {
    color: rgba(255, 255, 255, 0.82);
}


.message.received .message-username {
    color: var(--accent);
}


/* =========================================================
   MESSAGE BODY
========================================================= */

.message-body {
    display: block;

    white-space: pre-wrap;

    overflow-wrap: anywhere;
}


/* =========================================================
   DELETE BUTTON
========================================================= */

.delete-btn {
    position: absolute;

    top: -8px;
    right: -8px;

    background: #ef4444;

    color: white;

    border: none;

    border-radius: 50%;

    width: 20px;
    height: 20px;

    font-size: 10px;

    display: flex;

    align-items: center;
    justify-content: center;

    cursor: pointer;

    opacity: 0;

    transition:
        opacity 0.2s ease,
        transform 0.15s ease;

    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.2);
}


.message.sent:hover .delete-btn {
    opacity: 1;
}


.delete-btn:hover {
    transform: scale(1.1);

    background: #dc2626;
}


/* =========================================================
   BURN BADGE
========================================================= */

.burn-badge {
    font-size: 10px;

    display: block;

    opacity: 0.7;

    margin-top: 5px;
}


/* =========================================================
   FILE MESSAGES
========================================================= */

.file-link {
    color: inherit;

    text-decoration: underline;

    font-weight: 600;

    cursor: pointer;

    overflow-wrap: anywhere;
}


.file-link:hover {
    opacity: 0.8;
}


/* =========================================================
   TRANSFER BANNER
========================================================= */

.transfer-banner {
    background: var(--bg-card);

    border-top: 1px solid var(--border-color);

    padding: 6px 16px;

    font-size: 11px;

    color: var(--accent);

    font-weight: 500;
}


/* =========================================================
   SYSTEM MESSAGE
========================================================= */

.system-msg {
    align-self: center;

    font-size: 11px;

    color: var(--text-muted);

    background: var(--bg-card);

    padding: 4px 10px;

    border-radius: 9999px;

    border: 1px solid var(--border-color);

    margin: 4px 0;

    text-align: center;
}


/* =========================================================
   INPUT AREA
========================================================= */

.input-area {
    padding: 16px;

    background: var(--bg-card);

    border-top: 1px solid var(--border-color);

    display: flex;

    gap: 10px;

    align-items: center;
}


.input-area textarea {
    flex: 1;

    height: 42px;

    resize: none;

    font-family: inherit;

    font-size: 13px;

    padding-top: 11px;

    min-width: 0;
}


.send-btn {
    height: 42px;

    padding: 0 18px;

    flex-shrink: 0;
}


/* =========================================================
   USERNAME MODAL
========================================================= */

.username-modal {
    position: fixed;

    inset: 0;

    width: 100%;
    height: 100%;

    background: var(--modal-overlay);

    display: flex;

    align-items: center;
    justify-content: center;

    padding: 20px;

    z-index: 9999;

    backdrop-filter: blur(6px);

    -webkit-backdrop-filter: blur(6px);

    animation: modalFadeIn 0.2s ease-out;
}


@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}


.username-modal-content {
    width: 100%;

    max-width: 390px;

    background: var(--bg-card);

    border: 1px solid var(--border-color);

    border-radius: 16px;

    padding: 28px;

    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.45);

    animation: modalSlideUp 0.25s ease-out;
}


@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


.username-modal-icon {
    width: 52px;
    height: 52px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin: 0 auto 14px auto;

    border-radius: 16px;

    background: rgba(37, 99, 235, 0.1);

    border: 1px solid var(--accent);

    font-size: 24px;
}


.username-modal-content h2 {
    text-align: center;

    font-size: 20px;

    font-weight: 700;

    margin-bottom: 7px;
}


.username-modal-content > p {
    text-align: center;

    color: var(--text-muted);

    font-size: 13px;

    line-height: 1.5;

    margin-bottom: 20px;
}


.username-modal-content input {
    width: 100%;

    height: 42px;
}


.username-save-btn {
    width: 100%;

    height: 42px;

    margin-top: 14px;
}


/* =========================================================
   SCROLLBARS
========================================================= */

.chat-window::-webkit-scrollbar,
.card::-webkit-scrollbar {
    width: 7px;
}


.chat-window::-webkit-scrollbar-track,
.card::-webkit-scrollbar-track {
    background: transparent;
}


.chat-window::-webkit-scrollbar-thumb,
.card::-webkit-scrollbar-thumb {
    background: var(--border-color);

    border-radius: 999px;
}


.chat-window::-webkit-scrollbar-thumb:hover,
.card::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}


/* =========================================================
   MOBILE RESPONSIVE
========================================================= */

@media (max-width: 650px) {

    body {
        padding: 0;

        align-items: stretch;
    }


    .app-container {
        width: 100%;

        max-width: none;

        height: 100vh;
        min-height: 100vh;

        border-radius: 0;

        border-left: none;
        border-right: none;
    }


    .top-bar {
        padding: 10px 12px 0 12px;

        flex-wrap: wrap;
    }


    .username-controls {
        order: 2;

        width: 100%;

        margin-left: 0;

        justify-content: flex-end;

        padding-top: 6px;
    }


    .theme-toggle {
        order: 1;
    }


    .top-controls-left {
        order: 3;

        width: 100%;

        justify-content: flex-start;

        padding-bottom: 4px;
    }


    .app-header {
        padding-top: 12px;
    }


    .card {
        padding: 18px;
    }


    .connect-row {
        flex-direction: column;
    }


    .connect-row input,
    .connect-row button {
        width: 100%;
    }


    .message {
        max-width: 82%;
    }


    .input-area {
        padding: 10px;

        gap: 7px;
    }


    .input-area textarea {
        min-width: 0;
    }


    .send-btn {
        padding: 0 13px;
    }


    .send-btn span {
        display: none;
    }


    .username-modal-content {
        padding: 24px;

        max-width: calc(100vw - 30px);
    }

}


/* =========================================================
   VERY SMALL SCREENS
========================================================= */

@media (max-width: 400px) {

    .username-display {
        max-width: 120px;
    }


    #change-username-btn {
        padding-left: 6px;
        padding-right: 6px;
    }


    .message {
        max-width: 88%;
    }


    .chat-window {
        padding: 14px;
    }

}


/* =========================================================
   ROOMS: JOIN REQUESTS & MEMBERS
========================================================= */

.join-requests {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: calc(100vw - 32px);
}

.join-request {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    animation: fadeIn 0.2s ease-out;
}

.join-request-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    overflow-wrap: anywhere;
}

.join-request-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.room-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 8px 14px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.room-info strong {
    color: var(--text-main);
    letter-spacing: 2px;
}

.members-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
}

.member-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    font-size: 11px;
    color: var(--text-main);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 999px;
}

.member-kick {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-size: 11px;
    color: var(--danger);
}


/* Author credit under the title */
.made-by {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.4px;
    color: var(--accent);
    margin-bottom: 6px;
}