/* ─── Tokens ─────────────────────────────────────────────── */
:root {
    --bg:           #eef2f7;
    --bg-card:      #ffffff;
    --bg-input:     #ffffff;
    --bg-code:      #f8fafc;
    --border:       #d9e2ef;
    --border-inner: #e2e8f0;
    --text:         #1f2937;
    --text-muted:   #64748b;
    --text-heading: #111827;
    --text-label:   #475569;
    --accent:       #2563eb;
    --accent-hover: #1d4ed8;
    --online-bg:    #dcfce7;
    --online-fg:    #166534;
    --offline-bg:   #e2e8f0;
    --offline-fg:   #475569;
    --msg-bg:       #dcfce7;
    --msg-fg:       #166534;
    --shadow:       0 18px 60px rgba(15, 23, 42, 0.08);
    --btn-text:     #ffffff;
    --secondary-bg: #ffffff;
    --secondary-fg: #1f2937;
    --secondary-border: #cbd5e1;
    --input-border: #cbd5e1;
}

[data-theme="dark"] {
    --bg:           #000000;
    --bg-card:      #111111;
    --bg-input:     #111111;
    --bg-code:      #0a0a0a;
    --border:       #2a2a2a;
    --border-inner: #2a2a2a;
    --text:         #ffffff;
    --text-muted:   #888888;
    --text-heading: #ffffff;
    --text-label:   #888888;
    --accent:       #ffffff;
    --accent-hover: #cccccc;
    --online-bg:    #003300;
    --online-fg:    #00ff00;
    --offline-bg:   #1a1a1a;
    --offline-fg:   #888888;
    --msg-bg:       #003300;
    --msg-fg:       #00ff00;
    --shadow:       0 18px 60px rgba(0, 0, 0, 0.8);
    --btn-text:     #000000;
    --secondary-bg: #111111;
    --secondary-fg: #ffffff;
    --secondary-border: #333333;
    --input-border: #333333;
}

/* Auto dark if no explicit preference stored */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) {
        --bg:           #000000;
        --bg-card:      #111111;
        --bg-input:     #111111;
        --bg-code:      #0a0a0a;
        --border:       #2a2a2a;
        --border-inner: #2a2a2a;
        --text:         #ffffff;
        --text-muted:   #888888;
        --text-heading: #ffffff;
        --text-label:   #888888;
        --accent:       #ffffff;
        --accent-hover: #cccccc;
        --online-bg:    #003300;
        --online-fg:    #00ff00;
        --offline-bg:   #1a1a1a;
        --offline-fg:   #888888;
        --msg-bg:       #003300;
        --msg-fg:       #00ff00;
        --shadow:       0 18px 60px rgba(0, 0, 0, 0.8);
        --btn-text:     #000000;
        --secondary-bg: #111111;
        --secondary-fg: #ffffff;
        --secondary-border: #333333;
        --input-border: #333333;
    }
}

/* ─── Reset & base ───────────────────────────────────────── */
:root {
    color-scheme: light;
    font-family: Inter, Segoe UI, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}

[data-theme="dark"],
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    transition: background 0.2s, color 0.2s;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ─── Header ─────────────────────────────────────────────── */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 18px clamp(18px, 5vw, 72px);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 800;
    color: var(--text-heading);
}

.nav {
    display: flex;
    align-items: center;
    gap: 14px;
}

.nav form {
    margin: 0;
}

/* ─── Theme toggle ───────────────────────────────────────── */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-muted);
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--bg);
    text-decoration: none;
}

/* ─── Buttons ────────────────────────────────────────────── */
button,
.primary,
.button-link {
    border: 0;
    border-radius: 8px;
    padding: 11px 16px;
    font: inherit;
    font-weight: 700;
    color: var(--btn-text);
    background: var(--accent);
    cursor: pointer;
}

button:hover,
.primary:hover,
.button-link:hover {
    background: var(--accent-hover);
    text-decoration: none;
}

.secondary {
    border-radius: 8px;
    padding: 10px 15px;
    font-weight: 700;
    color: var(--secondary-fg);
    background: var(--secondary-bg);
    border: 1px solid var(--secondary-border);
}

.secondary:hover {
    background: var(--bg);
    text-decoration: none;
}

/* ─── Layout ─────────────────────────────────────────────── */
.page {
    width: min(1040px, calc(100% - 32px));
    margin: 0 auto;
    padding: 54px 0;
}

/* ─── Hero ───────────────────────────────────────────────── */
.hero {
    display: grid;
    align-items: center;
    min-height: 540px;
    padding: clamp(32px, 7vw, 72px);
    border-radius: 8px;
    color: #ffffff;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #2563eb 100%);
}

/* ─── Internet home ──────────────────────────────────────── */
.internet-home {
    display: grid;
    min-height: calc(100vh - 170px);
    place-items: center;
    border-radius: 8px;
    background: #000000;
}

