:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1d212c;
  --border: #262b38;
  --text: #e6e8ee;
  --muted: #8a91a3;
  --accent: #4f8cff;
  --accent-2: #2dd4bf;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  font-size: 14px;
}

* { box-sizing: border-box; }

/* hidden debe ganar siempre a cualquier display: flex/grid */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

body { display: flex; }

/* Sidebar */
#sidebar {
  width: 280px;
  flex: 0 0 280px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh;
}
#sidebar header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
#sidebar h1 {
  font-size: 14px;
  margin: 0 0 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
#search {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
}
#clients {
  list-style: none;
  margin: 0; padding: 6px 0;
  flex: 1;
  overflow-y: auto;
}
#clients li {
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  display: flex; flex-direction: column; gap: 2px;
}
#clients li:hover { background: var(--bg-3); }
#clients li.active {
  background: var(--bg-3);
  border-left-color: var(--accent);
}
#clients li .name {
  font-weight: 500;
  font-size: 13px;
}
#clients li .web {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#clients li .badges {
  margin-top: 4px;
  display: flex; gap: 4px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.dot.on { background: var(--ok); }
.dot.off { background: var(--danger); }
#sidebar footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}
#sidebar footer .footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 22px;
}
#sidebar footer .footer-row + .footer-row { margin-top: 6px; }
#sidebar footer .footer-actions { display: flex; gap: 6px; }
#sidebar footer button {
  padding: 3px 8px;
  font-size: 11px;
}
#me-info { color: var(--muted); }
#me-info strong { color: var(--text); }
#me-info .role-pill { margin-left: 6px; }

/* Main */
#main {
  flex: 1;
  height: 100vh;
  overflow-y: auto;
}
.empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%;
  color: var(--muted);
}

