/* Moonlight-Web — Main Stylesheet */

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

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --border: #2a2a4a;
}

html {
    height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-card) var(--bg-primary);
}

html::-webkit-scrollbar {
    width: 8px;
}

html::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

html::-webkit-scrollbar-thumb {
    background: var(--bg-card);
    border-radius: 4px;
    border: 1px solid var(--border);
}

html::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
                 Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.5;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.version {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Main content */

#main-content {
    flex: 1;
    min-height: 0;
    padding: 24px;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    background-color: var(--accent);
    color: #fff;
    transition: background-color 0.15s, opacity 0.15s;
}

.btn:hover { background-color: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-loading,
.btn-loading:hover {
    opacity: 0.55;
    cursor: wait;
    pointer-events: none;
    position: relative;
}

.btn-loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 8px;
    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); }
}

.btn-secondary {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

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

.btn-neutral {
    background-color: #1565c0;
    color: #fff;
}

.btn-neutral:hover { background-color: #1976d2; }

/* Hosts View */

.hosts-view {
    width: 100%;
}

.hosts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.hosts-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.hosts-actions {
    display: flex;
    gap: 8px;
}

/* Host cards */

.hosts-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hosts-empty,
.hosts-error {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-secondary);
    background-color: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.empty-icon {
    display: block;
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

.host-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    transition: border-color 0.2s;
}

.host-card:hover {
    border-color: var(--accent);
}

.host-card.offline {
    opacity: 0.55;
}

.host-card-icon {
    flex-shrink: 0;
}

.status-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.25rem;
    background-color: var(--bg-card);
}

.status-icon.ready   { color: var(--success); }
.status-icon.locked  { color: var(--warning); }
.status-icon.offline { color: var(--error); }

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

.host-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.host-address {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: 'Consolas', 'Courier New', monospace;
}

.host-gpu {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.host-resolution {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 1px;
}

.host-card-status {
    flex-shrink: 0;
}

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-badge.ready   { background-color: rgba(76, 175, 80, 0.15); color: var(--success); }
.status-badge.locked  { background-color: rgba(255, 152, 0, 0.15); color: var(--warning); }
.status-badge.offline { background-color: rgba(244, 67, 54, 0.15); color: var(--error); }

.host-card-actions {
    flex-shrink: 0;
}

.btn-open {
    background-color: var(--success);
    font-weight: 600;
}

.btn-open:hover {
    background-color: #43a047;
}

.btn-pair {
    font-size: 0.8rem;
    padding: 6px 14px;
}

.host-card-remove {
    flex-shrink: 0;
}

.host-unreachable {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Footer */

.app-footer {
    text-align: center;
    padding: 8px 24px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    background-color: var(--bg-secondary);
    flex-shrink: 0;
}

/* Responsive */

@media (max-width: 600px) {
    #main-content {
        padding: 12px;
    }

    .app-header {
        padding: 10px 16px;
    }

    .host-card {
        flex-wrap: wrap;
        padding: 12px 14px;
        gap: 10px;
    }

    .host-card-actions {
        width: 100%;
    }

    .host-card-actions .btn {
        width: 100%;
    }

    .host-card-remove {
        width: 100%;
        margin-left: 0;
    }

    .btn-remove {
        width: 100%;
    }
}

/* ========================================================================
   Pairing Dialog
   ======================================================================== */

.pairing-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.65);
    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(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px 28px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.pairing-dialog h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: var(--text-primary);
}

.pairing-instruction {
    margin: 0 0 20px 0;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.pairing-status-text {
    font-size: 13px;
    margin: 0 0 14px 0;
    min-height: 18px;
}

.pairing-info {
    color: var(--text-secondary);
}

.pairing-error {
    color: #f87171;
}

.pairing-success {
    color: #4ade80;
}

.pairing-pin-display {
    font-size: 42px;
    font-family: monospace;
    letter-spacing: 12px;
    color: var(--btn-primary);
    background-color: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin: 0 auto 14px auto;
    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: 10px;
    justify-content: center;
    margin-top: 20px;
}

.pairing-actions .btn {
    min-width: 100px;
}

/* ========================================================================
   App List View
   ======================================================================== */

.apps-view {
    width: 100%;
}

.apps-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

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

.apps-host-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.apps-host-addr {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: 'Consolas', 'Courier New', monospace;
}

.apps-spacer {
    width: 100px;  /* Balance the back button */
}

.apps-loading,
.apps-error,
.apps-empty {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-secondary);
    background-color: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
}

/* App grid */

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}

