/* ==========================================================================
   WebBridge MCP — Modern Control Plane Design System
   ========================================================================== */

:root {
  --bg-app: #080b11;
  --bg-surface: #0f1420;
  --bg-card: #151c2e;
  --bg-card-hover: #1c253d;
  --bg-input: #0b0f18;
  --border-subtle: #1e293b;
  --border-card: #24324a;
  --border-focus: #38bdf8;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-cyan: #06b6d4;
  --accent-sky: #38bdf8;
  --accent-indigo: #6366f1;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #a855f7;

  --glow-sky: 0 0 20px -5px rgba(56, 189, 248, 0.35);
  --glow-emerald: 0 0 20px -5px rgba(16, 185, 129, 0.35);
  --glow-rose: 0 0 20px -5px rgba(244, 63, 94, 0.35);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, monospace;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-image: 
    radial-gradient(ellipse at 15% 0%, rgba(56, 189, 248, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 85% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 60%);
  background-attachment: fixed;
}

/* ── Typography & Links ─────────────────────────────────────── */
a {
  color: var(--accent-sky);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: #7dd3fc;
  text-decoration: underline;
}

/* ── App Shell ─────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 20, 32, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--glow-sky);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #ffffff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text .version-tag {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent-sky);
  background: rgba(56, 189, 248, 0.12);
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 0.35rem;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.header-status-strip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  background: rgba(22, 29, 47, 0.7);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-dot.active {
  background: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald);
  animation: pulse 2.5s infinite;
}

.status-dot.warning {
  background: var(--accent-amber);
  box-shadow: 0 0 10px var(--accent-amber);
}

.status-dot.danger {
  background: var(--accent-rose);
  box-shadow: 0 0 10px var(--accent-rose);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.65; transform: scale(0.9); }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* ── Navigation Tabs ───────────────────────────────────────── */
.nav-container {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 1.5rem;
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1.1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.nav-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.02);
}

.nav-tab.active {
  color: var(--accent-sky);
  border-bottom-color: var(--accent-sky);
  background: rgba(56, 189, 248, 0.04);
}

.nav-badge {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--border-subtle);
  color: var(--text-main);
}

.nav-tab.active .nav-badge {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent-sky);
}

/* ── Main Layout ───────────────────────────────────────────── */
.main-content {
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.75rem;
}

.view-section {
  display: none;
  animation: fadeIn 0.2s ease forwards;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Cards & Surfaces ──────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.35);
  position: relative;
  transition: border-color var(--transition-fast);
}

.card:hover {
  border-color: rgba(56, 189, 248, 0.3);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-subtitle {
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ── Grid Layouts ──────────────────────────────────────────── */
.grid-cols-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.grid-cols-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

/* ── Stat Metric Widget ────────────────────────────────────── */
.stat-card {
  background: linear-gradient(145deg, var(--bg-card), rgba(21, 28, 46, 0.6));
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0.4rem 0 0.25rem;
  color: var(--text-main);
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Buttons & Inputs ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #ffffff;
  box-shadow: 0 2px 10px -2px rgba(2, 132, 199, 0.4);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #0369a1, #1d4ed8);
  box-shadow: 0 4px 14px -2px rgba(2, 132, 199, 0.6);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-main);
  border-color: var(--border-card);
}
.btn-secondary:hover {
  background: rgba(51, 65, 85, 0.9);
  border-color: var(--text-dim);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.3);
}
.btn-danger:hover {
  background: #f43f5e;
  color: #ffffff;
  box-shadow: var(--glow-rose);
}

.btn-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.3);
}
.btn-warning:hover {
  background: #d97706;
  color: #ffffff;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.775rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-md);
}

.input, .select, .textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.input-code, .textarea-code {
  font-family: var(--font-mono);
  font-size: 0.825rem;
}

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-info {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-sky);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.badge-success {
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent-amber);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.badge-danger {
  background: rgba(244, 63, 94, 0.12);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.25);
}

.badge-purple {
  background: rgba(168, 85, 247, 0.12);
  color: var(--accent-purple);
  border: 1px solid rgba(168, 85, 247, 0.25);
}

/* ── Banner / Alerts ───────────────────────────────────────── */
.alert-banner {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.alert-banner.warn {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fef3c7;
}

.alert-banner.danger {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.3);
  color: #ffe4e6;
}

.alert-banner.info {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #e0f2fe;
}

/* ── Browser Tabs Grid ─────────────────────────────────────── */
.tabs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.25rem;
}

.tab-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
}

.tab-card:hover {
  border-color: rgba(56, 189, 248, 0.4);
  transform: translateY(-2px);
}

