/* ============================================================================
   Certificados Digitais — identidade visual base (design tokens)
   A cor primária é injetada em :root via branding.primary_color.
   ============================================================================ */

:root {
  --color-primary: #1F3864;
  --color-primary-600: #1F3864;
  --color-primary-50: rgba(31, 56, 100, 0.06);

  --color-bg: #f4f6fb;
  --color-surface: #ffffff;
  --color-text: #1a2233;
  --color-text-muted: #5b6678;
  --color-border: #e2e7f0;
  --color-success: #15864A;
  --color-danger: #c0392b;
  --color-warning: #b9770e;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 12px 32px -12px rgba(16, 24, 40, 0.22);
  --shadow-lg: 0 30px 60px -20px rgba(16, 24, 40, 0.32);

  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;

  --maxw: 1080px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--color-primary); }

/* ─── Layout público (split brand + form) ─────────────────────────────────── */

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}

.auth-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 48px;
  color: #fff;
  background:
    radial-gradient(120% 120% at 0% 0%, color-mix(in srgb, var(--color-primary) 78%, #000) 0%, var(--color-primary) 55%, color-mix(in srgb, var(--color-primary) 75%, #2d8bff) 100%);
  overflow: hidden;
}

.auth-brand::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(40% 40% at 85% 15%, rgba(255,255,255,0.12), transparent 70%),
    radial-gradient(35% 35% at 10% 90%, rgba(255,255,255,0.10), transparent 70%);
  pointer-events: none;
}

.auth-brand__logo {
  position: relative;
  z-index: 1;
  max-width: min(340px, 70%);
  max-height: 150px;
  margin-bottom: 28px;
  filter: drop-shadow(0 6px 20px rgba(0,0,0,0.22));
}

.auth-brand__logo--text {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
}

.auth-brand__tagline {
  position: relative;
  z-index: 1;
  max-width: 360px;
  text-align: center;
  font-size: 1.02rem;
  color: rgba(255,255,255,0.92);
}

.auth-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-card__head { margin-bottom: 26px; }

.auth-card__title {
  margin: 0 0 6px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-card__subtitle {
  margin: 0;
  color: var(--color-text-muted);
}

/* ─── Formulários ──────────────────────────────────────────────────────────── */

.field { margin-bottom: 18px; }

.field label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-text);
}

.input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-50);
}

.input--code {
  letter-spacing: 0.4em;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter .15s, transform .05s;
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn--ghost {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-border);
}

/* ─── Alertas ──────────────────────────────────────────────────────────────── */

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  margin-bottom: 18px;
  border: 1px solid transparent;
}

