:root {
  --bg: #f3f1eb;
  --ink: #1c2430;
  --line: #c9c3b6;
  --accent: #0b5f4b;
  --danger: #9b2c2c;
  --card: #fffdf8;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 0px;
  font-family: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(11, 95, 75, 0.08), transparent 40%),
    linear-gradient(180deg, #efe9dc, var(--bg));
  color: var(--ink);
  min-height: 100%;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  background: rgba(255, 253, 248, 0.96);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  backdrop-filter: blur(8px);
  z-index: 10;
}
.brand { display: flex; gap: 0.75rem; align-items: center; min-width: 0; }
.brand-logo {
  height: 32px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
.brand-text { color: #5b6470; font-size: 0.92rem; white-space: nowrap; }
.nav-desktop { display: flex; gap: 0.75rem; align-items: center; }
.topbar a { color: var(--ink); text-decoration: none; }

.wrap {
  max-width: 1100px;
  margin: 1rem auto;
  padding: 0 0.85rem 2rem;
}
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
h1 { margin: 0 0 0.35rem; font-size: 1.55rem; }
.hint { margin: 0 0 1rem; color: #5b6470; }
.empty { color: #5b6470; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white !important;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  min-height: 44px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn.ghost {
  background: transparent;
  color: var(--ink) !important;
  border: 1px solid var(--line);
}
.btn.danger { background: var(--danger); }
.btn.danger.ghost { background: transparent; color: var(--danger) !important; border-color: #e2b4b4; }

.search { display: flex; gap: 0.5rem; }
.search input, .form-acta input, .form-acta textarea, .form-acta select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
  min-height: 44px;
  font: inherit;
  font-size: 16px; /* evita zoom automático en iOS */
  background: #fff;
}
.form-acta textarea { min-height: 140px; line-height: 1.35; }
.form-acta input.readonly-num {
  background: #eef3f1;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  cursor: default;
}
.search button {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 0 1rem;
  cursor: pointer;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.7rem 0.45rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.85rem; color: #5b6470; font-weight: 600; }
tr.anulada { opacity: 0.65; text-decoration: line-through; }
.actions { display: flex; gap: 0.6rem; white-space: nowrap; }
.actions a { color: var(--accent); }

.flash-wrap { max-width: 1100px; margin: 1rem auto 0; padding: 0 1rem; }
.flash { padding: 0.7rem 1rem; border-radius: 10px; margin-bottom: 0.4rem; }
.flash.ok { background: #e5f4ee; color: #0b5f4b; }
.flash.error { background: #fde8e8; color: var(--danger); }

.form-acta fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0 0 1rem;
  padding: 1rem;
}
.form-acta legend { padding: 0 0.4rem; font-weight: 700; color: var(--accent); }
.form-acta label { display: block; margin-bottom: 0.7rem; font-size: 0.92rem; }
.grid-2, .grid-3 { display: grid; gap: 0.75rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 .full { grid-column: 1 / -1; }
.selector-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 1rem;
}
.selector-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 1rem;
  align-items: stretch;
}
.opt-card {
  display: grid;
  grid-template-columns: 1.15rem 1fr;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  min-height: 2.7rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  user-select: none;
}
.opt-card.compact { min-height: 2.5rem; }
.opt-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.opt-box {
  width: 1.05rem;
  height: 1.05rem;
  border: 1.5px solid #7a8490;
  border-radius: 4px;
  display: grid;
  place-items: center;
  background: #fff;
}
.opt-box::after {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  background: transparent;
  border-radius: 2px;
}
.opt-card:has(input:checked) {
  border-color: var(--accent);
  background: #e8f5f0;
  box-shadow: inset 0 0 0 1px rgba(11, 95, 75, 0.25);
}
.opt-card:has(input:checked) .opt-box {
  border-color: var(--accent);
  background: var(--accent);
}
.opt-card:has(input:checked) .opt-box::after {
  background: #fff;
}
.opt-text {
  font-size: 0.92rem;
  line-height: 1.2;
}
.opt-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.35rem 0 0;
}
.fojas-field {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0;
  min-height: 2.5rem;
}
.fojas-field input { max-width: 6rem; }
.extras { margin-top: 0.25rem; }

.firmas-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.firma-col {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  background: #fff;
}
.firma-col h3 { margin: 0 0 0.7rem; font-size: 1rem; }
.pad-wrap { margin-top: 0.4rem; }
.pad-label {
  font-size: 0.85rem;
  color: #5b6470;
  margin-bottom: 0.35rem;
}
.firma-pad {
  width: 100%;
  height: 180px;
  display: block;
  border: 1.5px dashed #9aa3ad;
  border-radius: 12px;
  background:
    linear-gradient(#fff, #fff),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 23px,
      rgba(0,0,0,0.04) 24px
    );
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
}
.pad-clear { margin-top: 0.55rem; width: 100%; }
.spacer-label { visibility: hidden; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  position: sticky;
  bottom: calc(0.5rem + var(--nav-h) + var(--safe-bottom));
  background: rgba(255, 253, 248, 0.96);
  padding: 0.65rem 0;
  z-index: 5;
}
.actions-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.actions-bar form { margin: 0; }
.actions-bar .btn { flex: 1 1 auto; }

.desktop-only { display: block; }
.mobile-only { display: none; }
.bottom-nav { display: none; }
.cards-mobile { display: grid; gap: 0.75rem; }
.acta-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 0.85rem;
}
.acta-card.anulada { opacity: 0.7; }
.acta-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.acta-card-body .muted { color: #5b6470; font-size: 0.9rem; margin-top: 0.2rem; }
.acta-card-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-top: 0.75rem;
}
.acta-card-actions .btn { padding: 0.55rem 0.4rem; font-size: 0.88rem; }

.detail { display: grid; grid-template-columns: 9rem 1fr; gap: 0.55rem 1rem; }
.detail dt { color: #5b6470; }
.detail dd { margin: 0; }
.pre { white-space: pre-wrap; }
.badge.danger {
  display: inline-block;
  background: #fde8e8;
  color: var(--danger);
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  vertical-align: middle;
}
.firmas-preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.firmas-preview figure {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem;
  background: #fff;
}
.firmas-preview figcaption {
  font-size: 0.8rem;
  color: #5b6470;
  margin-bottom: 0.35rem;
}
.firmas-preview img {
  width: 100%;
  height: 90px;
  object-fit: contain;
  display: block;
}

@media (max-width: 820px) {
  :root { --nav-h: 64px; }
  .nav-desktop { display: none; }
  .brand-text { display: none; }
  .desktop-only { display: none !important; }
  .mobile-only { display: block !important; }
  .bottom-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    padding: 0.45rem 0.75rem calc(0.45rem + var(--safe-bottom));
    background: rgba(255, 253, 248, 0.97);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }
  .bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: 48px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--ink);
    font-size: 0.8rem;
    font-weight: 600;
  }
  .bottom-nav a.active { background: #e8f5f0; color: var(--accent); }
  .bottom-nav .nav-primary {
    background: var(--accent);
    color: #fff !important;
  }
  .nav-ico { font-size: 1.1rem; line-height: 1; }

  .panel { padding: 1rem; border-radius: 14px; }
  h1 { font-size: 1.25rem; }
  .grid-2, .grid-3, .selector-grid, .selector-row, .firmas-panel, .detail, .firmas-preview {
    grid-template-columns: 1fr;
  }
  .opt-card { min-height: 48px; padding: 0.7rem 0.8rem; }
  .firma-pad { height: 220px; }
  .spacer-label { display: none; }
  .search { width: 100%; }
  .search button { min-height: 44px; }
  .form-actions .btn { flex: 1 1 100%; }
}

@media (min-width: 821px) {
  .topbar { padding: 1rem 1.5rem; }
  .brand-logo { height: 36px; }
}

.nav-user {
  color: #5b6470;
  font-size: 0.88rem;
  margin-right: 0.35rem;
}
.app-footer {
  text-align: center;
  color: #5b6470;
  font-size: 0.82rem;
  padding: 0.75rem 1rem calc(0.75rem + var(--nav-h) + var(--safe-bottom));
}

.login-body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.5rem 1.25rem 1.35rem;
  text-align: center;
}
.login-logo {
  width: min(280px, 100%);
  height: auto;
  display: block;
  margin: 0 auto 0.85rem;
}
.login-brand {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.login-sub {
  margin: 0.25rem 0 1.1rem;
  color: #5b6470;
}
.login-form {
  text-align: left;
  display: grid;
  gap: 0.75rem;
}
.login-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
}
.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
  min-height: 44px;
  font: inherit;
  font-size: 16px;
}
.login-form .btn { width: 100%; margin-top: 0.35rem; }
.login-footer {
  margin-top: 1.25rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  color: #5b6470;
  font-size: 0.85rem;
  line-height: 1.4;
}

@media (max-width: 820px) {
  .bottom-nav { grid-template-columns: 1fr 1fr 1fr; }
}
