:root {
    --bg: #0a0a14;
    --surface: #0f0f1e;
    --surface-raised: #141428;
    --text: #e0e0f0;
    --text-muted: #6a6a8a;
    --neon-pink: #ff2d95;
    --neon-cyan: #0ff;
    --neon-purple: #b347d8;
    --neon-blue: #4d7fff;
    --frost: #d0dff8;
    --danger: #ff3860;
    --success: #0ead69;
    --border: #1e1e3a;
    --border-glow: rgba(0, 255, 255, 0.15);
    --input-bg: #08081a;
    --radius: 8px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--neon-cyan);
    text-decoration: none;
    transition: text-shadow 0.2s;
}

a:hover {
    text-shadow: 0 0 8px var(--neon-cyan);
}

/* ---- Neon Brand ---- */
.neon-brand {
    font-family: 'Orbitron', monospace;
    letter-spacing: 0.05em;
    user-select: none;
}

.neon-btw {
    font-weight: 900;
    font-size: 1.2em;
}

.neon-btw .lb {
    color: #fff;
    text-shadow:
        0 0 3px #fff, 0 0 8px #fff,
        0 0 14px var(--neon-pink), 0 0 28px var(--neon-pink), 0 0 45px var(--neon-pink),
        1px 0 0 rgba(255,255,255,0.6),
        -1px 0 2px rgba(0,0,0,0.3);
    animation: tube-b 2.5s ease-in-out infinite alternate;
}

.neon-btw .lt {
    color: #fff;
    text-shadow:
        0 0 3px #fff, 0 0 8px #fff,
        0 0 14px var(--neon-purple), 0 0 28px var(--neon-purple), 0 0 45px var(--neon-purple),
        1px 0 0 rgba(255,255,255,0.6),
        -1px 0 2px rgba(0,0,0,0.3);
    animation: tube-t 2.5s ease-in-out infinite alternate;
    animation-delay: 0.3s;
}

.neon-btw .lw {
    color: #fff;
    text-shadow:
        0 0 3px #fff, 0 0 8px #fff,
        0 0 14px var(--neon-cyan), 0 0 28px var(--neon-cyan), 0 0 45px var(--neon-cyan),
        1px 0 0 rgba(255,255,255,0.6),
        -1px 0 2px rgba(0,0,0,0.3);
    animation: tube-w 2.5s ease-in-out infinite alternate;
    animation-delay: 0.6s;
}

.neon-dot {
    font-weight: 700;
    font-size: 0.8em;
    color: var(--frost);
    text-shadow:
        0 0 4px rgba(208, 223, 248, 0.6),
        0 0 11px rgba(208, 223, 248, 0.3);
}

.neon-brand-sm .neon-btw {
    font-size: 1em;
}

.neon-brand-sm .neon-dot {
    font-size: 0.7em;
}

@keyframes tube-b {
    from {
        text-shadow:
            0 0 3px #fff, 0 0 8px #fff,
            0 0 14px #ff2d95, 0 0 28px #ff2d95, 0 0 45px #ff2d95,
            1px 0 0 rgba(255,255,255,0.6),
            -1px 0 2px rgba(0,0,0,0.3);
    }
    to {
        text-shadow:
            0 0 5px #fff, 0 0 12px #fff,
            0 0 22px #ff2d95, 0 0 45px #ff2d95, 0 0 70px #ff2d95,
            2px 0 0 rgba(255,255,255,0.8),
            -1px 0 2px rgba(0,0,0,0.3);
    }
}

@keyframes tube-t {
    from {
        text-shadow:
            0 0 3px #fff, 0 0 8px #fff,
            0 0 14px #b347d8, 0 0 28px #b347d8, 0 0 45px #b347d8,
            1px 0 0 rgba(255,255,255,0.6),
            -1px 0 2px rgba(0,0,0,0.3);
    }
    to {
        text-shadow:
            0 0 5px #fff, 0 0 12px #fff,
            0 0 22px #b347d8, 0 0 45px #b347d8, 0 0 70px #b347d8,
            2px 0 0 rgba(255,255,255,0.8),
            -1px 0 2px rgba(0,0,0,0.3);
    }
}

