/* ============================================================
   EMERTCOM — Panel de administración
   ============================================================ */
:root {
  --bg: #0b0e12; --bg-2: #11151b; --surface: #161b22; --surface-2: #1c2530;
  --border: #232c38; --border-2: #2e3a49;
  --text: #e8edf2; --text-dim: #9aa7b4; --text-mute: #6b7885;
  --accent: #2f81f7; --accent-2: #4f9dff; --accent-soft: rgba(47,129,247,.12);
  --danger: #e5484d; --ok: #3fb950; --warn: #d29922;
  --radius: 12px; --font: 'Inter', system-ui, Segoe UI, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-2); text-decoration: none; }
h1, h2, h3 { letter-spacing: -.01em; }

/* ---------- Botones / campos ---------- */
.btn-admin {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: 11px 18px; font-weight: 600; font-size: 14.5px; cursor: pointer;
  font-family: var(--font); transition: background .2s ease, transform .15s ease;
}
.btn-admin:hover { background: var(--accent-2); transform: translateY(-1px); }
.btn-admin.ghost { background: transparent; border: 1px solid var(--border-2); color: var(--text); }
.btn-admin.ghost:hover { border-color: var(--accent); color: var(--accent-2); background: transparent; }
.btn-admin.danger { background: var(--danger); }
.btn-admin.danger:hover { background: #f0595e; }
.btn-admin.sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }

.field { margin-bottom: 15px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 11px 13px; color: var(--text);
  font-family: var(--font); font-size: 14.5px;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 90px; }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
@media (max-width: 640px) { .form-2col { grid-template-columns: 1fr; } }

/* Documentos: tabla de ítems + totales */
.doc-items td { padding: 6px; }
.doc-items input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 10px; color: var(--text); font-family: var(--font); font-size: 14px;
}
.doc-items input:focus, .doc-items select:focus { outline: none; border-color: var(--accent); }
.doc-items select.c-sel {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 10px; color: var(--text); font-family: var(--font); font-size: 14px;
}

/* Recuadro de datos del cliente seleccionado */
.cliente-info {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px 20px;
  background: var(--bg-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 18px;
}
.cliente-info .ci-dato { font-size: 13.5px; }
.cliente-info .ci-dato b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-mute); margin-bottom: 2px; }
.c-total { font-variant-numeric: tabular-nums; white-space: nowrap; }
.totales-box { max-width: 340px; margin-left: auto; margin-top: 16px; }
.tot-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.tot-row span { color: var(--text-dim); font-size: 14px; }
.tot-row b { font-variant-numeric: tabular-nums; }
.tot-row input { width: 120px; text-align: right; background: var(--bg-2); border: 1px solid var(--border); border-radius: 7px; padding: 6px 10px; color: var(--text); font-family: var(--font); }
.tot-row.total { border-bottom: 0; border-top: 2px solid var(--border-2); margin-top: 4px; padding-top: 12px; }
.tot-row.total span, .tot-row.total b { font-size: 18px; font-weight: 700; color: var(--text); }

.alert { padding: 11px 14px; border-radius: 9px; font-size: 14px; margin-bottom: 16px; }
.alert.error { background: rgba(229,72,77,.12); border: 1px solid rgba(229,72,77,.3); color: #ff9a9d; }
.alert.ok { background: rgba(63,185,80,.12); border: 1px solid rgba(63,185,80,.3); color: #6fdc82; }
.alert.warn { background: rgba(210,153,34,.12); border: 1px solid rgba(210,153,34,.3); color: #e2b155; }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse 60% 50% at 50% 0, rgba(47,129,247,.1), transparent 70%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 34px 30px; text-align: center; }
.login-brand img { height: 54px; margin: 0 auto 18px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 22px; }
.login-card form { text-align: left; }
.login-back { display: inline-block; margin-top: 18px; font-size: 13px; color: var(--text-mute); }

/* ---------- Layout del panel ---------- */
.admin-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); padding: 22px 16px; display: flex; flex-direction: column; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; padding: 0 6px; }
.sidebar-brand img { height: 34px; }
.nav-admin { display: flex; flex-direction: column; gap: 4px; }
.nav-admin a {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 9px;
  color: var(--text-dim); font-size: 14.5px; font-weight: 500; transition: background .15s ease, color .15s ease;
}
.nav-admin a:hover { background: var(--surface); color: var(--text); }
.nav-admin a.active { background: var(--accent-soft); color: var(--accent-2); }
.nav-admin a span.ic { font-size: 17px; width: 20px; text-align: center; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-mute); padding: 14px 13px 6px; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--border); }
.sidebar-user { font-size: 13px; color: var(--text-mute); margin-bottom: 10px; padding: 0 6px; }

