* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-primary: #0c0f1a;
    --bg-secondary: #111525;
    --bg-card: #161a2c;
    --bg-input: #1c2038;
    --border: #232840;
    --border-hover: #6c5ce7;
    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #555570;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-gradient: linear-gradient(135deg, #6c5ce7, #a855f7);
    --green: #00d2a0;
    --red: #ff5a5a;
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { color: #fff; }

/* ===== Top Bar ===== */
.top-bar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    height: 56px;
    display: flex;
    align-items: center;
}
.top-bar-inner {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.top-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.top-bar h1 {
    font-size: 17px;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.3px;
}
.top-sep { color: var(--border); font-weight: 300; }
.top-desc { color: var(--text-secondary); font-size: 13px; }
.top-right { display: flex; gap: 16px; }
.nav-link {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: all 0.2s;
}
.nav-link:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    text-decoration: none;
}

/* ===== Control Page Layout ===== */
.main-layout {
    display: flex;
    height: calc(100vh - 56px);
    padding: 16px 24px;
    gap: 16px;
}

.panel {
    overflow-y: auto;
}

.panel-left {
    width: 300px;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel-center {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.panel-right {
    width: 280px;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== Panel Cards ===== */
.panel-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 18px;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
}

/* ===== Form ===== */
.form-group {
    margin-bottom: 12px;
}
.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.2s;
    outline: none;
}
.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}
.form-group input::placeholder { color: var(--text-muted); }
.form-help {
    margin-top: 5px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-muted);
}

.form-row {
    display: flex;
    gap: 10px;
}
.flex-1 { flex: 1; }

/* ===== Connect / Disconnect ===== */
.btn-group-connect {
    margin-bottom: 8px;
}
.btn-connect,
.btn-disconnect {
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
    letter-spacing: 0.3px;
}
.btn-connect {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
}
.btn-connect:hover {
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.45);
    transform: translateY(-1px);
}
.btn-connect:active {
    transform: translateY(0);
}
.btn-disconnect {
    background: linear-gradient(135deg, #ff5a5a, #ff7a7a);
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 90, 90, 0.25);
}
.btn-disconnect:hover {
    box-shadow: 0 6px 20px rgba(255, 90, 90, 0.4);
    transform: translateY(-1px);
}

.status-bar {
    font-size: 12px;
    padding: 7px 12px;
    border-radius: 6px;
    text-align: center;
    font-weight: 500;
    background: rgba(255, 90, 90, 0.1);
    color: var(--red);
    border: 1px solid rgba(255, 90, 90, 0.15);
}
.status-bar.connected {
    background: rgba(0, 210, 160, 0.1);
    color: var(--green);
    border-color: rgba(0, 210, 160, 0.15);
}
.status-bar.connecting {
    background: rgba(108, 92, 231, 0.1);
    color: var(--accent-light);
    border-color: rgba(108, 92, 231, 0.15);
}

/* ===== Control Buttons ===== */
.btn-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.btn-grid.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}
.btn-ctrl {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 4px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.ctrl-icon {
    font-size: 16px;
    line-height: 1;
}
.btn-ctrl:hover {
    background: #1e2345;
    border-color: var(--accent);
    color: var(--text-primary);
}
.btn-ctrl:active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-ctrl.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-orient {
    padding: 9px 4px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-orient.active {
    background: var(--accent-gradient);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 10px rgba(108, 92, 231, 0.3);
}
.btn-orient:hover:not(.active) {
    border-color: var(--accent);
    color: var(--text-primary);
}

/* ===== Player ===== */
.player-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}
.player-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
}
.player-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.player-info {
    font-size: 12px;
    color: var(--text-muted);
}
.clipboard-hint {
    font-size: 11px;
    color: var(--green);
    background: rgba(0, 210, 160, 0.1);
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.clipboard-hint.visible {
    opacity: 1;
}

/* 剪贴板同步弹窗 */
.clip-popup {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}
.clip-popup.visible {
    display: flex;
}
.clip-popup-inner {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    min-width: 340px;
    max-width: 480px;
}
.clip-popup-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}
.clip-textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    padding: 10px;
    resize: vertical;
    font-family: inherit;
}
.clip-textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.clip-popup-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    justify-content: flex-end;
}

