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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3346;
  --text: #e4e6ef;
  --text2: #8b8fa7;
  --accent: #4f8cff;
  --accent-hover: #3a73e0;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --radius-sm: 4px;
}

[data-theme="light"] {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface2: #f0f2f5;
  --border: #d1d5db;
  --text: #1f2937;
  --text2: #6b7280;
  --accent: #3b7cff;
  --accent-hover: #2563eb;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ─── Topbar ─── */
.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo { font-size: 1.1rem; font-weight: 700; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active { color: var(--accent); background: rgba(79, 140, 255, 0.1); }

/* ─── Content ─── */
.content { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Split Layout ─── */
.split { display: grid; grid-template-columns: 280px 1fr; gap: 1.5rem; min-height: calc(100vh - 100px); }
.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}
.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.sidebar-header h3 { font-size: 0.875rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; }
.sidebar-list { list-style: none; }
.sidebar-item {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-item:hover { background: var(--surface2); }
.sidebar-item.active { background: rgba(79, 140, 255, 0.15); color: var(--accent); }
.sidebar-item .item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}
.editor-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  font-size: 0.95rem;
  min-height: 200px;
}

/* ─── Form Elements ─── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
input[type="text"],
input[type="number"],
input[type="url"],
input[type="email"],
input[type="tel"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

.radio-group, .checkbox-group { display: flex; gap: 1rem; flex-wrap: wrap; }
.radio-group label, .checkbox-group label {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.875rem; color: var(--text); cursor: pointer;
  text-transform: none; letter-spacing: normal; font-weight: 400;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #000; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn-lg { padding: 0.6rem 1.2rem; font-size: 0.9rem; }

.btn-group { display: flex; gap: 0.5rem; margin-top: 1rem; }

/* ─── Table ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin: 0.75rem 0;
}
.data-table th {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover td { background: rgba(79, 140, 255, 0.04); }
.data-table input, .data-table select {
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
}
.data-table .actions { white-space: nowrap; }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 1000;
  transition: opacity 0.3s, transform 0.3s;
}
.toast.hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--accent); color: #fff; }

/* ─── Badge ─── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge-constant { background: rgba(79, 140, 255, 0.15); color: var(--accent); }
.badge-rotating { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-auto { background: rgba(34, 197, 94, 0.15); color: var(--success); }

/* ─── Section Heading ─── */
.section-heading {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* ─── Progress ─── */
.progress-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  margin: 0.75rem 0;
}
.progress-bar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

/* ─── Results ─── */
.result-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 0.75rem;
}
.result-card.success { border-left: 3px solid var(--success); }
.result-card.error { border-left: 3px solid var(--danger); }

/* ─── Options Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-width: 400px;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h3 { margin-bottom: 1rem; }
.modal .btn-group { justify-content: flex-end; }

/* ─── Login Screen ─── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.3rem; }
.login-card .subtitle { color: var(--text2); font-size: 0.875rem; margin-bottom: 1.5rem; }
.login-card .form-group { margin-bottom: 1rem; }
.login-card .btn { width: 100%; justify-content: center; padding: 0.6rem; font-size: 0.9rem; margin-top: 0.5rem; }
.login-error {
  display: none;
  background: rgba(239,68,68,0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

/* ─── Topbar Right ─── */
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
}
.topbar-right .user-info { color: var(--text2); }
.topbar-right .btn { padding: 0.3rem 0.7rem; font-size: 0.75rem; }

/* ─── Pulse Animation ─── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ─── Disabled Button ─── */
.btn:disabled, .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ─── Secondary Button ─── */
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

