:root {
  --background: #f3f2ee;
  --foreground: #1c1c1c;
  --card: #fafaf7;
  --primary: #0061fe;
  --primary-foreground: #fafafa;
  --secondary: #e8e7e3;
  --muted: #e9e8e4;
  --muted-foreground: #7a7872;
  --destructive: #c23b2e;
  --success: #2f9d5a;
  --success-foreground: #fafafa;
  --ink: #161616;
  --ink-foreground: #f5f4f0;
  --border: #d4d3ce;
  --font: "Archivo", ui-sans-serif, system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-color: var(--border);
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

img {
  max-width: 100%;
  display: block;
}

.display-xl {
  font-family: var(--font);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.035em;
  line-height: 0.86;
  font-stretch: 75%;
  margin: 0;
}

.display-md {
  font-family: var(--font);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.03em;
  line-height: 0.9;
  font-stretch: 80%;
  margin: 0;
}

.label-mono {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.625rem;
}

.office-only {
  display: none;
}

.campo-only {
  display: block;
}

.shell {
  margin: 0 auto;
  min-height: 100vh;
  max-width: 520px;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--background);
  padding-bottom: 6rem;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 2px solid var(--foreground);
  background: color-mix(in srgb, var(--background) 95%, transparent);
  padding: 1rem 1.25rem;
  backdrop-filter: blur(8px);
}

.topbar-left {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.75rem;
}

.topbar img {
  height: 2.25rem;
  width: auto;
  max-width: 240px;
  object-fit: contain;
  object-position: left;
}

.btn-back {
  flex-shrink: 0;
  border: 2px solid var(--foreground);
  padding: 0.25rem 0.5rem;
}

.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 40;
  margin: 0 auto;
  display: grid;
  max-width: 520px;
  grid-template-columns: repeat(5, 1fr);
  border-top: 2px solid var(--foreground);
  background: var(--ink);
}

.bottom-nav a {
  display: flex;
  height: 4rem;
  align-items: center;
  justify-content: center;
  border-right: 1px solid color-mix(in srgb, var(--ink-foreground) 15%, transparent);
  color: color-mix(in srgb, var(--ink-foreground) 60%, transparent);
  text-align: center;
  padding: 0 0.15rem;
  font-size: 0.55rem;
}

.bottom-nav a:last-child {
  border-right: 0;
}

.bottom-nav a.active {
  background: var(--primary);
  color: var(--primary-foreground);
}

.office-aside {
  display: none;
  position: sticky;
  top: 0;
  height: 100vh;
  width: 13rem;
  flex-shrink: 0;
  flex-direction: column;
  border-right: 2px solid var(--foreground);
  background: var(--ink);
  color: var(--ink-foreground);
}

.office-brand {
  border-bottom: 2px solid var(--foreground);
  background: var(--background);
  padding: 0.75rem;
}

.office-brand img {
  width: 100%;
  object-fit: contain;
}

.office-nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 0.5rem;
}

.office-nav a {
  padding: 0.5rem;
  color: color-mix(in srgb, var(--ink-foreground) 65%, transparent);
  font-size: 0.65rem;
}

.office-nav a:hover {
  background: color-mix(in srgb, var(--ink-foreground) 10%, transparent);
  color: var(--ink-foreground);
}

.office-nav a.active {
  background: var(--primary);
  color: var(--primary-foreground);
}

.office-foot {
  border-top: 1px solid color-mix(in srgb, var(--ink-foreground) 15%, transparent);
  padding: 0.75rem;
  color: color-mix(in srgb, var(--ink-foreground) 40%, transparent);
  font-size: 0.6rem;
}

.office-head {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--foreground);
  background: color-mix(in srgb, var(--background) 95%, transparent);
  padding: 0.5rem 1.25rem;
  backdrop-filter: blur(8px);
}

.section {
  border-bottom: 2px solid var(--foreground);
  padding: 2rem 1.25rem;
}

.section:last-child {
  border-bottom: 0;
}

.section-pad {
  padding: 2rem 1.25rem;
}

.section-head {
  margin-bottom: 1.25rem;
}

.section-head.compact {
  margin-bottom: 0.5rem;
}