.player-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #080a14;
    position: relative;
    min-height: 0;
}

.player-viewport {
    position: relative;
    width: 720px;
    height: 1280px;
    max-width: 100%;
    max-height: 100%;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.28);
}

.player-placeholder,
.player-frame {
    position: absolute;
    inset: 0;
}

.player-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
    z-index: 1;
}
.player-placeholder svg {
    margin-bottom: 12px;
    opacity: 0.5;
}
.player-placeholder p {
    font-size: 14px;
    color: #555;
}

.player-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #000;
    display: none;
    z-index: 2;
}

/* ===== Session List ===== */
.session-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-hint {
    text-align: center;
    padding: 24px 0;
    color: var(--text-muted);
}
.empty-hint svg { margin-bottom: 8px; opacity: 0.4; }
.empty-hint p { font-size: 13px; }

.session-card {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 12px;
    border: 1px solid var(--border);
    transition: border-color 0.2s;
}
.session-card:hover {
    border-color: #333;
}
.session-card .s-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.session-card .s-ip {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    font-family: 'SF Mono', 'Menlo', monospace;
}
.session-card .s-status {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(0, 210, 160, 0.12);
    color: var(--green);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.session-card .s-detail {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.session-card .s-actions {
    display: flex;
    gap: 6px;
}
.session-card .btn-s {
    flex: 1;
    padding: 5px 0;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}
.session-card .btn-s:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: rgba(108, 92, 231, 0.08);
}
.session-card .btn-s.danger:hover {
    border-color: var(--red);
    color: var(--red);
    background: rgba(255, 90, 90, 0.08);
}

/* ===== Monitor Page ===== */
.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 10px;
}
.controls label { color: var(--text-secondary); font-size: 13px; }
.controls select {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}

.btn {
    padding: 7px 18px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: #5a4bd1; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-sm { padding: 5px 12px; font-size: 12px; margin-top: 10px; }

.stats-bar {
    display: flex;
    gap: 14px;
    padding: 20px 24px;
    justify-content: center;
    flex-wrap: wrap;
}
.stat-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 18px 36px;
    text-align: center;
    min-width: 155px;
    border: 1px solid var(--border);
}
.stat-value {
    display: block;
    font-size: 34px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -1px;
}
.stat-value.purple { color: var(--accent); }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 14px;
    padding: 0 24px 24px;
    max-width: 1400px;
    margin: 0 auto;
    align-items: start;
}
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    min-width: 0;
    overflow: hidden;
}
.card h3 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 13px;
    min-width: 0;
}
.card-row span:first-child {
    color: var(--text-secondary);
    min-width: 0;
}
.val { color: var(--text-primary); font-weight: 500; }
.val.purple { color: var(--accent); }
.val.green { color: var(--green); }
.val.red { color: var(--red); }

.progress-bar {
    margin-top: 12px;
    background: var(--bg-input);
    border-radius: 4px;
    height: 6px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 4px;
    transition: width 0.4s ease;
    width: 0%;
}

details { margin-top: 16px; }
summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 12px 14px;
    background: linear-gradient(180deg, rgba(28, 32, 56, 0.96), rgba(24, 28, 47, 0.96));
    border-radius: 10px;
    border: 1px solid rgba(108, 92, 231, 0.14);
    transition: all 0.2s ease;
    font-weight: 600;
    list-style: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}
summary::-webkit-details-marker {
    display: none;
}
summary::before {
    content: '>';
    display: inline-block;
    margin-right: 8px;
    color: var(--accent-light);
    transition: transform 0.2s ease;
}
details[open] > summary::before {
    transform: rotate(90deg);
}
summary:hover {
    border-color: rgba(108, 92, 231, 0.42);
    color: var(--text-primary);
}
summary #deviceCount,
summary #contentionCount {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 8px;
    margin-left: 2px;
    border-radius: 999px;
    background: rgba(108, 92, 231, 0.16);
    border: 1px solid rgba(108, 92, 231, 0.28);
    color: var(--accent-light);
    font-size: 11px;
    font-weight: 700;
}

.detail-hint {
    margin-top: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.08), rgba(0, 210, 160, 0.05));
    border: 1px solid rgba(108, 92, 231, 0.12);
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.65;
}