.main { padding: 28px 32px; overflow-x: hidden; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-head h1 { font-size: 24px; }
.page-head p { color: var(--text-dim); font-size: 14px; }

/* ---------- Tarjetas de resumen ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat .num { font-size: 30px; font-weight: 700; }
.stat .lbl { color: var(--text-dim); font-size: 13.5px; margin-top: 4px; }
.stat .ic { font-size: 22px; margin-bottom: 8px; display: block; }

/* ---------- Paneles / tablas ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin-bottom: 22px; }
.panel h2 { font-size: 17px; margin-bottom: 16px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--text-mute); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:hover td { background: var(--bg-2); }
.serie-badge { font-family: var(--mono); background: var(--accent-soft); color: var(--accent-2); padding: 3px 8px; border-radius: 6px; font-size: 13px; }
.estado { font-size: 12px; padding: 3px 9px; border-radius: 20px; font-weight: 600; }
.estado.abierta { background: rgba(63,185,80,.15); color: #6fdc82; }
.estado.cerrada { background: rgba(107,120,133,.15); color: var(--text-mute); }

/* ---------- Transcripción de chat ---------- */
.transcript { display: flex; flex-direction: column; gap: 10px; max-height: 460px; overflow-y: auto; padding: 4px; }
.tmsg { max-width: 78%; padding: 10px 13px; border-radius: 12px; font-size: 14px; }
.tmsg.visitante { align-self: flex-end; background: var(--accent); color: #fff; }
.tmsg.agente { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.tmsg.sistema { align-self: center; background: transparent; color: var(--text-mute); font-family: var(--mono); font-size: 12px; }
.tmsg .meta { display: block; font-size: 11px; opacity: .7; margin-top: 4px; }

/* Cuadro de respuesta del agente */
.reply-box { display: flex; gap: 10px; margin-top: 16px; align-items: flex-end; }
.reply-box textarea {
  flex: 1; background: var(--bg-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 11px 13px; color: var(--text); font-family: var(--font); font-size: 14.5px; resize: vertical; min-height: 46px;
}
.reply-box textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.reply-status { font-size: 13px; margin-top: 8px; min-height: 16px; }
.reply-status.ok { color: var(--ok); }
.reply-status.err { color: var(--danger); }

.datos-cliente { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 20px; margin-bottom: 18px; }
.dato { font-size: 14px; }
.dato b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-mute); margin-bottom: 2px; }

.muted { color: var(--text-mute); font-size: 13.5px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 14px; margin-bottom: 16px; }

/* ---------- Imágenes ---------- */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.img-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.img-preview { aspect-ratio: 16/10; background: var(--bg-2); display: grid; place-items: center; overflow: hidden; }
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-card .body { padding: 14px; }
.img-card .name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.img-card .desc { font-size: 12.5px; color: var(--text-mute); margin-bottom: 12px; }

/* Barra superior y hamburguesa (solo móvil) */
.admin-topbar { display: none; }
.sidebar-overlay { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .admin-shell { grid-template-columns: 1fr; }

  /* Barra superior fija con logo + hamburguesa */
  .admin-topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 40;
    background: var(--bg-2); border-bottom: 1px solid var(--border);
    padding: 10px 16px;
  }
  .admin-topbar img { height: 30px; }
  .admin-burger { background: none; border: 0; cursor: pointer; padding: 8px; display: flex; flex-direction: column; gap: 5px; }
  .admin-burger span { width: 24px; height: 2px; background: var(--text); border-radius: 2px; }

  /* Sidebar como panel deslizante desde la izquierda */
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 60;
    width: 270px; height: 100vh; flex-direction: column;
    transform: translateX(-100%); transition: transform .28s ease;
    overflow-y: auto; padding: 20px 16px;
  }
  .sidebar.open { transform: none; box-shadow: 8px 0 30px rgba(0,0,0,.5); }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 55; opacity: 0; visibility: hidden; transition: opacity .28s ease, visibility .28s ease; }
  .sidebar-overlay.show { display: block; opacity: 1; visibility: visible; }
  .sidebar-brand { display: flex; }

  .main { padding: 20px 16px; }

  /* Tablas anchas: scroll horizontal en vez de romper el layout */
  .panel { overflow-x: auto; }
  .table { min-width: 560px; }
  .page-head { align-items: flex-start; }
  .page-head h1 { font-size: 20px; }
  .form-2col { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .main { padding: 16px 12px; }
  .reply-box { flex-direction: column; align-items: stretch; }
  .reply-box .btn-admin { width: 100%; }
  .totales-box { max-width: 100%; }
  .doc-items { min-width: 480px; }
}