@keyframes tube-w {
    from {
        text-shadow:
            0 0 3px #fff, 0 0 8px #fff,
            0 0 14px #0ff, 0 0 28px #0ff, 0 0 45px #0ff,
            1px 0 0 rgba(255,255,255,0.6),
            -1px 0 2px rgba(0,0,0,0.3);
    }
    to {
        text-shadow:
            0 0 5px #fff, 0 0 12px #fff,
            0 0 22px #0ff, 0 0 45px #0ff, 0 0 70px #0ff,
            2px 0 0 rgba(255,255,255,0.8),
            -1px 0 2px rgba(0,0,0,0.3);
    }
}

@media screen and (prefers-reduced-motion) {
    .neon-btw .lb, .neon-btw .lt, .neon-btw .lw { animation: none; }
}

/* ---- Layout ---- */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ---- Header ---- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 20px rgba(255, 45, 149, 0.06);
}

.header h1 {
    font-size: 1.25rem;
}

.header nav {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.header nav a,
.header nav button {
    color: var(--text);
    background: none;
    border: none;
    font: inherit;
    cursor: pointer;
    font-size: 0.9rem;
    transition: color 0.2s, text-shadow 0.2s;
}

.header nav a:hover,
.header nav button:hover {
    color: var(--neon-cyan);
    text-shadow: 0 0 8px var(--neon-cyan);
}

/* ---- Auth view ---- */
.auth-container {
    max-width: 420px;
    margin: 5rem auto;
    text-align: center;
}

.auth-container h2 {
    margin-bottom: 2.5rem;
    font-size: 2.5rem;
}

.auth-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    position: relative;
    overflow: hidden;
}

.auth-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--neon-pink), var(--neon-cyan), var(--neon-purple));
    opacity: 0.7;
}

.auth-section h3 {
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.auth-section p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: box-shadow 0.2s, opacity 0.15s, transform 0.1s;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--neon-cyan);
    color: #0a0a14;
    font-weight: 600;
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
}

.btn-primary:hover {
    box-shadow:
        0 0 12px rgba(0, 255, 255, 0.5),
        0 0 30px rgba(0, 255, 255, 0.2);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 0 8px rgba(255, 56, 96, 0.3);
}

.btn-danger:hover {
    box-shadow:
        0 0 12px rgba(255, 56, 96, 0.5),
        0 0 30px rgba(255, 56, 96, 0.2);
}

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

.btn-secondary:hover {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.15);
}

.btn-small {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
}

/* ---- Inputs ---- */
input[type="text"],
input[type="url"],
input[type="password"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus-visible,
input[type="url"]:focus-visible,
input[type="password"]:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 1px;
    border-color: var(--neon-cyan);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.2);
}

input::placeholder {
    color: var(--text-muted);
}

/* Vertically stack form controls inside the auth view and any modal form
   that isn't already wrapping its fields in .form-group. Replaces per-element
   inline margin-top on successive siblings. */
#password-login-form > * + *,
#change-password-form .form-group + .form-group,
.auth-section form > * + * {
    margin-top: 0.75rem;
}

select {
    padding: 0.4rem 0.6rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

select:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 1px;
    border-color: var(--neon-cyan);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.2);
}

/* ---- Cards (orgs) ---- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
    position: relative;
    overflow: hidden;
}

.card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--neon-pink), var(--neon-purple));
    opacity: 0;
    transition: opacity 0.2s;
}

.card:hover {
    border-color: var(--neon-pink);
    box-shadow: 0 0 20px rgba(255, 45, 149, 0.12);
    transform: translateY(-2px);
}

.card:hover::after {
    opacity: 1;
}

.card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.3rem;
}

.card .role {
    font-size: 0.8rem;
    color: var(--neon-cyan);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

/* ---- Table ---- */
.table-wrap {
    overflow-x: auto;
    margin-top: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

thead th {
    text-align: left;
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--neon-cyan);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: var(--surface);
}

tbody td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr {
    transition: background 0.15s;
}

tbody tr:hover {
    background: rgba(0, 255, 255, 0.03);
}

