.range-toggle {
    display: inline-flex;
    background: var(--accent-soft);
    border-radius: 8px; padding: 3px;
    margin-bottom: 1.5rem;
  }

.range-toggle button {
    background: transparent; border: none;
    padding: 0.5rem 1rem;
    font-family: inherit; font-size: 0.85rem; font-weight: 500;
    cursor: pointer; color: var(--text-muted);
    border-radius: 6px; transition: all 0.15s;
  }

.range-toggle button.active {
    background: var(--bg); color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  }

.range-toggle button:not(.active):hover { color: var(--text); }

/* Two filters on one row. They compose (range AND method), so they sit side by
   side rather than stacked — stacking implies a hierarchy that isn't there. */
.method-toggle { margin-left: 0.5rem; }
@media (max-width: 560px) {
  .method-toggle { margin-left: 0; }
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.85rem;
    margin-bottom: 2rem;
  }

.kpi {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
  }

.kpi-label {
    font-size: 0.75rem; font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
    margin-bottom: 0.45rem;
  }

.kpi-value {
    font-size: 2rem; font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.1;
  }

.kpi-secondary {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 0.2rem;
    letter-spacing: -0.01em;
  }

.kpi-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
  }

.kpi.dark {
    background: var(--text); color: var(--bg);
    border-color: var(--text);
  }

.kpi.dark .kpi-label { color: rgba(255,255,255,0.6); }

.kpi.dark .kpi-sub { color: rgba(255,255,255,0.6); }

.section {
    margin-bottom: 2rem;
  }

.section-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 0.9rem;
  }

.section-title {
    font-size: 1.25rem; font-weight: 600;
    letter-spacing: -0.02em;
  }

.section-note {
    font-size: 0.78rem; color: var(--text-faint);
  }

.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
  }

.split {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 1.25rem;
  }

@media (max-width: 880px) { .split { grid-template-columns: 1fr; } }

.chart {
    height: 240px;
    display: flex; align-items: flex-end;
    gap: 0.35rem;
    padding: 0.5rem 0 1.75rem;
    position: relative;
    border-bottom: 1px solid var(--border);
  }

.chart-col {
    flex: 1;
    height: 100%;
    display: flex; flex-direction: column;
    align-items: stretch;
    justify-content: flex-end;
    position: relative;
    min-width: 0;
  }

.chart-bar {
    background: var(--text);
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: all 0.2s;
    cursor: default;
  }

.chart-bar.zero {
    background: var(--border);
    min-height: 2px;
  }

.chart-col:hover .chart-bar { background: var(--success); }

.chart-col:hover .chart-bar.zero { background: var(--text-faint); }

.chart-label {
    position: absolute;
    bottom: -1.4rem; left: 0; right: 0;
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
  }

.chart-tooltip {
    position: absolute;
    bottom: 100%; left: 50%;
    transform: translate(-50%, -4px);
    background: var(--text);
    color: var(--bg);
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0; pointer-events: none;
    transition: opacity 0.15s;
    z-index: 5;
  }

.chart-col:hover .chart-tooltip { opacity: 1; }

.chart-legend {
    display: flex; gap: 1rem;
    margin-top: 0.8rem;
    font-size: 0.75rem;
    color: var(--text-muted);
  }

.top-list { display: flex; flex-direction: column; gap: 0.5rem; }

.top-item {
    display: grid;
    grid-template-columns: 1.5rem 1fr auto;
    align-items: center; gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
  }

.top-item:last-child { border-bottom: none; }

.top-rank {
    font-size: 0.85rem; font-weight: 600;
    color: var(--text-faint);
    text-align: center;
  }

