:root {
  --bg: #0b101b;
  --surface: #121a2a;
  --surface-2: #182235;
  --border: #26344f;
  --text: #e6edf7;
  --muted: #8fa3bf;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #a855f7;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

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

.small {
  font-size: 12px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.accent-blue { color: #60a5fa; }
.accent-green { color: #4ade80; }
.accent-red { color: #f87171; }
.accent-purple { color: #c084fc; }

/* Login Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, #17243d, #090d16 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.brand-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.16);
  border: 1px solid rgba(59, 130, 246, 0.35);
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-card form {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Shell */
.app-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px 20px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title h1 {
  margin: 0;
  font-size: 20px;
}

.dot-live {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
  flex-shrink: 0;
}

.dot-live.online {
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}

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

/* Telemetry */
.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.metric-header strong {
  color: var(--text);
  font-size: 16px;
}

.metric-sub {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.speed-row, .counts-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.speed-row div, .counts-row div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.speed-row strong {
  font-size: 17px;
}

.counts-row strong {
  font-size: 19px;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: #0b1220;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #1e2d47;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #22c55e);
  transition: width 0.3s ease;
}

.progress-fill.warn {
  background: linear-gradient(90deg, #f59e0b, #fb923c);
}

.progress-fill.danger {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: #93c5fd;
  border-bottom-color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Panels & Controls */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.panel h2, .panel h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: #3d5278;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--text);
}

.full-width { width: 100%; }

.search-bar {
  display: grid;
  grid-template-columns: 1fr 160px 105px auto auto;
  gap: 10px;
}

@media (max-width: 900px) {
  .search-bar {
    grid-template-columns: 1fr;
  }
}

.import-drawer {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.import-grid {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 10px;
}

.row-end {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.alert {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

.error-text {
  color: #f87171;
  font-size: 13px;
}

/* Preview Table */
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filter-group, .action-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.checkbox-inline input {
  width: auto;
}

.table-wrap {
  overflow-x: auto;
}

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

.data-table th, .data-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid #1e2a40;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

.cover-thumb {
  width: 82px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: #0c1322;
  border: 1px solid var(--border);
  display: block;
}

.cover-placeholder {
  width: 82px;
  height: 56px;
  border-radius: 6px;
  background: #0c1322;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-ok { background: rgba(34, 197, 94, 0.18); color: #4ade80; }
.badge-info { background: rgba(59, 130, 246, 0.18); color: #60a5fa; }
.badge-warn { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.badge-err { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.badge-muted { background: rgba(143, 163, 191, 0.16); color: #cbd5e1; }

/* Queue Cards */
.pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}

.pill.active {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--primary);
  color: #93c5fd;
}

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

.task-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.task-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.task-bars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 720px) {
  .task-bars {
    grid-template-columns: 1fr;
  }
}

.bar-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 36px 12px;
}

/* Settings & Logs */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 960px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
}

.full-span {
  grid-column: 1 / -1;
}

.health-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: #0c1322;
  border: 1px solid var(--border);
  font-size: 12px;
}

.logs-box {
  background: #0a101c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  height: 430px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.log-line {
  word-break: break-word;
}

.log-INFO { color: #cbd5e1; }
.log-WARNING { color: #fbbf24; }
.log-ERROR { color: #f87171; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #1e293b;
  border: 1px solid #475569;
  color: #f8fafc;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  z-index: 200;
}
