/* ══════════════════════════════════════════════════════════════════
   Addaxis Nexus — tema claro e suave
   Paleta: fundos frios muito claros, cartões brancos, acento índigo.
   ══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e7ebf3;
  --text: #1e293b;
  --text-soft: #64748b;
  --text-faint: #94a3b8;
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --accent-soft: #eef2ff;
  --ok-bg: #ecfdf5;
  --ok-text: #047857;
  --warn-bg: #fff7ed;
  --warn-text: #c2410c;
  --danger-bg: #fef2f2;
  --danger-text: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.05);
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Inter", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

/* ── Estrutura ──────────────────────────────────────────────────── */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 36px 44px;
  max-width: 1180px;
}

/* ── Marca ──────────────────────────────────────────────────────── */

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #818cf8, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
}

.brand-mark-lg { width: 52px; height: 52px; font-size: 20px; border-radius: 14px; }

.brand-name { font-size: 17px; color: var(--text-soft); }
.brand-name strong { color: var(--text); font-weight: 700; }

/* ── Navegação ──────────────────────────────────────────────────── */

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-soft);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-icon { font-size: 16px; }

/* ── Rodapé da sidebar ──────────────────────────────────────────── */

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 14px; }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 14px;
}

.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-weight: 600; font-size: 14px; }
.user-role { color: var(--text-faint); font-size: 12px; text-transform: capitalize; }

.logout {
  display: block;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  text-align: center;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 14px;
  border: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
}

.logout:hover { background: var(--danger-bg); color: var(--danger-text); border-color: transparent; }

/* ── Cabeçalho de página ────────────────────────────────────────── */

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 26px; }
.page-header h1 { font-size: 24px; font-weight: 700; }
.page-subtitle { color: var(--text-soft); margin-top: 2px; }
.section-title { font-size: 15px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.06em; margin: 26px 0 12px; }

/* ── Cartões e estatísticas ─────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 18px;
}

.card h2 { font-size: 16px; font-weight: 600; margin-bottom: 14px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value { font-size: 30px; font-weight: 700; color: var(--accent-strong); }
.stat-warn .stat-value { color: var(--warn-text); }
.stat-label { color: var(--text-soft); font-size: 14px; }

/* ── Tabelas ────────────────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  color: var(--text-faint);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 10px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }

/* ── Badges e tags ──────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-muted { background: var(--bg); color: var(--text-soft); }

.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-soft);
  font-size: 12px;
  font-family: Consolas, monospace;
}

.tag-accent { background: var(--accent-soft); color: var(--accent-strong); }

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

/* ── Conectores ─────────────────────────────────────────────────── */

