:root {
  --bg: #f4f6f9; --panel: #fff; --text: #1b2130; --muted: #6b7385; --border: #e3e6ec;
  --primary: #2563eb; --primary-h: #1d4ed8; --danger: #dc2626; --ok: #16a34a; --warn: #b77900;
  --ok-bg: #e6f6ec; --warn-bg: #fff4d6; --bad-bg: #fde8e8; --badge-bg: #eef0f4;
  --sidebar: #111827; --sidebar-text: #c3cad6; --code-bg: #0f141c; --code-text: #d5dde9;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --panel: #151b24; --text: #e4e8ef; --muted: #8b93a5; --border: #252d3a;
    --ok-bg: #10301c; --warn-bg: #352a0a; --bad-bg: #3b1515; --badge-bg: #222a37; --sidebar: #090c11;
    --primary: #3b82f6; --primary-h: #2563eb;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 22px; }
h3 { font-size: 15px; margin-top: 8px; }
a { color: var(--primary); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.text-bad { color: var(--danger); }
.text-ok { color: var(--ok); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; color: #fff; padding: 2px 10px 22px; display: flex; align-items: center; gap: 8px; }
.logo-sm { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--primary); color: #fff; font-size: 15px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav { background: none; border: 0; color: inherit; text-align: left; padding: 9px 12px; border-radius: 7px; cursor: pointer; font: inherit; }
.nav:hover { background: rgba(255,255,255,.06); }
.nav.active { background: rgba(255,255,255,.12); color: #fff; }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }
.sidebar .btn.ghost { color: var(--sidebar-text); border-color: rgba(255,255,255,.15); background: transparent; }
main { flex: 1; padding: 26px 32px 48px; min-width: 0; max-width: 1400px; }
.tab-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.tab-head h2 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.banner { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 18px; display: grid; gap: 4px; }
.banner a { color: inherit; font-weight: 600; }

/* Botones / inputs */
.btn { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 7px 14px; border-radius: 7px; cursor: pointer; font: inherit; white-space: nowrap; box-shadow: var(--shadow); }
.btn:hover { background: var(--badge-bg); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; margin-top: 4px; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
input[type=checkbox] { width: 16px; height: 16px; margin: 0 8px 0 0; accent-color: var(--primary); }
label { display: block; margin-bottom: 12px; font-weight: 500; }
label small { font-weight: 400; color: var(--muted); }
label.check { display: flex; align-items: center; font-weight: 400; }
label.check.inline { margin: 0; }
.pad-top { padding-top: 28px; }
.search { width: 230px; margin: 0; }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }
.input-row .btn { margin-top: 4px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 2px; margin: 0 0 14px; }
legend { padding: 0 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--badge-bg); border-radius: 8px; padding: 3px; margin-bottom: 14px; }
.segmented button { border: 0; background: transparent; color: var(--muted); padding: 7px; border-radius: 6px; cursor: pointer; font: inherit; }
.segmented button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* Stats y tarjetas */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-v { font-size: 24px; font-weight: 700; }
.stat-k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat.ok .stat-v { color: var(--ok); }
.stat.warn .stat-v { color: var(--warn); }
.stat.bad .stat-v { color: var(--danger); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.route-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; box-shadow: var(--shadow); }
.route-card.off { opacity: .55; }
.rc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.rc-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.domain { font-weight: 600; color: var(--text); text-decoration: none; }
.domain:hover { color: var(--primary); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.grid-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 10px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }

/* Tablas */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th { text-align: left; font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--badge-bg) 40%, var(--panel)); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.disabled td { opacity: .5; }
.table.compact td { padding: 6px 14px; font-size: 13px; }
.table .path { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn { margin-left: 4px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 12px; background: var(--badge-bg); color: var(--muted); font-weight: 500; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--danger); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--bad-bg); }
.switch { width: 38px; height: 22px; border-radius: 999px; border: 0; background: var(--border); position: relative; cursor: pointer; padding: 0; }
.switch span { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch.on { background: var(--ok); }
.switch.on span { left: 19px; }
.spin { width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Logs */
.logbox { background: var(--code-bg); color: var(--code-text); border-radius: var(--radius); padding: 14px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; max-height: 72vh; overflow: auto; }
.log { padding: 2px 0; white-space: pre-wrap; word-break: break-word; }
.log.warn b { color: #f5c04a; }
.log.error b { color: #ff7a7a; }
.log.info b { color: #7fb4ff; }
.logbox .muted { color: #7a8597; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 360px; text-align: left; }
.logo { width: 46px; height: 46px; border-radius: 12px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 24px; margin-bottom: 14px; }

/* Diálogos */
.dialog { border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: min(620px, 94vw); background: var(--panel); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dialog.small-dialog { width: min(420px, 94vw); }
.dialog::backdrop { background: rgba(10, 14, 22, .55); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast { position: fixed; bottom: 22px; right: 22px; max-width: 420px; padding: 11px 16px; border-radius: var(--radius); background: var(--ok); color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 100; }
.toast.err { background: var(--danger); }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  main { padding: 18px 14px 40px; }
  .grid2, .grid-settings { grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; }
}
