/* ============================================================
   Tickventor - estilos base
   Tema: papel cálido + acento naranja, tipografía editorial
   ============================================================ */

:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f4f1ec;
  --text: #18181b;
  --text-2: #57534e;
  --text-3: #a8a29e;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;

  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-bg: #fff7ed;
  --accent-border: #fed7aa;

  --success: #15803d;
  --success-bg: #f0fdf4;
  --warning: #a16207;
  --warning-bg: #fefce8;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --info: #1d4ed8;
  --info-bg: #eff6ff;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.12);

  --font-display: "Instrument Serif", "Times New Roman", serif;
  --font-ui: "Manrope", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
.display { font-family: var(--font-display); font-weight: 400; letter-spacing: -0.02em; }
.mono { font-family: var(--font-mono); }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

button { font-family: inherit; cursor: pointer; }

/* Inputs ----------------------------------------------------- */
.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms, background 120ms;
}
.input:hover, .textarea:hover, .select:hover { border-color: var(--text-3); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.12);
}
.textarea { resize: vertical; min-height: 80px; font-family: inherit; line-height: 1.5; }

label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }

/* Botones ---------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  font-size: 13px; font-weight: 500;
  border-radius: 7px;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  transition: all 120ms;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent); color: white; border-color: var(--accent);
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 2px 6px -1px rgba(234, 88, 12, 0.3);
}
.btn-primary:hover {
  background: var(--accent-hover); border-color: var(--accent-hover);
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 4px 10px -2px rgba(234, 88, 12, 0.4);
}
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger {
  background: var(--danger); color: white; border-color: var(--danger);
}
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-icon { width: 32px; padding: 0; }
.btn-icon svg { width: 15px; height: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Pills / badges --------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; font-size: 11px; font-weight: 500;
  border-radius: 999px; line-height: 1.6;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.pill-success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.pill-warning { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.pill-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.pill-info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.pill-accent { background: var(--accent-bg); color: var(--accent); border-color: transparent; }

/* Cards / paneles -------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 160ms;
}
.card:hover { box-shadow: var(--shadow); }
.card-noshadow { box-shadow: none; }
.card-noshadow:hover { box-shadow: none; }

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-header strong {
  font-size: 13px;
  font-weight: 600;
}
.card-body { padding: 18px; }

/* Tablas refinadas ------------------------------------------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left;
  padding: 10px 18px;
  font-weight: 500; font-size: 10px;
  color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
table.tbl td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.tbl tr { transition: background 100ms; }
table.tbl tr:hover td { background: var(--surface-2); }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl .row-action {
  opacity: 0;
  transition: opacity 120ms;
}
table.tbl tr:hover .row-action { opacity: 1; }

/* Modales ---------------------------------------------------- */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade 180ms ease-out;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 220ms cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-lg { max-width: 760px; }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--surface-2);
  border-bottom-left-radius: 12px; border-bottom-right-radius: 12px;
}

/* Toasts ----------------------------------------------------- */
#toasts {
  position: fixed; top: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 220ms cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
  max-width: 360px;
}
.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }

/* Layout helpers --------------------------------------------- */
.shell { display: flex; min-height: 100vh; background: var(--bg); }

/* Sidebar v2 ------------------------------------------------- */
.sidebar {
  width: 244px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.sidebar-brand {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 11px;
}
.sidebar-brand .logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #ea580c, #fb923c);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px -2px rgba(234, 88, 12, 0.4);
  position: relative;
}
.sidebar-brand .logo::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 9px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.3);
}
.sidebar-brand .logo svg { width: 18px; height: 18px; color: white; }
.sidebar-brand h1 {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1;
  font-weight: 400;
  margin: 0;
}
.sidebar-brand small {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  color: var(--text-3);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.sidebar-nav {
  padding: 14px 12px;
  flex: 1;
  overflow-y: auto;
}
.sidebar-nav .group-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 14px 12px 6px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms;
  position: relative;
  margin-bottom: 1px;
}
.sidebar-nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav a.active {
  background: var(--accent-bg);
  color: var(--accent);
}
.sidebar-nav a.active::before {
  content: "";
  position: absolute;
  left: -12px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.sidebar-nav a svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  stroke-width: 1.8;
}
.sidebar-nav a .nav-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--surface-2);
  color: var(--text-2);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
}
.sidebar-nav a.active .nav-badge {
  background: var(--accent);
  color: white;
}

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms;
}
.sidebar-user:hover { background: var(--surface-2); }
.avatar {
  width: 32px; height: 32px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ea580c, #fb923c);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px -2px rgba(234, 88, 12, 0.4);
}
.avatar.avatar-md { width: 36px; height: 36px; font-size: 13px; }
.avatar.avatar-lg { width: 44px; height: 44px; font-size: 15px; }
.sidebar-user .info {
  flex: 1; min-width: 0;
  font-size: 12px;
}
.sidebar-user .info .name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .info .role {
  color: var(--text-3);
  font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .signout {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  border: none; background: transparent; cursor: pointer;
  flex-shrink: 0;
}
.sidebar-user .signout:hover { background: var(--bg); color: var(--danger); }
.sidebar-user .signout svg { width: 15px; height: 15px; }

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

/* Topbar v2 -------------------------------------------------- */
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  flex-shrink: 0;
}
.topbar-title {
  display: flex; align-items: center; gap: 10px;
  min-width: 0;
}
.topbar-title h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 0; line-height: 1;
}
.topbar-actions {
  display: flex; align-items: center; gap: 10px;
}