.section-head .kicker {
  color: var(--primary);
}

.section-head h2 {
  margin-top: 0.5rem;
  font-size: 2rem;
}

.section-head.compact h2 {
  margin-top: 0.125rem;
  font-size: 1rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  font-stretch: normal;
  line-height: 1.3;
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--foreground);
  margin-top: 1.5rem;
}

.kpi {
  background: var(--background);
  padding: 1rem;
}

.kpi .num {
  font-size: 1.875rem;
}

.kpi .lbl {
  margin-top: 0.25rem;
  color: var(--muted-foreground);
}

.dash {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.dash-hero {
  display: grid;
  gap: 0.75rem;
}

.dash-hero-item {
  border: 2px solid var(--foreground);
  padding: 1.15rem 1rem 1.25rem;
}

.dash-hero-item.is-pending {
  background: color-mix(in srgb, var(--primary) 12%, var(--card));
}

.dash-hero-item.is-done {
  background: var(--ink);
  color: var(--ink-foreground);
  border-color: var(--ink);
}

.dash-hero-item.is-done .label-mono {
  color: color-mix(in srgb, var(--ink-foreground) 70%, transparent);
}

.dash-amount {
  margin: 0.4rem 0 0;
  font-weight: 800;
  font-size: 2rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.dash-sub {
  margin: 0.45rem 0 0;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.dash-hero-item.is-done .dash-sub {
  color: color-mix(in srgb, var(--ink-foreground) 72%, transparent);
}

.dash-grid {
  display: grid;
  gap: 0.75rem;
}

.dash-card {
  border: 2px solid var(--foreground);
  background: var(--card);
  padding: 1rem;
}

.dash-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.dash-card-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.dash-card-head a {
  color: var(--primary);
  flex-shrink: 0;
}

.dash-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.dash-stat,
.dash-fact {
  display: block;
  padding: 0.75rem 0.7rem 0.85rem;
  border: 2px solid var(--foreground);
  color: inherit;
}

.dash-stat.is-pending {
  background: color-mix(in srgb, var(--primary) 8%, var(--card));
}

.dash-stat.is-done {
  background: color-mix(in srgb, var(--success) 12%, var(--card));
}

.dash-count {
  margin: 0.35rem 0 0;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.dash-eur {
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dash-bar {
  margin-top: 0.85rem;
  height: 0.5rem;
  background: var(--secondary);
  border: 2px solid var(--foreground);
}

.dash-bar span {
  display: block;
  height: 100%;
  background: var(--success);
}

.dash-bar-lbl {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.dash-partial {
  display: block;
  margin-top: 0.75rem;
  padding: 0.55rem 0.7rem;
  border: 2px dashed var(--foreground);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--foreground);
  background: color-mix(in srgb, var(--primary) 6%, var(--card));
}

.dash-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.dash-fact .dash-eur {
  font-size: 0.8rem;
}

a.dash-stat:hover,
a.dash-fact:hover,
.dash-partial:hover,
.dash-alert:hover {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.dash-alert {
  display: block;
  padding: 0.85rem 1rem;
  border: 2px solid var(--foreground);
  background: color-mix(in srgb, var(--destructive) 10%, var(--card));
  font-weight: 700;
  font-size: 0.9rem;
}

.dash .actions-2 {
  margin-top: 0;
}

.actions-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.5rem;
  padding: 0 0.75rem;
  text-align: center;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.btn-ghost {
  border: 2px solid var(--foreground);
  color: var(--foreground);
}

.btn-success {
  background: var(--success);
  color: var(--success-foreground);
}

.btn-danger {
  border: 2px solid var(--foreground);
  color: var(--destructive);
}

.btn-dash {
  border: 2px dashed var(--foreground);
}

.btn-sm {
  min-height: 3rem;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 2px solid var(--foreground);
  border-bottom: 2px solid var(--foreground);
}

.doc-list li {
  border-bottom: 2px solid var(--foreground);
}

.doc-list li:last-child {
  border-bottom: 0;
}

.doc-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  padding: 1rem 0;
  align-items: start;
}

.doc-row .meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.doc-row h3 {
  margin: 0.5rem 0 0;
  font-size: 1.125rem;
}

.doc-row .sub {
  margin: 0.25rem 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.doc-row .amt {
  text-align: right;
  flex-shrink: 0;
}

.badge {
  padding: 0.125rem 0.5rem;
}

.badge-borrador,
.badge-pendiente {
  background: var(--secondary);
  color: var(--foreground);
}

.badge-enviado,
.badge-emitida {
  background: var(--primary);
  color: var(--primary-foreground);
}

.badge-firmado,
.badge-aceptado,
.badge-procesado {
  background: var(--success);
  color: var(--success-foreground);
}

.badge-rechazado,
.badge-error {
  background: var(--destructive);
  color: #fff;
}

.badge-facturado {
  background: var(--ink);
  color: var(--ink-foreground);
}

.badge-facturado_parcial,
.badge-anticipo {
  background: color-mix(in srgb, var(--primary) 18%, var(--secondary));
  color: var(--foreground);
}

.badge-resto {
  background: var(--success);
  color: var(--success-foreground);
}

.acciones-doc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0 0 0.75rem;
  align-items: center;
}

.acciones-doc .btn {
  min-height: 0;
  height: auto;
  line-height: 1.2;
  padding: 0.2rem 0.5rem;
  width: auto;
  font-size: 0.6rem;
}

.table td:last-child {
  vertical-align: middle;
  white-space: nowrap;
  width: 1%;
}

.table .acciones-doc {
  padding: 0;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0.25rem;
}

.table .acciones-doc .btn {
  min-height: 0;
  height: auto;
  padding: 0.125rem 0.45rem;
}

.actions-2 .acciones-doc {
  grid-column: 1 / -1;
  padding: 0;
}

.actions-2 .acciones-doc .btn {
  min-height: 3.5rem;
  height: auto;
  flex: 1;
  font-size: inherit;
}

.flash {
  margin: 0.75rem 1.25rem 0;
  padding: 0.75rem;
  border: 2px solid var(--foreground);
  font-size: 0.875rem;
  font-weight: 600;
}

.flash-error {
  color: var(--destructive);
}

.flash-ok {
  color: var(--success);
}

.muted {
  color: var(--muted-foreground);
}

.auth {
  margin: 0 auto;
  display: flex;
  min-height: 100vh;
  max-width: 520px;
  flex-direction: column;
  justify-content: center;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--background);
  padding: 2.5rem 1.25rem;
}

.auth img {
  margin: 0 auto;
  height: 3.5rem;
  width: auto;
  object-fit: contain;
}

.auth h1 {
  margin-top: 2rem;
  font-size: 2.4rem;
}

.auth .lead {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.field {
  display: block;
}

.field + .field {
  margin-top: 1.25rem;
}

.input,
.select,
.textarea {
  width: 100%;
  margin-top: 0.5rem;
  border: 2px solid var(--foreground);
  background: var(--card);
  padding: 0.75rem;
  font-size: 1rem;
  border-radius: 0;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.textarea {
  min-height: 8rem;
  resize: vertical;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.totals {
  background: var(--ink);
  color: var(--ink-foreground);
  padding: 1.5rem 1.25rem;
}

.totals .row {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  color: color-mix(in srgb, var(--ink-foreground) 60%, transparent);
}

.totals .row + .row {
  margin-top: 0.5rem;
}

.totals .total {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid color-mix(in srgb, var(--ink-foreground) 20%, transparent);
}

.totals .total .num {
  font-size: 1.875rem;
  color: var(--primary-foreground);
}

.photos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--foreground);
}

.photo {
  position: relative;
  aspect-ratio: 1;
  background: var(--secondary);
}

.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo .x {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  background: var(--background);
  padding: 0 0.375rem;
  font-size: 0.75rem;
}

.firma-canvas {
  width: 100%;
  height: 9rem;
  touch-action: none;
  border: 2px dashed var(--foreground);
  background: #fff;
}

.table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  border: 2px solid var(--foreground);
  text-align: left;
  table-layout: auto;
}

.table thead {
  background: var(--ink);
  color: var(--ink-foreground);
}

.table th {
  padding: 0.5rem 0.75rem;
  font-weight: 400;
}

.table td {
  padding: 0.5rem 0.75rem;
  vertical-align: top;
  font-size: 0.875rem;
  border-top: 2px solid var(--foreground);
  background: var(--card);
}

.table tbody tr:hover td {
  background: var(--secondary);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.chip {
  border: 1px solid var(--foreground);
  padding: 0.25rem 0.625rem;
  font-size: 0.65rem;
  background: var(--background);
}

.chip.active {
  background: var(--foreground);
  color: var(--background);
}

.suggest {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  border: 2px solid var(--foreground);
}

.suggest button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  text-align: left;
  border-top: 2px solid var(--foreground);
}

.suggest li:first-child button {
  border-top: 0;
}

.lineas-head,
.linea-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 3.5rem 4.5rem 5rem;
  gap: 0.5rem;
  align-items: center;
}

.lineas-head {
  border-bottom: 2px solid var(--foreground);
  padding: 0.375rem 0;
  color: var(--muted-foreground);
}

.linea-view {
  border-bottom: 1px solid var(--foreground);
  padding: 0.375rem 0;
}

.linea-view p {
  margin: 0;
  font-size: 0.875rem;
}

.right {
  text-align: right;
}

.sumas {
  margin-top: 0.5rem;
  font-size: 0.875rem;
}

.sumas .row {
  display: flex;
  justify-content: space-between;
}

.sumas .row.total {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 2px solid var(--foreground);
  font-weight: 600;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  padding: 1.25rem;
}

.modal.open {
  display: flex;
}

.modal-box {
  width: 100%;
  max-width: 28rem;
  border: 2px solid var(--foreground);
  background: var(--background);
  padding: 1.25rem;
}

.grid-btns {
  display: grid;
  gap: 0.75rem;
}

.notas-box {
  border: 2px dashed var(--foreground);
  padding: 0.75rem;
  background: color-mix(in srgb, var(--primary) 6%, var(--card));
}

.empty {
  border-top: 2px solid var(--foreground);
  border-bottom: 2px solid var(--foreground);
  padding: 1.5rem 0;
  color: var(--muted-foreground);
}

.hidden {
  display: none !important;
}

.space-y > * + * {
  margin-top: 1.25rem;
}

.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-5 { margin-top: 1.25rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }

.error {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--destructive);
}

.ok {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--success);
}

@media (min-width: 960px) {
  .campo-only,
  .topbar,
  .bottom-nav {
    display: none !important;
  }

  .office-only {
    display: revert;
  }

  .shell {
    display: flex;
    max-width: none;
    border: 0;
    padding-bottom: 0;
  }

  .office-aside {
    display: flex;
  }

  .office-head {
    display: flex;
  }

  .main {
    flex: 1;
  }

  .body {
    margin: 0 auto;
    max-width: 56rem;
    padding: 1rem 1.25rem;
  }

  .body.wide {
    max-width: none;
    width: 100%;
  }

  .section {
    border-bottom: 1px solid var(--foreground);
    padding: 0 0 0.75rem;
    margin-bottom: 1rem;
  }

  .section-pad {
    padding: 0;
  }

  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
    margin-top: 0.75rem;
  }

  .dash-hero,
  .dash-grid {
    grid-template-columns: 1fr 1fr;
  }

  .dash-amount {
    font-size: 2.35rem;
  }

  .kpi {
    padding: 0.625rem 0.75rem;
  }

  .kpi .num {
    font-size: 1.25rem;
  }

  .actions-2 {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .btn,
  .btn-sm {
    min-height: 2.25rem;
    height: 2.25rem;
    padding: 0 1rem;
    font-size: 0.65rem;
  }

  .acciones-doc .btn,
  .table .acciones-doc .btn {
    min-height: 0;
    height: auto;
    padding: 0.125rem 0.45rem;
    font-size: 0.6rem;
  }

  .photos {
    grid-template-columns: repeat(4, 1fr);
  }

  .photo {
    aspect-ratio: 4 / 3;
  }

  .modal {
    align-items: center;
  }

  .office-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
  }

  .doc-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
  }

  .doc-hero .amt {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
    text-transform: none;
    letter-spacing: 0;
    font-stretch: normal;
  }
}
