:root {
  color-scheme: dark;
  --red: #e4192a;
  --red-dark: #b90f1d;
  --red-soft: rgb(228 25 42 / 14%);
  --background: #050d14;
  --surface: #071722;
  --panel: #0a1c28;
  --panel-soft: #0d2230;
  --border: #1b3849;
  --border-soft: #122c3b;
  --text: #f3f7fb;
  --muted: #9fb1c1;
  --green: #24c875;
  --amber: #f1b734;
  --blue: #6f96b5;
  --radius: 10px;
  --sidebar-width: 224px;
  --content-width: 1400px;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--background); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: radial-gradient(circle at 78% 4%, rgb(25 75 101 / 18%), transparent 31rem), var(--background);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgb(228 25 42 / 27%);
  outline-offset: 2px;
}

.app-layout { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 12;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  padding: 14px 10px;
  background: linear-gradient(180deg, #071724 0%, #06111a 68%, #050d14 100%);
  border-right: 1px solid var(--border);
}

.workspace { min-width: 0; margin-left: var(--sidebar-width); }
.brand { display: flex; min-width: 0; }

.brand-sidebar {
  display: grid;
  gap: 8px;
  padding: 0 4px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-logo-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgb(255 255 255 / 35%);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 24%);
}

.brand-sidebar .brand-logo-shell { width: 100%; height: 62px; padding: 7px 9px; }

.brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.brand-copy strong,
.brand-copy small,
.app-title strong,
.app-title small { display: block; }
.brand-copy strong { font-size: 0.91rem; }

.brand-copy small,
.app-title small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.main-nav { display: grid; gap: 5px; margin-top: 16px; }

.nav-button {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  min-height: 46px;
  padding: 8px 10px;
  color: #c7d5e0;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 650;
}

