/* INEC Conecta — design tokens + component primitives.
 *
 * Source of truth: ./diseno/design/InecConecta_color_tokens.png (light mode
 * reference). This file adapts the same ROLE tokens to dark mode:
 *   - Brand primaries are LIGHTENED so they keep readable contrast on dark
 *     surfaces (the design system's #AB8620 ocre is too dark for buttons).
 *   - Text roles are INVERTED (text/primary → near-white; text/muted → mid
 *     gray).
 *   - Surfaces are the system's dark backgrounds (var(--bg) etc.).
 *
 * The CSS also ships the shadcn-style component primitives (.btn, .card,
 * .field, .alert, ...) used across the operator console and /get/ pages.
 */

/* ===== Tokens ===== */
:root {
  /* Brand */
  --color-primary: #d4af37;
  --color-primary-hover: #e8c56a;
  --color-primary-fg: #1a1408;

  --color-secondary: #4fae7e;
  --color-secondary-hover: #6bc998;
  --color-secondary-fg: #08221a;

  /* Feedback */
  --color-success: #2dd055;
  --color-success-bg: rgba(45, 208, 85, 0.12);
  --color-success-border: #1f9c3d;

  --color-error: #e5484d;
  --color-error-bg: rgba(229, 72, 77, 0.12);
  --color-error-border: #c73136;
  --color-error-fg: #ffe5e9;

  --color-warning: #d4a06b;
  --color-warning-bg: rgba(212, 160, 107, 0.12);
  --color-warning-border: #a37a4a;

  /* Text (inverted for dark mode) */
  --color-text: #fafafa;
  --color-text-muted: #a1a1a1;
  --color-text-bold: #c1c1c1;

  /* Surfaces */
  --color-bg: #0f1419;
  --color-bg-elevated: #1a1f2c;
  --color-bg-hover: #252b3a;
  --color-bg-overlay: rgba(0, 0, 0, 0.5);

  /* Borders */
  --color-border: #2a2f3a;
  --color-border-strong: #3a4150;
  --color-border-input: #3a4150;

  /* Focus ring */
  --color-ring: rgba(212, 175, 55, 0.4);

  /* Legacy aliases (some inline styles and the /get/ page still use these). */
  --bg: var(--color-bg);
  --fg: var(--color-text);
  --muted: var(--color-text-muted);
  --card: var(--color-bg-elevated);
  --border: var(--color-border);
  --accent: var(--color-primary);
  --ok: var(--color-success);
  --warn: var(--color-warning);
  --err: var(--color-error);
}

/* `hidden` is a global HTML attribute that should hide the element with
 * display:none. But class-based rules like `.alert { display: flex }`
 * override it because they have higher specificity in the cascade order.
 * This re-asserts `hidden` so toggling the attribute is enough to show/hide
 * elements like #login-error and #dashboard. */
[hidden] {
  display: none !important;
}

/* ===== Base ===== */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font:
    14px/1.5 system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
}

/* ===== Page chrome ===== */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.page__main {
  flex: 1;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
.page__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
}
.page__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.page__main {
  flex: 1;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
.page__footer {
  text-align: center;
  padding: 1.25rem 1rem 1.5rem;
  color: #b8b8b8;
  font-size: 0.85rem;
}
.page__intro {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0.25rem 0 0;
}

/* ===== Buttons (.btn + modifiers) ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background 150ms ease,
    color 150ms ease,
    border-color 150ms ease;
  text-decoration: none;
  font-family: inherit;
  line-height: 1.2;
}
.btn:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}
.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn--primary {
  background: var(--color-primary);
  color: var(--color-primary-fg);
}
.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}
.btn--secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border-color: var(--color-border-input);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--color-bg-hover);
}
.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--color-bg-elevated);
  color: var(--color-text);
}
.btn--danger {
  background: var(--color-error);
  color: var(--color-error-fg);
}
.btn__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ===== Cards ===== */
.card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.5rem;
  color: var(--color-text);
}
.card--narrow {
  max-width: 460px;
  margin: 2rem auto;
}
.card__header {
  margin-bottom: 1rem;
}
.card__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}
.card__description {
  margin: 0.25rem 0 0;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* ===== Forms / Fields ===== */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}
.field__label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}
.field__hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border-input);
  border-radius: 6px;
  font-family: inherit;
}
.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-ring);
}
.input::placeholder {
  color: var(--color-text-muted);
}

/* ===== Alerts ===== */
.alert {
  display: flex;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  font-size: 0.875rem;
  align-items: flex-start;
}
.alert__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 0.1rem;
}
.alert__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.alert__title {
  font-weight: 600;
  margin: 0;
}
.alert__description {
  color: inherit;
  opacity: 0.9;
  margin: 0.25rem 0 0;
}
.alert--success {
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
  color: var(--color-success);
}
.alert--error {
  background: var(--color-error-bg);
  border-color: var(--color-error-border);
  color: var(--color-error);
}
.alert--warning {
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
  color: var(--color-warning);
}