.app-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 16px;
    text-align: center;
    transition: border-color 0.2s, transform 0.15s;
    cursor: pointer;
}

.app-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.app-card-image {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 8px;
    background-color: var(--bg-card);
    margin-bottom: 2px;
}

.app-card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.app-card-image .app-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 2rem;
}

.app-card-name {
    font-weight: 500;
    font-size: 0.9rem;
    line-height: 1.3;
    word-break: break-word;
}

.app-card-actions {
    margin-top: 4px;
}

/* ========================================================================
   Toast Notifications
   ======================================================================== */

#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    color: #fff;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);

    /* Slide in from right */
    animation: toastSlideIn 0.3s ease forwards;
}

.toast-exit {
    animation: toastFadeOut 0.3s ease forwards;
}

.toast-success {
    background-color: #2e7d32;
    border: 1px solid #4caf50;
}

.toast-error {
    background-color: #b71c1c;
    border: 1px solid #f44336;
}

.toast-warning {
    background-color: #e65100;
    border: 1px solid #ff9800;
}

.toast-info {
    background-color: #0d47a1;
    border: 1px solid #2196f3;
}

@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);
    }
}

/* Responsive grid adjustments */

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

    .apps-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
    }

    .apps-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    .apps-spacer {
        display: none;
    }
}

/* ========================================================================
   Settings View
   ======================================================================== */

.settings-view,
.admin-view {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

.settings-header,
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.settings-header h2,
.admin-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Admin close button (X) */

.view-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.view-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.settings-section {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
    margin-bottom: 20px;
}

.settings-section-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.settings-section-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 20px;
}

.settings-section-desc code {
    font-family: 'Consolas', 'Courier New', monospace;
    background-color: var(--bg-primary);
    padding: 1px 5px;
    border-radius: 3px;
}

.settings-section-desc a {
    color: var(--text-secondary);
    text-decoration: underline;
}

.settings-section-desc a:hover {
    color: var(--text-primary);
}

.settings-field {
    padding-top: 20px;
}

.settings-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

/* Description text under setting labels — replaces previous tooltips */
.setting-desc {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 8px;
}

/* Checkbox description: indent to align with checkbox text */
.settings-checkbox-label + .setting-desc {
    padding-left: 28px;
}

.settings-input {
    display: block;
    width: 100%;
    padding: 10px 14px;
    font-size: 0.875rem;
    font-family: 'Consolas', 'Courier New', monospace;
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

.settings-input:focus {
    border-color: var(--accent);
}

.settings-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

/* Select dropdown (video codec selector, etc.) */

.settings-select {
    display: block;
    width: 100%;
    padding: 10px 14px;
    font-size: 0.875rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s;
    appearance: auto;
    -webkit-appearance: auto;
}

.settings-select:focus {
    border-color: var(--accent);
}

.settings-select option {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* ── Range slider (bitrate) ────────────────────────────────────────────────────── */

.settings-slider {
    display: block;
    width: 100%;
    height: 6px;
    margin: 10px 0 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-card);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    transition: background 0.15s;
}

.settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4a90d9;
    border: 2px solid var(--bg-primary);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    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: #4a90d9;
    border: 2px solid var(--bg-primary);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.settings-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
    user-select: none;
}

.settings-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.4;
}

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

.settings-hint a:hover {
    text-decoration: underline;
}

/* Checkbox styled as a toggle-like row */
.settings-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
}

.settings-checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 2px;
    accent-color: #4a90d9;
    cursor: pointer;
}

