/* ==========================================================================
   teleportex — стили пользовательской части
   ========================================================================== */

:root {
    --bg: #0b0b0f;
    --surface: #17171c;
    --surface-2: #212128;
    --surface-3: #2b2b33;
    --border: #2c2c34;
    --border-strong: #3a3a44;
    --text: #ececf1;
    --muted: #8e8e96;
    --accent: #6c6af2;
    --accent-2: #8b7cf8;
    --accent-soft: rgba(108, 106, 242, 0.14);
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --radius: 14px;
    --radius-lg: 24px;
    --font: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
}

html,
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
    line-height: 1.45;
}

a {
    color: var(--accent-2);
}

:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Скрытое поле-ловушка для ботов */
.hp-field {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.container {
    background: var(--surface);
    padding: 32px 28px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 720px;
}

/* ---------- Логотип ---------- */
.brand {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0 14px;
    margin-bottom: 1rem;
}

.brand-link {
    font-size: 1.9rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--text);
    text-decoration: none;
    opacity: 0.92;
}

.brand-link .dot {
    color: var(--accent-2);
}

.brand-tagline {
    color: var(--muted);
    font-size: 0.85rem;
}

/* ---------- Кнопки ---------- */
button {
    font: inherit;
}

.btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
    transition: background .2s ease, border-color .2s ease, filter .2s ease, opacity .2s ease;
}

.btn-block {
    width: 100%;
}

.btn.secondary {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn.secondary:hover {
    border-color: #4a4a56;
}

.btn.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border: none;
    color: #fff;
    font-weight: 500;
}

.btn.primary:hover:not(:disabled) {
    filter: brightness(1.1);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn.is-busy {
    cursor: progress;
    opacity: 0.75;
}

.btn-icon {
    width: 48px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font-size: 1.15rem;
    cursor: pointer;
    transition: border-color .2s ease;
}

.btn-icon:hover {
    border-color: var(--accent);
}

.btn-pill {
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .2s ease, background .2s ease, color .2s ease;
}

.btn-pill:hover {
    border-color: #4a4a56;
    background: #34343d;
}

.btn-pill.danger:hover {
    border-color: var(--red);
    color: var(--red);
}

/* ---------- Поля ввода ---------- */
input[type="text"],
input[type="password"],
textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font: inherit;
    font-size: 1rem;
    padding: 12px 14px;
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 106, 242, 0.18);
}

.field {
    margin: 14px 0;
}

.field-label {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    margin-bottom: 8px;
    padding: 0 4px;
}

.pass-row {
    display: flex;
    gap: 8px;
}

.pass-row input {
    flex: 1;
    min-width: 0;
    font-family: var(--mono);
    letter-spacing: 0.02em;
}

/* ---------- Сегментированный переключатель ---------- */
.segmented {
    border: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.segmented input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented label {
    flex: 1;
    text-align: center;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
    transition: all .2s ease;
}

.segmented label:hover {
    color: var(--text);
    border-color: #4a4a56;
}

.segmented input:checked + label {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-soft);
}

.segmented input:focus-visible + label {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
}

.intent-switch label {
    font-size: 0.95rem;
    padding: 11px 12px;
}

.lifetime-switch {
    margin-bottom: 16px;
}

.lifetime-switch .field-label {
    width: 100%;
    margin-bottom: 2px;
}

/* Режимы формы: создание / вход */
.enter-form .only-join {
    display: none;
}

.enter-form.is-join .only-join {
    display: revert;
}

.enter-form.is-join .only-create {
    display: none;
}

.enter-form.is-join .btn .only-join {
    display: inline;
}

/* ---------- Форма входа: [Создать][Войти][пароль][срок][⚄] ---------- */
.enter-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.enter-row > * {
    flex-shrink: 0;
}

.btn-enter {
    padding: 0 16px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .2s ease, filter .2s ease, opacity .2s ease;
}

.btn-enter.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border: none;
    color: #fff;
    font-weight: 500;
}

.btn-enter.primary:hover {
    filter: brightness(1.1);
}

.btn-enter.secondary {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-enter.secondary:hover {
    border-color: var(--accent);
}

.btn-enter.is-busy {
    cursor: progress;
    opacity: 0.7;
}

.enter-row .enter-pass {
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--mono);
    letter-spacing: 0.02em;
}

.enter-select {
    width: 80px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
	text-align: center;
    font: inherit;
    font-size: 0.95rem;
    padding: 0 10px;
    cursor: pointer;
    outline: none;
}

