/* ============================================================
   Dulzia — operations dashboard
   Aesthetic: warm modern patisserie. Cream canvas, raspberry +
   caramel accents, Fraunces display serif over DM Sans.
   ============================================================ */

:root {
  --cream:      #FBF6EF;
  --cream-2:    #F3E9DC;
  --paper:      #FFFFFF;
  --ink:        #2B2118;
  --ink-soft:   #6F6256;
  --muted:      #9C8E7E;
  --line:       rgba(43, 33, 24, 0.12);
  --line-soft:  rgba(43, 33, 24, 0.06);

  --berry:      #8E2D4D;   /* primary accent */
  --berry-dk:   #6F2240;
  --caramel:    #C8772E;   /* secondary accent */
  --rose:       #E8B4B8;
  --green:      #4E7A51;
  --green-bg:   #E6EFE4;
  --amber:      #B7791F;
  --amber-bg:   #FBEFD6;
  --red:        #B23A48;
  --red-bg:     #F6E0E1;

  --shadow-sm: 0 1px 2px rgba(43, 33, 24, 0.06), 0 1px 3px rgba(43, 33, 24, 0.05);
  --shadow-md: 0 6px 20px rgba(43, 33, 24, 0.08);
  --shadow-lg: 0 18px 50px rgba(43, 33, 24, 0.16);
  --radius: 16px;
  --radius-sm: 10px;

  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "DM Sans", -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(200, 119, 46, 0.10), transparent 60%),
    radial-gradient(1000px 500px at -10% 110%, rgba(142, 45, 77, 0.08), transparent 55%),
    var(--cream);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
}

h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; color: var(--ink); line-height: 1.1; }
a { color: var(--berry); }
button { font-family: var(--body); cursor: pointer; }
input, select, textarea { font-family: var(--body); font-size: 0.95rem; }

/* ---------------- Layout ---------------- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--berry-dk), var(--berry));
  color: #fdeef0;
  padding: 26px 18px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: baseline; gap: 8px; margin-bottom: 24px; padding-left: 8px; }
.brand .logo { font-family: var(--display); font-size: 1.9rem; font-weight: 600; color: #fff; letter-spacing: -0.5px; }
.brand .logo em { color: var(--rose); font-style: normal; }
.brand .tag { font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(255,255,255,0.6); }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 11px;
  color: rgba(255, 240, 242, 0.82); font-weight: 500; font-size: 0.92rem;
  border: none; background: transparent; width: 100%; text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item .ic { width: 18px; text-align: center; font-size: 1.05rem; opacity: 0.9; }
.nav-item:hover { background: rgba(255, 255, 255, 0.10); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, 0.16); color: #fff; }
.nav-item .badge {
  margin-left: auto; background: var(--caramel); color: #fff;
  font-size: 0.68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; min-width: 18px; text-align: center;
}
.sidebar .spacer { flex: 1; }
.sidebar .footnote { font-size: 0.7rem; color: rgba(255,255,255,0.5); padding: 8px; line-height: 1.5; }
.sidebar .footnote b { color: rgba(255,255,255,0.8); font-weight: 600; }
.logout-btn { margin-top: 6px; background: none; border: 1px solid rgba(255,255,255,0.3); color: rgba(255,255,255,0.75); border-radius: 8px; padding: 3px 10px; font: inherit; cursor: pointer; }
.logout-btn:hover { color: #fff; border-color: rgba(255,255,255,0.6); }
.print-wrap { position: relative; }
.print-wrap .btn { white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 30px; border-bottom: 1px solid var(--line);
  background: rgba(251, 246, 239, 0.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.4rem; }
.topbar .sub { color: var(--ink-soft); font-size: 0.85rem; margin-top: 2px; }
.topbar .grow { flex: 1; }

.content { padding: 26px 30px 60px; max-width: 1400px; width: 100%; }
.view { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- Pills / status ---------------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  border: 1px solid var(--line);
  background: var(--paper);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok { background: var(--green-bg); color: var(--green); border-color: transparent; }
.pill.ok .dot { background: var(--green); animation: pulse 2s infinite; }
.pill.warn { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.pill.warn .dot { background: var(--amber); }
.pill.off { background: var(--red-bg); color: var(--red); border-color: transparent; }
.pill.off .dot { background: var(--red); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--paper); color: var(--ink); font-weight: 600; font-size: 0.9rem;
  box-shadow: var(--shadow-sm); transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
}
.btn:hover { box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--berry); color: #fff; border-color: transparent; }
.btn.primary:hover { background: var(--berry-dk); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.sm { padding: 6px 11px; font-size: 0.82rem; border-radius: 9px; }
.btn.danger { color: var(--red); border-color: var(--red-bg); }
.btn.danger:hover { background: var(--red-bg); }

/* ---------------- Cards / panels ---------------- */
.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card.pad { padding: 20px 22px; }
.card-h { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-h h3 { font-size: 1.15rem; }
.card-h .grow { flex: 1; }
.grid { display: grid; gap: 16px; }

/* KPI cards */
.kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.kpi { padding: 18px 20px; }
.kpi .label { font-size: 0.78rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }
.kpi .value { font-family: var(--display); font-size: 2.1rem; margin-top: 6px; color: var(--berry); }
.kpi .value.ink { color: var(--ink); }

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 700; }
td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.num { font-variant-numeric: tabular-nums; }
/* Pedidos "Envío" cell: switch + label on one line, the three buttons under them,
   so the column stays narrow and the table fits inside its card. */
