/* Moonlight-Web — Components: buttons, cards, fields, badges, toasts,
 * dialogs, tables. One grammar, consumed by every view. */

/* ════════════════════════════════════════════════════════════════════════
   Buttons — one gabarit, colour by variant
   ════════════════════════════════════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 9px 18px;
    border: none;
    border-radius: 0;
    /* Notched (bevelled) corner — the CP2077 signature */
    clip-path: var(--notch-sm);
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    /* Default = primary action */
    background: var(--accent-1);
    color: var(--on-accent);
    transition: background 0.15s, color 0.15s, filter 0.2s, transform 0.08s,
                opacity 0.15s;
}
.btn:hover {
    background: var(--accent-strong);
    color: var(--on-accent);
    filter: var(--glow-accent);
}
.btn:active {
    transform: translateY(1px);
    background: var(--accent-deep);
}
.btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
    box-shadow: none;
}

/* Secondary — dark surface, cyan neon inset edge (follows the notch) */
.btn-secondary {
    background: var(--surface-3);
    color: var(--text-1);
    box-shadow: var(--edge-cyan);
}
.btn-secondary:hover {
    background: var(--surface-4);
    color: var(--neon-cyan);
    box-shadow: var(--edge-cyan);
    filter: var(--glow-cyan);
}

/* Neutral — yellow outline (used by "Add Manually", "Reset Defaults") */
.btn-neutral {
    background: var(--accent-soft);
    color: var(--accent-1);
    box-shadow: var(--edge-accent);
}
.btn-neutral:hover {
    background: rgba(252, 238, 10, 0.2);
    color: var(--accent-strong);
    box-shadow: var(--edge-accent);
    filter: var(--glow-accent);
}

/* Success — host "Open" / save-style positive action */
.btn-save {
    background: var(--accent-1);
    color: var(--on-accent);
}
.btn-open {
    background: var(--c-success);
    color: #06281b;
}
.btn-open:hover {
    background: #4eb87c;
    color: #06281b;
}
.btn-save:disabled {
    background: var(--surface-3);
    color: var(--text-3);
}

/* Danger */
.btn-danger {
    background: var(--c-danger);
    color: #2a0809;
    border-color: transparent;
}
.btn-danger:hover {
    background: #e04a51;
}
.btn-danger:disabled {
    opacity: 0.4;
}

/* Link-style button */
.btn-link {
    background: none;
    border: none;
    box-shadow: none;
    color: var(--accent-1);
    text-decoration: underline;
    padding: 2px 4px;
    font-weight: 500;
}
.btn-link:hover {
    background: none;
    color: var(--accent-strong);
}

/* Sizes */
.btn-small,
.btn-pair {
    padding: 5px 12px;
    font-size: var(--fs-xs);
    border-radius: var(--radius-sm);
}

/* Wake-on-LAN — amber edge to set it apart from the cyan "Pair" action */
.btn-wol {
    color: var(--accent-1);
    box-shadow: var(--edge-accent);
}
.btn-wol:hover {
    color: var(--accent-strong);
    box-shadow: var(--edge-accent);
}
.btn-pagination {
    background: var(--surface-3);
    color: var(--text-1);
    min-width: 90px;
    box-shadow: var(--edge-cyan);
}
.btn-pagination:hover:not(:disabled) {
    background: var(--surface-4);
}
.btn-pagination:disabled {
    opacity: 0.35;
    cursor: default;
}

/* Loading spinner suffix */
.btn-loading,
.btn-loading:hover {
    opacity: 0.6;
    cursor: wait;
    pointer-events: none;
    position: relative;
}
.btn-loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: var(--space-2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btnSpin 0.6s linear infinite;
    flex-shrink: 0;
}
@keyframes btnSpin { to { transform: rotate(360deg); } }

/* Icon button (header) */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-icon:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-1);
}
.btn-icon.nav-active {
    background: var(--accent-soft);
    border-color: var(--accent-ring);
    color: #cdddff;
}
.btn-icon svg { display: block; }

/* Close (×) button used in view headers */
.view-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.view-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-1);
}

/* ════════════════════════════════════════════════════════════════════════
   Card surface (host cards, app cards, settings sections share this look)
   ════════════════════════════════════════════════════════════════════════ */
.host-card,
.app-card,
.settings-section {
    /* Frosted glass with a cyan sheen, notched corners and a neon cyan inset
       edge that follows the bevel. Outer shadow is clipped by clip-path, so
       depth/glow comes from the inset edge (and a drop-shadow on hover). */
    background:
        linear-gradient(150deg, rgba(0, 229, 255, 0.06), rgba(0, 229, 255, 0) 60%),
        var(--surface-glass);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border: none;
    border-radius: 0;
    clip-path: var(--notch-lg);
    box-shadow: var(--edge-cyan), var(--glass-highlight);
}

/* ════════════════════════════════════════════════════════════════════════
   Form fields
   ════════════════════════════════════════════════════════════════════════ */
