/* ==========================================================================
   SAE-NFC-e — design system
   Tokens em :root (tema claro) e sobrescritos em prefers-color-scheme: dark.
   ========================================================================== */

:root {
  --bg: #f4f6fb;
  --bg-glow: rgba(99, 102, 241, 0.14);

  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;

  --border: #e5e8f0;
  --border-strong: #d3d9e6;

  --text: #0f172a;
  --text-muted: #5b6779;
  --text-faint: #94a3b8;

  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-contrast: #ffffff;
  --brand-soft: #eef2ff;
  --brand-ring: rgba(79, 70, 229, 0.2);

  --ok: #047857;
  --ok-soft: #ecfdf5;
  --ok-border: #a7f3d0;

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;

  --warn: #b45309;

  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 32px -14px rgba(15, 23, 42, 0.2);
  --shadow-btn: 0 6px 18px -8px rgba(79, 70, 229, 0.55);

  --radius-lg: 18px;
  --radius-md: 11px;

  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Cascadia Mono", Menlo,
    Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #090d16;
    --bg-glow: rgba(99, 102, 241, 0.18);

    --surface: #111827;
    --surface-2: #161f30;
    --surface-3: #1c2637;

    --border: #242f45;
    --border-strong: #33405c;

    --text: #e8ecf7;
    --text-muted: #97a3b8;
    --text-faint: #6b7789;

    --brand: #6366f1;
    --brand-hover: #7c7ff5;
    --brand-contrast: #ffffff;
    --brand-soft: rgba(99, 102, 241, 0.16);
    --brand-ring: rgba(129, 140, 248, 0.3);

    --ok: #34d399;
    --ok-soft: rgba(16, 185, 129, 0.12);
    --ok-border: rgba(16, 185, 129, 0.35);

    --danger: #f87171;
    --danger-soft: rgba(239, 68, 68, 0.12);
    --danger-border: rgba(239, 68, 68, 0.3);

    --warn: #fbbf24;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 24px 48px -24px rgba(0, 0, 0, 0.9);
    --shadow-btn: 0 6px 18px -8px rgba(99, 102, 241, 0.7);
  }
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 40px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(70ch 50ch at 50% -15%, var(--bg-glow), transparent 70%);
}

h1,
h2,
p {
  margin: 0;
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.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;
}

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

.muted strong {
  color: var(--text);
  font-weight: 600;
}

.muted a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
}

.muted a:hover {
  text-decoration: underline;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
}

/* ---------- layout ---------- */

.shell {
  width: 100%;
  max-width: 520px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 16px;
  padding-left: 2px;
}

.brand-mark {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  background: linear-gradient(140deg, #6366f1, #4338ca);
  box-shadow: var(--shadow-btn);
}

.brand-mark svg {
  width: 19px;
  height: 19px;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 22px;
}

.foot {
  margin-top: 14px;
  padding-left: 4px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.foot a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.foot a:hover {
  color: var(--brand);
}

/* ---------- página de documento (política de privacidade) ---------- */

.doc-shell {
  max-width: 660px;
}

.doc {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-muted);
}

.doc-lead {
  font-size: 14.5px;
  color: var(--text);
  padding: 13px 15px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.doc strong {
  color: var(--text);
}

.doc h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 26px 0 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.doc h3 {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin: 18px 0 6px;
}

.doc p {
  margin-bottom: 10px;
}

.doc ul {
  margin: 0 0 12px;
  padding-left: 20px;
}

.doc li {
  margin-bottom: 5px;
}

.doc code {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text);
}

.doc-note {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  font-size: 13px;
}

.doc-note-inline {
  display: inline-block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-faint);
}

.doc-contact {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.doc .btn-block {
  text-decoration: none;
  margin-top: 22px;
}

.view {
  animation: fadeIn 0.2s ease-out;
}

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

/* ---------- abas de modo ---------- */

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 22px;
  border-radius: 12px;
  background: var(--surface-3);
}

.mode {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.mode svg {
  width: 15px;
  height: 15px;
}

.mode:hover {
  color: var(--text);
}

.mode:has(input:checked) {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.14);
}

.mode:has(input:focus-visible) {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* ---------- campos ---------- */

.field + .field {
  margin-top: 18px;
}

.label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 7px;
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}

.label-row .label {
  margin: 0;
}

.input {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: var(--text-faint);
}

.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.input-key {
  font-family: var(--font-mono);
  font-size: 13.5px;
  letter-spacing: 0.02em;
}

.input-key::placeholder {
  font-family: var(--font-sans);
  letter-spacing: normal;
}

.input-wrap {
  position: relative;
}

.input-wrap .input {
  padding-right: 42px;
}

.pw-toggle {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}

.pw-toggle:hover {
  color: var(--text);
  background: var(--surface-3);
}

.pw-toggle svg {
  width: 17px;
  height: 17px;
}

.pw-toggle .icon-off {
  display: none;
}

.pw-toggle.is-visible .icon-on {
  display: none;
}