/* ===== sr-only (a11y) ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Tables (operator console) ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}
.data-table th,
.data-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.data-table th {
  background: #15191f;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}
.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}
.token-cell {
  font-family: ui-monospace, 'Cascadia Mono', Menlo, monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
  cursor: pointer;
  user-select: all;
}
.status-active {
  color: var(--color-success);
}
.status-consumed,
.status-expired {
  color: var(--color-text-muted);
}
.status-revoked {
  color: var(--color-error);
}

/* ===== Legacy aliases — keep /get/ page-local classes working ===== */
/* /get/'s index.html still uses .otp-card / .otp-result / .otp-digit / etc.
 * Re-use the design system tokens so the visual identity stays consistent. */
.otp-card {
  /* alias of .card--narrow */
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
  max-width: 460px;
  margin: 2rem auto;
  padding: 2rem 1.5rem 1.5rem;
}
.otp-lock {
  display: block;
  margin: 0 auto 0.5rem;
  width: 88px;
  height: 112px;
}
.otp-digits {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.75rem 0 1rem;
}
.otp-digit {
  width: 2.5rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}
.otp-result {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 4px;
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  color: var(--color-text);
}
.otp-meta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
  text-align: center;
}

/* Compact dark-bg variant of the shared page footer (used in /get/ which
 * loads /ui/styles.css and might want a slightly different color). */
.page-footer {
  text-align: center;
  padding: 1.25rem 1rem 1.5rem;
  color: #b8b8b8;
  font-size: 0.85rem;
}

/* ===== Operator-console dashboard layout =====
 *
 * Page-specific tweaks for the operator console. The component
 * primitives (.btn / .card / .field / .alert / .data-table) are defined
 * earlier in this file.
 *
 * Why this lives here (and not as an inline <style> in index.html):
 * the CSP delivered via the <meta> tag is `style-src 'self'` (no
 * 'unsafe-inline'). Inline <style> blocks get blocked by the browser.
 * External stylesheets loaded via <link rel="stylesheet"> are allowed.
 *
 * Layout notes:
 * - .dashboard-counters uses a media query so the three counter cards
 *   collapse to one column on narrow viewports and force a 3-col grid
 *   above 700px. Predictable and works regardless of intrinsic content
 *   width.
 * - .dashboard-actions uses flex-wrap so the two search inputs + the
 *   Buscar button can wrap on narrow viewports. min-width:0 lets the
 *   inputs shrink past their intrinsic placeholder width.
 * - .revoke-btn is produced dynamically by app.js's renderRow(); it's
 *   defined here so the stream table stays styled even though the class
 *   is not declared in the static HTML.
 */
.dashboard-counters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
@media (min-width: 700px) {
  .dashboard-counters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.dashboard-counters > .card {
  text-align: center;
  padding: 1rem;
}
.dashboard-counters strong {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.1;
}
.dashboard-counters span {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dashboard-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.dashboard-actions .input {
  flex: 1 1 200px;
  min-width: 0;
}
.dashboard-actions .btn {
  flex: 0 0 auto;
}
.dashboard h2 {
  margin: 1.5rem 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}
.revoke-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--color-error-border);
  color: var(--color-error);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}
.revoke-btn:hover {
  background: var(--color-error);
  color: var(--color-error-fg);
}

/* User-info chip in the operator console header (shown after login). */
.user-info__name {
  margin-right: 0.75rem;
  color: var(--color-text-muted);
}

/* ===== Operator issuance panel (P1.3) =====
 *
 * The "Emitir código" card lives at the top of the operator dashboard
 * and lets a logged-in operator POST /v1/operator/otps (re-using the
 * existing operator session + X-CSRF-Token header). On success the
 * returned token is shown ONCE in a dismissible panel with a
 * copy-to-clipboard button and its expires_at; the panel explains the
 * code will not be shown again. The token is never written to
 * localStorage, sessionStorage, or cookies — the dismiss handler drops
 * the in-memory reference and removes the panel from the DOM.
 */
.issuance-panel {
  margin-bottom: 1.5rem;
}
.issuance-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.issuance-result {
  margin-top: 1.25rem;
}
.issuance-result-panel {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  color: var(--color-text);
}
.issuance-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.issuance-result-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-success);
}
.issuance-dismiss {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-family: inherit;
}
.issuance-dismiss:hover {
  background: var(--color-bg-hover);
  color: var(--color-text);
}
.issuance-dismiss:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}
.issuance-token-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.issuance-token {
  flex: 1 1 auto;
  min-width: 0;
  font-family: ui-monospace, 'Cascadia Mono', Menlo, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  user-select: all;
  text-align: center;
  word-break: break-all;
}
.issuance-copy {
  flex: 0 0 auto;
}
.issuance-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 0 0 0.75rem;
}
.issuance-meta code {
  color: var(--color-text);
  background: transparent;
  font-family: ui-monospace, 'Cascadia Mono', Menlo, monospace;
}
.issuance-warning {
  margin: 0;
  font-size: 0.8rem;
  color: var(--color-warning);
}
