/* The Bridge - Command Center | Phone-first dark theme */

:root {
    --bg: #0a0e14;
    --bg-gradient: linear-gradient(180deg, #0d1219 0%, #0a0e14 100%);
    --surface: #131a24;
    --surface-raised: #1a2332;
    --surface-overlay: #1f2d3f;
    --border: #2a3a50;
    --border-bright: #3d5570;
    --text: #f0f4f8;
    --text-secondary: #b8c8d8;
    --text-muted: #7a8ea0;
    --accent: #4a9eff;
    --accent-glow: rgba(74, 158, 255, 0.2);
    --green: #3dd68c;
    --green-glow: rgba(61, 214, 140, 0.15);
    --yellow: #f0c030;
    --red: #ff5c5c;
    --red-glow: rgba(255, 92, 92, 0.15);
    --orange: #ff9940;
    --purple: #b388ff;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --header-height: 56px;
    --output-collapsed: 44px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }


/* ========== LOGIN SCREEN ========== */

#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg-gradient);
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px 28px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.login-icon {
    color: var(--accent);
    margin-bottom: 16px;
}

.login-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 3px;
    color: var(--text);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 32px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#login-token {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

#login-token:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-btn {
    padding: 14px;
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.login-btn:active {
    transform: scale(0.97);
}

.login-error {
    margin-top: 12px;
    color: var(--red);
    font-size: 14px;
}


/* ========== HEADER ========== */

#header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: linear-gradient(180deg, #141c28 0%, var(--surface) 100%);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.header-title {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 2.5px;
    color: var(--text);
}

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

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background: var(--green);
    box-shadow: 0 0 8px var(--green-glow);
}

.status-dot.disconnected {
    background: var(--red);
    box-shadow: 0 0 8px var(--red-glow);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    transition: color 0.15s, background 0.15s;
}

.icon-btn:hover, .icon-btn:active {
    color: var(--text);
    background: var(--surface-raised);
}


/* ========== MAIN CONTENT ========== */

#main {
    position: fixed;
    top: var(--header-height);
    left: 0; right: 0;
    bottom: var(--output-collapsed);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px;
    padding-bottom: calc(20px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
}

.section {
    margin-bottom: 28px;
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-left: 2px;
}


/* ========== QUICK ACTIONS ========== */

.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 88px;
    padding: 16px 12px;
    background: var(--surface);
    border: 2px solid color-mix(in srgb, var(--btn-color) 25%, var(--border));
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, color-mix(in srgb, var(--btn-color) 8%, transparent) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.2s;
}

.action-btn:hover::before,
.action-btn:active::before {
    opacity: 1;
}

.action-btn:active {
    transform: scale(0.96);
    border-color: var(--btn-color);
}

.action-btn.running {
    border-color: var(--btn-color);
    animation: pulse-border 1.5s ease-in-out infinite;
}

.action-btn.running::before {
    opacity: 1;
}

.action-btn.running .action-icon {
    animation: spin-slow 2s linear infinite;
}

@keyframes pulse-border {
    0%, 100% { box-shadow: 0 0 8px color-mix(in srgb, var(--btn-color) 20%, transparent); }
    50% { box-shadow: 0 0 20px color-mix(in srgb, var(--btn-color) 40%, transparent); }
}

@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.action-icon {
    width: 28px;
    height: 28px;
    color: var(--btn-color);
    flex-shrink: 0;
}

.action-label {
    font-size: 14px;
    line-height: 1.2;
    text-align: center;
}


/* ========== ROOM CONTROLS ========== */

.room-controls {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
}

.control-row + .control-row {
    border-top: 1px solid var(--border);
}

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

.control-icon {
    width: 24px;
    height: 24px;
    color: var(--accent);
    flex-shrink: 0;
    transition: color 0.2s;
}

.control-icon.muted {
    color: var(--red);
}

.control-label {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    display: block;
}

.control-desc {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 52px;
    height: 30px;
    flex-shrink: 0;
    display: inline-block;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-bright);
    border-radius: 15px;
    transition: background 0.25s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}


/* ========== APP DOCK ========== */

.app-dock {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.dock-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 88px;
    padding: 16px 12px;
    background: var(--surface);
    border: 2px solid color-mix(in srgb, var(--tile-color) 20%, var(--border));
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    position: relative;
}

.dock-tile:active {
    transform: scale(0.96);
    border-color: var(--tile-color);
}

.dock-tile-muted {
    opacity: 0.5;
}

.dock-icon {
    width: 28px;
    height: 28px;
    color: var(--tile-color);
    flex-shrink: 0;
}

.dock-label {
    font-size: 14px;
    line-height: 1.2;
    text-align: center;
}

.dock-badge {
    position: absolute;
    top: 8px;
    right: 10px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}


/* ========== PANELS ========== */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
    animation: panel-in 0.2s ease;
}

@keyframes panel-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.panel-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: var(--radius-xs);
    line-height: 1;
}

.panel-close:active {
    background: var(--surface-raised);
    color: var(--text);
}


/* ========== TODO LIST ========== */

