:root {
  color-scheme: light;
  --background: #f4f8fc;
  --surface: #fff;
  --text: #192d49;
  --muted: #4d5e73;
  --line: #dce3ed;
  --accent: #f29b60;
  --accent-hover: #ffc69e;
  --tint: #e8f3fd;
  font: 100%/1.5 system-ui, sans-serif;
  color: var(--text);
  background: var(--background);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
.topbar { background: var(--text); color: white; border-bottom: 3px solid #599adb; }
.top-inner, main { width: min(1110px, calc(100% - 2rem)); margin-inline: auto; }
.top-inner, nav, .brand, .heading, .panel-head, .filters, .actions { display: flex; align-items: center; gap: .75rem; }
.top-inner, .heading, .panel-head { justify-content: space-between; }
.top-inner { min-height: 4.3rem; }
.brand { font-weight: 750; white-space: nowrap; }
.brand-icon { display: block; width: 3rem; height: 3rem; object-fit: cover; border: 2px solid #9bc9ef; border-radius: .65rem; background: white; }
main { padding-block: 2.2rem; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.65rem, 4vw, 2.4rem); line-height: 1.14; letter-spacing: -.035em; }
h2, legend { font-size: 1.13rem; font-weight: 740; }
h3 { font-size: 1rem; }
.heading { margin-bottom: 1.55rem; }
.heading p, .muted, .storage-note, small { color: var(--muted); }
.heading p { margin-top: .45rem; }
button, .button, input, select, textarea { font: inherit; }
button, .button { display: inline-flex; justify-content: center; align-items: center; min-height: 2.75rem; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: .55rem; background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; font-weight: 660; }
button:hover, .button:hover { background: var(--tint); }
button:disabled { opacity: .65; cursor: wait; }
.primary { background: var(--accent); border-color: #cd7543; color: #14253d; }
.primary:hover { background: var(--accent-hover); }
nav button[aria-current], .text-button { color: #234e78; border-color: transparent; }
.text-button { background: transparent; padding-left: 0; min-height: 2rem; margin-bottom: .55rem; }
:focus-visible { outline: 3px solid #5987f0; outline-offset: 2px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin-bottom: 1.45rem; }
.stats > div, .panel { border: 1px solid var(--line); border-radius: .9rem; background: var(--surface); min-width: 0; }
.stats > div { padding: .8rem 1rem; }
.stats span { display: block; color: var(--muted); font-size: .91rem; }
.stats strong { font-size: 1.65rem; line-height: 1.2; }
.panel-head, .form-panel, .receipt, .sidebar { padding: 1.15rem; }
.panel-head { flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.filters { flex-wrap: wrap; }
.filters input { width: min(17rem, 100%); }
.filters label { display: block; }
.form-panel { margin: 0 0 1rem; }
legend { padding-inline: .4rem; }
label { display: grid; gap: .35rem; font-weight: 645; font-size: .93rem; }
input, select, textarea { width: 100%; min-height: 2.75rem; padding: .52rem .65rem; color: var(--text); border: 1px solid #acb9cc; border-radius: .53rem; background: var(--surface); font-weight: 400; font-size: 1rem; }
textarea { resize: vertical; }
small { font-size: .85rem; font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1rem; }
.wide { grid-column: 1 / -1; }
.actions { justify-content: end; }
.empty { text-align: center; color: var(--muted); padding: 2.6rem 1rem; }
.row { display: grid; grid-template-columns: 7rem minmax(0,1fr) 9rem 8rem auto; gap: .7rem; align-items: center; padding: .85rem 1.15rem; }
.row + .row { border-top: 1px solid var(--line); }
.row strong, .row span, dd { overflow-wrap: anywhere; }
.row .muted { display: block; }
.detail-actions { display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; justify-content: end; }
.history-heading { border-top: 1px solid var(--line); margin-top: .45rem; padding-top: .65rem; }
.status { width: fit-content; border-radius: .38rem; background: var(--tint); color: #234491; padding: .22rem .5rem; font-size: .88rem; font-weight: 690; }
.status[data-type="Entregado"] { background: #e7f6eb; color: #1b6034; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; gap: 1rem; }
.sidebar { display: grid; gap: .7rem; margin-bottom: 1rem; }
dl { display: grid; grid-template-columns: minmax(8rem, 1fr) minmax(0,2fr); margin: 1rem 0; }
dt, dd { margin: 0; padding: .5rem .15rem; border-bottom: 1px solid var(--line); }
dt { color: var(--muted); }
dd { white-space: pre-wrap; }
.photos { display: flex; gap: .65rem; flex-wrap: wrap; }
.photo-picker { display: grid; gap: .55rem; padding: .8rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--background); }
.photo-buttons { display: flex; flex-wrap: wrap; gap: .45rem; }
.delivery-evidence { margin-top: 1rem; }
.photos:empty { display: none; }
h3 + .photos { margin-top: .55rem; }
.photos img { display: block; width: 7rem; height: 6rem; object-fit: cover; border-radius: .45rem; border: 1px solid var(--line); }
.photos figure { margin: 0; display: grid; gap: .35rem; }
.photos figure button { min-height: 2rem; font-size: .86rem; }
#history { color: var(--muted); margin: .15rem 0 0; padding-left: 1.2rem; font-size: .9rem; }
#history li + li { margin-top: .3rem; }
#notice { position: fixed; z-index: 2; bottom: 1rem; right: 1rem; max-width: calc(100% - 2rem); padding: .75rem 1rem; border-radius: .5rem; background: var(--text); color: white; box-shadow: 0 .3rem 1rem #18253a33; }
#notice.error { background: #8e2630; }
.storage-note { margin-top: .8rem; font-size: .9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 730px) {
  .row { grid-template-columns: minmax(0, 1fr) auto; }
  .row button { grid-column: 2; grid-row: 1 / 3; }
  .row > :nth-child(3), .row > :nth-child(4) { grid-row: auto; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 470px) {
  main { padding-top: 1.5rem; }
  .top-inner { gap: .35rem; }
  .brand { white-space: normal; font-size: .88rem; gap: .4rem; line-height: 1.15; }
  .brand-icon { flex: 0 0 2.3rem; width: 2.3rem; height: 2.3rem; }
  #detail > .heading { align-items: start; }
  .detail-actions { flex-direction: column-reverse; align-items: end; flex-shrink: 0; }
  nav { gap: .15rem; white-space: nowrap; }
  nav button { font-size: .87rem; padding-inline: .45rem; }
  .grid, .filters, .filters label { width: 100%; }
  .grid { grid-template-columns: 1fr; }
  .filters input { width: 100%; }
  .stats { gap: .45rem; }
  .stats > div { padding: .65rem .45rem; }
  .stats span { font-size: .82rem; }
}
@media print {
  :root { background: white; }
  .topbar, #detail > .heading, .detail-grid > div, #notice, .delivery-evidence { display: none !important; }
  main { margin: 0; padding: 0; width: 100%; }
  .detail-grid { display: block; }
  .receipt { border: 0; padding: 0; }
  .photos img { object-fit: contain; width: 10rem; height: 8rem; }
  dt, dd, .photos img { break-inside: avoid; }
}

/* Administración */
.admin-tabs,.admin-toolbar { display:flex; flex-wrap:wrap; gap:.65rem; margin:1rem 0; align-items:end; }
.admin-tabs [aria-pressed="true"] { background:var(--accent); border-color:#cd7543; }
.admin-cards button { display:grid; justify-content:start; text-align:left; gap:.3rem; align-content:center; padding:.8rem; }
.admin-cards button span { color:var(--muted); }
.admin-cards button strong { font-size:1.5rem; }
.admin-toolbar label { flex:1 1 9rem; }
.table-scroll { overflow-x:auto; }
.admin-table { width:100%; border-collapse:collapse; font-size:.92rem; }
.admin-table th,.admin-table td { padding:.7rem .55rem; text-align:left; border-bottom:1px solid var(--line); vertical-align:top; min-width:5.5rem; }
.admin-table th { background:var(--tint); }
.admin-table select { min-width:12rem; }
.admin-table a { color:#234e78; }
.backup-error { color:#8e2630; }
@media (max-width:600px) {
  .top-inner { flex-wrap:wrap; padding:.45rem 0; }
  .top-inner nav { flex-wrap:wrap; }
  .admin-tabs { margin-top:.5rem; }
  .admin-cards button { padding:.45rem; }
}
