:root,
[data-theme="dark"] {
  --bg: #0e141b;
  --bg-2: #151d28;
  --surface: #1c2633;
  --line: #2a3648;
  --text: #e8eef7;
  --muted: #8b9bb0;
  --accent: #3d9cf0;
  --accent-2: #2b7ec9;
  --ok: #3ecf8e;
  --warn: #f5a524;
  --danger: #f31260;
  --on-accent: #061018;
  --row-hover: #243044;
  --tab-idle: #101820;
  --tab-hover: #182230;
  --login-glow: #1a3a5c;
  --badge-ok-bg: #163627;
  --badge-info-bg: #1a3348;
  --badge-warn-bg: #3a2c12;
  --badge-danger-bg: #3a1524;
  --badge-danger-fg: #ff8fb0;
  --radius: 12px;
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
}

[data-theme="light"] {
  --bg: #eef3f8;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --line: #d0dbe6;
  --text: #15202b;
  --muted: #5b6b7c;
  --accent: #1b75c4;
  --accent-2: #155f9e;
  --ok: #1a8a55;
  --warn: #b86a00;
  --danger: #c0124a;
  --on-accent: #ffffff;
  --row-hover: #e7f1fb;
  --tab-idle: #e4ebf3;
  --tab-hover: #d7e2ed;
  --login-glow: #c5dcf5;
  --badge-ok-bg: #d7f3e5;
  --badge-info-bg: #d6eaf8;
  --badge-warn-bg: #fde9c8;
  --badge-danger-bg: #fad4e0;
  --badge-danger-fg: #a10d3c;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
html.layout-fill,
html.layout-fill body {
  height: 100%;
  overflow: hidden;
}
body.layout-fill {
  display: flex;
  flex-direction: column;
}
body.layout-fill .page {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
code { font-size: 0.9em; color: var(--accent); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.login-wrap {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(800px 400px at 20% 0%, var(--login-glow) 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
  display: grid;
  gap: 14px;
}
.brand { letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); margin: 0; font-size: 0.75rem; }
.login-card h1 { margin: 0; font-size: 1.45rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
label { display: grid; gap: 6px; font-size: 0.85rem; color: var(--muted); }
input, select, textarea {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.password-field {
  position: relative;
  display: block;
}
.password-field input {
  width: 100%;
  padding-right: 42px;
}
.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.password-toggle:hover { color: var(--text); background: var(--surface); }
.password-toggle:focus-visible { outline: 2px solid var(--accent); }
.password-toggle svg { width: 20px; height: 20px; }
.password-toggle svg[hidden] { display: none; }

.theme-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
}
.theme-toggle:hover { color: var(--text); background: var(--surface); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle svg[hidden] { display: none; }
.theme-toggle-float {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--line);
  color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.error { color: var(--danger); margin: 0; font-size: 0.9rem; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  gap: 16px;
}
.topbar nav { display: flex; gap: 8px; align-items: center; }
.topbar nav a {
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
}
.topbar nav a:hover { background: var(--surface); text-decoration: none; }
.topbar nav a.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.topbar-right { display: flex; gap: 12px; align-items: center; margin-left: auto; }

.page { padding: 20px; max-width: 1200px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex: 0 0 auto; }
.page-head h1 { margin: 0; font-size: 1.4rem; }
.tenant-title {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}
.tenant-url {
  font-size: 1.05rem;
  color: var(--accent);
}
.tenant-susc {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar input { flex: 1; max-width: 420px; }
.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; background: var(--bg-2); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: lowercase;
}
.badge.administrador { background: var(--badge-ok-bg); color: var(--ok); }
.badge.usuario { background: var(--badge-info-bg); color: var(--accent); }
.badge.consultor { background: var(--badge-warn-bg); color: var(--warn); }
.badge.asignado { background: var(--badge-warn-bg); color: var(--warn); }
body[data-nivel="consultor"] .write-only { display: none !important; }
.badge.suspendido, .badge.suspendida, .badge.pendiente { background: var(--badge-warn-bg); color: var(--warn); }
.badge.cancelado, .badge.cancelada, .badge.vencida, .badge.sin_suscripcion { background: var(--badge-danger-bg); color: var(--badge-danger-fg); }

.tabs { display: flex; gap: 6px; margin: 16px 0; flex-wrap: wrap; }
.tab { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: transparent; cursor: pointer; color: var(--text); }
.tab.active { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.panel { display: none; }
.panel.active { display: block; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-2 .full { grid-column: 1 / -1; }
.dt-pair { display: flex; gap: 8px; }
.dt-pair input[type="date"] { flex: 1.2; }
.dt-pair input[type="time"] { flex: 1; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.modal {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-2);
  color: var(--text);
  width: min(720px, 94vw);
  padding: 0;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.55); }
.modal form { padding: 22px; display: grid; gap: 12px; }
.modal h2 { margin: 0 0 8px; }
.modal.modal-sm { width: min(480px, 94vw); }
.modal.modal-sm form { display: grid; gap: 12px; }
#lbl-password-hint:empty { display: none; }

.folder-tabs {
  display: grid;
  gap: 0;
}
.folder-tabs .tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 3px;
  align-items: flex-end;
  margin: 0;
  padding: 0 10px 0 1px;
  position: relative;
  z-index: 1;
}
.folder-tabs .tab {
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  background: var(--tab-idle);
  color: var(--muted);
  padding: 8px 16px 10px;
  margin: 0 0 -1px;
  position: relative;
  font-weight: 500;
}
.folder-tabs .tab:hover:not(.active) {
  background: var(--tab-hover);
  color: var(--text);
}
.folder-tabs .tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  z-index: 2;
  padding-bottom: 11px;
}
.folder-tabs .tab-panels {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 0 12px 12px 12px;
  background: var(--surface);
  padding: 16px;
  position: relative;
  z-index: 0;
}
.folder-tabs .panel,
.folder-tabs .panel.active {
  grid-area: 1 / 1;
  display: grid;
  gap: 12px;
  align-content: start;
  min-height: 0;
}
.folder-tabs .panel {
  visibility: hidden;
  pointer-events: none;
}
.folder-tabs .panel.active {
  visibility: visible;
  pointer-events: auto;
}

.folder-tabs-page {
  margin-top: 8px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.folder-tabs-page .tabs {
  flex: 0 0 auto;
  flex-wrap: wrap;
}
.folder-tabs-page .tab-panels {
  flex: 1;
  min-height: 0;
  display: grid;
  overflow: hidden;
}
.folder-tabs-page .panel,
.folder-tabs-page .panel.active {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.folder-tabs-page .panel {
  visibility: hidden;
  pointer-events: none;
}
.folder-tabs-page .panel.active {
  visibility: visible;
  pointer-events: auto;
  display: flex;
  overflow: auto;
}
.folder-tabs-page .panel-fill.active {
  overflow: hidden;
}
.folder-tabs-page .panel-fill .table-wrap-fill,
.folder-tabs-page .panel-fill .log-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.folder-tabs-page .table-wrap {
  background: var(--bg-2);
}
.table-wrap-fill thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.table-wrap-fill tbody tr {
  cursor: default;
}

.modal-msg {
  width: min(440px, 94vw);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.modal-msg form {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 4px;
  padding: 28px 24px 22px;
}
.modal-msg h2 { margin: 8px 0 4px; font-size: 1.2rem; }
.modal-msg #dlg-message-body {
  margin: 0 0 8px;
  line-height: 1.45;
  max-width: 36ch;
  white-space: pre-line;
}
.modal-msg .actions {
  width: 100%;
  justify-content: center;
  margin-top: 12px;
}
.modal-msg-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
}
.modal-msg-ok .modal-msg-icon {
  background: var(--badge-ok-bg);
  color: var(--ok);
}
.modal-msg-ok .modal-msg-icon::before { content: "✓"; }
.modal-msg-warn .modal-msg-icon {
  background: var(--badge-warn-bg);
  color: var(--warn);
}
.modal-msg-warn .modal-msg-icon::before { content: "!"; }
.modal-msg-err .modal-msg-icon {
  background: var(--badge-danger-bg);
  color: var(--danger);
}
.modal-msg-err .modal-msg-icon::before { content: "!"; }

.toast {
  position: fixed;
  right: 16px;
  top: 16px;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }

.log-item { font-size: 0.85rem; padding: 8px 0; border-bottom: 1px solid var(--line); }
.log-item .meta { color: var(--muted); font-size: 0.78rem; }

@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