.settings-checkbox-text {
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.settings-note {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-top: 8px;
    padding-left: 28px;
}

.settings-actions {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

.btn-save {
    background-color: var(--accent);
    font-weight: 500;
}

.btn-save:disabled {
    opacity: 0.5;
    cursor: default;
    background-color: var(--bg-card);
    color: var(--text-secondary);
}

.settings-status {
    margin-top: 16px;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.settings-status-ok {
    background-color: rgba(76, 175, 80, 0.12);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: #a5d6a7;
}

.settings-status-ok a {
    color: #81c784;
    text-decoration: underline;
    font-family: 'Consolas', 'Courier New', monospace;
}

.settings-status-pending {
    background-color: rgba(255, 152, 0, 0.12);
    border: 1px solid rgba(255, 152, 0, 0.3);
    color: #ffcc80;
}

/* Header action buttons */

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.btn-icon:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.btn-icon.nav-active {
    background-color: var(--accent);
    color: #fff;
}

.btn-icon svg {
    display: block;
}

/* ── Internet Access (deSEC dynamic DNS) ───────────────────────────────────── */

/* Domain row: label + URL */
.tunnel-domain-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    padding-left: 28px;  /* Align with text under checkbox */
}

.tunnel-domain-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Clickable URL link (tunnel active) */
.tunnel-url-link {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-decoration: underline;
    word-break: break-all;
}

.tunnel-url-link:hover {
    color: #64b5f6;
}

/* Disabled/grayed URL (tunnel inactive) */
.tunnel-url-disabled {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
    opacity: 0.5;
    word-break: break-all;
    cursor: default;
}

/* Info/error text */
.tunnel-info {
    position: relative;
    font-size: 0.8rem;
    line-height: 1.4;
    padding: 8px 28px 8px 12px;  /* Right padding for close button */
    border-radius: 6px;
    margin-top: 4px;
}

.tunnel-info-neutral {
    color: var(--text-secondary);
    padding-top: 0;
}

.tunnel-info-success {
    background: rgba(38, 166, 154, 0.12);
    border: 1px solid rgba(38, 166, 154, 0.3);
    color: #80cbc4;
}

.tunnel-info-error {
    background: rgba(244, 67, 54, 0.12);
    border: 1px solid rgba(244, 67, 54, 0.3);
    color: #ef9a9a;
}

.tunnel-info-pending {
    background: rgba(255, 152, 0, 0.12);
    border: 1px solid rgba(255, 152, 0, 0.3);
    color: #ffcc80;
}

.tunnel-info-warning {
    background: rgba(255, 152, 0, 0.08);
    border: 1px solid rgba(255, 152, 0, 0.2);
    color: var(--text-secondary);
}

/* Spinner for "Starting..." state */
.tunnel-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 152, 0, 0.3);
    border-top-color: #ffcc80;
    border-radius: 50%;
    animation: tunnelSpin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 4px;
}

@keyframes tunnelSpin {
    to { transform: rotate(360deg); }
}

/* Close button for tunnel info messages (×) */
.tunnel-info-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    color: inherit;
    opacity: 0.5;
    padding: 0 2px;
}

.tunnel-info-close:hover {
    opacity: 1;
}

/* ── Internet Info Box (blue-ish info frame) ──────────────────────────────── */

.internet-info-box {
    background: rgba(33, 150, 243, 0.08);
    border: 1px solid rgba(33, 150, 243, 0.2);
    border-radius: 6px;
    padding: 12px 14px;
    margin-top: 12px;
    font-size: 0.8rem;
    line-height: 1.55;
    color: var(--text-secondary);
}

.internet-info-box p {
    margin-bottom: 4px;
}

.internet-info-box p:last-child {
    margin-bottom: 0;
}

.internet-important-label {
    color: #ffc107;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.internet-info-box code {
    font-family: 'Consolas', 'Courier New', monospace;
    background: rgba(33, 150, 243, 0.12);
    padding: 1px 5px;
    border-radius: 3px;
}

.internet-info-error {
    background: rgba(244, 67, 54, 0.1);
    border-color: rgba(244, 67, 54, 0.25);
    color: #ef9a9a;
}

/* DNS propagation indicator */

.dns-propagating {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    margin-top: 12px;
    background: rgba(255, 152, 0, 0.1);
    border: 1px solid rgba(255, 152, 0, 0.2);
    border-radius: 6px;
    font-size: 0.8rem;
    color: #ffcc80;
    line-height: 1.4;
}

/* Inline text colors */

.text-success {
    color: #4caf50;
}

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


