:root {
  color-scheme: light;
  --bg: #f3f5f2;
  --panel: #ffffff;
  --ink: #1c2520;
  --muted: #627069;
  --line: #d8dfd8;
  --brand: #f7b733;
  --brand-dark: #a76410;
  --accent: #19735c;
  --accent-dark: #10513f;
  --danger: #a33a2b;
  --shadow: 0 18px 60px rgba(38, 51, 45, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(247, 183, 51, 0.16), rgba(25, 115, 92, 0) 38%),
    var(--bg);
}

body.booting .app-shell {
  visibility: hidden;
}

body.login-only .app-shell {
  min-height: 100vh;
  display: grid;
  align-items: center;
}

body.login-only .workspace {
  grid-template-columns: minmax(0, 860px);
  justify-content: center;
}

body.login-only .summary-panel {
  display: none;
}

body.login-only .form-panel {
  padding: 32px;
}

body.login-only .auth-panel {
  margin: 0;
  padding: 0;
  border-bottom: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.summary-panel,
.form-panel,
.report-sheet {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.summary-panel {
  position: sticky;
  top: 24px;
  min-height: calc(100vh - 48px);
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.brand-mark {
  position: relative;
  width: 82px;
  height: 82px;
  margin-bottom: 22px;
}

.sun-core,
.ray {
  position: absolute;
  display: block;
}

.sun-core {
  width: 44px;
  height: 44px;
  left: 19px;
  top: 19px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: inset -8px -8px 0 rgba(167, 100, 16, 0.16);
}

.ray {
  width: 14px;
  height: 76px;
  left: 34px;
  top: 3px;
  border-radius: 999px;
  background: rgba(247, 183, 51, 0.58);
}

.ray-a {
  transform: rotate(0deg);
}

.ray-b {
  transform: rotate(45deg);
}

.ray-c {
  transform: rotate(90deg);
}

.ray-d {
  transform: rotate(135deg);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.7rem);
  line-height: 0.94;
  max-width: 10ch;
}

.subtitle {
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.live-summary {
  margin: auto 0 0;
  display: grid;
  gap: 12px;
}

.connection-card {
  margin-top: 18px;
  padding: 14px;
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  background: #f9faf7;
}

.connection-card > div:first-child {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.connection-card span {
  font-weight: 900;
}

.connection-card small,
.panel-hint,
.history-meta,
.history-empty {
  color: var(--muted);
}

.connection-card small {
  overflow-wrap: anywhere;
}

.mini-button {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.connection-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.live-summary div {
  padding: 14px;
  border: 1px solid var(--line);
  background: #f9faf7;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

dd {
  margin: 4px 0 0;
  font-weight: 800;
  font-size: 1.35rem;
}

.form-panel {
  padding: 26px;
}

.setup-panel,
.auth-panel,
.admin-panel {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.panel-hint {
  margin: -8px 0 14px;
  line-height: 1.5;
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.auth-actions {
  margin-top: 14px;
}

.setup-help {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.setup-help a {
  color: var(--accent-dark);
  font-weight: 800;
}

.user-menu {
  margin-bottom: 24px;
  padding-bottom: 18px;
  display: grid;
  grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.user-menu div:first-child {
  display: grid;
  gap: 4px;
}

.user-menu strong {
  font-size: 1.05rem;
}

.user-menu small {
  color: var(--muted);
}

.user-menu-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.menu-button {
  min-height: 74px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  color: var(--ink);
  background: #fbfcfa;
  cursor: pointer;
}

.menu-button span {
  font-weight: 900;
}

.menu-button small {
  color: var(--muted);
}

.menu-button.is-active {
  border-color: var(--accent);
  background: #eaf4ef;
  box-shadow: inset 4px 0 0 var(--accent);
}

.field-command {
  display: flex;
  gap: 10px;
  align-items: end;
}

.managed-users-list {
  display: grid;
  gap: 10px;
}

.managed-user-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.managed-user-card strong {
  overflow-wrap: anywhere;
}

.managed-user-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.managed-user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: end;
}

.section-heading {
  margin: 6px 0 18px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 {
  font-size: 1.22rem;
}

.section-heading.compact {
  margin-top: 0;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 30px;
}

label {
  display: grid;
  gap: 7px;
}

label span,
.signature-head span {
  color: #2d3832;
  font-size: 0.9rem;
  font-weight: 700;
}

.wide {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfcfa;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(25, 115, 92, 0.12);
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.unit-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px;
  align-items: center;
}

.unit-input input {
  border-radius: 8px 0 0 8px;
}

.unit-input strong {
  min-height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  background: #eef3ee;
  color: var(--accent-dark);
}

.dynamic-section {
  border-top: 1px solid var(--line);
  padding-top: 22px;
  margin-top: 6px;
}

.serial-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.serial-list:empty::before {
  content: "Sin equipos cargados";
  display: block;
  grid-column: 1 / -1;
  padding: 14px;
  color: var(--muted);
  border: 1px dashed var(--line);
  background: #fbfcfa;
}

.serial-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  background: #fbfcfa;
  border-radius: 8px;
}

.serial-card strong {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8f2ed;
  color: var(--accent-dark);
}

.serial-card label {
  gap: 5px;
}

.serial-card span {
  font-size: 0.8rem;
}

.signature-area {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  overflow: hidden;
}

.signature-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.signature-head div {
  display: grid;
  gap: 3px;
}

.signature-head small {
  color: var(--muted);
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef3ee;
  color: var(--accent-dark);
  cursor: pointer;
}

.icon-button:hover {
  background: #e1ece5;
}

#signaturePad {
  display: block;
  width: 100%;
  height: 190px;
  touch-action: none;
  cursor: crosshair;
}

.check-row {
  margin: 16px 0 22px;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: start;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.check-row span {
  line-height: 1.45;
}

.actions,
.report-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary,
.secondary {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: #ffffff;
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.secondary:hover {
  background: #f6f8f4;
}

.report-view {
  margin-top: 18px;
}

.history-section {
  margin-top: 34px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.history-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.history-card h3 {
  font-size: 1rem;
  margin-bottom: 5px;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.86rem;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: end;
}

.history-empty {
  padding: 14px;
  border: 1px dashed var(--line);
  background: #fbfcfa;
}

.report-toolbar {
  margin-bottom: 14px;
}

.report-sheet {
  padding: 34px;
}

.report-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 18px;
  margin-bottom: 24px;
}

.report-header h2 {
  margin-top: 5px;
  font-size: 1.7rem;
}

.report-badge {
  min-width: 150px;
  border: 1px solid var(--line);
  padding: 12px;
  text-align: right;
}

.report-badge span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.report-badge strong {
  display: block;
  margin-top: 3px;
  font-size: 1.2rem;
}

.report-block {
  margin-top: 22px;
}

.report-block h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  margin: 0;
}

.report-grid div {
  border-bottom: 1px solid var(--line);
  padding: 7px 0;
}

.report-grid dd {
  font-size: 0.98rem;
  font-weight: 700;
}

.two-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.report-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 6px;
}

.declaration,
.notes-out {
  line-height: 1.55;
}

.notes-out {
  margin-top: 10px;
  color: var(--muted);
}

.signature-report {
  margin-top: 42px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
}

.signature-report div {
  min-height: 120px;
  display: grid;
  align-content: end;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 9px;
}

.signature-report img {
  max-width: 100%;
  max-height: 100px;
  object-fit: contain;
  object-position: left bottom;
}

.signature-report span:first-child {
  font-weight: 800;
}

.signature-report span:last-child {
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    position: static;
    min-height: auto;
  }

  .live-summary {
    margin-top: 20px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .form-panel,
  .report-sheet,
  .summary-panel {
    padding: 18px;
  }

  .section-heading {
    display: grid;
    justify-content: start;
    align-items: start;
    gap: 4px;
  }

  .field-grid,
  .auth-grid,
  .history-controls,
  .managed-user-card,
  .serial-list,
  .report-grid,
  .two-columns,
  .signature-report {
    grid-template-columns: 1fr;
  }

  .live-summary {
    grid-template-columns: 1fr;
  }

  .actions,
  .report-toolbar,
  .connection-actions,
  .field-command,
  .user-menu,
  .user-menu-actions,
  .managed-user-actions,
  .history-actions,
  .history-card {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary,
  .secondary {
    width: 100%;
  }

  .report-header {
    display: grid;
  }

  .report-badge {
    text-align: left;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .workspace,
  .report-toolbar {
    display: none !important;
  }

  .app-shell,
  .report-view {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  #reportView {
    display: block !important;
  }

  .report-sheet {
    box-shadow: none;
    border: 0;
    padding: 0;
  }
}
