:root {
  --bg: #f7f4f8;
  --card: #fff;
  --txt: #302b35;
  --muted: #766e79;
  --a: #8d5a87;
  --a2: #eadceb;
  --line: #e6dfe8;
  --bad: #b94a5a;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--txt);
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app { display: flex; min-height: 100vh; }

/* ---- Barra lateral (escritorio) ---- */
.side {
  width: 230px;
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 22px 15px;
}
.brand { font-size: 21px; font-weight: 800; margin: 0 8px 24px; }
.brand span { color: var(--a); }
.nav button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 12px;
  border-radius: 10px;
  margin: 4px 0;
  font-size: 15px;
}
.nav button:hover, .nav .active { background: var(--a2); color: var(--a); font-weight: 700; }

.main { flex: 1; padding: 26px; max-width: 1400px; margin: auto; width: 100%; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: 24px; }

.btn {
  border: 0; border-radius: 10px; padding: 10px 15px;
  background: var(--a); color: #fff; font-weight: 700;
  touch-action: manipulation;
}
.btn.secondary { background: #eee8ef; color: var(--txt); }
.btn.danger { background: #f4dfe3; color: #913747; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: 15px;
  padding: 18px; box-shadow: 0 2px 8px #00000008;
}
.label { color: var(--muted); font-size: 13px; }
.metric { font-size: 27px; font-weight: 800; margin-top: 5px; word-break: break-word; }

.panel { margin-top: 18px; }
.panel h2 { font-size: 18px; margin: 0 0 12px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input { max-width: 390px; }
.toolbar input, .toolbar select,
.field input, .field select, .field textarea {
  border: 1px solid #d9d1dc; border-radius: 9px; padding: 10px;
  background: #fff; width: 100%;
}

.tablewrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 780px; }
.table th, .table td { padding: 11px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
.table th { color: var(--muted); font-size: 11px; text-transform: uppercase; }

.badge { display: inline-block; padding: 5px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.paid, .pagado { background: #dff0e6; color: #31704f; }
.pending, .pendiente { background: #f8e3e5; color: #9b3748; }
.partial, .parcial { background: #fdf0dc; color: #9a6a1f; }
.excess, .excedente { background: #e2edf7; color: #2f5f85; }
.delivered, .entregado { background: #e5e1f3; color: #65528f; }
.progress, .enproceso { background: #e4edf7; color: #416783; }
.received, .recibido { background: #eee; color: #666; }
.ready, .listo { background: #e8f2e6; color: #4c7a45; }
.cancelled, .cancelado { background: #ececec; color: #7a7a7a; text-decoration: line-through; }
.dei { background: #ebf0e2; color: #51603c; }

.empty { text-align: center; color: var(--muted); padding: 28px; }

.modal { position: fixed; inset: 0; background: #0008; display: none; align-items: center; justify-content: center; padding: 18px; z-index: 9; }
.modal.show { display: flex; }
.modalbox { background: #fff; border-radius: 16px; padding: 22px; width: min(780px, 96vw); max-height: 92vh; overflow: auto; }
.mhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.mhead h2 { margin: 0 0 18px; }

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.full { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 18px; }
.loginbox { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 32px; width: min(390px, 92vw); text-align: center; }
.loginbox .brand { margin: 0 0 10px; }
.loginbox h2 { margin: 10px 0; }
.loginbox input { width: 100%; padding: 12px; border: 1px solid #d9d1dc; border-radius: 9px; margin: 10px 0; }
.error { color: var(--bad); min-height: 20px; font-size: 13px; }

.btn-google {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #000; border: 1px solid #d9d1dc; border-radius: 9px;
  padding: 11px 12px; font-weight: 600; margin: 12px 0 0; touch-action: manipulation;
}
.btn-google:hover { background: #f7f7f7; }
.divider {
  display: flex; align-items: center; gap: 10px; color: var(--muted);
  font-size: 12px; text-transform: uppercase; margin: 14px 0 4px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.note-oauth { font-size: 12px; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs .tab { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 600; }
.tabs .tab.active { background: var(--a); border-color: var(--a); color: #fff; }

.paylist .payrow { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.payrow .grow { flex: 1; min-width: 200px; }
.summary-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.summary-line strong { font-size: 16px; }

.note { background: #faf6fb; border: 1px dashed var(--line); border-radius: 10px; padding: 12px; font-size: 13px; color: var(--muted); margin-top: 12px; }

.action-bar { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .side { width: 72px; padding: 18px 8px; }
  .brand { font-size: 0; text-align: center; }
  .brand span { font-size: 22px; }
  .nav button { font-size: 0; text-align: center; padding: 14px 4px; }
  .nav button::first-letter { font-size: 20px; }
  .grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 620px) {
  .app { display: block; }
  .side {
    position: fixed; bottom: 0; left: 0; right: 0; width: 100%; height: auto;
    padding: 6px; z-index: 8; border-right: 0;
    border-top: 1px solid var(--line);
  }
  .brand { display: none; }
  .nav { display: flex; justify-content: space-around; }
  .nav button { margin: 0; padding: 10px 6px; font-size: 11px; flex: 1; text-align: center; border-radius: 8px; }
  .nav button::first-letter { font-size: 18px; }
  .main { padding: 16px 14px 82px; }
  .grid { grid-template-columns: 1fr 1fr; }
  .form { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .modalbox { padding: 16px; }
  .table { min-width: 0; }
}

/* ---- Historial de pedidos (ficha de clienta) ---- */
.hist { margin-top: 14px; }
.hist-toggle {
  width: 100%; text-align: left; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-weight: 700; color: var(--a);
  font-size: 14px; cursor: pointer; transition: background .15s;
}
.hist-toggle:hover { background: var(--a2); }
.hist-body {
  margin-top: 10px; border: 1px solid var(--line); border-radius: 10px;
  background: #fcfbfd; padding: 10px; max-height: 320px; overflow-y: auto;
}