.connector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.connector-card { margin-bottom: 0; display: flex; flex-direction: column; gap: 10px; }
.connector-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.connector-head h3 { font-size: 16px; font-weight: 600; }
.connector-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.connector-link { color: var(--accent-strong); font-size: 13px; text-decoration: none; word-break: break-all; }
.connector-link:hover { text-decoration: underline; }
.connector-broken { border-color: #fecaca; }

/* ── Monitoramento do proxy ────────────────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.proxy-monitor { width: 100%; }
.proxy-page-header { gap: 18px; flex-wrap: wrap; }

.page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.proxy-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.proxy-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px currentColor;
  opacity: 0.8;
}

.proxy-status.is-loading,
.proxy-status.is-unknown { background: var(--bg); color: var(--text-soft); }
.proxy-status.is-ok { background: var(--ok-bg); color: var(--ok-text); }
.proxy-status.is-warn,
.proxy-status.is-stale { background: var(--warn-bg); color: var(--warn-text); }
.proxy-status.is-danger { background: var(--danger-bg); color: var(--danger-text); }

.proxy-error { margin-bottom: 14px; }
.proxy-warnings { margin-bottom: 14px; }
.proxy-warnings ul { margin: 0; padding-left: 20px; }
.proxy-warnings li + li { margin-top: 3px; }

.proxy-sync-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: -14px 0 18px;
  color: var(--text-soft);
  font-size: 13px;
}

.proxy-sync-line > :last-child { white-space: nowrap; }

.proxy-health-grid,
.proxy-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.health-card {
  min-width: 0;
  min-height: 132px;
  margin-bottom: 0;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  border-left-width: 3px;
}

.health-card.is-ok { border-left-color: #10b981; }
.health-card.is-warn,
.health-card.is-stale { border-left-color: #f59e0b; }
.health-card.is-danger { border-left-color: #ef4444; }
.health-card.is-unknown { border-left-color: var(--border); }

.health-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
}

.health-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--text-faint);
}

.health-card.is-ok .health-dot { background: #10b981; box-shadow: 0 0 0 3px var(--ok-bg); }
.health-card.is-warn .health-dot,
.health-card.is-stale .health-dot { background: #f59e0b; box-shadow: 0 0 0 3px var(--warn-bg); }
.health-card.is-danger .health-dot { background: #ef4444; box-shadow: 0 0 0 3px var(--danger-bg); }

.health-kicker {
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.health-state {
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.health-detail {
  overflow: hidden;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-card {
  min-width: 0;
  gap: 8px;
  padding: 18px 20px;
}

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

.metric-state {
  overflow: hidden;
  color: var(--text-faint);
  font-family: Consolas, monospace;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-value {
  font-size: 28px;
  line-height: 1.1;
}

.metric-card.is-warn .metric-value { color: var(--warn-text); }
.metric-card.is-danger .metric-value { color: var(--danger-text); }
.metric-card.is-unknown .metric-value { color: var(--text-faint); }

.metric-detail {
  overflow: hidden;
  color: var(--text-soft);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg);
}

.meter-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.35s ease;
}

.metric-card.is-warn .meter-fill { background: #f59e0b; }
.metric-card.is-danger .meter-fill { background: #ef4444; }
.metric-card.is-unknown .meter-fill { background: var(--text-faint); }

.network-metric-card { justify-content: space-between; }

.network-rates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.network-rates > div { min-width: 0; }
.network-direction { display: block; color: var(--text-faint); font-size: 11px; }
.network-rate { display: block; overflow: hidden; color: var(--accent-strong); font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }

.proxy-detail-grid,
.proxy-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.proxy-detail-card,
.chart-card { min-width: 0; }

.card-subtitle {
  margin-top: -9px;
  color: var(--text-soft);
  font-size: 13px;
}

.detail-list { display: grid; gap: 0; }

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child { border-bottom: 0; }
.detail-row dt { color: var(--text-soft); }
.detail-row dd { text-align: right; font-weight: 600; overflow-wrap: anywhere; }

.chart-card { padding-bottom: 16px; }

.chart-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-soft);
  font-size: 11px;
}

.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-item::before { content: ""; width: 14px; height: 3px; border-radius: 999px; }
.legend-cpu::before { background: var(--accent); }
.legend-memory::before { background: #14b8a6; }
.legend-rx::before { background: #3b82f6; }
.legend-tx::before { background: #f59e0b; }

.proxy-chart {
  display: block;
  width: 100%;
  height: 180px;
  overflow: visible;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(238, 242, 255, 0.65), rgba(255, 255, 255, 0));
}

.chart-grid-line { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-line { stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-line.chart-line-cpu { stroke: var(--accent); }
.chart-line.chart-line-memory { stroke: #14b8a6; }
.chart-line.chart-line-rx { stroke: #3b82f6; }
.chart-line.chart-line-tx { stroke: #f59e0b; }
.chart-point.chart-line-cpu { fill: var(--accent); }
.chart-point.chart-line-memory { fill: #14b8a6; }
.chart-point.chart-line-rx { fill: #3b82f6; }
.chart-point.chart-line-tx { fill: #f59e0b; }
.chart-axis-label,
.chart-empty { fill: var(--text-faint); font: 12px "Segoe UI", system-ui, sans-serif; }

.proxy-table-card,
.proxy-logs-card { min-width: 0; }
.table-wrap { width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
.proxy-requests-table { min-width: 520px; }
.proxy-requests-table td { vertical-align: middle; }
.request-method { color: var(--accent-strong); }
.request-destination { max-width: 320px; overflow-wrap: anywhere; }
.empty-cell { padding: 28px 10px !important; color: var(--text-soft); text-align: center !important; }

.proxy-logs-head { align-items: flex-end; }

.log-controls {
  display: grid;
  grid-template-columns: auto minmax(120px, auto) auto minmax(120px, auto);
  align-items: center;
  gap: 7px;
}

.log-controls label {
  color: var(--text-soft);
  font-size: 12px;
}

.log-controls select {
  width: auto;
  min-width: 120px;
  padding: 7px 30px 7px 10px;
  border-radius: 8px;
  font-size: 13px;
}

.log-viewer {
  min-height: 230px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid #2f2a43;
  border-radius: 10px;
  background: #1e1b2e;
  color: #ddd9ec;
  font: 12px/1.55 Consolas, "Cascadia Code", monospace;
  scrollbar-color: #514a70 #1e1b2e;
}

.log-line {
  display: grid;
  grid-template-columns: 72px minmax(90px, auto) 58px minmax(240px, 1fr);
  gap: 10px;
  padding: 5px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
}

.log-line:last-child { border-bottom: 0; }
.log-time { color: #8f89aa; }
.log-service { color: #aaa3cb; }
.log-level { color: #a5b4fc; font-weight: 700; }
.log-level-warning .log-level { color: #fbbf24; }
.log-level-error .log-level { color: #fca5a5; }
.log-level-debug .log-level { color: #94a3b8; }
.log-message { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.log-empty { padding: 28px 16px; color: #8f89aa; text-align: center; }
.log-count { margin-top: 7px; color: var(--text-faint); font-size: 11px; text-align: right; }

/* ── Botões e formulários ───────────────────────────────────────── */

.btn {
  display: inline-block;
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: scale(0.99); }
.btn:disabled { cursor: wait; opacity: 0.65; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-ghost { background: var(--bg); color: var(--text-soft); text-decoration: none; }
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger-text); }
.btn-danger:hover { background: #fecaca; }

a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.inline-form { display: inline; }

.form-card { max-width: 560px; display: flex; flex-direction: column; gap: 8px; }
.form-card label { margin-top: 8px; }
.form-card .btn { margin-top: 16px; align-self: flex-start; }

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin-bottom: 0; }
.form-inline { display: flex; gap: 8px; align-items: center; }
.form-inline input { width: 220px; padding: 8px 12px; font-size: 14px; }