tbody tr:last-child td {
    border-bottom: none;
}

.truncate {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
}

.actions {
    display: flex;
    gap: 0.4rem;
    white-space: nowrap;
}

/* ---- Links view toolbar ---- */
.toolbar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.toolbar input[type="text"] {
    flex: 1;
    min-width: 160px;
}

.back-link {
    display: inline-block;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--neon-cyan);
    text-shadow: none;
}

.section-title {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.section-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

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

/* ---- Org settings bar ---- */
.org-settings {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ---- Modal overlay ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 90%;
    max-width: 480px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(255, 45, 149, 0.08);
}

.modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--neon-pink), var(--neon-cyan));
}

.modal h3 {
    margin-bottom: 1rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.slug-row {
    display: flex;
    gap: 0.5rem;
}

.slug-row input {
    flex: 1;
}

.delay-row select {
    width: 100%;
}

.qr-preview {
    text-align: center;
    margin: 1rem 0;
}

.qr-preview img {
    border-radius: var(--radius);
    background: #fff;
    padding: 4px;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* ---- QR Modal ---- */
.qr-modal {
    max-width: 540px;
}

.qr-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.qr-modal-body {
    text-align: center;
    background: #fff;
    border-radius: var(--radius);
    padding: 1rem;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-modal-body img,
.qr-modal-body svg {
    max-width: 100%;
    height: auto;
}

.qr-modal-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.qr-format-toggle {
    display: flex;
    gap: 0.25rem;
}

.qr-format-toggle .btn.active {
    background: var(--neon-cyan);
    color: var(--bg);
    font-weight: 600;
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
}

.qr-format-toggle .btn:not(.active) {
    background: var(--surface-raised);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.qr-size-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.qr-size-control label {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.qr-size-control input[type="range"] {
    flex: 1;
    min-width: 80px;
    accent-color: var(--neon-cyan);
}

#qr-size-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 45px;
}

/* Clickable QR thumbnail */
tbody td img.qr-thumb {
    cursor: pointer;
    transition: opacity 0.15s, box-shadow 0.2s;
    border-radius: 4px;
}

tbody td img.qr-thumb:hover {
    opacity: 0.85;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
}

/* ---- Org users panel ---- */
.org-users-panel {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.role-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.role-badge-admin {
    color: var(--neon-cyan);
    border-color: rgba(0, 255, 255, 0.3);
}

.role-badge-member {
    color: var(--text-muted);
}

.status-pill {
    display: inline-block;
    font-size: 0.7rem;
    color: var(--neon-pink);
    background: rgba(255, 45, 149, 0.1);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1px solid rgba(255, 45, 149, 0.3);
}

/* ---- Temp password reveal ---- */
.temp-password-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0 0.5rem;
    padding: 0.75rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.temp-password-row code {
    flex: 1;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1rem;
    letter-spacing: 0.05em;
    word-break: break-all;
    color: var(--neon-cyan);
}

.temp-password-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ---- Devices list ---- */
.device-list {
    margin-top: 1rem;
}

.device-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.5rem;
    transition: border-color 0.2s;
}

.device-item:hover {
    border-color: var(--neon-cyan);
}

.device-info {
    font-size: 0.9rem;
}

.device-info .label {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ---- Error / status messages ---- */
.error-msg {
    background: rgba(255, 56, 96, 0.1);
    color: var(--danger);
    border: 1px solid rgba(255, 56, 96, 0.3);
    border-radius: var(--radius);
    padding: 0.6rem 1rem;
    margin-top: 1rem;
    font-size: 0.85rem;
}

.empty-msg {
    text-align: center;
    color: var(--text);
    padding: 2rem;
    font-size: 0.9rem;
}

/* ---- Screen reader only ---- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---- Hidden utility ---- */
.hidden {
    display: none !important;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .header {
        flex-direction: column;
        gap: 0.75rem;
    }

    .toolbar {
        flex-direction: column;
    }

    .toolbar input[type="text"] {
        width: 100%;
    }

    .device-item {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .auth-container h2 {
        font-size: 2rem;
    }
}
