:root {
  color-scheme: light;
  --navy-950: #0a1628;
  --navy-900: #10233e;
  --navy-800: #17345a;
  --blue-600: #1769aa;
  --blue-500: #2384cf;
  --blue-100: #dceefe;
  --slate-700: #34445a;
  --slate-600: #526176;
  --slate-500: #718096;
  --slate-300: #ced7e3;
  --slate-200: #e4eaf1;
  --slate-100: #f1f5f9;
  --surface: #ffffff;
  --success: #0b7a53;
  --success-soft: #e7f7ef;
  --warning: #9a6700;
  --warning-soft: #fff6db;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --shadow: 0 18px 50px rgba(15, 35, 62, .09);
  --shadow-sm: 0 5px 18px rgba(15, 35, 62, .07);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #edf2f7; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--navy-950);
  background:
    radial-gradient(circle at 5% 0%, rgba(35, 132, 207, .1), transparent 28rem),
    linear-gradient(180deg, #f7f9fc 0, #edf2f7 100%);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: var(--blue-600); font-weight: 650; text-decoration: none; }
a:hover { color: var(--navy-800); text-decoration: underline; }
.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid rgba(255,255,255,.1);
  background: linear-gradient(115deg, var(--navy-950), var(--navy-800));
  box-shadow: 0 4px 18px rgba(10, 22, 40, .18);
}
.app-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1180px, calc(100% - 32px));
  min-height: 72px;
  margin: auto;
}
.brand { display: flex; align-items: center; gap: 12px; color: white; }
.brand:hover { color: white; text-decoration: none; }
.brand__mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 12px;
  background: linear-gradient(145deg, var(--blue-500), #62b6ef);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.3);
  font-size: 17px;
  font-weight: 850;
  letter-spacing: -.04em;
}
.brand__text strong, .brand__text span { display: block; }
.brand__text strong { font-size: 18px; letter-spacing: -.02em; }
.brand__version { margin-left: 4px; color: #9ec9ea; font-size: 11px; font-weight: 750; letter-spacing: .03em; vertical-align: 2px; }
.brand__text span { color: #c7d7ea; font-size: 12px; font-weight: 500; }
.header-link { color: #d8e8f8; font-size: 14px; }
.header-link:hover { color: white; }

.app-shell { width: min(1180px, calc(100% - 32px)); margin: 32px auto 56px; }
.content-card {
  overflow: hidden;
  padding: clamp(22px, 3vw, 38px);
  border: 1px solid rgba(206, 215, 227, .85);
  border-radius: var(--radius);
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow);
}
.page-login .app-shell { width: min(500px, calc(100% - 32px)); margin-top: 8vh; }
.page-login .content-card { padding: 40px; }
.page-login form { display: grid; gap: 18px; }
.page-login form label { display: grid; gap: 7px; font-weight: 700; }
.page-login form br { display: none; }
.page-login form button { width: 100%; margin-top: 4px; }
.app-footer { padding: 0 16px 28px; color: var(--slate-500); text-align: center; font-size: 12px; }

h1, h2, h3 { margin: 0 0 .7em; color: var(--navy-950); line-height: 1.18; letter-spacing: -.025em; }
h1 { font-size: clamp(26px, 4vw, 38px); }
h2 { margin-top: 1.7em; font-size: 21px; }
p { margin: .65em 0 1.1em; }
.muted, .hint { color: var(--slate-600); }
.eyebrow { margin: 0 0 5px; color: var(--blue-600); font-size: 12px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-heading h1 { margin-bottom: 6px; }
.page-heading p { margin: 0; color: var(--slate-600); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.button, button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--blue-600);
  color: white;
  box-shadow: 0 3px 8px rgba(23, 105, 170, .17);
  font: inherit;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.button:hover, button:hover { background: var(--navy-800); color: white; text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.button--secondary { border-color: var(--slate-300); background: white; color: var(--navy-800); box-shadow: none; }
.button--secondary:hover { background: var(--slate-100); color: var(--navy-950); }
.button--danger, .danger-button { background: var(--danger); }
.button--success { background: var(--success); }
.primary { background: var(--blue-600); }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin: 22px 0 28px; }
.stat-card { padding: 18px 20px; border: 1px solid var(--slate-200); border-radius: 13px; background: linear-gradient(145deg,#fff,#f8fbfe); box-shadow: var(--shadow-sm); }
.stat-card span { display: block; color: var(--slate-600); font-size: 13px; font-weight: 650; }
.stat-card strong { display: block; margin-top: 2px; font-size: 30px; letter-spacing: -.04em; }
.stat-card--success strong { color: var(--success); }
.stat-card--danger strong { color: var(--danger); }

.filter-bar { display: flex; gap: 10px; margin-bottom: 18px; padding: 12px; border: 1px solid var(--slate-200); border-radius: 12px; background: var(--slate-100); }
.filter-bar input { flex: 1; min-width: 180px; }
.filter-bar label { display: grid; gap: 4px; color: var(--slate-600); font-size: 12px; font-weight: 800; }
.filter-bar label input { min-width: 155px; font-weight: 400; }
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #b8c5d4;
  border-radius: 8px;
  outline: none;
  background: white;
  color: var(--navy-950);
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(35,132,207,.14); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--blue-600); }
textarea { min-height: 90px; resize: vertical; }
label { color: var(--slate-700); }

.table-wrap { overflow-x: auto; border: 1px solid var(--slate-200); border-radius: 12px; }
table { width: 100%; border: 0; border-collapse: collapse; background: white; }
th { padding: 12px 14px; border-bottom: 1px solid var(--slate-200); background: #f5f8fb; color: var(--slate-600); font-size: 12px; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
td { padding: 14px; border-bottom: 1px solid var(--slate-200); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fbfe; }
.id-link { display: inline-grid; min-width: 38px; min-height: 32px; place-items: center; border-radius: 8px; background: var(--blue-100); }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.status-badge::before { width: 7px; height: 7px; border-radius: 50%; background: currentColor; content: ""; }
.status-vigente { background: var(--success-soft); color: var(--success); }
.status-cancelado { background: var(--danger-soft); color: var(--danger); }
.status-borrador { background: var(--warning-soft); color: var(--warning); }
.empty-state { padding: 34px; color: var(--slate-600); text-align: center; }

.detail-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; color: var(--slate-600); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 9px; margin: 22px 0; }
.detail-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0; overflow: hidden; margin: 0; border: 1px solid var(--slate-200); border-radius: 12px; }
.detail-grid div { padding: 15px 18px; border-right: 1px solid var(--slate-200); border-bottom: 1px solid var(--slate-200); }
.detail-grid div:nth-child(2n) { border-right: 0; }
.detail-grid dt { color: var(--slate-600); font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.detail-grid dd { margin: 4px 0 0; font-weight: 650; }
.timeline { padding: 0; list-style: none; }
.timeline > li { position: relative; margin: 0 0 12px; padding: 18px 20px 18px 24px; border: 1px solid var(--slate-200); border-radius: 12px; background: white; }
.timeline > li::before { position: absolute; top: 0; bottom: 0; left: 0; width: 5px; border-radius: 12px 0 0 12px; background: var(--blue-500); content: ""; }
details { margin-top: 10px; padding: 9px 12px; border-radius: 8px; background: var(--slate-100); }
summary { color: var(--blue-600); font-weight: 750; cursor: pointer; }
.action-card, .destructive-card { margin-top: 24px; padding: 20px; border: 1px solid var(--slate-200); border-radius: 12px; background: #f8fbfe; }
.action-card h2, .destructive-card h2 { margin-top: 0; }
.action-card--danger, .destructive-card { border-color: #efc2bd; background: var(--danger-soft); }
.action-card--success { border-color: #aedcc8; background: var(--success-soft); }

.document-form, .version-form, .settings { max-width: 900px; }
.settings { max-width: 720px; }
.settings form { display: grid; gap: 16px; }
.settings input { text-transform: uppercase; }
.document-form fieldset { margin: 0 0 24px; padding: 0; border: 0; }
.document-form legend { margin-bottom: 12px; font-size: 17px; font-weight: 800; }
.format-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(240px,1fr)); gap: 12px; }
.format-card { display: flex; gap: 12px; padding: 16px; border: 1px solid var(--slate-300); border-radius: 11px; background: white; cursor: pointer; }
.format-card:has(input:checked) { border-color: var(--blue-500); background: #f2f9ff; box-shadow: 0 0 0 3px rgba(35,132,207,.12); }
.format-card input { margin-top: 4px; }
.format-card small { display: block; margin-top: 4px; color: var(--slate-600); }
.fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.document-form > form > .fields { grid-template-columns: repeat(3,minmax(0,1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; }
.field.wide, .wide { grid-column: 1/-1; }
.generic-fields { display: none; margin-top: 24px !important; padding: 20px !important; border: 1px solid var(--slate-200) !important; border-radius: 12px; background: #f8fbfe; }
.document-form form:has(input[value="GENERIC"]:checked) .generic-fields { display: block; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 22px; }
.warning, .errors, .success { padding: 13px 16px; border-left: 4px solid; border-radius: 8px; }
.warning { border-color: var(--warning); background: var(--warning-soft); }
.errors { border-color: var(--danger); background: var(--danger-soft); }
.success { border-color: var(--success); background: var(--success-soft); }
.qr-preview { display: inline-flex; padding: 14px; border: 1px solid var(--slate-200); border-radius: 14px; background: white; box-shadow: var(--shadow-sm); }
.qr-preview img { display: block; max-width: 100%; height: auto; }

@media (max-width: 780px) {
  .app-header__inner, .app-shell { width: min(100% - 20px, 1180px); }
  .app-shell { margin-top: 18px; }
  .content-card { padding: 20px 16px; border-radius: 13px; }
  .brand__text span { display: none; }
  .page-heading { display: block; }
  .page-heading .toolbar { margin-top: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; }
  .fields, .document-form > form > .fields { grid-template-columns: 1fr; }
  .field.wide, .wide { grid-column: auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid div { border-right: 0; }
  .table-wrap { border: 0; overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody { display: grid; gap: 12px; }
  tbody tr { padding: 8px 14px; border: 1px solid var(--slate-200); border-radius: 12px; box-shadow: var(--shadow-sm); }
  td { display: grid; grid-template-columns: minmax(92px, .42fr) 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--slate-100); }
  td::before { color: var(--slate-500); font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; content: attr(data-label); }
  td:last-child { border-bottom: 0; }
  td.empty-state { display: block; }
  td.empty-state::before { content: none; }
}
