:root {
  --bg: #f6f6f8; --panel: #fff; --line: #e4e4ea; --text: #1d1d28; --muted: #6b6b7b;
  --brand: #1769d1; --nav: #1d1d28; --danger: #d33c3c; --soft: #eef3fb; --ok: #1a8a4a;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font: 14px/1.5 Inter, system-ui, sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.ok { color: var(--ok); } .bad { color: var(--danger); }
code { background: #efeff3; padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap;
  text-decoration: none; color: var(--text); }
.btn:hover { background: #f2f2f5; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger:hover { color: var(--danger); border-color: #f3c2c2; background: #fdecec; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.block-w { width: 100%; }

input:not([type=checkbox]), select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd3f5; border-color: var(--brand); }
input[readonly] { background: #f7f7fa; }
textarea { resize: vertical; }

/* Acceso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #a78bfa, #60a5fa); }
.auth-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 28px; border: 3px solid #000;
  box-shadow: 6px 7px 0 #000; display: grid; gap: 12px; }
.auth-card h1 { margin: 0; }
.auth-card p { margin: 0 0 4px; }
.auth-card label { display: grid; gap: 4px; font-weight: 500; }
.auth-logo { font-size: 28px; color: #8b5cf6; line-height: 1; }
.alert { background: #fdecec; color: #9b1c1c; padding: 10px 12px; border-radius: 8px; }

/* Estructura */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.nav { background: var(--nav); color: #fff; padding: 14px 10px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 17px; padding: 6px 10px 14px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px; color: #fff;
  background: none; border: 0; cursor: pointer; text-decoration: none; font-weight: 600; text-align: left; }
.nav-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active { background: rgba(255,255,255,.16); }
.nav-spacer { flex: 1; }
.content { padding: 24px; max-width: 900px; width: 100%; display: flex; flex-direction: column; gap: 14px; }
.content > p { margin: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.empty { text-align: center; color: var(--muted); padding: 28px; }
.card.scroll { overflow-x: auto; padding: 6px 12px; }
.card-head, .head-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card-head h2 { margin: 0; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 5px; font-weight: 500; }
.form small { font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 4px; margin: 0; }
legend { font-weight: 500; padding: 0 4px; }
.btn-row { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch { display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--brand); }
.counter { font-size: 12px; color: var(--muted); text-align: right; margin-top: -2px; }

.flash { background: #e7f6ec; color: #145c33; padding: 10px 14px; border-radius: 8px; }
.notice { background: #fff6e0; color: #6b4a00; padding: 10px 14px; border-radius: 8px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi span { color: var(--muted); font-size: 12px; display: block; }
.kpi strong { font-size: 24px; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 500; }
.tbl .r { text-align: right; }
.tbl tr.off td { opacity: .5; }
.tbl tr.err td { background: #fdf3f3; color: #8a1f1f; }
.nowrap { white-space: nowrap; }

.rule-list { display: grid; gap: 10px; }
.rule { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.rule.off { background: #fafafa; }
.rule.off .rule-main { opacity: .55; }
.rule-main { color: inherit; text-decoration: none; min-width: 0; display: grid; gap: 4px; }
.rule-actions { display: flex; gap: 6px; }
.badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge { background: #efeff3; color: #555; font-size: 11.5px; padding: 2px 8px; border-radius: 99px; }
.badge.kw { background: var(--soft); color: var(--brand); font-weight: 600; }
.badge.dark { background: #1d1d28; color: #fff; }
.clamp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.copy { display: flex; gap: 6px; }
.status { margin: 0 0 12px; padding-left: 4px; list-style: none; display: grid; gap: 4px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pager { display: flex; gap: 8px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .nav { flex-direction: row; overflow-x: auto; height: auto; padding: 8px; z-index: 5; }
  .nav .brand, .nav-spacer { display: none; }
  .nav form { display: contents; }
  .nav-item { width: auto; white-space: nowrap; font-size: 13px; }
  .content { padding: 14px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid2, .btn-row { grid-template-columns: 1fr; }
  .rule { grid-template-columns: 1fr; }
}