.settings-label,
.login-label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: 600;
    margin-bottom: var(--space-2);
    color: var(--text-1);
}
.login-label {
    font-weight: 500;
    color: var(--text-2);
    font-size: 0.82rem;
}

.setting-desc {
    display: block;
    font-size: var(--fs-xs);
    color: var(--text-2);
    line-height: 1.45;
    margin-bottom: var(--space-2);
}
.settings-checkbox-label + .setting-desc {
    padding-left: 30px;
}

.settings-input,
.login-input,
.login-pin-input {
    display: block;
    width: 100%;
    padding: 10px 14px;
    /* Same mono font as admin .pin-display, but discreet (smaller, lighter). */
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 1px;
    background-color: var(--surface-1);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-sm);
    color: var(--text-1);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.settings-input { font-family: var(--font-mono); }
.settings-input:focus,
.login-input:focus,
.login-pin-input:focus {
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.settings-input::placeholder,
.login-input::placeholder,
.login-pin-input::placeholder {
    color: var(--text-3);
}

/* Login name: left-aligned, full width to fit a 24-char session name. */
.login-input {
    text-align: left;
}
/* Login PIN: centered "123 456", larger and a bit wider. letter-spacing keeps
 * normal digit tracking; word-spacing trims the mono space to a small gap. */
.login-pin-input {
    text-align: center;
    width: 11ch;
    margin-left: auto;
    margin-right: auto;
    font-size: 1.3rem;
    letter-spacing: 1px;
    word-spacing: -0.35em;
}

/* Select — custom chevron, identical everywhere */
.settings-select {
    display: block;
    width: 100%;
    padding: 10px 38px 10px 14px;
    font-size: var(--fs-sm);
    background-color: var(--surface-1);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-sm);
    color: var(--text-1);
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23aab3c4' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.settings-select:focus {
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.settings-select option {
    background-color: var(--surface-1);
    color: var(--text-1);
}
.settings-select option:disabled {
    color: var(--text-3);
    font-style: italic;
}

/* Range slider */
.settings-slider {
    display: block;
    width: 100%;
    height: 6px;
    margin: 12px 0 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--surface-4);
    border-radius: var(--radius-pill);
    outline: none;
    cursor: pointer;
}
.settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-1);
    border: 3px solid var(--surface-1);
    cursor: pointer;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    transition: transform 0.1s;
}
.settings-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}
.settings-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-1);
    border: 3px solid var(--surface-1);
    cursor: pointer;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
}
.settings-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: var(--fs-xs);
    color: var(--text-3);
    margin-top: 2px;
    user-select: none;
}

/* Checkbox row */
.settings-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    cursor: pointer;
}
.settings-checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 2px;
    accent-color: var(--accent-1);
    cursor: pointer;
}
.settings-checkbox-text {
    font-size: var(--fs-sm);
    line-height: 1.4;
    color: var(--text-1);
}

/* Hints / notes / inline status */
.settings-hint {
    font-size: var(--fs-xs);
    color: var(--text-2);
    margin-top: var(--space-1);
    line-height: 1.45;
}
.settings-hint a {
    color: var(--accent-1);
    text-decoration: none;
}
.settings-hint a:hover { text-decoration: underline; }

.settings-note {
    font-size: var(--fs-xs);
    color: var(--text-2);
    line-height: 1.45;
    margin-top: var(--space-2);
    padding-left: 30px;
}

.settings-status {
    margin-top: var(--space-4);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    line-height: 1.45;
}
.settings-status-ok {
    background-color: var(--c-success-soft);
    border: 1px solid rgba(62, 201, 138, 0.3);
    color: #9be7c4;
}
.settings-status-ok a {
    color: var(--c-success);
    text-decoration: underline;
    font-family: var(--font-mono);
}
.settings-status-pending {
    background-color: var(--c-warning-soft);
    border: 1px solid rgba(240, 180, 41, 0.3);
    color: #f3d488;
}

/* ════════════════════════════════════════════════════════════════════════
   Badges
   ════════════════════════════════════════════════════════════════════════ */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border: 1px solid currentColor;
}
.status-badge.ready   { background-color: var(--c-success-soft); color: var(--c-success); }
.status-badge.locked  { background-color: var(--c-warning-soft); color: var(--c-warning); }
.status-badge.offline { background-color: var(--c-danger-soft);  color: var(--c-danger); }

/* ════════════════════════════════════════════════════════════════════════
   Toasts
   ════════════════════════════════════════════════════════════════════════ */