.alert--error  { background: #fdecea; color: var(--color-danger);  border-color: #f5c6c2; }
.alert--notice { background: #e8f4ff; color: #1c5a8c;             border-color: #bfe0fa; }

/* ─── Resultado de validação ───────────────────────────────────────────────── */

.result {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 22px;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.result__badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.result__badge--valid     { background: #e6f5ee; color: var(--color-success); }
.result__badge--invalid   { background: #fdecea; color: var(--color-danger); }
.result__badge--warning   { background: #fdf3e2; color: var(--color-warning); }

.result dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; }
.result dt { color: var(--color-text-muted); font-size: 0.88rem; }
.result dd { margin: 0; font-weight: 600; }

/* ─── Ações secundárias (voltar / reenviar / links entre telas) ─────────────── */

.auth-actions {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; flex-wrap: wrap; margin-top: 20px;
}
.auth-actions form { display: inline; margin: 0; }
.auth-actions__sep { color: var(--color-text-muted); }
.auth-actions .btn--link {
  font-size: 0.9rem; cursor: pointer; background: none; border: none;
  color: var(--color-primary); text-decoration: none; padding: 0; font-family: inherit;
}
.auth-actions .btn--link:hover { text-decoration: underline; }

/* ─── Assinatura "Desenvolvido por OJSBR" ──────────────────────────────────── */

.dev-by {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 34px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  opacity: 0.85;
}

.dev-by img { height: 18px; width: auto; }
.dev-by a { display: inline-flex; align-items: center; }

.auth-brand .dev-by {
  position: absolute;
  bottom: 26px;
  left: 0;
  right: 0;
  z-index: 1;
  color: rgba(255,255,255,0.8);
}
.auth-brand .dev-by img { filter: brightness(0) invert(1); opacity: 0.9; }

/* ─── Responsivo ───────────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand {
    padding: 40px 24px 70px;
    min-height: 260px;
  }
  .auth-brand__logo { max-height: 96px; margin-bottom: 16px; }
}

/* ============================================================================
   Painel administrativo
   ============================================================================ */

.btn--sm { width: auto; padding: 8px 14px; font-size: 0.88rem; }

.text-muted { color: var(--color-text-muted); }

.app {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 22px 16px;
}

.sidebar__brand {
  padding: 6px 8px 22px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 16px;
  min-height: 56px;
  display: flex;
  align-items: center;
}
.sidebar__brand img { max-width: 100%; max-height: 52px; width: auto; }
.sidebar__brand strong { font-size: 1.1rem; color: var(--color-primary); }

.sidebar__nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.sidebar__link {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.94rem;
  transition: background .12s, color .12s;
}
.sidebar__link:hover { background: var(--color-primary-50); }
.sidebar__link.is-active {
  background: var(--color-primary);
  color: #fff;
}

.sidebar__foot { padding-top: 16px; border-top: 1px solid var(--color-border); }
.sidebar__foot .dev-by { margin-top: 0; }

.app__main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.topbar__title { margin: 0; font-size: 1.3rem; font-weight: 700; }
.topbar__user { display: flex; align-items: center; gap: 14px; font-size: 0.92rem; color: var(--color-text-muted); }

.app__content { padding: 28px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
}
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card__value { font-size: 2rem; font-weight: 800; color: var(--color-primary); letter-spacing: -0.02em; }
.card__label { color: var(--color-text-muted); font-size: 0.92rem; margin-top: 4px; }

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.panel__title { margin: 0 0 10px; font-size: 1.15rem; font-weight: 700; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar__foot { display: none; }
}

/* ─── Componentes administrativos ──────────────────────────────────────────── */

.alert--success { background: #e6f5ee; color: var(--color-success); border-color: #bfe7d2; }
.alert--warning { background: #fdf3e2; color: var(--color-warning); border-color: #f3dfb4; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.toolbar form { display: flex; gap: 8px; }
.toolbar .input { width: 260px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn--inline { width: auto; padding: 10px 16px; }
.btn--danger { background: var(--color-danger); }
.btn--success { background: var(--color-success); }
.btn--link { width:auto; background:none; color:var(--color-primary); padding:0; }

.table-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--color-border); font-size: 0.92rem; }
.table th { background: #f7f9fc; font-weight: 600; color: var(--color-text-muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--color-primary-50); }
.table a { font-weight: 600; text-decoration: none; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.74rem; font-weight: 700; }
.badge--draft    { background: #eef1f6; color: #5b6678; }
.badge--ready    { background: #e8f4ff; color: #1c5a8c; }
.badge--issued   { background: #e6f5ee; color: var(--color-success); }
.badge--archived { background: #f3e9e9; color: #8a5151; }
.badge--locked   { background: #fdf3e2; color: var(--color-warning); }

.form-grid { display: grid; gap: 18px; max-width: 640px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field--inline { margin: 0; }
textarea.input { resize: vertical; min-height: 90px; }
textarea.code {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.5;
  min-height: 320px;
  white-space: pre;
  tab-size: 2;
}
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235b6678' d='M6 8 0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

.page-head { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head__crumb { color: var(--color-text-muted); font-size: 0.86rem; margin-bottom: 4px; }
.page-head__crumb a { text-decoration: none; }

.help { font-size: 0.82rem; color: var(--color-text-muted); margin-top: 6px; }
.empty { padding: 48px 24px; text-align: center; color: var(--color-text-muted); }

.progress { height: 14px; background: var(--color-border); border-radius: 999px; overflow: hidden; }
.progress__bar { height: 100%; width: 0; background: var(--color-primary); border-radius: 999px; transition: width .25s ease; }

.tabs { display:flex; gap: 6px; border-bottom: 1px solid var(--color-border); margin-bottom: 22px; }
.tab { padding: 10px 16px; font-weight:600; color: var(--color-text-muted); text-decoration:none; border-bottom: 2px solid transparent; }
.tab.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.var-list { display:flex; flex-wrap:wrap; gap:6px; }
.var-chip {
  font-family: monospace; font-size: 0.76rem;
  background: var(--color-primary-50); color: var(--color-primary);
  padding: 4px 8px; border-radius: 6px; cursor: pointer; border:1px solid transparent;
  max-width: 100%; box-sizing: border-box; line-height: 1.4;
  word-break: break-all; overflow-wrap: anywhere;
}
.var-chip:hover { border-color: var(--color-primary); }

.checks li { color: var(--color-danger); font-size: 0.88rem; }
.checks.warn li { color: var(--color-warning); }

.editor-grid { display:grid; grid-template-columns: 1fr 280px; gap: 22px; align-items:start; }
@media (max-width: 1000px){ .editor-grid { grid-template-columns: 1fr; } .grid-2 { grid-template-columns: 1fr; } }

/* ─── Editor com prévia ao vivo (split redimensionável) ───────────────────── */
.tpl-split { display: flex; align-items: flex-start; width: 100%; }
.tpl-edit { flex: 1 1 0; min-width: 340px; }
.tpl-resizer {
  flex: 0 0 10px; align-self: stretch; cursor: col-resize;
  margin: 0 10px; border-radius: 5px; background: var(--color-border);
  position: relative;
}
.tpl-resizer::before {
  content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 2px; height: 28px; background: var(--color-text-muted); border-radius: 2px; opacity: .5;
}
.tpl-resizer:hover { background: var(--color-primary); }
.tpl-preview {
  flex: 0 0 480px; min-width: 300px;
  position: sticky; top: 16px; align-self: flex-start;
  display: flex; flex-direction: column; gap: 10px;
  height: calc(100vh - 32px);
}
.tpl-preview__bar { display:flex; align-items:center; gap:12px; flex-wrap:wrap; }
.tpl-preview__bar label { font-size: .85rem; color: var(--color-text-muted); display:flex; align-items:center; gap:6px; }
.tpl-preview iframe {
  flex: 1; width: 100%; border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); background: #fff;
}
.tpl-preview__status { font-size: .8rem; color: var(--color-text-muted); min-height: 1em; }
.tpl-preview__error { color: var(--color-danger); font-size: .85rem; }
.tpl-cols { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap:16px; margin-top:18px; }

@media (max-width: 1100px) {
  .tpl-split { flex-direction: column; }
  .tpl-resizer { display: none; }
  .tpl-preview { flex-basis: auto !important; width: 100%; position: static; height: 80vh; margin-top: 18px; }
}