#editor { padding: 20px 28px; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px; margin-bottom: 16px;
}
.topbar h2 { margin: 0 0 4px; font-size: 18px; }
.topbar a { color: var(--accent); font-size: 13px; text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.actions { display: flex; gap: 8px; }

button {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.primary:hover { background: #6aa1ff; }
button.ghost { background: transparent; }

.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}
.tabs button {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  color: var(--muted);
  white-space: nowrap;
}
.tabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.pane h3 {
  margin: 18px 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.pane h3:first-child { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
}
.grid label.full { grid-column: 1 / -1; }
.row { display: flex; gap: 18px; flex-wrap: wrap; }

label {
  display: flex; flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

input, select, textarea {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  resize: vertical;
}

.hint { color: var(--muted); font-size: 12px; margin: 0 0 8px; }

.status {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 12px;
}
.status.global {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
}
.status.ok    { background: rgba(34,197,94,0.12);  color: #4ade80; }
.status.err   { background: rgba(239,68,68,0.12);  color: #f87171; }
.status.info  { background: rgba(79,140,255,0.12); color: #93b7ff; }

.check-result {
  margin-top: 18px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}
.check-result .row { display: flex; justify-content: space-between; padding: 4px 0; }
.check-result .row + .row { border-top: 1px solid var(--border); }
.code-2xx { color: var(--ok); }
.code-3xx { color: var(--accent-2); }
.code-4xx { color: var(--warn); }
.code-5xx, .code-000 { color: var(--danger); }

/* ---------- Dashboard cards ---------- */
.dash-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}
.card-value { font-size: 32px; font-weight: 600; line-height: 1; }
.card-value-sm { font-size: 14px; color: var(--text); }
.card-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.score-bar {
  margin-top: 10px;
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}
.score-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--danger), var(--warn) 50%, var(--ok));
  width: 0%;
  transition: width 0.4s ease;
}
.dash-summary {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  display: flex; gap: 10px;
}
.dash-summary .ok { color: var(--ok); }
.dash-summary .warn { color: var(--warn); }
.dash-summary .fail { color: var(--danger); }

/* ---------- Chart (SVG simple) ---------- */
.chart {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}
.chart svg { width: 100%; height: 100%; display: block; }
.chart .empty-msg { font-style: italic; }

.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li {
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 12px;
}
.alerts li.warn { border-left-color: var(--warn); }
.alerts li.empty { border-left-color: var(--ok); color: var(--muted); }

/* ---------- Audit ---------- */
.audit-result {
  margin: 16px 0;
}
.audit-result .audit-head {
  display: flex; gap: 14px; align-items: center;
  margin-bottom: 12px;
}
.audit-result .audit-head .big-score {
  font-size: 42px; font-weight: 700; line-height: 1;
  padding: 8px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 80px; text-align: center;
}
.audit-result .meta { color: var(--muted); font-size: 12px; }
.audit-result ul.checks {
  list-style: none; padding: 0; margin: 0;
}
.audit-result ul.checks li {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  align-items: start;
  font-size: 13px;
}
.audit-result .pill {
  display: inline-block;
  font-size: 10px; font-weight: 700;
  padding: 3px 8px; border-radius: 3px;
  text-transform: uppercase; letter-spacing: 0.05em;
  text-align: center;
}
.pill.ok   { background: rgba(34,197,94,0.18);  color: #4ade80; }
.pill.warn { background: rgba(245,158,11,0.18); color: #fbbf24; }
.pill.fail { background: rgba(239,68,68,0.18);  color: #f87171; }
.audit-result .check-label { font-weight: 500; }
.audit-result .check-detail { color: var(--muted); font-size: 12px; margin-top: 2px; }

.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: flex; justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.history li .h-score {
  font-weight: 600;
}

/* ---------- SERP table ---------- */
table.serp {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.serp th, table.serp td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.serp th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 500;
}
table.serp input, table.serp select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 5px 8px;
  font-size: 12px;
  border-radius: 4px;
  color: var(--text);
  width: 100%;
}
table.serp .pos { font-weight: 600; }
table.serp .pos.top { color: var(--ok); }
table.serp .pos.mid { color: var(--warn); }
table.serp .pos.low { color: var(--danger); }
table.serp button.del {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 14px;
}
table.serp button.del:hover { color: var(--danger); }

#admin-view { padding: 20px 28px; }
#admin-view .topbar {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
#admin-view .topbar h2 { margin: 0 0 4px; font-size: 18px; }
.role-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.role-pill.admin  { background: rgba(79,140,255,0.18); color: #93b7ff; }
.role-pill.editor { background: rgba(45,212,191,0.18); color: #5eead4; }
.role-pill.viewer { background: rgba(138,145,163,0.18); color: var(--muted); }

/* Tabs internas tipo "mini" para Rutinas */
.tab-mini {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-right: none;
  color: var(--muted);
  font-size: 12px;
  border-radius: 0;
  cursor: pointer;
}
.tab-mini:first-child { border-radius: 4px 0 0 4px; }
.tab-mini:last-child  { border-radius: 0 4px 4px 0; border-right: 1px solid var(--border); }
.tab-mini.active {
  background: var(--bg-3);
  color: var(--text);
  border-color: var(--accent);
}
.tab-mini:hover:not(.active) { color: var(--text); }

#rutinas-list li {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
#rutinas-list li:hover { background: var(--bg-3); }
#rutinas-list .meta-pill {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
}
#rutinas-detail pre {
  white-space: pre-wrap;
  font-size: 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 6px;
  max-height: 60vh;
  overflow: auto;
}

/* ---------- Plan de acción ---------- */
.filter { font-size: 11px; color: var(--muted); }
.filter select { width: auto; min-width: 110px; }
.plan-stats {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
}
.plan-stats span { margin-left: 10px; }
.plan-form {
  margin-top: 18px;
  padding: 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.priority-pill, .status-pill {
  display: inline-block;
  font-size: 10px; font-weight: 700;
  padding: 3px 8px; border-radius: 3px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.priority-pill.high { background: rgba(239,68,68,0.18);  color: #f87171; }
.priority-pill.med  { background: rgba(245,158,11,0.18); color: #fbbf24; }
.priority-pill.low  { background: rgba(138,145,163,0.18); color: var(--muted); }

.status-pill.todo        { background: rgba(138,145,163,0.18); color: var(--muted); }
.status-pill.in_progress { background: rgba(79,140,255,0.18);  color: #93b7ff; }
.status-pill.done        { background: rgba(34,197,94,0.18);   color: #4ade80; }
.status-pill.blocked     { background: rgba(239,68,68,0.18);   color: #f87171; }

.due-overdue { color: var(--danger); font-weight: 600; }
.due-soon    { color: var(--warn);   font-weight: 600; }

#plan-table td .action-title { font-weight: 500; }
#plan-table td .action-desc {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
  max-width: 480px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#plan-table td .src-tag {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
}

/* PSI */
.psi-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.psi-cards .card { padding: 10px 12px; }
.psi-score { font-size: 28px; font-weight: 700; }
.psi-score.good  { color: var(--ok); }
.psi-score.avg   { color: var(--warn); }
.psi-score.bad   { color: var(--danger); }
.psi-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  font-size: 12px;
}
.psi-metrics .row { padding: 6px 10px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 4px; display: flex; justify-content: space-between;}
.psi-metrics .row strong { color: var(--text); }
