:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #0c4a8a;
  --accent-hover: #09396b;
  --accent-soft: #eff6ff;
  --ok: #15803d;
  --err: #b91c1c;
  --err-bg: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.06);
  --radius: 10px;
  --radius-sm: 7px;
  --t: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #1e293b;
  --line-strong: #334155;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --ok: #22c55e;
  --err: #f87171;
  --err-bg: rgba(239, 68, 68, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  transition: background-color var(--t), color var(--t);
  -webkit-font-smoothing: antialiased;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.s247-fade {
  animation: fadeSlideIn 0.28s ease-out both;
}

/* Header */
.s247-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px 24px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  transition: background-color var(--t), border-color var(--t);
}

.s247-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.s247-logo-wrap {
  display: inline-flex;
  align-items: center;
  padding: 0;
  background: transparent;
  border: 0;
  text-decoration: none;
}

.s247-logo-wrap img {
  height: 32px;
  width: auto;
  display: block;
}

.logo-dark { display: none !important; }
[data-theme="dark"] .logo-light { display: none !important; }
[data-theme="dark"] .logo-dark { display: block !important; }

.s247-title-group h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.s247-title-group p {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.s247-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.s247-nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  transition: background-color var(--t), color var(--t);
}

.s247-nav a:hover {
  background: var(--surface-alt);
  color: var(--ink);
}

.s247-nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Theme Toggle Button */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--t), border-color var(--t), transform 0.12s ease;
}

.theme-toggle:hover {
  background: var(--surface-alt);
  border-color: var(--line-strong);
}

.theme-toggle:active {
  transform: scale(0.97);
}

.theme-toggle svg {
  width: 15px;
  height: 15px;
  display: block;
}

/* Main container */
.s247-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

/* Typography & Sections */
h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.sec-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 26px 0 10px;
  flex-wrap: wrap;
}

.vacio {
  color: var(--muted);
  font-size: 13px;
}

/* Cards & Panels */
.s247-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--t), border-color var(--t), box-shadow var(--t), transform var(--t);
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  margin-bottom: 10px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
}

th, td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 11px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th:last-child, td:last-child { border-right: 0; }
tr:last-child td { border-bottom: 0; }

th {
  background: var(--surface-alt);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:hover td,
table tr:not(:first-child):hover td {
  background: var(--surface-alt);
}

.center { text-align: center; }

/* Form controls & Buttons */
select, input, textarea, button {
  font: inherit;
  border-radius: var(--radius-sm);
  transition: border-color var(--t), background-color var(--t), color var(--t), box-shadow var(--t), transform 0.1s ease;
}

select, input, textarea {
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--surface-alt);
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.small {
  padding: 4px 10px;
  font-size: 12px;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input[type="checkbox"].toggle {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--ok);
}

.cell-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--surface);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: none;
  z-index: 50;
  max-width: 360px;
  animation: fadeSlideIn 0.2s ease-out;
}

.toast.err {
  background: var(--err);
  color: #fff;
}

/* Dialog */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  width: min(680px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-md);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 4px;
}

.field input, .field select {
  width: 100%;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.check-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}

.check-inline input { width: auto; }

.var-box {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface-alt);
  margin-top: 12px;
}

.var-row {
  display: grid;
  grid-template-columns: 1.1fr 1.3fr .8fr .9fr auto;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.var-row input, .var-row select {
  width: 100%;
  font-size: 12px;
  padding: 5px 7px;
}

@media (max-width: 640px) {
  .s247-header { padding: 12px 16px; }
  .s247-main { padding: 16px; }
  .var-row { grid-template-columns: 1fr 1fr; }
}