.internet-icon {
    position: relative;
    width: min(34vw, 220px);
    aspect-ratio: 1;
    border: 8px solid #ffffff;
    border-radius: 50%;
}

.internet-icon::before,
.internet-icon::after,
.internet-icon span::before,
.internet-icon span::after {
    content: '';
    position: absolute;
    background: #ffffff;
}

.internet-icon::before {
    left: 50%;
    top: -8px;
    width: 8px;
    height: calc(100% + 16px);
    transform: translateX(-50%);
}

.internet-icon::after {
    left: -8px;
    top: 50%;
    width: calc(100% + 16px);
    height: 8px;
    transform: translateY(-50%);
}

.internet-icon span::before,
.internet-icon span::after {
    inset: 28px 16px;
    border: 7px solid #ffffff;
    border-left: 0;
    border-right: 0;
    border-radius: 50%;
    background: transparent;
}

.internet-icon span::after {
    inset: 16px 42px;
    border-top: 0;
    border-bottom: 0;
    border-left: 7px solid #ffffff;
    border-right: 7px solid #ffffff;
}

/* ─── Typography ─────────────────────────────────────────── */
.eyebrow {
    margin: 0 0 12px;
    text-transform: uppercase;
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0;
}

h1 {
    margin: 0 0 18px;
    font-size: clamp(2rem, 7vw, 4.75rem);
    line-height: 1;
    letter-spacing: 0;
    color: var(--text-heading);
}

.lead {
    max-width: 680px;
    margin: 0 0 28px;
    font-size: 1.2rem;
    line-height: 1.6;
}

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

/* ─── Panels / Cards ─────────────────────────────────────── */
.auth-panel,
.profile,
.chat-panel,
.wide-panel {
    width: min(520px, 100%);
    margin: 0 auto;
    padding: 28px;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.wide-panel {
    width: 100%;
}

.auth-panel h1,
.profile h1,
.wide-panel h1 {
    color: var(--text-heading);
    font-size: 2rem;
}

/* ─── Profile layout ─────────────────────────────────────── */
.profile-layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.profile-layout .profile {
    width: 100%;
}

.chat-panel {
    width: 100%;
}

/* ─── Chat ───────────────────────────────────────────────── */
.chat-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.chat-heading h2 {
    margin: 0;
    color: var(--text-heading);
    font-size: 1.65rem;
}

.chat-heading span {
    display: inline-grid;
    min-width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 8px;
    color: var(--btn-text);
    background: var(--accent);
    font-weight: 800;
}

.chat-list {
    display: grid;
    gap: 12px;
    max-height: 430px;
    overflow-y: auto;
    padding-right: 6px;
}

.chat-message {
    padding: 13px 14px;
    border: 1px solid var(--border-inner);
    border-radius: 8px;
    background: var(--bg-code);
}

.chat-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 7px;
}

.chat-meta time {
    color: var(--text-muted);
    font-size: 0.86rem;
    white-space: nowrap;
}

.chat-message p {
    margin: 0;
    line-height: 1.45;
}

.empty-chat {
    margin: 0;
    padding: 18px;
    border: 1px dashed var(--border-inner);
    border-radius: 8px;
    color: var(--text-muted);
    text-align: center;
}

.chat-form {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.chat-form textarea {
    width: 100%;
    resize: vertical;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 12px 14px;
    font: inherit;
    background: var(--bg-input);
    color: var(--text);
}

/* ─── Devices table ──────────────────────────────────────── */
.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.dark {
    color: var(--text-label);
}

.counter {
    display: inline-grid;
    min-width: 44px;
    height: 44px;
    place-items: center;
    border-radius: 8px;
    color: #ffffff;
    background: var(--text-heading);
    font-weight: 800;
}

.device-table-wrap {
    overflow-x: auto;
}

.device-table {
    width: 100%;
    min-width: 860px;
    border-collapse: collapse;
}

.device-table th,
.device-table td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--border-inner);
    text-align: left;
    vertical-align: top;
}

.device-table th {
    color: var(--text-label);
    font-size: 0.86rem;
    text-transform: uppercase;
}

.user-agent {
    max-width: 360px;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.status {
    display: inline-block;
    min-width: 68px;
    border-radius: 8px;
    padding: 6px 9px;
    font-size: 0.84rem;
    font-weight: 800;
    text-align: center;
}

.online {
    color: var(--online-fg);
    background: var(--online-bg);
}

.offline {
    color: var(--offline-fg);
    background: var(--offline-bg);
}

.empty {
    color: var(--text-muted);
    text-align: center;
}

/* ─── Auth forms ─────────────────────────────────────────── */
.auth-form {
    display: grid;
    gap: 16px;
}

.auth-form label {
    display: grid;
    gap: 7px;
    font-weight: 700;
}

.auth-form input {
    width: 100%;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 12px 14px;
    font: inherit;
    background: var(--bg-input);
    color: var(--text);
}

.auth-form small,
.muted {
    color: var(--text-muted);
    line-height: 1.5;
}

.auth-form button {
    margin-top: 6px;
}

.error {
    color: #f87171;
    font-size: 0.9rem;
}

/* ─── Flash messages ─────────────────────────────────────── */
.messages {
    margin-bottom: 18px;
}

.message {
    margin: 0;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--msg-bg);
    color: var(--msg-fg);
}