.key-card { border-color: #bbf7d0; }
.key-box {
  background: var(--ok-bg);
  border: 1px dashed #86efac;
  border-radius: 10px;
  padding: 14px 16px;
  font-family: Consolas, monospace;
  font-size: 14px;
  word-break: break-all;
  -webkit-user-select: all;
  user-select: all;
  margin-top: 10px;
}

label { font-weight: 600; font-size: 14px; color: var(--text); }

input[type="email"], input[type="password"], input[type="text"], select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.alert { border-radius: 10px; padding: 11px 14px; font-size: 14px; margin-bottom: 4px; }
.alert-error { background: var(--danger-bg); color: var(--danger-text); }
.alert-warning { background: var(--warn-bg); color: var(--warn-text); }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); margin-bottom: 18px; }
.alert-ok a { color: var(--ok-text); font-weight: 600; }

.form-hint { font-size: 13px; margin-top: 6px; }

/* ── Tela de login ──────────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(600px 300px at 15% 10%, rgba(129, 140, 248, 0.10), transparent),
    radial-gradient(600px 300px at 85% 90%, rgba(45, 212, 191, 0.08), transparent),
    var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 40px 36px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.login-brand h1 { font-size: 24px; font-weight: 400; color: var(--text-soft); }
.login-brand h1 strong { color: var(--text); font-weight: 700; }
.login-subtitle { color: var(--text-faint); font-size: 14px; }

.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { margin-top: 8px; }
.login-form .btn { margin-top: 16px; }

.login-footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

@media (max-width: 940px) {
  .proxy-detail-grid,
  .proxy-charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 10px 12px;
    padding: 12px 16px 10px;
  }
  .brand { grid-column: 1; grid-row: 1; min-width: 0; padding: 0; }
  .nav {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }
  .nav-item { flex: 0 0 auto; white-space: nowrap; }
  .sidebar-footer {
    grid-column: 2;
    grid-row: 1;
    margin-left: 0;
    border-top: none;
    padding-top: 0;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .logout { margin-top: 0; }
  .content { padding: 24px 18px; }
  .proxy-sync-line { flex-direction: column; gap: 3px; margin-top: -12px; }
  .proxy-sync-line > :last-child { white-space: normal; }
  .proxy-logs-head { align-items: stretch; }
  .log-controls { grid-template-columns: auto minmax(0, 1fr); }
  .log-controls select { width: 100%; }
  .log-line { grid-template-columns: 68px minmax(80px, 1fr) 54px; gap: 7px; }
  .log-message { grid-column: 1 / -1; padding-bottom: 2px; }
}

@media (max-width: 600px) {
  .sidebar-footer .user-meta { display: none; }
  .proxy-page-header { align-items: flex-start; }
  .page-actions { width: 100%; justify-content: space-between; }
  .proxy-health-grid,
  .proxy-metrics-grid { grid-template-columns: 1fr; }
  .health-card { min-height: 112px; }
  .health-detail,
  .metric-detail {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }
  .detail-row { align-items: flex-start; }
  .chart-legend { gap: 8px; }
}

@media (max-width: 340px) {
  .brand-name { display: none; }
  .sidebar { padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .meter-fill { transition: none; }
}