.tab-card.active-tab {
  border-color: var(--accent-sky);
  box-shadow: var(--glow-sky);
}

.tab-card-header {
  padding: 0.85rem 1rem;
  background: rgba(11, 15, 24, 0.6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.tab-index-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 7px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--accent-sky);
}

.tab-card-body {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.tab-title-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-url-text {
  font-family: var(--font-mono);
  font-size: 0.775rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-meta-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.775rem;
  color: var(--text-dim);
  margin-top: auto;
}

.tab-card-actions {
  padding: 0.65rem 1rem;
  background: rgba(11, 15, 24, 0.4);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* ── Live Logs Viewer ──────────────────────────────────────── */
.logs-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  min-height: 520px;
  background: #06090e;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.logs-toolbar {
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.logs-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.logs-terminal {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
}

.log-entry-row {
  display: flex;
  gap: 0.75rem;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  align-items: baseline;
}

.log-entry-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.log-time {
  color: var(--text-dim);
  white-space: nowrap;
  font-size: 0.75rem;
}

.log-level {
  font-weight: 700;
  font-size: 0.72rem;
  width: 50px;
  text-align: center;
  border-radius: 3px;
  padding: 1px 4px;
}

.log-level.DEBUG { color: #64748b; background: rgba(100, 116, 139, 0.15); }
.log-level.INFO  { color: #38bdf8; background: rgba(56, 189, 248, 0.15); }
.log-level.WARN  { color: #fbbf24; background: rgba(251, 191, 36, 0.15); }
.log-level.ERROR { color: #f87171; background: rgba(248, 113, 113, 0.15); }

.log-cat {
  color: #a78bfa;
  font-weight: 600;
  font-size: 0.75rem;
  white-space: nowrap;
}

.log-msg {
  color: var(--text-main);
  flex: 1;
  word-break: break-word;
}

.log-meta {
  color: #6ee7b7;
  font-size: 0.75rem;
}

/* ── Storage Progress Bar ──────────────────────────────────── */
.storage-bar-wrapper {
  height: 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  margin: 0.85rem 0;
}

.storage-bar-seg {
  height: 100%;
  transition: width 0.3s ease;
}

.seg-logs { background: var(--accent-sky); }
.seg-profile { background: var(--accent-indigo); }
.seg-session { background: var(--accent-purple); }
.seg-stats { background: var(--accent-emerald); }
.seg-settings { background: var(--accent-amber); }
.seg-other { background: var(--text-dim); }

.storage-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

/* ── Settings Form ─────────────────────────────────────────── */
.settings-group {
  margin-bottom: 2rem;
}

.settings-group-header {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.5rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.setting-row {
  display: grid;
  grid-template-columns: 280px 1fr 140px;
  align-items: start;
  gap: 1.5rem;
  padding: 1.1rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.setting-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.setting-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  line-height: 1.4;
}

.setting-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.setting-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-end;
}

/* ── Table Components ──────────────────────────────────────── */
.table-responsive {
  overflow-x: auto;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.data-table th {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--text-main);
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* ── Modals (<dialog>) ─────────────────────────────────────── */
dialog {
  margin: auto;
  padding: 0;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-xl);
  max-width: 650px;
  width: 90vw;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  outline: none;
}

dialog::backdrop {
  background: rgba(4, 7, 12, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-content {
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

/* ── Toast Container ───────────────────────────────────────── */
#toastContainer {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 0.8rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  color: var(--text-main);
  font-size: 0.85rem;
  animation: slideIn 0.25s ease forwards;
  max-width: 420px;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast.toast-success { border-left: 4px solid var(--accent-emerald); }
.toast.toast-error { border-left: 4px solid var(--accent-rose); }
.toast.toast-info { border-left: 4px solid var(--accent-sky); }

/* ── Login Overlay ─────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 17, 0.95);
  backdrop-filter: blur(20px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-xl);
  padding: 2.25rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.8);
  text-align: center;
}

/* ── Floating Action Bar (Save pending changes) ────────────── */
.save-changes-bar {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: rgba(15, 20, 32, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid var(--accent-sky);
  box-shadow: var(--glow-sky);
  border-radius: 999px;
  padding: 0.65rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  z-index: 500;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.save-changes-bar.visible {
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive rules ──────────────────────────────────────── */
@media (max-width: 900px) {
  .setting-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .setting-meta {
    align-items: flex-start;
  }
  .header-status-strip {
    display: none;
  }
  .grid-cols-2 {
    grid-template-columns: 1fr;
  }
}