.content { padding: 28px; flex: 1; overflow-y: auto; }

/* Estados vacíos --------------------------------------------- */
.empty {
  text-align: center; padding: 60px 20px;
  color: var(--text-2);
}
.empty .display { font-size: 28px; color: var(--text); margin-bottom: 6px; }

/* Splits ----------------------------------------------------- */
.row-flex { display: flex; gap: 12px; }
.row-flex > * { flex: 1; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--text-2); }
.tiny { font-size: 11px; }
.dim { color: var(--text-3); }

/* KPI cards (dashboards) ------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 200ms, box-shadow 200ms;
  animation: kpi-in 600ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.kpi-card:nth-child(1) { animation-delay: 0ms; }
.kpi-card:nth-child(2) { animation-delay: 60ms; }
.kpi-card:nth-child(3) { animation-delay: 120ms; }
.kpi-card:nth-child(4) { animation-delay: 180ms; }
.kpi-card:nth-child(5) { animation-delay: 240ms; }
@keyframes kpi-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kpi-card .kpi-icon {
  position: absolute; top: 16px; right: 18px;
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
}
.kpi-card .kpi-icon svg { width: 16px; height: 16px; stroke-width: 1.8; }
.kpi-card .lbl {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
  position: relative;
}
.kpi-card .num {
  font-family: var(--font-display);
  font-size: 38px;
  line-height: 1;
  margin-bottom: 4px;
  position: relative;
  letter-spacing: -0.02em;
}
.kpi-card .sub {
  color: var(--text-2);
  font-size: 12px;
}
.kpi-card.kpi-accent {
  background: linear-gradient(135deg, var(--accent-bg) 0%, var(--surface) 70%);
  border-color: var(--accent-border);
}
.kpi-card.kpi-accent .num { color: var(--accent); }
.kpi-card.kpi-accent .kpi-icon {
  background: rgba(234, 88, 12, 0.12);
  color: var(--accent);
}
.kpi-trend {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600;
  padding: 1px 6px; border-radius: 999px;
  margin-left: 6px;
}
.kpi-trend.up { background: var(--success-bg); color: var(--success); }
.kpi-trend.down { background: var(--danger-bg); color: var(--danger); }
.kpi-trend.flat { background: var(--surface-2); color: var(--text-2); }

/* Animaciones ------------------------------------------------ */
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Detalle ticket --------------------------------------------- */
.note {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  background: var(--surface);
}
.note-interna {
  background: var(--warning-bg);
  border-color: #fde68a;
}
.note-cliente { border-left: 3px solid var(--accent); }
.note-agente { border-left: 3px solid var(--info); }
.note-meta {
  font-size: 11px; color: var(--text-2);
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 6px;
}
.note-content { white-space: pre-wrap; word-break: break-word; }

/* Estado dot ------------------------------------------------- */
.dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--accent);
  margin-right: 6px;
  vertical-align: middle;
}

/* Responsive ------------------------------------------------- */
@media (max-width: 760px) {
  .sidebar { width: 64px; }
  .sidebar-brand h1 { display: none; }
  .sidebar-brand small { display: none; }
  .sidebar-nav a span { display: none; }
  .sidebar-foot { display: none; }
}