.pw-toggle.is-visible .icon-off {
  display: block;
}

/* contador / validação da chave */

.hint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 11.5px;
  min-height: 16px;
}

.hint-counter {
  color: var(--text-faint);
  font-family: var(--font-mono);
}

.hint-ok {
  color: var(--ok);
  font-weight: 600;
}

.hint-err {
  color: var(--danger);
  font-weight: 600;
}

/* ---------- ambiente (toggle compacto) ---------- */

.row-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 9px 9px 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.row-inline-label {
  font-size: 13px;
  font-weight: 600;
}

.switch {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 9px;
  background: var(--surface-3);
}

.switch label {
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.switch label:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.15);
}

.switch label[data-tone="prod"]:has(input:checked) {
  color: var(--warn);
}

.switch label:has(input:focus-visible) {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* ---------- dropzone ---------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 24px 16px;
  text-align: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragging {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}

.dropzone svg {
  width: 20px;
  height: 20px;
  opacity: 0.75;
}

.dz-title {
  font-size: 13.5px;
}

.dz-title b {
  color: var(--brand);
}

.dz-hint {
  font-size: 11.5px;
  color: var(--text-faint);
}

.dz-file {
  display: none;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropzone.has-file {
  border-style: solid;
  border-color: var(--ok-border);
  background: var(--ok-soft);
  color: var(--text);
}

.dropzone.has-file .dz-file {
  display: block;
}

.dropzone.compact {
  padding: 13px;
  gap: 4px;
}

/* ---------- certificados ---------- */

.cert-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 210px;
  overflow-y: auto;
}

.cert-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.cert-card:not(.expired):hover {
  border-color: var(--brand);
}

.cert-radio {
  flex: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  transition: border 0.15s ease;
}

.cert-body {
  flex: 1;
  min-width: 0;
}

.cert-name {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cert-meta {
  display: block;
  font-size: 11.5px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cert-card.selected {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.cert-card.selected .cert-radio {
  border-color: var(--brand);
  border-width: 4.5px;
}

.cert-card.expired {
  opacity: 0.5;
  cursor: not-allowed;
}

/* botão de excluir: discreto, aparece no hover/foco do card */
.cert-del {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.cert-card:hover .cert-del,
.cert-del:focus-visible {
  opacity: 1;
}

.cert-del:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.cert-del svg {
  width: 14px;
  height: 14px;
}

/* em telas de toque não existe hover: mantém sempre visível */
@media (hover: none) {
  .cert-del {
    opacity: 1;
  }
}

.tag {
  flex: none;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 10.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-muted);
}

.tag-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.empty {
  padding: 18px 14px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-faint);
  font-size: 12.5px;
}

.panel {
  margin-top: 8px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* ---------- botões ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--brand);
  color: var(--brand-contrast);
  box-shadow: var(--shadow-btn);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn-ghost {
  background: var(--surface-3);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--border);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
}

.btn:disabled {
  cursor: not-allowed;
  background: var(--surface-3);
  color: var(--text-faint);
  box-shadow: none;
}

.btn-block {
  width: 100%;
  margin-top: 20px;
}

.btn-row {
  display: flex;
  gap: 9px;
  margin-top: 20px;
}

.btn-row .btn {
  flex: 1;
}

.btn-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-link:hover {
  text-decoration: underline;
}

/* botão em estado de carregamento */

.btn .btn-spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn.is-loading .btn-spinner {
  display: block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- resultado ---------- */

.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px 4px 0;
}

.result-icon {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  margin-bottom: 14px;
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid var(--ok-border);
}

.result-icon svg {
  width: 24px;
  height: 24px;
}

.result-icon .icon-bad,
.result.is-error .result-icon .icon-ok {
  display: none;
}

.result.is-error .result-icon {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-border);
}

.result.is-error .result-icon .icon-bad {
  display: block;
}

.result-title {
  font-size: 16.5px;
  font-weight: 700;
}

.result-msg {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 40ch;
}

.result-msg:empty {
  display: none;
}

.result-code {
  margin-top: 9px;
  padding: 3px 9px;
  border-radius: 99px;
  border: 1px solid var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

.result-code:empty {
  display: none;
}

.result-detail {
  margin-top: 12px;
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-align: left;
  word-break: break-word;
  max-height: 120px;
  overflow: auto;
}

.result-detail:empty {
  display: none;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  max-width: 100%;
  padding: 5px 11px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip svg {
  flex: none;
  width: 13px;
  height: 13px;
  color: var(--text-faint);
}

.file-chip:empty {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 480px) {
  body {
    padding: 24px 12px;
  }

  .card {
    padding: 18px;
  }

  .input-key {
    font-size: 12.5px;
    letter-spacing: 0;
  }

  .row-inline {
    flex-direction: column;
    align-items: stretch;
    gap: 9px;
    padding: 11px;
  }

  .switch label {
    flex: 1;
    text-align: center;
  }
}