.enter-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 106, 242, 0.18);
}

.enter-row .btn-icon {
    min-height: 48px;
}

/* Узкий экран: все кнопки в ряд сверху, поле пароля — на всю ширину снизу */
@media (max-width: 560px) {
    .enter-row {
        flex-wrap: wrap;
    }

    .enter-row .btn-enter,
    .enter-row .enter-select {
        flex: 1 1 0;
        min-height: 46px;
        padding: 0 8px;
    }

    .enter-row .enter-select {
        width: auto;
        min-width: 80px;
    }

    .enter-row .enter-pass {
        order: 1;
        flex-basis: 100%;
    }
}

.hint {
    color: var(--muted);
    font-size: 0.8rem;
    margin-top: 10px;
    padding: 0 4px;
}

/* ---------- Статус комнаты ---------- */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 12px;
    background: var(--surface-2);
    padding: 10px 14px;
    border-radius: 18px;
    border: 1px solid var(--border);
}

.status-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.room-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    max-width: 260px;
    min-width: 0;
    transition: border-color .2s ease;
}

.room-chip:hover {
    border-color: var(--accent);
}

.chip-icon {
    font-size: 0.8rem;
    opacity: 0.7;
}

.chip-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.role-badge {
    color: var(--muted);
    font-size: 0.85rem;
    white-space: nowrap;
}

.partner {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.82rem;
}

.status-circle {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--muted);
}

.partner[data-state="offline"] .status-circle {
    background: var(--orange);
}

.partner[data-state="online"] .status-circle {
    background: var(--green);
    animation: glow 2s infinite;
}

.partner[data-state="online"] .partner-text {
    color: var(--text);
}

@keyframes glow {
    0% { box-shadow: 0 0 0 0 rgba(48, 209, 88, 0.45); }
    70% { box-shadow: 0 0 0 7px rgba(48, 209, 88, 0); }
    100% { box-shadow: 0 0 0 0 rgba(48, 209, 88, 0); }
}

.status-meta {
    color: var(--muted);
    font-size: 0.8rem;
    padding: 8px 4px 0;
    margin-bottom: 14px;
    min-height: 1.4em;
}

/* ---------- Редактор ---------- */
textarea {
    min-height: 220px;
    resize: vertical;
    line-height: 1.55;
}

.editor.is-over textarea {
    border-color: var(--red);
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 6px 4px 0;
    min-height: 1.6em;
}

.char-counter {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.editor.is-over .char-counter {
    color: var(--red);
    font-weight: 600;
}

.typing-indicator {
    color: var(--green);
    font-style: italic;
    font-size: 0.85rem;
    animation: pulse 1.5s infinite;
}

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

.text-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.text-actions .btn.primary {
    flex: 1.4;
}

.banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-top: 10px;
    padding: 10px 14px;
    border: 1px dashed var(--accent);
    border-radius: var(--radius);
    background: var(--accent-soft);
    color: var(--accent-2);
    font-size: 0.88rem;
    animation: fadeSlide .25s ease;
}

.banner.warning {
    border-color: rgba(255, 159, 10, 0.5);
    background: rgba(255, 159, 10, 0.1);
    color: var(--orange);
}

.banner-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* ---------- Сообщения ---------- */
.message {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.92rem;
    border: 1px solid transparent;
    animation: fadeSlide .25s ease;
}

@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: none; }
}

.message.success {
    background: rgba(48, 209, 88, 0.12);
    color: var(--green);
    border-color: rgba(48, 209, 88, 0.3);
}

.message.error {
    background: rgba(255, 69, 58, 0.12);
    color: var(--red);
    border-color: rgba(255, 69, 58, 0.3);
}

.message.warning,
.message.info {
    background: rgba(255, 159, 10, 0.12);
    color: var(--orange);
    border-color: rgba(255, 159, 10, 0.3);
}

.toast-region {
    position: fixed;
    left: 50%;
    bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 50;
    pointer-events: none;
    width: min(92vw, 480px);
}

.toast {
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 0.88rem;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    animation: toastIn .2s ease;
    text-align: center;
}