/* ─── Info color ─── */
:root { --info: #38bdf8; }

/* ─── Stat Cards ─── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  overflow: hidden;
  min-width: 0;
}
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.75rem; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Dashboard Grid ─── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.dashboard-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

/* ─── Status Badges ─── */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-badge.success { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-badge.error { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.status-badge.warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.status-badge.healthy { background: rgba(34, 197, 94, 0.15); color: var(--success); }

/* ─── Project Stats ─── */
.project-stat { margin-bottom: 0.75rem; }
.project-stat-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.3rem; font-size: 0.85rem; }
.progress-bar-container {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

/* ─── Health Issues ─── */
.health-issue {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}
.health-issue.error { background: rgba(239, 68, 68, 0.08); }
.health-issue.warning { background: rgba(245, 158, 11, 0.08); }
.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.health-dot.error { background: var(--danger); }
.health-dot.warning { background: var(--warning); }
.health-dot.healthy { background: var(--success); }

/* ─── Quick Actions ─── */
.quick-actions {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.action-buttons { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ─── Filter Row ─── */
.filter-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--surface);
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}
.filter-row select, .filter-row input { max-width: 200px; }
.input { padding: 0.5rem 0.75rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 0.875rem; }
.input-sm { padding: 0.35rem 0.6rem; font-size: 0.8rem; }
input[type="date"] { color-scheme: dark; }

/* ─── Pagination ─── */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
}

/* ─── Link Style ─── */
.link { color: var(--accent); text-decoration: none; font-size: 0.8rem; }
.link:hover { text-decoration: underline; }

/* ─── Detail Grid ─── */
.detail-grid { display: flex; flex-direction: column; gap: 0.5rem; }
.detail-row { display: flex; gap: 1rem; font-size: 0.85rem; }
.detail-label { color: var(--text2); min-width: 140px; font-weight: 600; }
.detail-value { color: var(--text); word-break: break-all; white-space: pre-wrap; }

/* ─── Modal Header ─── */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.modal-body { max-height: 60vh; overflow-y: auto; }

/* ─── Notification Panel ─── */
.notification-panel {
  position: fixed;
  top: 56px;
  right: 0;
  width: 380px;
  max-height: calc(100vh - 56px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  z-index: 150;
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
  transition: transform 0.2s;
}
.notification-panel.hidden { transform: translateX(100%); pointer-events: none; }
.notif-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.notif-header h3 { font-size: 0.95rem; }
.notif-list { padding: 0.5rem; }
.notif-item {
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
  border-left: 3px solid transparent;
  font-size: 0.85rem;
}
.notif-item.unread { background: rgba(79, 140, 255, 0.05); border-left-color: var(--accent); }
.notif-title { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; margin-bottom: 0.3rem; }
.notif-msg { color: var(--text2); font-size: 0.8rem; }
.notif-time { color: var(--text2); font-size: 0.7rem; margin-top: 0.3rem; }
.notif-type-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 600;
}
.notif-type-badge.info { background: rgba(56, 189, 248, 0.15); color: var(--info); }
.notif-type-badge.warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.notif-type-badge.error { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.notif-type-badge.success { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.notification-btn { position: relative; }
.notif-icon { font-size: 1.1rem; }
.notif-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
}

/* ─── Proxy Health ─── */
.proxy-controls {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  background: var(--surface);
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.proxy-results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  min-height: 60px;
}
.state-grid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.state-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 1rem;
}
.state-btn {
  width: 48px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.state-btn.untested { background: var(--surface2); color: var(--text2); }
.state-btn.working { background: rgba(34, 197, 94, 0.2); color: var(--success); border-color: var(--success); }
.state-btn.failed { background: rgba(239, 68, 68, 0.2); color: var(--danger); border-color: var(--danger); }
.state-btn:hover { transform: scale(1.05); }
.state-legend {
  display: flex;
  gap: 1.5rem;
  font-size: 0.8rem;
  color: var(--text2);
}
.state-legend > span { display: flex; align-items: center; gap: 0.4rem; }

/* ─── Multi-Select Dropdown ─── */
.multi-select-dropdown {
  position: relative;
}
.multi-select-display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  min-height: 38px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.multi-select-display:hover {
  border-color: var(--accent);
}
.multi-select-options {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.multi-select-option {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}
.multi-select-option:hover {
  background: var(--surface);
}
.multi-select-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .split { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; height: auto; padding: 0.75rem; gap: 0.5rem; }
  .tabs { flex-wrap: wrap; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .login-card { margin: 1rem; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .notification-panel { width: 100%; }
  .proxy-controls { flex-direction: column; }
  .filter-row { flex-direction: column; }
  .filter-row select, .filter-row input { max-width: 100%; }
}