.detail-table {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 10px;
}
.detail-table table {
    width: 100%;
    font-size: 12px;
    border-collapse: collapse;
}
.detail-table th {
    text-align: left;
    padding: 7px 10px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.3px;
}
.detail-table td {
    padding: 7px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.detail-table tr:hover td {
    background: rgba(108, 92, 231, 0.04);
}

#deviceList.detail-table {
    max-height: 360px;
    padding-right: 4px;
    overflow-x: auto;
}

#deviceList .empty-state {
    padding: 28px 18px;
    text-align: center;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(108, 92, 231, 0.2);
    color: var(--text-secondary);
}

.session-inspector-panel {
    margin-top: 14px;
    padding: 14px;
    border-radius: 14px;
    border: 1px solid rgba(108, 92, 231, 0.14);
    background:
        radial-gradient(circle at top right, rgba(108, 92, 231, 0.1), transparent 34%),
        linear-gradient(180deg, rgba(20, 24, 42, 0.98), rgba(16, 20, 34, 0.98));
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.03),
        0 10px 22px rgba(4, 8, 18, 0.16);
}

.session-inspector-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.session-inspector-item {
    min-width: 0;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(108, 92, 231, 0.08);
}

.session-inspector-item-wide {
    grid-column: 1 / -1;
}

.session-inspector-label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.session-inspector-value {
    display: block;
    min-width: 0;
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-inspector-item-wide .session-inspector-value {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.55;
}

.session-inspector-mono {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 11.5px;
}

.session-detail-board {
    min-width: 690px;
}

.session-detail-head,
.session-detail-item {
    display: grid;
    grid-template-columns: minmax(180px, 2.4fr) minmax(84px, 0.9fr) minmax(72px, 0.75fr) minmax(70px, 0.7fr) minmax(88px, 0.95fr) minmax(72px, 0.7fr) auto;
    gap: 10px;
    align-items: center;
}

.session-detail-head {
    padding: 0 12px 8px;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.35px;
}

.session-detail-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-detail-item {
    position: relative;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 14px;
    background:
        radial-gradient(circle at top right, rgba(108, 92, 231, 0.1), transparent 36%),
        linear-gradient(180deg, rgba(20, 24, 42, 0.98), rgba(16, 20, 34, 0.98));
    border: 1px solid rgba(108, 92, 231, 0.12);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.03),
        0 10px 22px rgba(4, 8, 18, 0.2);
}

.session-detail-item::before {
    content: '';
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, rgba(0, 210, 160, 0.45), rgba(108, 92, 231, 0));
    opacity: 0.7;
}

.session-cell {
    min-width: 0;
    color: var(--text-secondary);
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-cell.device {
    color: var(--text-primary);
    font-weight: 600;
    font-family: 'SF Mono', 'Menlo', monospace;
}

.session-cell.device .session-cell-sub {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 11px;
}

.session-cell.session-id {
    color: var(--accent-light);
    font-weight: 600;
}

.session-cell.traffic,
.session-cell.timeout {
    color: var(--text-primary);
    font-weight: 600;
}

.session-health {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.session-health.healthy {
    color: var(--green);
    background: rgba(0, 210, 160, 0.12);
    border-color: rgba(0, 210, 160, 0.2);
}

.session-health.expiring,
.session-health.idle {
    color: #ffd166;
    background: rgba(255, 209, 102, 0.12);
    border-color: rgba(255, 209, 102, 0.2);
}

.session-health.timeout,
.session-health.preempted,
.session-health.disconnected {
    color: #ff8585;
    background: rgba(255, 90, 90, 0.12);
    border-color: rgba(255, 90, 90, 0.2);
}

.session-action {
    margin-top: 0;
    flex-shrink: 0;
    padding: 4px 12px;
    box-shadow: none;
}

@media (max-width: 900px) {
    .session-inspector-grid {
        grid-template-columns: 1fr;
    }

    .session-inspector-item-wide {
        grid-column: auto;
    }

    .session-detail-board {
        min-width: 760px;
    }
}

/* monitor top-bar center mode */
body > .top-bar:only-of-type {
    justify-content: center;
}
.subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 6px;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2e40; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3e50; }

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.panel-card, .card, .stat-item {
    animation: fadeIn 0.3s ease;
}