.todo-input-row {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

#todo-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

#todo-input:focus {
    border-color: var(--green);
}

.todo-add-btn {
    width: 44px;
    height: 44px;
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.1s;
}

.todo-add-btn:active {
    transform: scale(0.93);
}

.todo-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

.todo-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(42, 58, 80, 0.5);
    transition: background 0.1s;
}

.todo-item:last-child {
    border-bottom: none;
}

.todo-item:active {
    background: var(--surface-raised);
}

.todo-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-bright);
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    background: transparent;
}

.todo-checkbox.checked {
    background: var(--green);
    border-color: var(--green);
}

.todo-checkbox.checked::after {
    content: '';
    width: 6px;
    height: 12px;
    border: solid #fff;
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg) translate(-1px, -1px);
}

.todo-text {
    flex: 1;
    font-size: 15px;
    color: var(--text);
    word-break: break-word;
}

.todo-text.done {
    text-decoration: line-through;
    color: var(--text-muted);
}

.todo-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s;
}

.todo-delete:hover, .todo-delete:active {
    opacity: 1;
    color: var(--red);
}

.todo-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}


/* ========== TRADING PANEL ========== */

.trading-content {
    padding: 16px;
}

.trading-stat-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.trading-stat {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}

.trading-stat-value {
    font-size: 20px;
    font-weight: 800;
}

.trading-stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.pnl-positive { color: var(--green); }
.pnl-negative { color: var(--red); }

.trading-table {
    width: 100%;
    font-size: 13px;
    border-collapse: collapse;
}

.trading-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 6px;
    border-bottom: 1px solid var(--border);
}

.trading-table td {
    padding: 8px 6px;
    border-bottom: 1px solid rgba(42, 58, 80, 0.4);
    color: var(--text-secondary);
}

.trading-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 16px 0 8px;
}

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


/* ========== CAST PANEL ========== */

.cast-content {
    padding: 0;
}

.cast-input-row {
    display: flex;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

#cast-url {
    flex: 1;
    padding: 12px 14px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

#cast-url:focus {
    border-color: var(--purple);
}

.cast-go-btn {
    width: 48px;
    height: 48px;
    background: var(--purple);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, opacity 0.15s;
}

.cast-go-btn:active {
    transform: scale(0.93);
}

.cast-go-btn.casting {
    pointer-events: none;
    background: color-mix(in srgb, var(--purple) 60%, var(--bg));
}

.cast-go-spinner { display: none; }
.cast-go-btn.casting .cast-go-icon { display: none; }
.cast-go-btn.casting .cast-go-spinner { display: block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.cast-quick-btn.loading {
    pointer-events: none;
    opacity: 0.7;
    position: relative;
}

.cast-quick-btn.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    border-top-color: var(--qc-color);
    animation: spin 0.8s linear infinite;
}

.cast-platform {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.cast-platform-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--purple);
}

.cast-status-display {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.cast-quick-section {
    padding: 12px 16px;
}

.cast-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.cast-quick-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.cast-quick-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid color-mix(in srgb, var(--qc-color) 25%, var(--border));
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.cast-quick-btn svg {
    color: var(--qc-color);
    flex-shrink: 0;
}

.cast-quick-btn:active {
    transform: scale(0.96);
    border-color: var(--qc-color);
}

.cast-output {
    max-height: 200px;
    overflow-y: auto;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.cast-output pre {
    font-family: 'SF Mono', 'Cascadia Code', 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
}


/* ========== OUTPUT PANEL ========== */

#output-panel {
    position: fixed;
    left: 0; right: 0;
    bottom: 0;
    z-index: 90;
    background: var(--surface);
    border-top: 1px solid var(--border);
    transition: height 0.25s ease;
    display: flex;
    flex-direction: column;
}

#output-panel.collapsed {
    height: var(--output-collapsed);
}

#output-panel.expanded {
    height: 45vh;
}

.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: pointer;
    flex-shrink: 0;
    min-height: var(--output-collapsed);
    user-select: none;
}

#output-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

#output-title.active {
    color: var(--accent);
}

.output-controls {
    display: flex;
    gap: 8px;
}

.output-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-xs);
    transition: color 0.15s;
}

.output-btn:hover, .output-btn:active {
    color: var(--text);
}

#output-panel.expanded #output-toggle svg {
    transform: rotate(180deg);
}

.output-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 16px 16px;
    display: none;
}

#output-panel.expanded .output-body {
    display: block;
}

#output-text {
    font-family: 'SF Mono', 'Cascadia Code', 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
}


/* ========== RESPONSIVE ========== */

@media (min-width: 600px) {
    .quick-actions {
        grid-template-columns: repeat(3, 1fr);
    }
    .app-dock {
        grid-template-columns: repeat(4, 1fr);
    }
    #main {
        padding: 24px 20px;
    }
    .action-btn, .dock-tile {
        min-height: 96px;
    }
}

@media (min-width: 900px) {
    #main {
        max-width: 800px;
        margin: 0 auto;
        padding: 28px 24px;
    }
}


/* ========== SCROLLBAR ========== */

::-webkit-scrollbar {
    width: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--border-bright);
}