.envio-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; width: 150px; }
/* Pasted map links and emoji names have no spaces: let them break instead of
   widening the whole table. */
.wrap-any { overflow-wrap: anywhere; }

/* Inputs */
.input, input[type=text], input[type=number], input[type=password], textarea, select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); color: var(--ink); transition: border 0.15s, box-shadow 0.15s;
}
.input:focus, input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--berry); box-shadow: 0 0 0 3px rgba(142, 45, 77, 0.12);
}
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
/* The checkbox fills the switch and sits on top (invisible) so clicks toggle it. */
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }
.switch .track { position: absolute; inset: 0; background: #d9cebf; border-radius: 999px; transition: 0.2s; z-index: 1; }
.switch .track::before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: var(--shadow-sm); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::before { transform: translateX(20px); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--cream-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 0.85rem; }
.chip button { border: none; background: none; color: var(--muted); font-size: 1rem; line-height: 1; padding: 0 2px; }
.chip button:hover { color: var(--red); }

/* status badges for orders/contacts */
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.74rem; font-weight: 700; }
.tag.PENDIENTE_PAGO { background: var(--amber-bg); color: var(--amber); }
.tag.PAGO_CONFIRMADO { background: var(--green-bg); color: var(--green); }
.tag.EN_RUTA { background: #E3ECF7; color: #3A6EA5; }
.tag.ENTREGADO { background: #EAE6F2; color: #6A4C93; }
.tag.CANCELADO { background: var(--red-bg); color: var(--red); }
.tag.REVISION { background: var(--amber-bg); color: var(--amber); }
.tag.ACTIVE { background: var(--cream-2); color: var(--ink-soft); }

/* ---------------- Chats ---------------- */
.chat-wrap { display: grid; grid-template-columns: 300px 1fr; gap: 16px; height: calc(100vh - 150px); }
.chat-side { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.chat-side .chat-list { flex: 1; min-height: 0; }
.chat-list { overflow-y: auto; }
.chat-list .conv { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.chat-list .conv:hover { background: var(--cream); }
.chat-list .conv.active { background: var(--cream-2); }
.conv .av { width: 38px; height: 38px; border-radius: 50%; background: var(--rose); color: var(--berry-dk); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.conv .meta { min-width: 0; flex: 1; }
.conv .meta .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .meta .pv { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.more-btn { display: block; margin: 14px auto 6px; }
.conv .conv-tag { display: inline-block; font-size: 0.62rem; padding: 1px 8px; margin-top: 3px; }
.copyable { cursor: pointer; border-bottom: 1px dotted currentColor; }
.copyable:hover { color: var(--berry); }

.chat-panel { display: flex; flex-direction: column; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.chat-head-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.chat-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; background: var(--cream); }
.bubble { max-width: 72%; padding: 9px 13px; border-radius: 14px; font-size: 0.92rem; box-shadow: var(--shadow-sm); white-space: pre-wrap; word-wrap: break-word; }
.bubble .who { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.6; margin-bottom: 2px; }
.bubble .tm { font-size: 0.65rem; color: var(--muted); margin-top: 4px; text-align: right; }
.bubble.in { align-self: flex-start; background: var(--paper); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: #FCE9EC; border-bottom-right-radius: 4px; }
.bubble.bot { background: #EAF3EA; }
.bubble img { max-width: 220px; border-radius: 10px; display: block; }
.chat-foot { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--paper); }
.chat-foot input { flex: 1; }
.empty { color: var(--muted); text-align: center; padding: 40px; }

/* bars (mini chart) */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 130px; padding-top: 10px; }
.bars .bar { flex: 1; background: linear-gradient(180deg, var(--caramel), var(--berry)); border-radius: 6px 6px 0 0; min-height: 3px; position: relative; transition: height 0.4s; }
.bars .bar span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 0.62rem; color: var(--muted); }

/* toast */
#toast { position: fixed; bottom: 24px; right: 24px; z-index: 160; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 11px; box-shadow: var(--shadow-lg); font-size: 0.9rem; animation: fade 0.2s; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

/* payment alert modal */
.pay-overlay { position: fixed; inset: 0; z-index: 150; background: rgba(43, 33, 24, 0.45); display: grid; place-items: center; animation: fade 0.18s ease; backdrop-filter: blur(2px); }
.pay-box { width: 380px; max-width: 92vw; background: var(--paper); border-radius: 20px; padding: 28px 26px; text-align: center; box-shadow: var(--shadow-lg); border-top: 6px solid var(--green); animation: popIn 0.25s cubic-bezier(.2,.9,.3,1.3); }
.pay-box.warn { border-top-color: var(--amber); }
.pay-emoji { font-size: 2.6rem; line-height: 1; }
.pay-title { font-family: var(--display); font-size: 1.5rem; margin-top: 8px; color: var(--green); }
.pay-box.warn .pay-title { color: var(--amber); }
.pay-amount { font-family: var(--display); font-size: 2.4rem; margin: 6px 0; color: var(--ink); }
.pay-name { font-weight: 600; }
.pay-note { color: var(--ink-soft); font-size: 0.9rem; margin-top: 8px; }
.pay-actions { display: flex; gap: 8px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
@keyframes popIn { from { opacity: 0; transform: scale(0.9) translateY(10px); } to { opacity: 1; transform: none; } }

/* generic edit modal */
.modal-box { width: 580px; max-width: 94vw; max-height: 90vh; overflow-y: auto; background: var(--paper); border-radius: 18px; padding: 24px; box-shadow: var(--shadow-lg); animation: popIn 0.2s ease; }
.modal-box label.field { margin-bottom: 12px; }

/* Manual order — dessert picker (linked to the Menu flavors) */
.flavor-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 4px; }
.flavor-row { display: flex; align-items: center; gap: 8px; }
.flavor-row .fpick { display: flex; align-items: center; gap: 8px; flex: 1; margin: 0; cursor: pointer; min-width: 0; }
.flavor-row .fname { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flavor-row .fchk { width: 18px; height: 18px; accent-color: var(--berry); cursor: pointer; flex-shrink: 0; }
.flavor-row .fqty { width: 54px; flex-shrink: 0; }
@media (max-width: 560px) { .flavor-pick { grid-template-columns: 1fr; } }

/* login */
#login { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: var(--cream); }
#login .box { width: 340px; text-align: center; }
#login .logo { font-family: var(--display); font-size: 3rem; color: var(--berry); }
#login .logo em { color: var(--caramel); font-style: normal; }
#login .remember { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 0.88rem; color: var(--ink-soft); cursor: pointer; text-align: left; }
#login .remember input { width: 18px; height: 18px; margin: 0; accent-color: var(--berry); cursor: pointer; }

.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.wrap-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hidden { display: none !important; }
.qr-img { width: 260px; height: 260px; border-radius: 12px; border: 1px solid var(--line); background: #fff; padding: 10px; }
.cols-2 { grid-template-columns: 1fr 1fr; }

/* Pausa rápida del bot (barra superior) */
.pause-wrap { position: relative; }
.pause-btn { white-space: nowrap; }
.pause-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 220px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(43, 33, 24, 0.15); padding: 6px; }
.pause-menu-h { font-size: 0.75rem; color: var(--ink-soft); padding: 4px 8px 6px; }
.pause-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px; font: inherit; cursor: pointer; color: inherit; }
.pause-menu button:hover { background: var(--cream-2); }

/* "Cerrar tienda hoy" — left of the pause button */
.store-wrap { position: relative; }
.store-btn { white-space: nowrap; }
.store-btn.closed { background: #fff4e0; border-color: #e0a93b; color: #8a5a00; font-weight: 700; }

/* ---------------- Phone and tablet ----------------
   Up to 900px the sidebar becomes a drawer opened with ☰, and an open chat fills
   the screen with ← to go back. Up to 640px (phones) the top bar fits on two
   rows, the order lists turn into one card per order, and other tables scroll
   sideways. */
.nav-toggle, .chat-back, .pill-short { display: none; }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: auto; z-index: 130;
    width: 270px; max-width: 84vw; overflow-y: auto;
    transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  .nav-backdrop { position: fixed; inset: 0; z-index: 125; background: rgba(43, 33, 24, 0.4); display: none; }
  body.nav-open .nav-backdrop { display: block; }
  .nav-item { padding: 12px; font-size: 1rem; }
  .topbar { flex-wrap: wrap; gap: 10px 12px; padding: 12px 18px; }
  .content { padding: 20px 18px 56px; }
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center; position: relative; flex-shrink: 0;
    width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--paper); color: var(--ink); font-size: 1.25rem; line-height: 1;
  }

  .cols-2 { grid-template-columns: 1fr; }
  .chat-wrap { grid-template-columns: 1fr; height: auto; }
  .chat-list { max-height: calc(100vh - 300px); max-height: calc(100dvh - 300px); min-height: 260px; }
  .chat-wrap .chat-panel { display: none; }
  .chat-wrap.show-panel .chat-panel { display: flex; position: fixed; inset: 0; z-index: 110; border: none; border-radius: 0; }
  body.chat-open { overflow: hidden; }
  .chat-back { display: inline-flex; font-size: 1.1rem; }
  .chat-head { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .chat-head-actions { flex: 0 0 100%; flex-direction: row; align-items: center; justify-content: space-between; }
  .chat-body { padding: 12px; }
  .chat-foot { padding: 10px; }
  .bubble { max-width: 86%; }
  .bubble img { max-width: 100%; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 10px 12px; }
  .topbar-title { flex: 1; min-width: 0; }
  .topbar h1 { font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .sub { display: none; }
  .topbar .pill { order: 1; font-size: 0.72rem; padding: 4px 9px; }
  .pill-long { display: none; }
  .pill-short { display: inline; }
  .topbar .grow { order: 2; flex: 0 0 100%; height: 0; }
  .pause-wrap { order: 3; }
  .store-wrap { order: 4; }
  .pause-menu { left: 0; right: auto; }
  .print-wrap { display: none; } /* the printer switch belongs to the store PC */

  .content { padding: 14px 12px 48px; }
  .card.pad { padding: 14px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .value { font-size: 1.5rem; }
  .bars { gap: 3px; }
  .bar-mm { display: none; }
  /* 16px text stops iPhones from zooming in when a field is tapped */
  input, select, textarea, .input { font-size: 16px; }
  #toast { left: 12px; right: 12px; bottom: 16px; }
  #login .box { width: 100%; max-width: 340px; padding: 0 16px; }

  .content table:not(.stack) { display: block; overflow-x: auto; }
  table.stack, table.stack tbody { display: block; }
  table.stack thead { display: none; }
  table.stack tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 12px; margin-bottom: 10px;
    border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
  }
  table.stack td { padding: 0; border: none; text-align: left; min-width: 0; overflow-wrap: anywhere; }
  table.stack td.wide { grid-column: 1 / -1; }
  table.stack .envio-cell { width: auto; }
  table.stack td::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  }
  table.stack td[data-label=""]::before { display: none; }
}
