/* keylo-client — styles.css
   Sistema de diseño Keylo. Sidebar blanca luminosa. Sin frameworks CSS. */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500&family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600&display=swap');

/* ── Variables ────────────────────────────────────────────────────────────── */

:root {
  --bg:      #F7F5F2;
  --surface: #FFFFFF;
  --navy:    #1A1A2E;
  --gold:    #D1C4A7;
  --border:  #E8E4DC;
  --muted:   #9B9589;
  --success: #5A9A4A;
  --warning: #C07A20;
  --info:    #4A7BC8;
  --danger:  #C0392B;

  --sidebar-w: 180px;
  --topbar-h:  56px;

  --font-display: 'Playfair Display', serif;
  --font-body:    'DM Sans', system-ui, sans-serif;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* ── Reset mínimo ─────────────────────────────────────────────────────────── */

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

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--navy);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
img { display: block; max-width: 100%; }

/* ── Layout principal ─────────────────────────────────────────────────────── */

#layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

#topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
}

#app-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  background: var(--bg);
}

/* Login: sin sidebar ni topbar */
body.page-login #layout { display: block; }
body.page-login #sidebar,
body.page-login #topbar  { display: none; }
body.page-login #main { overflow: visible; height: auto; }
body.page-login #app-content { padding: 0; background: var(--bg); overflow: visible; }

/* ── Sidebar (blanca) ─────────────────────────────────────────────────────── */

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 0.5px solid var(--border);
}

.sidebar-logo-text {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  color: var(--navy);
  letter-spacing: 0.3px;
}

.sidebar-logo-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  padding: 10px 0;
  flex: 1;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
  border-left: 2px solid transparent;
  cursor: pointer;
}

.nav-item:hover {
  color: var(--navy);
  background: var(--bg);
}

.nav-item.active {
  color: var(--navy);
  background: var(--bg);
  border-left-color: var(--navy);
}

.nav-item svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* ── Agent widget en sidebar ──────────────────────────────────────────────── */

.sidebar-agent-widget {
  margin: 8px 12px 0;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border);
}

.sidebar-agent-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

/* ── Sidebar footer ───────────────────────────────────────────────────────── */

.sidebar-footer {
  padding: 14px 16px;
  border-top: 0.5px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  border: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--navy);
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }

.sidebar-user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--muted);
}

.sidebar-logout {
  background: none;
  border: none;
  color: var(--muted);
  padding: 4px;
  display: flex;
  transition: color 0.15s;
}

.sidebar-logout:hover { color: var(--navy); }

/* ── Topbar ───────────────────────────────────────────────────────────────── */

.topbar-title { font-size: 15px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ── Tipografía ───────────────────────────────────────────────────────────── */

h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.page-title { font-size: 20px; font-weight: 600; }

/* ── Cards ────────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 0.5px solid var(--border);
}

.card-title { font-size: 14px; font-weight: 600; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: 20px;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ── Tablas ───────────────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafaf8; }

.table-actions { display: flex; gap: 8px; align-items: center; }

/* ── Formularios ──────────────────────────────────────────────────────────── */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.form-group:last-of-type { margin-bottom: 0; }

label { font-size: 13px; font-weight: 500; color: #4b4b4b; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
select,
textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: 14px;
  color: var(--navy);
  background: var(--surface);
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--navy); }
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
select { cursor: pointer; }

/* ── Botones ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary { background: var(--navy); color: var(--gold); }
.btn-primary:hover:not(:disabled) { background: #2d2d4e; }

.btn-secondary { background: var(--bg); color: var(--navy); border: 0.5px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-danger { background: #fef2f2; color: var(--danger); border: 0.5px solid #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fee2e2; }

.btn-ghost { background: transparent; color: var(--muted); padding: 6px 10px; }
.btn-ghost:hover:not(:disabled) { color: var(--navy); background: var(--bg); }

.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }

.btn-icon {
  padding: 6px;
  background: transparent;
  border: none;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.btn-icon:hover { color: var(--navy); background: var(--bg); }
.btn-icon svg   { width: 15px; height: 15px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-starter     { background: #eff6ff; color: #1d4ed8; }
.badge-profesional { background: #f0fdf4; color: #166534; }
.badge-business    { background: #fefce8; color: #854d0e; }
.badge-active      { background: #f0fdf4; color: #166534; }
.badge-inactive    { background: #f9fafb; color: var(--muted); }
.badge-suspended   { background: #fef2f2; color: var(--danger); }
.badge-open        { background: #eff6ff; color: #1d4ed8; }
.badge-in-progress { background: #fff7ed; color: #9a3412; }
.badge-closed      { background: #f9fafb; color: var(--muted); }
.badge-info        { background: #eff6ff; color: #1d4ed8; }

/* ── Status dots ──────────────────────────────────────────────────────────── */

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-on   { background: var(--success); }
.dot-off  { background: #d1d5db; }
.dot-warn { background: var(--warning); }

/* ── Toggle switch ────────────────────────────────────────────────────────── */

.toggle-wrap { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }

.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 20px;
  transition: background 0.2s;
}

.toggle input:checked + .toggle-track { background: var(--navy); }

.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  pointer-events: none;
}

.toggle input:checked ~ .toggle-thumb { transform: translateX(16px); }

/* ── Utilidades ───────────────────────────────────────────────────────────── */

.flex         { display: flex; }
.flex-col     { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.ml-auto  { margin-left: auto; }
.mt-4     { margin-top: 4px; }
.mt-8     { margin-top: 8px; }
.mt-16    { margin-top: 16px; }
.mt-24    { margin-top: 24px; }
.mb-8     { margin-bottom: 8px; }
.mb-16    { margin-bottom: 16px; }
.mb-24    { margin-bottom: 24px; }
.w-full   { width: 100%; }

.text-muted    { color: var(--muted); }
.text-small    { font-size: 12px; }
.text-xs       { font-size: 11px; }
.text-success  { color: var(--success); }
.text-warning  { color: var(--warning); }
.text-danger   { color: var(--danger); }
.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }

.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Modal ────────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: modal-fade 0.18s ease;
}

@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-up 0.2s ease;
}

@keyframes modal-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 14px;
  border-bottom: 0.5px solid var(--border);
}

.modal-title   { font-size: 15px; font-weight: 600; flex: 1; }
.modal-body    { padding: 20px; }
.modal-footer  {
  padding: 14px 20px;
  border-top: 0.5px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Banner de feedback temporal ─────────────────────────────────────────── */

.feedback-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  animation: banner-in 0.2s ease;
  white-space: nowrap;
}

@keyframes banner-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.feedback-banner.success { background: #f0fdf4; color: #166534; border: 0.5px solid #bbf7d0; }
.feedback-banner.error   { background: #fef2f2; color: var(--danger); border: 0.5px solid #fecaca; }

/* ── Skeleton loading ─────────────────────────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, #f0efed 25%, #e8e5e0 50%, #f0efed 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── Estado vacío ─────────────────────────────────────────────────────────── */

.empty-state { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty-state-title { font-size: 15px; font-weight: 500; color: var(--navy); margin-bottom: 8px; }
.empty-state-text  { font-size: 13px; margin-bottom: 20px; }

/* ── Sección divider ──────────────────────────────────────────────────────── */

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 0.5px solid var(--border);
}

/* ── Dos columnas ─────────────────────────────────────────────────────────── */

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* ── Login ────────────────────────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 500;
  color: var(--navy);
  text-align: center;
  margin-bottom: 4px;
}

.login-subtitle { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 32px; }

.login-error {
  background: #fef2f2;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.login-error.visible { display: block; }
