:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #687381;
  --line: #d8dee6;
  --panel: #ffffff;
  --surface: #f4f7fa;
  --surface-strong: #eaf0f6;
  --brand: #0b5d73;
  --brand-dark: #073d4d;
  --accent: #8a4b18;
  --ok: #176a3a;
  --warn: #9b6400;
  --danger: #a13535;
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--surface);
}

body:not(.is-authenticated) .app-shell {
  display: none;
}

body.is-authenticated .login-screen {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(rgba(7, 61, 77, 0.86), rgba(7, 61, 77, 0.78)),
    linear-gradient(135deg, #f5f8fb, #dce7ee);
}

.login-card {
  width: min(430px, 100%);
  padding: 24px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.2);
}

.login-card h1 {
  color: var(--ink);
  font-size: 1.55rem;
  margin-bottom: 6px;
}

.login-card p {
  margin: 0 0 18px;
}

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

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  padding: 18px clamp(16px, 3vw, 34px);
  color: white;
  background: linear-gradient(120deg, var(--brand-dark), var(--brand));
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.75rem;
  letter-spacing: 0;
  opacity: 0.82;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 3vw, 2.1rem);
}

h2 {
  font-size: 1.25rem;
}

h3 {
  font-size: 1rem;
}

.session {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: end;
  min-width: min(360px, 52vw);
}

.session-meta {
  display: grid;
  gap: 3px;
  text-align: right;
}

.session span {
  text-align: right;
  font-size: 0.9rem;
  opacity: 0.86;
}

.sync-label {
  font-size: 0.76rem;
}

.sync-label.is-pending {
  color: #ffe8a3;
}

.sync-label.is-local {
  color: #ffd0d0;
}

.sync-label.is-server {
  color: #d4f8df;
}

.session button {
  border: 1px solid rgba(255, 255, 255, 0.36);
  color: white;
  background: rgba(255, 255, 255, 0.12);
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px clamp(12px, 3vw, 28px);
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.tab,
.primary,
.secondary,
.text-button {
  border-radius: var(--radius);
  border: 1px solid transparent;
  min-height: 40px;
  padding: 9px 12px;
}

.tab {
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.tab.is-active {
  color: var(--brand-dark);
  background: var(--surface-strong);
  border-color: #c8d6e2;
}

main {
  padding: clamp(14px, 3vw, 28px);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 16px;
}

.toolbar-title {
  display: grid;
  gap: 4px;
}

.toolbar-title p,
.muted {
  margin: 0;
  color: var(--muted);
}

.primary {
  color: white;
  background: var(--brand);
  border-color: var(--brand);
}

.secondary {
  color: var(--brand-dark);
  background: white;
  border-color: #b9c9d6;
}

.text-button {
  color: var(--brand-dark);
  background: transparent;
  border-color: #c8d6e2;
}

.text-button.danger {
  color: var(--danger);
  border-color: #e5c2c2;
}

.text-button:disabled,
.primary:disabled,
.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.stat {
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat strong {
  display: block;
  font-size: 1.5rem;
  margin-bottom: 2px;
}

.filters,
.form-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.filters {
  align-items: end;
  margin-bottom: 14px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 0.82rem;
}

.field input,
.field select,
.field textarea,
td input {
  width: 100%;
  border: 1px solid #c9d2dc;
  border-radius: var(--radius);
  padding: 10px;
  color: var(--ink);
  background: white;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.check-list {
  gap: 6px;
}

.check-option {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: 0.9rem;
}

.check-option input {
  width: auto;
}

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 850px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #ffffff;
  background: #344553;
  font-weight: 650;
}

tbody tr:nth-child(even) {
  background: #f8fafc;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
}

.status.borrador {
  color: #5c4700;
  background: #fff1bd;
}

.status.generado,
.status.en-curso {
  color: var(--ok);
  background: #dff3e8;
}

.status.finalizado,
.status.archivado {
  color: #344553;
  background: #e9edf2;
}

.status.caducado,
.status.eliminado {
  color: var(--danger);
  background: #f7dfdf;
}

.attention-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.attention-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  white-space: nowrap;
}

.attention-badge.warning {
  color: #5c4700;
  background: #fff1bd;
}

.attention-badge.danger {
  color: var(--danger);
  background: #f7dfdf;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.panel {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel-header {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

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

.movement-row {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr 1fr 0.7fr 0.7fr 0.7fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  background: #f7f9fb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.notice {
  margin: 0 0 14px;
  padding: 11px 12px;
  color: #4f3b00;
  background: #fff4cc;
  border: 1px solid #ead48f;
  border-radius: var(--radius);
  white-space: pre-line;
}

.notice.success {
  color: #154d2d;
  background: #e0f5e9;
  border-color: #b8dfc6;
}

.timeline {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline li {
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.qr-display {
  display: grid;
  place-items: center;
  width: fit-content;
  min-width: 176px;
  min-height: 176px;
  margin: 12px 0;
  border: 10px solid white;
  outline: 1px solid var(--line);
  background: white;
}

.qr-svg,
.qr-display img {
  display: block;
  fill: #101820;
}

.modal-root {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(13, 22, 30, 0.42);
  z-index: 20;
}

.modal-root.is-open {
  display: grid;
}

.modal {
  width: min(760px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
  padding: 18px;
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}

.modal .button-row {
  margin-top: 16px;
}

.master-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.master-item {
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.master-item.is-inactive {
  opacity: 0.55;
}

@media (max-width: 980px) {
  .stats,
  .filters,
  .form-grid,
  .settings-grid,
  .master-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .movement-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar {
    display: grid;
  }

  .session {
    min-width: 100%;
  }

  .stats,
  .filters,
  .form-grid,
  .settings-grid,
  .master-list,
  .movement-row {
    grid-template-columns: 1fr;
  }

  main {
    padding: 12px;
  }

  .panel,
  .filters {
    padding: 12px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar .button-row,
  .toolbar .primary,
  .toolbar .secondary {
    width: 100%;
  }
}