.toast.success { border-color: rgba(48, 209, 88, 0.45); }
.toast.error { border-color: rgba(255, 69, 58, 0.55); color: #ffb3ad; }
.toast.warning { border-color: rgba(255, 159, 10, 0.5); }

.toast.is-leaving {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .25s ease, transform .25s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ---------- История ---------- */
.history-section {
    margin-top: 22px;
}

.history-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.88rem;
    cursor: pointer;
    padding: 6px 4px;
    background: none;
    border: none;
    transition: color .2s ease;
}

.history-toggle::before {
    content: '▸';
    font-size: 0.75rem;
    transition: transform .2s ease;
}

.history-toggle[aria-expanded="true"]::before {
    transform: rotate(90deg);
}

.history-toggle:hover,
.history-toggle[aria-expanded="true"] {
    color: var(--text);
}

.history-badge {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-2);
}

.history-container {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--muted);
}

.history-refresh {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
    transition: color .2s ease, transform .3s ease;
}

.history-refresh:hover {
    color: var(--text);
    transform: rotate(90deg);
}

.history-list {
    max-height: 360px;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-state {
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 12px;
}

.history-state.error {
    color: var(--red);
}

.chat-message {
    max-width: 88%;
}

.chat-message.by-guest {
    align-self: flex-end;
}

.message-meta {
    font-size: 0.72rem;
    color: var(--muted);
    padding: 0 6px 4px;
    display: flex;
    gap: 8px;
}

.chat-message.by-guest .message-meta {
    justify-content: flex-end;
}

.message-bubble {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

.chat-message.by-guest .message-bubble {
    background: rgba(108, 106, 242, 0.12);
    border-color: rgba(108, 106, 242, 0.28);
}

.message-text {
    font-size: 0.88rem;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.message-text.empty {
    color: var(--muted);
    font-style: italic;
}

.message-tools {
    display: flex;
    gap: 12px;
    margin-top: 6px;
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent-2);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 0;
}

.link-btn:hover {
    text-decoration: underline;
}

/* ---------- Действия с комнатой ---------- */
.room-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ---------- Справка ---------- */
.info-note {
    font-size: 0.83rem;
    color: var(--muted);
    margin-top: 26px;
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 22px;
    line-height: 1.65;
}

.info-note p + p {
    margin-top: 6px;
}

/* ---------- Ошибки ---------- */
.error-page {
    text-align: center;
    padding: 12px 0;
}

.error-code {
    font-size: 3rem;
    font-weight: 300;
    color: var(--accent-2);
    letter-spacing: -0.03em;
}

.error-message {
    margin: 8px 0 22px;
    color: var(--text);
}

.error-actions .btn {
    flex: none;
    min-width: 200px;
}

.error-details {
    margin-top: 22px;
    text-align: left;
    white-space: pre-wrap;
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--muted);
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 12px;
    max-height: 320px;
    overflow: auto;
}

/* ---------- Подвал ---------- */
.site-footer {
    margin-top: 16px;
}

.lang-switcher {
    display: flex;
    gap: 4px;
    font-size: 0.78rem;
}

.lang-switcher a,
.lang-switcher span {
    padding: 4px 8px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
}

.lang-switcher a:hover {
    color: var(--text);
    background: var(--surface);
}

.lang-switcher .lang-current {
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
}

/* ---------- Установщик ---------- */
.install-title {
    font-size: 1.35rem;
    font-weight: 500;
    margin-bottom: 6px;
}

.install-step {
    font-size: 1rem;
    font-weight: 500;
    margin: 22px 0 10px;
}

.checklist {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.9rem;
}

.checklist li {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.check-mark {
    width: 18px;
    text-align: center;
    font-weight: 700;
}

.checklist .ok .check-mark { color: var(--green); }
.checklist .fail .check-mark { color: var(--red); }
.checklist .warn .check-mark { color: var(--orange); }

.code-line {
    margin: 8px 0;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-all;
    user-select: all;
}

.install .message p + p {
    margin-top: 6px;
}

.install-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.install-form .field-label {
    margin: 8px 0 0;
}

.install-form .hint {
    margin-top: 0;
}

.install-form .btn {
    margin-top: 12px;
}

.next-steps {
    margin: 16px 0 0 18px;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.install-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 22px;
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* ---------- Прочее ---------- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 8px;
}

@media (max-width: 520px) {
    body {
        padding: 10px;
        justify-content: flex-start;
    }

    .container {
        padding: 22px 16px;
        border-radius: 20px;
    }

    .brand-link {
        font-size: 1.6rem;
    }

    .text-actions {
        flex-wrap: wrap;
    }

    .text-actions .btn.primary {
        flex-basis: 100%;
        order: -1;
    }

    .room-chip {
        max-width: 180px;
    }

    .room-actions {
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
