:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #646b78;
  --border: #e2e5ea;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --danger: #c4314b;
  --ok: #1f8a4c;
  --row-hover: #f2f4f8;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e8eaee;
    --muted: #9198a5;
    --border: #2c3039;
    --accent: #6d8cff;
    --accent-text: #0b0d12;
    --danger: #ff6b81;
    --ok: #4fd18b;
    --row-hover: #20242c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.15rem; margin-bottom: 1rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; margin: -0.4rem 0 0.9rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.88em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---------- Controles ---------- */
input, select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
button:disabled { opacity: 0.6; cursor: progress; }

label { display: block; margin-bottom: 0.9rem; }
label > span { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.3rem; }
label small { display: block; margin-top: 0.25rem; }

.error { color: var(--danger); margin: 0 0 0.9rem; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 1.75rem; }
.login-card h1 { margin-bottom: 0.25rem; }
.login-card button { width: 100%; }

/* ---------- Panel ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.content { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

.toolbar { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; }
.toolbar input { flex: 1; }
.toolbar select { width: auto; max-width: 260px; }

.host { display: block; font-size: 0.8rem; color: var(--muted); }
.host.global { font-style: italic; }
.grid-source { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.grid-source label { margin-bottom: 0.4rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.65rem 0.85rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
tr.disabled td:not(:last-child):not(:nth-last-child(2)) { opacity: 0.5; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

td.dest { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.dest a { color: inherit; }
.note { display: block; font-size: 0.82rem; color: var(--muted); }
.tag {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  padding: 0.05rem 0.4rem; border-radius: 4px; margin-left: 0.35rem;
  background: var(--row-hover); border: 1px solid var(--border); color: var(--muted);
  vertical-align: 1px;
}
.actions { display: flex; gap: 0.4rem; justify-content: flex-end; }
.empty { padding: 2rem; text-align: center; margin: 0; }

/* Interruptor */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 22px; cursor: pointer;
  background: var(--border); transition: background 0.15s;
}
.switch span::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: transform 0.15s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Editor ---------- */
dialog {
  width: min(560px, calc(100% - 32px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.5rem;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.checks { margin-bottom: 0.75rem; }
.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; margin-bottom: 0.4rem; }
.check input { width: auto; }
.editor-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

/* ---------- Aviso ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 0.6rem 1rem; border-radius: 8px; font-size: 0.9rem;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
  max-width: calc(100% - 32px);
}

/* ---------- Móvil ---------- */
@media (max-width: 720px) {
  .toolbar { flex-direction: column; }
  .grid-2, .grid-source { grid-template-columns: 1fr; }
  .toolbar select { width: 100%; max-width: none; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { padding: 0.6rem 0.25rem; border-bottom: 1px solid var(--border); }
  td { border: 0; padding: 0.2rem 0.75rem; }
  td.dest { max-width: none; white-space: normal; word-break: break-all; }
  .num { text-align: left; }
  td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 0.85rem; }
  .actions { justify-content: flex-start; margin-top: 0.3rem; }
}
