:root {
  --bg: #0d0b14;
  --surface: #16131f;
  --surface-2: #1e1a2b;
  --border: #2c2640;
  --text: #ece9f5;
  --muted: #9a93b0;
  --accent: #ff2e93;
  --accent-2: #a43bff;
  --ok: #2fd07a;
  --warn: #ffb020;
  --danger: #ff4d5e;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin-top: 8px; }
a { color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 12px var(--accent); }

/* --- Botones y campos --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #463d63; background: #252036; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn-primary:hover { filter: brightness(1.1); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-danger:hover { background: #ff6573; }
.btn-danger-ghost { color: var(--danger); }
.btn-small { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

input, select {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input:disabled, select:disabled { opacity: .55; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row input { flex: 1; }
.error { color: var(--danger); margin: 0; font-weight: 600; }

/* --- Inicio de sesión --- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 20% 10%, #2a1340 0, transparent 45%), radial-gradient(circle at 85% 90%, #3a0f2a 0, transparent 40%), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.login-card .brand { margin-bottom: 22px; color: var(--muted); font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-card .btn { padding: 11px; margin-top: 4px; }

/* --- Panel --- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: rgba(13,11,20,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { font-size: 24px; font-weight: 800; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat.warn .stat-value { color: var(--warn); }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 9px 14px; border-radius: 9px; border: 1px solid transparent; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-2); border-color: var(--border); color: var(--text); }

.panel { display: flex; flex-direction: column; gap: 14px; }
.panel[hidden] { display: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.filter { width: auto; min-width: 200px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid h2 { grid-column: 1 / -1; margin-bottom: 0; }
.span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; }
.form-actions p { margin: 0 auto 0 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: rgba(255,255,255,.02); }
td.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.small-table th, .small-table td { padding: 6px 8px; font-size: 12px; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--border); }
.pill-admin { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }
.pill-activo { color: var(--ok); }
.pill-revocado { color: var(--danger); }
.pill-vencido { color: var(--warn); }
.pill-ev-bad { color: var(--danger); }
.pill-ev-info { color: #6fb7ff; }
.pill-ev-admin { color: #c79bff; }

dialog { width: min(640px, calc(100% - 32px)); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 22px; }
dialog::backdrop { background: rgba(0,0,0,.6); }

.toast { position: fixed; right: 16px; bottom: 16px; z-index: 20; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast-ok { background: #15392a; border: 1px solid #22744b; }
.toast-error { background: #43161d; border: 1px solid #8b2b37; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 20px; }
  .filter { min-width: 0; width: 100%; }
  .card-head .input-row { width: 100%; flex-wrap: wrap; }
  td.actions { justify-content: flex-start; }
}

/* --- Google Drive --- */
.pill-conectado { color: var(--ok); }
.pill-pendiente { color: var(--warn); }
.drive-copy { display: flex; flex-direction: column; gap: 8px; }
.drive-copy-label { min-width: 190px; font-size: 12px; font-weight: 600; color: var(--muted); }
#drive-actions { justify-content: flex-start; }
@media (max-width: 640px) {
  .drive-copy .input-row { flex-direction: column; align-items: stretch; }
}

/* --- Páginas públicas (privacidad y condiciones) --- */
.legal-body { padding: 32px 16px 60px; }
.legal { max-width: 760px; margin: 0 auto; line-height: 1.6; }
.legal .brand { margin-bottom: 24px; color: var(--muted); font-size: 13px; }
.legal h2 { margin-top: 28px; }
.legal ul { padding-left: 20px; }
.legal li { margin-bottom: 6px; }
.legal a { color: #ff7ab8; }