#toast-container {
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: 380px;
    pointer-events: none;
}
.toast {
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    font-weight: 500;
    line-height: 1.4;
    color: #fff;
    cursor: pointer;
    pointer-events: auto;
    border: 1px solid var(--border-2);
    box-shadow: var(--shadow-3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: toastSlideIn 0.3s ease forwards;
}
.toast-exit {
    animation: toastFadeOut 0.3s ease forwards;
}
.toast-success { background: rgba(36, 110, 79, 0.92);  border-color: var(--c-success); }
.toast-error   { background: rgba(140, 41, 45, 0.92);  border-color: var(--c-danger); }
.toast-warning { background: rgba(150, 110, 20, 0.92); border-color: var(--c-warning); }
.toast-info    { background: rgba(28, 88, 130, 0.92);  border-color: var(--c-info); }

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(60px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastFadeOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

@media (max-width: 600px) {
    #toast-container {
        bottom: var(--space-3);
        right: var(--space-3);
        left: var(--space-3);
        max-width: none;
    }
}

/* ════════════════════════════════════════════════════════════════════════
   Dialog (pairing + future modal dialogs)
   ════════════════════════════════════════════════════════════════════════ */
.pairing-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.pairing-dialog {
    background-color: var(--surface-2);
    border: none;
    border-radius: 0;
    clip-path: var(--notch-lg);
    box-shadow: var(--edge-cyan);
    padding: var(--space-6) var(--space-5);
    max-width: 380px;
    width: 90%;
    text-align: center;
}
.pairing-dialog h3 {
    margin-bottom: var(--space-2);
    font-size: var(--fs-lg);
    color: var(--text-1);
}
.pairing-instruction {
    margin-bottom: var(--space-5);
    font-size: var(--fs-sm);
    color: var(--text-2);
    line-height: 1.5;
}
.pairing-status-text {
    font-size: var(--fs-sm);
    margin-bottom: var(--space-3);
    min-height: 18px;
}
.pairing-info    { color: var(--text-2); }
.pairing-error   { color: var(--c-danger); }
.pairing-success { color: var(--c-success); }

.pairing-pin-display {
    font-size: 42px;
    font-family: var(--font-mono);
    letter-spacing: 12px;
    color: var(--accent-1);
    background-color: var(--surface-1);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin: 0 auto var(--space-3);
    width: fit-content;
    min-width: 160px;
    user-select: all;
    opacity: 0;
    transition: opacity 0.3s;
}
.pairing-pin-display.visible { opacity: 1; }

.pairing-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    margin-top: var(--space-5);
}
.pairing-actions .btn { min-width: 100px; }

/* ════════════════════════════════════════════════════════════════════════
   Tables + pagination
   ════════════════════════════════════════════════════════════════════════ */
.sessions-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--space-2);
    font-size: 0.82rem;
}
.sessions-table th {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-1);
    color: var(--text-2);
    font-weight: 600;
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.sessions-table td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-1);
    vertical-align: middle;
}
.sessions-table tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}
.sessions-table th:last-child,
.sessions-table td:last-child {
    text-align: center;
    width: 80px;
}
.sessions-table tr.session-row-streaming td {
    background: var(--c-success-soft);
}
.sessions-table tr.session-row-streaming:hover td {
    background: rgba(62, 201, 138, 0.18);
}
/* Editable session name: looks like plain text until hovered/focused. */
.session-name-edit {
    display: inline-block;
    min-width: 2ch;
    padding: 1px 4px;
    margin: -1px -4px;
    border-radius: var(--radius-1);
    cursor: text;
    outline: none;
    transition: background 0.12s ease, box-shadow 0.12s ease;
}
.session-name-edit:hover {
    background: rgba(255, 255, 255, 0.06);
}
.session-name-edit:focus {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 1px var(--c-accent, var(--border-1));
}

.session-streaming-badge {
    display: inline-block;
    margin-left: var(--space-2);
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--c-success);
    background: var(--c-success-soft);
    vertical-align: middle;
    white-space: nowrap;
    animation: session-streaming-pulse 1.6s ease-in-out infinite;
}
@keyframes session-streaming-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

.sessions-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-3);
    padding-top: var(--space-2);
    border-top: 1px solid var(--border-1);
}
.pagination-info {
    font-size: 0.82rem;
    color: var(--text-2);
    min-width: 100px;
    text-align: center;
}

/* ════════════════════════════════════════════════════════════════════════
   Inline SVG icons (js/ui/icons.js) — sized to the local font, currentColor
   ════════════════════════════════════════════════════════════════════════ */
.icon {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    vertical-align: -0.125em;
}

/* ════════════════════════════════════════════════════════════════════════
   Utilities — small helpers so view templates carry no inline style
   ════════════════════════════════════════════════════════════════════════ */
.u-hidden { display: none; }
.u-mono { font-family: var(--font-mono); }
.u-row { display: flex; gap: var(--space-2); align-items: center; }
.u-grow { flex: 1; }
.u-shrink-0 { flex-shrink: 0; }
.u-center { text-align: center; }
.u-mt-2 { margin-top: var(--space-2); }
.u-mt-3 { margin-top: var(--space-3); }
.u-mb-1 { margin-bottom: var(--space-1); }
.u-mb-2 { margin-bottom: var(--space-2); }
.u-ml-2 { margin-left: var(--space-2); }
.u-pt-0 { padding-top: 0; }
.u-pt-3 { padding-top: var(--space-3); }
