/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --primary: #0071e3;
  --primary-hover: #0058b9;
  --success: #34c759;
  --success-bg: #e8f9ed;
  --warning: #ff9500;
  --warning-bg: #fff5e6;
  --danger: #ff3b30;
  --danger-bg: #ffecea;
  --text: #1d1d1f;
  --text-secondary: #86868b;
  --border: #d2d2d7;
  --border-light: #e8e8ed;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
}
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
.hidden { display: none !important; }
b { font-weight: 600; }

/* === Login === */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--surface); border-radius: 20px; padding: 48px 40px; text-align: center; box-shadow: var(--shadow-lg); width: 380px; max-width: 90vw; }
.login-logo { margin-bottom: 16px; }
.login-card h1 { font-size: 24px; font-weight: 600; margin-bottom: 4px; }
.login-sub { color: var(--text-secondary); font-size: 13px; margin-bottom: 32px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input {
  padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; font-family: var(--font); outline: none; transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,113,227,0.1); }
.login-card button {
  padding: 12px 16px; background: var(--primary); color: #fff; border: none;
  border-radius: var(--radius-sm); font-size: 15px; font-weight: 500; cursor: pointer;
  transition: background 0.2s;
}
.login-card button:hover { background: var(--primary-hover); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* === Dashboard Layout === */
.dashboard { min-height: 100vh; }
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,0.85); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  padding: 0 24px; height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 17px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; }

.stat-chips { display: flex; gap: 8px; }
.stat-chip {
  background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 4px 12px; display: flex; flex-direction: column; align-items: center; min-width: 64px;
}
.stat-label { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 14px; font-weight: 500; color: var(--text); }

.action-bar { padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; }
.action-left { display: flex; gap: 8px; }
.main { padding: 0 24px 48px; }

/* === Stream Grid === */
.stream-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }

.stream-card {
  background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border-light);
  overflow: hidden; transition: box-shadow 0.2s;
}
.stream-card:hover { box-shadow: var(--shadow); }

.stream-card-header { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-light); }
.stream-card-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.stream-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- 拖拽排序 --- */
.drag-handle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 22px; flex-shrink: 0;
  color: var(--text-secondary, #86868b); cursor: grab; border-radius: 4px;
  margin-right: -4px; touch-action: none;
}
.drag-handle:hover { color: var(--text); background: rgba(0,0,0,0.05); }
.drag-handle:active { cursor: grabbing; }
.stream-card.dragging { opacity: 0.45; }
.stream-card.drag-over-before { box-shadow: -3px 0 0 0 var(--primary), var(--shadow); }
.stream-card.drag-over-after { box-shadow: 3px 0 0 0 var(--primary), var(--shadow); }

.status-badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 20px; font-size: 11px; font-weight: 500; white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-running { background: var(--success-bg); color: #1a8a3a; }
.status-running .status-dot { background: var(--success); animation: pulse 2s infinite; }
.status-stopped { background: #f0f0f3; color: var(--text-secondary); }
.status-stopped .status-dot { background: var(--text-secondary); }
.status-error { background: var(--danger-bg); color: #c0281f; }
.status-error .status-dot { background: var(--danger); }
.status-reconnecting { background: var(--warning-bg); color: #b36b00; }
.status-reconnecting .status-dot { background: var(--warning); animation: pulse 1s infinite; }
.status-waiting { background: var(--warning-bg); color: #b36b00; }
.status-waiting .status-dot { background: var(--warning); animation: pulse 1.6s infinite; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.stream-card-body { padding: 14px 20px; display: flex; flex-direction: column; gap: 8px; }
.stream-info-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.stream-info-label { color: var(--text-secondary); min-width: 56px; }
.stream-info-value { color: var(--text); font-family: var(--mono); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stream-info-value.truncate { max-width: 240px; }

.stream-stats { display: flex; gap: 16px; padding-top: 4px; }
.stream-stat { font-size: 11px; }
.stream-stat-label { color: var(--text-secondary); }
.stream-stat-value { font-weight: 500; margin-left: 4px; }

.stream-card-actions { padding: 12px 20px; border-top: 1px solid var(--border-light); display: flex; gap: 8px; flex-wrap: wrap; }

/* === Empty State === */
.empty-state { text-align: center; padding: 80px 20px; color: var(--text-secondary); }
.empty-state h2 { font-size: 18px; margin: 16px 0 8px; color: var(--text); }
.empty-state p { font-size: 13px; margin-bottom: 24px; }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid transparent; transition: all 0.15s;
  font-family: var(--font); text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover:not(:disabled) { filter: brightness(0.9); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { filter: brightness(0.9); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--border-light); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon { padding: 6px; width: 32px; height: 32px; }

/* === Modal === */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 200;
  background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 480px; max-width: 90vw; max-height: 90vh; display: flex; flex-direction: column;
  animation: slideUp 0.2s ease;
}
.modal-large { width: 800px; }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { font-size: 17px; font-weight: 600; }
.modal-close {
  background: none; border: none; font-size: 24px; color: var(--text-secondary); cursor: pointer;
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s; line-height: 1;
}
.modal-close:hover { background: var(--border-light); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding-top: 20px; }

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

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: var(--font); outline: none; transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--surface); color: var(--text);
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,113,227,0.1); }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-check-group { display: flex; align-items: flex-end; }
.proxy-input-row { display: flex; gap: 8px; align-items: center; }
.proxy-input-row input { flex: 1; min-width: 0; }
.proxy-input-row .btn { white-space: nowrap; flex-shrink: 0; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.checkbox-label input { width: 18px; height: 18px; accent-color: var(--primary); }

/* === Log Content === */
.log-body { padding: 0; background: #1d1d1f; }
.log-content {
  font-family: var(--mono); font-size: 12px; color: #e0e0e6; padding: 16px;
  height: 480px; overflow-y: auto; line-height: 1.6; white-space: pre-wrap; word-break: break-all;
}
.log-line { padding: 1px 0; }
.log-time { color: #6e6e76; }
.log-sys { color: #58c6ff; }
.log-err { color: #ff6b6b; }
.log-warn { color: #ffb340; }

.log-content::-webkit-scrollbar { width: 6px; }
.log-content::-webkit-scrollbar-track { background: transparent; }
.log-content::-webkit-scrollbar-thumb { background: #424245; border-radius: 3px; }

/* === Toast === */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 13px; z-index: 300; box-shadow: var(--shadow-lg);
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* === Responsive === */
@media (max-width: 768px) {
  .header { padding: 0 12px; }
  .stat-chips { display: none; }
  .stream-grid { grid-template-columns: 1fr; }
  .main { padding: 0 12px 48px; }
  .action-bar { padding: 12px; }
}
/* Transitional states remain stoppable while awaiting network/process teardown. */
.status-resolving, .status-connecting, .status-stopping { background: #fff4dc; color: #8a5b00; }