.nav-button:hover { color: #fff; background: rgb(255 255 255 / 4%); }

.nav-button.is-active {
  color: #fff;
  background: linear-gradient(90deg, rgb(228 25 42 / 23%), rgb(228 25 42 / 6%));
  border-color: rgb(228 25 42 / 18%);
  box-shadow: inset 3px 0 var(--red);
}

.nav-icon { color: #d7e4ed; font-size: 1.22rem; line-height: 1; text-align: center; }
.nav-button.is-active .nav-icon { color: var(--red); }

.nav-badge {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  place-items: center;
  color: #fff;
  background: var(--red);
  border-radius: 999px;
  font-size: 0.67rem;
  font-weight: 800;
}

.nav-badge[hidden] { display: none; }

.sidebar-footer {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding: 12px 6px 2px;
  color: #71899b;
  font-size: 0.69rem;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 66px;
  padding: 10px clamp(16px, 2.5vw, 32px);
  background: rgb(5 15 23 / 92%);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand-mobile { display: none; }
.app-title strong { font-size: 1rem; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

.connection-status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 5px 10px;
  color: #74eba7;
  background: rgb(11 86 53 / 22%);
  border: 1px solid rgb(36 200 117 / 32%);
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 700;
}

.connection-status::before { margin-right: 6px; content: "●"; }

.connection-status.is-offline {
  color: #ffd879;
  background: rgb(138 101 0 / 18%);
  border-color: rgb(241 183 52 / 36%);
}

.app-shell {
  width: min(100%, var(--content-width));
  margin: 0 auto;
  padding: 16px clamp(14px, 2.4vw, 30px) 44px;
}

.view[hidden] { display: none; }

.section-heading,
.panel-heading,
.record-main,
.record-actions,
.detail-actions,
.form-actions,
.alert-toolbar,
.alert-toolbar-actions,
.document-current { display: flex; align-items: center; }

.section-heading,
.panel-heading { justify-content: space-between; gap: 14px; }
.section-heading { margin-bottom: 12px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.45rem, 2.2vw, 1.9rem); line-height: 1.12; }
h2 { margin-bottom: 0; font-size: 1.08rem; }
h3 { margin-bottom: 4px; font-size: 0.98rem; }

.eyebrow {
  margin-bottom: 3px;
  color: var(--red);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.11em;
}

.muted { margin: 4px 0 0; color: var(--muted); font-size: 0.82rem; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-card,
.panel,
.record-card,
.detail-card {
  background: linear-gradient(145deg, rgb(13 34 48 / 96%), rgb(7 24 35 / 96%));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgb(0 0 0 / 13%);
}

.summary-card {
  position: relative;
  min-height: 82px;
  padding: 12px 13px 12px 17px;
  overflow: hidden;
  border-left: 4px solid var(--accent, var(--blue));
}

.summary-card::after {
  position: absolute;
  inset: auto -17px -25px auto;
  width: 64px;
  height: 64px;
  background: var(--accent, var(--blue));
  border-radius: 50%;
  content: "";
  opacity: 0.07;
}

.summary-value { display: block; margin-bottom: 5px; font-size: 1.58rem; font-weight: 800; line-height: 1; }
.summary-label { color: #c7d3dd; font-size: 0.68rem; font-weight: 750; letter-spacing: 0.035em; }
.panel { padding: 14px; }
.panel-heading { margin-bottom: 11px; }
.record-list { display: grid; gap: 10px; }

#upcoming-list,
#certificate-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.record-card {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 13px;
  overflow: hidden;
  border-left: 4px solid var(--blue);
}

.record-card.status-vigente { border-left-color: var(--green); }
.record-card.status-por-vencer,
.record-card.status-vence-hoy { border-left-color: var(--amber); }

.record-card.status-vencido {
  border-left-color: var(--red);
  background: linear-gradient(130deg, rgb(228 25 42 / 12%), transparent 62%), linear-gradient(145deg, rgb(13 34 48 / 96%), rgb(7 24 35 / 96%));
}

.record-main { align-items: flex-start; justify-content: space-between; gap: 10px; }
.record-main > div { min-width: 0; }

.record-main h3,
.record-main p,
.record-meta span,
.record-meta strong { overflow-wrap: anywhere; }

.record-meta { display: grid; gap: 4px; margin-top: 9px; color: var(--muted); font-size: 0.79rem; }
.record-meta strong { color: #fff; font-size: 0.9rem; }

.record-actions,
.detail-actions,
.form-actions { flex-wrap: wrap; gap: 8px; }
.record-actions { justify-content: flex-end; margin-top: auto; padding-top: 12px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 25px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 850;
  white-space: nowrap;
}

.status-vigente .status-badge,
.status-badge.status-vigente { color: #052918; background: #5ae49a; }

.status-por-vencer .status-badge,
.status-badge.status-por-vencer,
.status-vence-hoy .status-badge,
.status-badge.status-vence-hoy { color: #372500; background: #ffd66b; }

.status-vencido .status-badge,
.status-badge.status-vencido { color: #4e050c; background: #ff8f99; }

.button,
.text-button,
.action-link,
.filter-chip { min-height: 38px; border-radius: 7px; font-weight: 700; }
.button { padding: 8px 13px; border: 1px solid transparent; }

.button-primary {
  color: #fff;
  background: linear-gradient(135deg, #ef1c2e, #d81221);
  box-shadow: 0 7px 18px rgb(228 25 42 / 17%);
}

.button-primary:hover,
.button-primary:focus-visible { background: var(--red-dark); }
.button-secondary { color: var(--text); background: #0d2130; border-color: #355164; }
.button-dark { color: var(--text); background: #102635; border-color: #355164; }
.button-danger { color: #ff7d89; background: transparent; border-color: rgb(228 25 42 / 60%); }
.button-danger-solid { color: #fff; background: var(--red); border-color: var(--red); }
.button:disabled { cursor: not-allowed; opacity: 0.58; }

.text-button,
.action-link { padding: 6px 9px; color: #ff5664; background: transparent; border: 0; }
.action-link { min-height: 34px; border: 1px solid rgb(228 25 42 / 74%); }

.list-tools {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.search-field input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  color: var(--text);
  background: #071722;
  border: 1px solid #294658;
  border-radius: 8px;
}

.search-field input::placeholder { color: #71899a; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.filter-chip {
  min-height: 34px;
  padding: 6px 10px;
  color: var(--muted);
  background: #071722;
  border: 1px solid #294658;
  font-size: 0.76rem;
}

.filter-chip.is-active { color: #fff; background: var(--red-soft); border-color: var(--red); }

.form-panel { max-width: 980px; margin: 0 auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: grid; gap: 6px; color: #d7e2ea; font-size: 0.82rem; font-weight: 700; }
.field-wide { grid-column: 1 / -1; }

.field input,
.field textarea {
  width: 100%;
  min-height: 43px;
  padding: 9px 10px;
  color: var(--text);
  background: #071722;
  border: 1px solid #294658;
  border-radius: 7px;
  font-weight: 400;
}

.field textarea { resize: vertical; }
.field input[type="date"] { color-scheme: dark; }
.field input[type="file"] { min-height: 49px; padding: 8px; background: #06131d; }

.document-field {
  padding: 11px;
  background: rgb(3 13 20 / 45%);
  border: 1px dashed #355164;
  border-radius: 8px;
}

.document-current { justify-content: space-between; gap: 10px; }
.field input:focus,
.field textarea:focus,
.search-field input:focus { border-color: var(--red); }

.form-error {
  margin-top: 13px;
  padding: 10px 11px;
  color: #ffc2c7;
  background: rgb(228 25 42 / 12%);
  border: 1px solid rgb(228 25 42 / 40%);
  border-radius: 8px;
}

.form-actions { margin-top: 16px; }

.detail-card { max-width: 1040px; margin: 0 auto; overflow: hidden; }

.detail-header {
  padding: 17px;
  background: linear-gradient(115deg, rgb(228 25 42 / 13%), transparent 48%), #071722;
  border-bottom: 1px solid var(--border);
}

.detail-header .status-badge { margin-top: 8px; }
.detail-header .muted { color: #b9c8d3; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 18px;
  margin: 0;
  padding: 6px 17px;
}

.detail-row { display: grid; gap: 4px; padding: 11px 0; border-bottom: 1px solid var(--border-soft); }
.detail-row dt { color: var(--muted); font-size: 0.68rem; font-weight: 750; text-transform: uppercase; }
.detail-row dd { margin: 0; overflow-wrap: anywhere; font-size: 0.87rem; }
.detail-actions { padding: 13px 17px 17px; }

.detail-documents {
  display: grid;
  gap: 8px;
  padding: 13px 17px;
  background: #06131d;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.document-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.document-line strong,
.document-line span { display: block; }
.document-line span { margin-top: 2px; color: var(--muted); font-size: 0.75rem; }

.alert-toolbar { justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.alert-toolbar p { margin-bottom: 0; }
.alert-toolbar-actions { flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.alerts-panel + .alerts-panel { margin-top: 12px; }
.alert-card { border-left-color: var(--amber); }
.alert-card.is-overdue { border-left-color: var(--red); }
.history-list { display: grid; gap: 7px; }

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}

.history-item:last-child { border-bottom: 0; }
.history-item span,
.history-item time { color: var(--muted); font-size: 0.75rem; }

.empty-state {
  grid-column: 1 / -1;
  padding: 26px 13px;
  color: var(--muted);
  text-align: center;
  background: rgb(7 23 34 / 65%);
  border: 1px dashed #294658;
  border-radius: var(--radius);
}

.toast {
  position: fixed;
  right: 14px;
  bottom: 16px;
  left: 14px;
  z-index: 30;
  max-width: 520px;
  margin: 0 auto;
  padding: 11px 13px;
  color: #fff;
  background: #102635;
  border: 1px solid var(--border);
  border-left: 5px solid var(--red);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgb(0 0 0 / 35%);
}

.pdf-viewer,
.restore-dialog {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  padding: 12px;
  place-items: center;
  background: rgb(0 0 0 / 78%);
}

.pdf-viewer[hidden],
.restore-dialog[hidden] { display: none; }

.pdf-viewer-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 1000px);
  height: min(92vh, 900px);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pdf-viewer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.pdf-viewer iframe { width: 100%; height: 100%; background: #fff; border: 0; }
.backup-panel { max-width: 760px; }
.backup-panel > p { color: var(--muted); }

.backup-status {
  display: grid;
  gap: 4px;
  margin: 16px 0;
  padding: 13px;
  background: #06131d;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.backup-status span { color: var(--muted); font-size: 0.7rem; font-weight: 750; text-transform: uppercase; }
.backup-actions,
.restore-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.backup-message { min-height: 1.3em; margin: 12px 0 0; }
.backup-message.is-error { color: #ff7d89; font-weight: 700; }

.backup-warning,
.restore-warning {
  margin: 13px 0 0;
  padding: 10px 11px;
  color: #f8d783 !important;
  background: rgb(138 101 0 / 16%);
  border: 1px solid rgb(241 183 52 / 24%);
  border-radius: 8px;
  font-size: 0.8rem;
}

.restore-card {
  width: min(100%, 480px);
  padding: 21px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.restore-card h2 { margin-bottom: 15px; }
.restore-summary { display: grid; gap: 0; margin: 0; border: 1px solid var(--border); border-radius: 8px; }
.restore-summary > div { display: flex; justify-content: space-between; gap: 14px; padding: 10px 11px; border-bottom: 1px solid var(--border); }
.restore-summary > div:last-child { border-bottom: 0; }
.restore-summary dt { color: var(--muted); }
.restore-summary dd { margin: 0; font-weight: 750; }
.restore-actions { justify-content: flex-end; margin-top: 17px; }
.mobile-nav { display: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 1180px) {
  #upcoming-list,
  #certificate-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 899px) {
  .sidebar { display: none; }
  .workspace { margin-left: 0; }

  .app-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    min-height: 64px;
    padding: 8px 14px;
  }

  .brand-mobile { display: block; }
  .brand-mobile .brand-logo-shell { width: 112px; height: 39px; padding: 4px 6px; }
  .app-title strong { font-size: 0.92rem; }
  .app-title small { font-size: 0.68rem; }

  .connection-status {
    width: 31px;
    min-width: 31px;
    padding: 0;
    justify-content: center;
    overflow: hidden;
    color: transparent;
    white-space: nowrap;
  }

  .connection-status::before { margin: 0; color: #74eba7; }
  .connection-status.is-offline::before { color: #ffd879; }
  .app-shell { padding-bottom: 92px; }

  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
    min-height: 68px;
    padding: 6px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: rgb(5 15 23 / 97%);
    border-top: 1px solid var(--border);
    box-shadow: 0 -9px 28px rgb(0 0 0 / 25%);
    backdrop-filter: blur(14px);
  }

  .mobile-nav-button {
    position: relative;
    display: grid;
    min-width: 0;
    min-height: 48px;
    place-items: center;
    align-content: center;
    gap: 2px;
    color: #9eb1c1;
    background: transparent;
    border: 0;
    border-radius: 8px;
  }

  .mobile-nav-button > span:first-child { font-size: 1.1rem; line-height: 1; }
  .mobile-nav-button small { font-size: 0.61rem; font-weight: 700; }
  .mobile-nav-button.is-active { color: var(--red); }
  .mobile-nav-button .nav-badge { position: absolute; top: 0; right: 17%; }

  .mobile-new-button {
    align-self: start;
    width: 48px;
    height: 48px;
    margin: -20px auto 0;
    color: #fff;
    background: var(--red);
    border: 3px solid #07131d;
    border-radius: 50%;
    box-shadow: 0 8px 20px rgb(228 25 42 / 34%);
    font-size: 1.55rem;
    font-weight: 400;
  }

  .toast { bottom: 78px; }
}

@media (max-width: 699px) {
  .app-header { grid-template-columns: auto minmax(0, 1fr) auto; }
  .brand-mobile .brand-logo-shell { width: 102px; }
  .app-title small { display: none; }
  .app-shell { padding-top: 12px; }
  .desktop-new { display: none; }
  .summary-grid { gap: 7px; }
  .summary-card { min-height: 72px; padding: 10px 6px 9px 10px; border-left-width: 3px; }
  .summary-value { font-size: 1.35rem; }
  .summary-label { font-size: 0.57rem; }
  .panel { padding: 12px; }

  #upcoming-list,
  #certificate-list,
  .form-grid,
  .detail-grid { grid-template-columns: minmax(0, 1fr); }

  .field-wide { grid-column: auto; }
  .list-tools { grid-template-columns: 1fr; }
  .filter-chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filter-chip { min-width: 0; padding-inline: 4px; font-size: 0.66rem; }
  .section-heading { align-items: flex-start; }
  .record-main { flex-direction: row; }

  .record-actions .action-link,
  .record-actions .button { flex: 1 1 auto; }

  .alert-toolbar,
  .document-line { width: 100%; align-items: stretch; flex-direction: column; }

  .alert-toolbar-actions,
  .alert-toolbar-actions .button,
  .document-line .button { width: 100%; }

  .form-actions .button,
  .detail-actions .button { flex: 1 1 100%; }
  .history-item { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 390px) {
  .app-title { display: none; }
  .app-header { grid-template-columns: minmax(0, 1fr) auto; }
  .brand-mobile .brand-logo-shell { width: 128px; }
  .backup-actions .button,
  .restore-actions .button { width: 100%; }
}

@media (max-width: 350px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
