* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: #eef1f5; color: #1e293b; }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #f8fafc, #e2e8f0); }
.login-card { background: #fff; padding: 34px; border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,.1); width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 4px 0 8px; font-size: 20px; text-align: center; }
.login-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; margin: 0 auto; color: #fff; }
.login-card label { display: flex; flex-direction: column; font-size: 13px; color: #64748b; gap: 4px; }
.login-card input { padding: 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; }
.login-card button { margin-top: 8px; border: none; color: #fff; padding: 11px; border-radius: 8px; font-weight: 600; font-size: 15px; cursor: pointer; }
.login-error { background: #fee2e2; color: #b91c1c; padding: 9px; border-radius: 8px; font-size: 13px; text-align: center; }

/* Top bar */
.panel-top { display: flex; align-items: center; gap: 20px; color: #fff; padding: 0 20px; height: 56px; }
.pt-brand strong { font-size: 17px; }
.pt-sub { opacity: .8; font-size: 12px; margin-left: 8px; }
.pt-nav { display: flex; gap: 4px; flex: 1; }
.pt-nav a { color: #fff; text-decoration: none; padding: 8px 14px; border-radius: 8px; font-size: 14px; opacity: .85; }
.pt-nav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.pt-nav a.active { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.pt-user { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.pt-logout { color: #fff; text-decoration: none; border: 1px solid rgba(255,255,255,.4); padding: 5px 12px; border-radius: 8px; }
.pt-logout:hover { background: rgba(255,255,255,.15); }

/* Impersonation banner */
.imp-banner { background: #fef9c3; color: #854d0e; padding: 10px 20px; display: flex; align-items: center; gap: 14px; font-size: 14px; border-bottom: 1px solid #fde68a; }
.imp-banner a { color: #92400e; font-weight: 600; }

/* Main */
.panel-main { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.panel-title { font-size: 22px; margin: 0 0 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Cards & grid */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { background: #fff; border: 1px solid #e2e8f0; border-radius: 14px; padding: 18px; }
.card h3 { margin: 0 0 6px; font-size: 14px; color: #64748b; font-weight: 600; }
.card .big { font-size: 28px; font-weight: 700; }

.section { background: #fff; border: 1px solid #e2e8f0; border-radius: 14px; padding: 20px; margin-bottom: 20px; }
.section h2 { font-size: 16px; margin: 0 0 14px; }

/* Tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #e2e8f0; }
.tbl th { color: #64748b; font-size: 12px; text-transform: uppercase; }

/* Buttons */
.btn { display: inline-block; border: none; cursor: pointer; border-radius: 8px; padding: 9px 15px; font-size: 14px; font-weight: 600; text-decoration: none; color: #fff; background: var(--area, #7C3AED); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-ghost { background: #f1f5f9; color: #334155; border: 1px solid #e2e8f0; }
.btn-danger { background: #ef4444; }
.btn-ok { background: #16a34a; }

/* Forms */
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 13px; color: #64748b; }
.form-row input, .form-row select { padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; color: #1e293b; }
/* Filas con checkbox: checkbox y texto en la misma línea */
.form-row:has(input[type="checkbox"]) { flex-direction: row; align-items: center; gap: 8px; }
.form-row input[type="checkbox"] { width: 16px; height: 16px; padding: 0; flex: 0 0 auto; }
.form-inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }

.pill { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; background: #e2e8f0; color: #334155; }
.pill-ok { background: #dcfce7; color: #16a34a; }
.pill-off { background: #fee2e2; color: #dc2626; }
/* Estados de pedido: cada uno con su color para leerlos de un vistazo. */
.pill-pendiente { background: #fef3c7; color: #b45309; }  /* esperando pago: no ha ido a cocina */
.pill-recibido { background: #e0e7ff; color: #4338ca; }
.pill-enviando { background: #e0e7ff; color: #4338ca; }
.pill-en_revo { background: #dbeafe; color: #1d4ed8; }
.pill-confirmado { background: #dbeafe; color: #1d4ed8; }
.pill-listo { background: #dcfce7; color: #15803d; }
.pill-entregado { background: #dcfce7; color: #166534; }
.pill-cerrado { background: #dcfce7; color: #166534; }
.pill-cancelado { background: #fee2e2; color: #b91c1c; }
.pill-error { background: #fee2e2; color: #b91c1c; }
.rep-badge { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; background: #e2e8f0; color: #475569; white-space: nowrap; }
.muted { color: #64748b; font-size: 13px; }
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.alert-ok { background: #dcfce7; color: #166534; }
.alert-err { background: #fee2e2; color: #b91c1c; }
code { font-family: ui-monospace, monospace; background: #f1f5f9; padding: 2px 6px; border-radius: 5px; }
a.link { color: var(--area, #7C3AED); }

/* ===== Mejoras UI/UX ===== */
.panel-top { flex-wrap: wrap; height: auto; min-height: 56px; padding-top: 8px; padding-bottom: 8px; gap: 8px 20px; }
.pt-nav { overflow-x: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.pt-nav a { white-space: nowrap; }
.pt-rol { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; background: rgba(255,255,255,.18); padding: 3px 8px; border-radius: 20px; font-weight: 600; }
.pt-name { font-weight: 600; }
.tbl td { vertical-align: top; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl tbody tr.row-reputacion-mala { background: #eaf2fb; }
.tbl tbody tr.row-reputacion-mala:hover { background: #dbeafe; }
.tbl tbody tr.row-cancelado { background: #fee2e2; }
.tbl tbody tr.row-cancelado:hover { background: #fecaca; }
.tbl tbody tr.row-terminado { background: #dcfce7; }
.tbl tbody tr.row-terminado:hover { background: #bbf7d0; }
.tbl tbody tr.row-flash { animation: row-flash-blink 0.8s ease-in-out infinite; }
@keyframes row-flash-blink { 0%, 100% { background-color: #fef08a; } 50% { background-color: #facc15; } }
details > summary { cursor: pointer; font-weight: 600; }
details > summary:hover { color: var(--area, #7C3AED); }
.form-row textarea { padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; color: #1e293b; font-family: inherit; }
.btn-ghost:hover { background: #e2e8f0; }
.card { transition: border-color .15s, box-shadow .15s; }
.card:hover { border-color: #cbd5e1; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--area, #7C3AED); outline-offset: 0; }
.btn:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid #0ea5e9; outline-offset: 2px; }
.section > h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ===== Modales ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-overlay[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 14px; width: min(720px, 100%); max-height: 88vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid #e2e8f0; font-size: 15px; position: sticky; top: 0; background: #fff; }
.modal-close { border: none; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; color: #64748b; }
.modal-close:hover { color: #1e293b; }
.modal-body { padding: 18px; }

/* ===== Pestañas (Pedidos / Conversaciones) ===== */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 2px solid #e2e8f0; }
.tab { background: none; border: none; padding: 10px 20px; font-size: 15px; font-weight: 600; color: #64748b; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab:hover { color: #334155; }
.tab.active { color: var(--area, #16a34a); border-bottom-color: var(--area, #16a34a); }

/* ===== Conversaciones (estilo WhatsApp) ===== */
.conv-layout { display: grid; grid-template-columns: 340px 1fr; border: 1px solid #e2e8f0; border-radius: 14px; overflow: hidden; background: #fff; height: calc(100vh - 230px); height: calc(100dvh - 230px); min-height: 0; }
.conv-sidebar { border-right: 1px solid #e2e8f0; display: flex; flex-direction: column; background: #f8fafc; min-width: 0; min-height: 0; }
.conv-filters { padding: 12px; border-bottom: 1px solid #e2e8f0; background: #fff; }
.conv-filters .quick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.conv-filters .quick button { border: 1px solid #cbd5e0; background: #fff; color: #334155; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; cursor: pointer; }
.conv-filters .quick button.active { background: var(--area, #16a34a); color: #fff; border-color: var(--area, #16a34a); }
.conv-filters .range { display: flex; gap: 6px; align-items: center; }
.conv-filters .range input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid #cbd5e0; border-radius: 6px; font-size: 12px; }
.conv-filters .range button { border: none; background: var(--area, #16a34a); color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; }
.conv-lista { flex: 1; overflow-y: auto; min-height: 0; }
.conv-day { padding: 7px 14px; font-size: 11px; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: .3px; background: #eef2f7; position: sticky; top: 0; z-index: 1; }
.conv-item { display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid #eef2f7; align-items: center; }
.conv-item:hover { background: #f1f5f9; }
.conv-item.active { background: #e0f2fe; }
.conv-avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--area, #16a34a); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 16px; flex: 0 0 auto; }
.conv-item-body { flex: 1; min-width: 0; }
.conv-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: #64748b; white-space: nowrap; }
.conv-phone { font-size: 11px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 13px; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item.unread .conv-name { font-weight: 700; }
.conv-item.unread .conv-preview { color: #1e293b; font-weight: 600; }
.conv-dot { width: 9px; height: 9px; border-radius: 50%; background: #25d366; flex: 0 0 auto; }

.conv-chat { display: flex; flex-direction: column; background: #ece5dd; min-width: 0; min-height: 0; }
.conv-chat-header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #f0f2f5; border-bottom: 1px solid #e2e8f0; }
.conv-chat-header .conv-avatar { width: 36px; height: 36px; font-size: 14px; }
.conv-chat-title { flex: 1; min-width: 0; }
.conv-chat-title .name { font-weight: 600; font-size: 15px; }
.conv-chat-title .phone { font-size: 12px; color: #64748b; }
.conv-mensajes { flex: 1; overflow-y: auto; min-height: 0; padding: 16px; display: flex; flex-direction: column; gap: 3px; }
.conv-bubble { max-width: 72%; padding: 7px 11px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.conv-bubble.in { background: #fff; align-self: flex-start; border-top-left-radius: 2px; }
.conv-bubble.out { background: #d9fdd3; align-self: flex-end; border-top-right-radius: 2px; }
.conv-bubble .meta { font-size: 10px; color: #8696a0; text-align: right; margin-top: 2px; }
.conv-day-sep { text-align: center; margin: 8px 0; }
.conv-day-sep span { background: #fff; color: #54656f; font-size: 12px; padding: 4px 10px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.1); }
.conv-input { display: flex; gap: 8px; padding: 12px 16px; background: #f0f2f5; }
.conv-input input { flex: 1; padding: 10px 14px; border: 1px solid #cbd5e0; border-radius: 20px; font-size: 14px; }
.conv-empty { display: grid; place-items: center; height: 100%; color: #64748b; text-align: center; padding: 20px; }
.conv-empty .big { font-size: 40px; margin-bottom: 8px; }

/* Móvil (vertical) o pantalla baja (horizontal): apilar la lista encima y el
   chat debajo, en vez de dos columnas, para que la lista quede visible. */
@media (max-width: 820px), (max-height: 500px) {
    .conv-layout { grid-template-columns: 1fr; height: auto; }
    .conv-sidebar { border-right: none; border-bottom: 1px solid #e2e8f0; max-height: 40vh; }
}

/* Pantalla baja (móvil en horizontal): más espacio para la lista y filtros compactos */
@media (max-height: 500px) {
    .conv-sidebar { max-height: 55vh; }
    .conv-filters { padding: 8px; }
    .conv-filters .quick { margin-bottom: 6px; }
}

/* ===== Detalle de pedido (responsive) ===== */
.detalle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.detalle-grid > div { min-width: 0; }
.detalle-cliente-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; font-size: 14px; }

@media (max-width: 768px) {
    .detalle-grid { grid-template-columns: 1fr; }
    .detalle-cliente-grid { grid-template-columns: 1fr; }
    #modalDetalle > div { padding: 16px; margin: 16px auto; }
}

/* ===== Notificaciones (luz parpadeante) ===== */
.notif-indicador { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding: 4px 12px; border-radius: 20px; background: #fef2f2; border: 1px solid #fecaca; font-size: 12px; font-weight: 600; color: #b91c1c; cursor: pointer; white-space: nowrap; }
.notif-dot { width: 10px; height: 10px; border-radius: 50%; background: #ef4444; flex: 0 0 auto; }
.notif-indicador.blink .notif-dot { animation: notif-blink 1s infinite; }
@keyframes notif-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.15; } }