/* ─── Profile DL ─────────────────────────────────────────── */
.profile dl {
    display: grid;
    gap: 14px;
    margin: 0;
}

.profile dl div {
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-inner);
}

.profile dt {
    color: var(--text-muted);
    font-size: 0.92rem;
}

.profile dd {
    margin: 5px 0 0;
    font-weight: 800;
    color: var(--text-heading);
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 640px) {
    .site-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .nav {
        width: 100%;
        flex-wrap: wrap;
    }

    .hero {
        min-height: 460px;
    }

    .profile-layout {
        grid-template-columns: 1fr;
    }

    .internet-home {
        min-height: calc(100vh - 230px);
    }

    .internet-icon {
        width: min(58vw, 190px);
    }
}

/* ─── NV Logo ────────────────────────────────────────────── */
.nv-logo {
    font-size: clamp(5rem, 20vw, 14rem);
    font-weight: 900;
    color: #ffffff;
    letter-spacing: -0.04em;
    line-height: 1;
    user-select: none;
}

/* ─── Chat clear button ──────────────────────────────────── */
.chat-heading-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.clear-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 8px;
    font-size: 1rem;
    background: #ef4444;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.clear-btn:hover {
    background: #dc2626;
}

/* ─── Home layout ────────────────────────────────────────── */
.home-layout {
    display: grid;
    grid-template-columns: 1fr minmax(320px, 480px);
    gap: 32px;
    align-items: center;
    min-height: calc(100vh - 170px);
}

.home-chat {
    width: 100%;
    margin: 0;
    align-self: stretch;
    display: flex;
    flex-direction: column;
}

.home-chat .chat-list {
    flex: 1;
    max-height: 60vh;
}

.guest-fields {
    display: grid;
    gap: 8px;
}

.guest-fields input {
    width: 100%;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 10px 14px;
    font: inherit;
    background: var(--bg-input);
    color: var(--text);
}

@media (max-width: 768px) {
    .home-layout {
        grid-template-columns: 1fr;
        min-height: unset;
    }

    .nv-logo {
        text-align: center;
        padding: 32px 0 0;
    }
}

/* ─── Direct Messages ────────────────────────────────────── */
.dm-list {
    display: grid;
    gap: 2px;
}

.dm-item-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dm-item-row .dm-item {
    flex: 1;
}

.dm-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s;
}

.dm-item:hover {
    background: var(--bg);
    text-decoration: none;
}

.dm-unread {
    background: var(--bg-code);
}

.dm-avatar {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--btn-text);
    font-weight: 800;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.dm-info {
    flex: 1;
    min-width: 0;
}

.dm-header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 3px;
}

.dm-header time {
    color: var(--text-muted);
    font-size: 0.82rem;
    white-space: nowrap;
}

.dm-preview {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-badge {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    background: var(--accent);
    color: var(--btn-text);
    font-size: 0.78rem;
    font-weight: 800;
    padding: 0 6px;
}

.dm-panel {
    max-width: 680px;
}

.dm-conv-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-inner);
}

.back-link {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-right: 4px;
}

.dm-messages {
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dm-msg {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.45;
}

.dm-msg p {
    margin: 0 0 4px;
}

.dm-msg time {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.dm-msg-out {
    align-self: flex-end;
    background: var(--accent);
    color: var(--btn-text);
    border-bottom-right-radius: 4px;
}

.dm-msg-out time {
    color: rgba(255,255,255,0.65);
    text-align: right;
}

.dm-msg-in {
    align-self: flex-start;
    background: var(--bg-code);
    border: 1px solid var(--border-inner);
    border-bottom-left-radius: 4px;
}

/* ─── E2E Encryption ─────────────────────────────────────── */
.e2e-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    margin-left: 8px;
}

.e2e-ok {
    background: var(--online-bg);
    color: var(--online-fg);
}

.e2e-warn {
    background: #fef3c7;
    color: #92400e;
}

[data-theme="dark"] .e2e-warn {
    background: #451a03;
    color: #fbbf24;
}

.e2e-loading {
    background: var(--offline-bg);
    color: var(--offline-fg);
}

.e2e-unlock-panel {
    padding: 16px;
    border: 1px solid var(--border-inner);
    border-radius: 8px;
    background: var(--bg-code);
    margin-bottom: 16px;
}

.e2e-unlock-panel p {
    margin: 0 0 10px;
    font-weight: 600;
}

.e2e-input {
    width: 100%;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 10px 14px;
    font: inherit;
    background: var(--bg-input);
    color: var(--text);
}