.top-rank.gold   { color: #d97706; }

.top-rank.silver { color: #6b7280; }

.top-rank.bronze { color: #92400e; }

.top-name {
    font-size: 0.95rem; font-weight: 500;
    overflow: hidden; text-overflow: ellipsis;
  }

.top-name-bar {
    display: block;
    height: 4px; background: var(--accent-soft);
    border-radius: 2px; margin-top: 0.3rem;
    overflow: hidden;
  }

.top-name-bar-fill {
    display: block; height: 100%;
    background: var(--text);
    border-radius: 2px;
  }

.top-qty {
    font-size: 0.85rem; font-weight: 600;
    color: var(--text);
    text-align: right;
    white-space: nowrap;
  }

.top-qty small {
    display: block;
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.72rem;
  }

.table-wrap {
    overflow-x: auto;
    margin: 0 -1.5rem;
    padding: 0 1.5rem;
  }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
  }

th, td {
    text-align: left;
    padding: 0.7rem 0.6rem;
    border-bottom: 1px solid var(--border);
  }

th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
  }

td.num { text-align: right; font-variant-numeric: tabular-nums; }

th.num { text-align: right; }

tbody tr:hover { background: var(--surface); }

.method-pill {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 500;
    background: var(--accent-soft);
    color: var(--text);
  }

.method-pill.cash { background: #f0fdf4; color: var(--success); }

.method-pill.card { background: #eff6ff; color: #1e40af; }

.paid-tag {
    display: inline-block;
    margin-left: 0.3rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    vertical-align: middle;
  }

.total-pyg {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
  }

.total-usd {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
  }

.checkbox {
    width: 18px; height: 18px;
    cursor: pointer;
    accent-color: var(--text);
    vertical-align: middle;
  }

tbody tr.selected { background: #fffbeb; }

tbody tr.selected:hover { background: #fef3c7; }

.actions-bar {
    display: flex; align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    background: var(--text);
    color: var(--bg);
    border-radius: 10px;
    font-size: 0.85rem;
    animation: slideIn 0.2s ease-out;
  }

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
  }

.actions-bar-count { font-weight: 600; }

.actions-bar-spacer { flex: 1; }

.actions-bar button {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: var(--bg);
    padding: 0.4rem 0.85rem;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
  }

.actions-bar button:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.5); }

.actions-bar button.danger {
    background: var(--danger);
    border-color: var(--danger);
  }

.actions-bar button.danger:hover { background: #b91c1c; border-color: #b91c1c; }

.danger-zone {
    margin-top: 2rem;
    padding: 1rem 1.25rem;
    border: 1px dashed #fca5a5;
    background: #fef2f2;
    border-radius: 10px;
    display: flex; align-items: center;
    gap: 1rem; flex-wrap: wrap;
  }

.danger-zone-text {
    font-size: 0.85rem; color: #991b1b;
    flex: 1; min-width: 200px;
  }

.danger-zone-text strong { display: block; margin-bottom: 0.15rem; }

.danger-zone button {
    background: transparent;
    border: 1px solid #dc2626;
    color: #dc2626;
    padding: 0.5rem 0.9rem;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
  }

.danger-zone button:hover { background: var(--danger); color: var(--bg); }

.modal {
    background: var(--bg);
    border-radius: 14px;
    padding: 1.75rem;
    max-width: 420px; width: 100%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
    animation: modalIn 0.2s ease-out;
  }

.modal h3 {
    font-size: 1.2rem; font-weight: 600;
    margin-bottom: 0.3rem; letter-spacing: -0.02em;
  }

.modal-sub {
    font-size: 0.85rem; color: var(--text-muted);
    margin-bottom: 1.25rem;
  }

.pin-input {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1.4rem; font-weight: 600;
    color: var(--text);
    text-align: center;
    letter-spacing: 0.5em;
    margin-bottom: 0.75rem;
    transition: all 0.15s;
  }

.pin-input:focus {
    outline: none; border-color: var(--text);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
  }

.pin-input.error {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
    animation: shake 0.3s;
  }

.confirm-input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
    margin-bottom: 0.75rem;
  }

.confirm-input:focus {
    outline: none; border-color: var(--text);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
  }

.pin-error {
    font-size: 0.8rem;
    color: var(--danger);
    margin-bottom: 0.5rem;
    min-height: 1.2em;
  }

.modal-actions-row {
    display: flex; gap: 0.5rem; justify-content: flex-end;
  }

.modal-btn {
    border: 1px solid var(--text);
    background: var(--text); color: var(--bg);
    padding: 0.6rem 1rem;
    font-family: inherit; font-size: 0.85rem; font-weight: 500;
    cursor: pointer; border-radius: 6px;
    transition: all 0.15s;
  }

.modal-btn:hover { background: #262626; }

.modal-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.modal-btn.ghost {
    background: transparent; color: var(--text);
    border-color: var(--border-strong);
  }

.modal-btn.ghost:hover { background: var(--accent-soft); border-color: var(--text); }

.modal-btn.danger {
    background: var(--danger); border-color: var(--danger);
  }

.modal-btn.danger:hover { background: #b91c1c; border-color: #b91c1c; }

.items-preview {
    color: var(--text-muted);
    font-size: 0.8rem;
    overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 280px;
    display: inline-block;
  }

.item-list {
    display: flex; flex-direction: column;
    gap: 0.5rem;
    max-width: 360px;
  }

.item-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    column-gap: 0.6rem;
    font-size: 0.85rem;
  }

.item-name { font-weight: 500; }

.item-price {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
  }

.item-sides {
    grid-column: 1 / -1;
    margin-top: 0.15rem;
    padding-left: 0.7rem;
    border-left: 2px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
  }

.item-side-price {
    font-variant-numeric: tabular-nums;
    color: var(--text-faint);
  }

.status {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
  }

.status.error {
    background: #fef2f2; color: var(--danger);
    border-radius: 8px;
  }

@media (max-width: 640px) {
    body { padding: 1rem 0.85rem 2rem; }
    header {
      padding-bottom: 1rem; margin-bottom: 1.25rem;
      gap: 0.6rem;
    }
    .header-left { gap: 0.75rem; flex: 1; min-width: 0; }
    .logo { font-size: 1.4rem; }
    .logo small { font-size: 0.7rem; }
    .back-link {
      padding: 0.45rem 0.65rem;
      font-size: 0.8rem;
    }
    .back-link span { display: none; }

    .range-toggle {
      width: 100%; padding: 2px;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
    .range-toggle button {
      padding: 0.5rem 0.85rem; font-size: 0.8rem;
      white-space: nowrap; flex: 1;
    }

    .kpi-grid { gap: 0.6rem; margin-bottom: 1.5rem; grid-template-columns: 1fr 1fr; }
    .kpi { padding: 1rem; }
    .kpi-value { font-size: 1.6rem; }
    .kpi-label { font-size: 0.7rem; }

    .section { margin-bottom: 1.5rem; }
    .section-title { font-size: 1.1rem; }
    .card { padding: 1rem; }

    .chart { height: 180px; gap: 0.2rem; padding-bottom: 1.5rem; }
    .chart-label { font-size: 0.6rem; }

    .top-item { grid-template-columns: 1.3rem 1fr auto; gap: 0.5rem; padding: 0.5rem 0; }
    .top-name { font-size: 0.9rem; }

    
    .table-wrap { margin: 0 -1rem; padding: 0 1rem; }
    table thead { display: none; }
    table, tbody, tr, td { display: block; width: 100%; }
    tbody tr {
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 0.7rem 0.85rem;
      margin-bottom: 0.5rem;
      display: grid;
      grid-template-columns: auto 1fr auto;
      grid-template-areas:
        "check date amount"
        "check method method"
        "check items items";
      gap: 0.3rem 0.6rem;
      align-items: center;
    }
    tbody tr:hover { background: var(--bg); }
    tbody tr.selected { background: #fffbeb; }
    tbody td { border: none !important; padding: 0 !important; }
    tbody td:nth-child(1) { grid-area: check; }
    tbody td:nth-child(2) { grid-area: date; font-weight: 500; }
    tbody td:nth-child(2)::after {
      content: ' · ' attr(data-time);
      color: var(--text-muted); font-weight: 400; font-size: 0.85rem;
    }
    tbody td:nth-child(3) { display: none; } 
    tbody td:nth-child(4) { grid-area: method; }
    tbody td:nth-child(5) {
      grid-area: items;
      font-size: 0.8rem; color: var(--text-muted);
    }
    tbody td:nth-child(6) {
      grid-area: amount;
      font-weight: 600; font-size: 1rem;
      text-align: right;
    }
    .item-list { max-width: 100%; gap: 0.4rem; }
    .item-row { font-size: 0.82rem; }
    .item-sides { font-size: 0.72rem; }

    .danger-zone { flex-direction: column; align-items: stretch; text-align: center; }
    .danger-zone button { width: 100%; }

    .actions-bar { flex-wrap: wrap; padding: 0.6rem 0.85rem; font-size: 0.8rem; }

    .modal { padding: 1.25rem; border-radius: 12px; }
    .pin-input { font-size: 1.2rem; padding: 0.7rem 0.85rem; }

    .lock-pin-input { font-size: 1.35rem; padding: 0.8rem 0.85rem; }
    .lock-title { font-size: 1.25rem; }

    .footer-note { margin-top: 1.5rem; }
  }

@media (max-width: 380px) {
    .logo { font-size: 1.2rem; }
    .range-toggle button { padding: 0.45rem 0.6rem; font-size: 0.75rem; }
  }
/* Per-item note in the stats order breakdown */
.item-note {
  font-size: 0.8rem;
  color: #8a6d13;
  font-style: italic;
  margin-top: 0.15rem;
}

/* Shown when stats are rendered from the local copy because the server
   couldn't be reached (e.g. writing facturas with no signal). */
.offline-notice {
  background: #fff8e1;
  border: 1px solid #f0d98c;
  color: #8a6d13;
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Same notice, different cause: the server answered and failed. Deliberately
   red rather than amber — amber reads as "wait and it'll clear", which is true
   of no signal and false of a 500. */
.offline-notice.server-error {
  background: #fef2f2;
  border-color: #f3b6b6;
  color: #a11a1a;
}

/* Order name shown against a recorded order */
.order-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}

/* ---- Orders by name (facturas helper) ---- */
.facturas-btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.55rem 0.9rem;
  margin: 0 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit; font-size: 0.85rem; font-weight: 500;
  cursor: pointer;
}
.facturas-btn:hover { border-color: var(--text); }

.facturas-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 60;
  align-items: center; justify-content: center;
  padding: 1rem;
}
.facturas-backdrop.open { display: flex; }

.facturas-panel {
  background: var(--bg);
  border-radius: 14px;
  width: 100%; max-width: 560px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.facturas-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.15rem 0.5rem;
}
.facturas-head h3 { margin: 0; font-size: 1.05rem; }
.facturas-close {
  border: none; background: none; font-size: 1.5rem; line-height: 1;
  color: var(--text-muted); cursor: pointer; padding: 0 0.25rem;
}
.facturas-sub {
  padding: 0 1.15rem 0.6rem;
  font-size: 0.78rem; color: var(--text-muted);
}
.facturas-search-wrap { padding: 0 1.15rem 0.75rem; }
.facturas-search {
  width: 100%; box-sizing: border-box;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 0.9rem;
  background: var(--bg); color: var(--text);
}
.facturas-search:focus { outline: none; border-color: var(--text); }

.facturas-body {
  overflow-y: auto;
  padding: 0 1.15rem 1.15rem;
  -webkit-overflow-scrolling: touch;
}

.fac-order {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.6rem;
}
.fac-head {
  display: flex; align-items: baseline; gap: 0.5rem;
}
.fac-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.4rem; height: 1.4rem;
  border-radius: 50%;
  background: var(--text); color: var(--bg);
  font-size: 0.72rem; font-weight: 600;
  flex-shrink: 0;
}
.fac-name { font-weight: 600; font-size: 0.95rem; flex: 1; }
.fac-total { font-weight: 600; font-size: 0.9rem; }
.fac-meta {
  font-size: 0.72rem; color: var(--text-muted);
  margin: 0.25rem 0 0.4rem 1.9rem;
}
.fac-items { margin-left: 1.9rem; }
.fac-item {
  display: flex; justify-content: space-between; gap: 0.5rem;
  font-size: 0.85rem; padding: 0.1rem 0;
}
.fac-item-price { color: var(--text-muted); }
.fac-side { font-size: 0.78rem; color: var(--text-muted); padding-left: 0.6rem; }
.fac-note { font-size: 0.78rem; color: #8a6d13; font-style: italic; padding-left: 0.6rem; }