/* ===============================================================
   LEX · App shell · CSS compartido por todas las pantallas internas
   =============================================================== */

:root {
  --color-bg: #ffffff;
  --color-bg-app: #f8fafc;
  --color-bg-soft: #fafafa;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-text-subtle: #94a3b8;
  --color-border: #e2e8f0;
  --color-border-soft: #f1f5f9;

  --color-accent-50: #f5f3ff;
  --color-accent-100: #ede9fe;
  --color-accent-200: #ddd6fe;
  --color-accent-300: #c4b5fd;
  --color-accent-500: #8b5cf6;
  --color-accent-600: #7c3aed;
  --color-accent-700: #6d28d9;

  --color-warning: #f59e0b;
  --color-warning-soft: #fef3c7;
  --color-warning-text: #92400e;
  --color-danger: #ef4444;
  --color-danger-soft: #fef2f2;
  --color-success: #10b981;
  --color-success-soft: #d1fae5;
  --color-info: #0ea5e9;
  --color-info-soft: #e0f2fe;

  --font-base: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.08);

  --sidebar-width: 248px;
  --sidebar-mini-width: 64px;
  --topbar-height: 60px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-base);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--color-accent-600); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ============ APP SHELL ============ */
.app {
  min-height: 100vh;
  position: relative;
}

/* ============ SIDEBAR (fixed, full-height) ============ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: white;
  border-right: 1px solid var(--color-border);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  z-index: 60;
  overflow-y: auto;
  transition: transform 0.25s ease, width 0.25s ease;
}
.sidebar-brand { display: flex; align-items: center; padding: 6px 8px 18px; text-decoration: none; }
.sidebar-brand-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--color-accent-600);
  white-space: nowrap;
}
.sidebar-section { margin-bottom: 4px; }
.sidebar-section-title {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--color-text-subtle);
  padding: 12px 12px 6px;
  white-space: nowrap;
}
.sidebar-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--color-text-muted); font-size: 0.92rem; font-weight: 500;
  margin-bottom: 2px; transition: background 0.15s, color 0.15s;
  text-decoration: none; white-space: nowrap;
}
.sidebar-item:hover { background: var(--color-bg-app); color: var(--color-text); }
.sidebar-item.active { background: var(--color-accent-50); color: var(--color-accent-700); font-weight: 600; }
.sidebar-item .icon { flex-shrink: 0; width: 18px; display: inline-flex; justify-content: center; }
.sidebar-item .count {
  margin-left: auto; font-size: 0.74rem;
  background: var(--color-bg-app); color: var(--color-text-muted);
  padding: 1px 7px; border-radius: 100px; font-weight: 600;
}
.sidebar-item.active .count { background: white; color: var(--color-accent-700); }
.sidebar-spacer { flex: 1; min-height: 16px; }

.plan-card {
  background: var(--color-bg-app); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.plan-card-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.plan-card-name { font-size: 0.78rem; font-weight: 700; color: var(--color-text); }
.plan-card-action { font-size: 0.74rem; color: var(--color-accent-600); font-weight: 600; }
.plan-card-progress { height: 6px; background: white; border-radius: 100px; overflow: hidden; margin-bottom: 6px; }
.plan-card-progress-fill { height: 100%; background: linear-gradient(90deg, var(--color-accent-500), var(--color-accent-700)); border-radius: 100px; }
.plan-card-meta { font-size: 0.74rem; color: var(--color-text-muted); font-family: var(--font-mono); display: flex; justify-content: space-between; }

.cta-new {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%;
  background: var(--color-accent-600); color: white;
  border: none; border-radius: var(--radius);
  padding: 10px 12px; font-size: 0.9rem; font-weight: 600;
  text-decoration: none; transition: all 0.15s;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.22);
  white-space: nowrap;
}
.cta-new:hover { background: var(--color-accent-700); transform: translateY(-1px); color: white; }

/* ============ BACKDROP (móvil cuando sidebar abierto) ============ */
.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 55;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}

/* ============ TOPBAR ============ */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 50;
  transition: left 0.25s ease;
}
.hamburger {
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
  margin-right: 14px;
  flex-shrink: 0;
  transition: all 0.15s;
}
.hamburger:hover { background: var(--color-bg-app); color: var(--color-text); }
.topbar-search { position: relative; flex: 1; max-width: 520px; margin-right: 32px; min-width: 0; }
.topbar-search input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  background: var(--color-bg-app);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-base);
  font-size: 0.9rem;
  color: var(--color-text);
}
.topbar-search input::placeholder { color: var(--color-text-subtle); }
.topbar-search input:focus {
  outline: none; background: white;
  border-color: var(--color-accent-300);
  box-shadow: 0 0 0 3px var(--color-accent-100);
}
.topbar-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--color-text-subtle); pointer-events: none; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.icon-btn {
  position: relative; width: 36px; height: 36px;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); transition: all 0.15s;
}
.icon-btn:hover { background: var(--color-bg-app); color: var(--color-text); }
.icon-btn .badge {
  position: absolute; top: 6px; right: 6px;
  background: var(--color-danger); color: white;
  font-size: 0.66rem; font-weight: 700;
  border: 2px solid white;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.user-trigger {
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius); padding: 4px 10px 4px 4px;
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; color: inherit; text-decoration: none;
}
.user-trigger:hover { background: var(--color-bg-app); }
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--color-accent-100); color: var(--color-accent-700);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.78rem;
}
.user-name { font-size: 0.86rem; font-weight: 600; }
@media (max-width: 720px) { .user-name { display: none; } }

/* ============ CONTENT ============ */
.content {
  margin-left: var(--sidebar-width);
  padding-top: var(--topbar-height);
  transition: margin-left 0.25s ease;
  width: auto;
}
main.content {
  margin-left: var(--sidebar-width);
  padding: calc(var(--topbar-height) + 24px) 32px 64px;
  transition: margin-left 0.25s ease;
  min-height: 100vh;
  width: auto;
}
.content-inner {
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

/* ============ COLLAPSED STATE (desktop) ============ */
.app.sidebar-collapsed .sidebar { transform: translateX(-100%); }
.app.sidebar-collapsed .topbar { left: 0; }
.app.sidebar-collapsed .content,
.app.sidebar-collapsed main.content { margin-left: 0; }

/* ============ MOBILE (<= 900px): sidebar siempre como drawer ============ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .topbar { left: 0; }
  .content, main.content { margin-left: 0; padding-left: 16px; padding-right: 16px; }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .app.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  main.content { padding-left: 16px; padding-right: 16px; }
}

/* ============ HEADERS / BREADCRUMB ============ */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 24px; flex-wrap: wrap;
}
.page-title { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; color: var(--color-text); }
.page-subtitle { margin: 0; color: var(--color-text-muted); font-size: 0.92rem; }

.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; color: var(--color-text-muted); margin-bottom: 18px; }
.breadcrumb a { color: var(--color-text-muted); transition: color 0.15s; }
.breadcrumb a:hover { color: var(--color-accent-600); }
.breadcrumb .sep { color: var(--color-text-subtle); }
.breadcrumb .current { color: var(--color-text); font-weight: 600; }

/* ============ BUTTONS ============ */
.btn-primary {
  background: var(--color-accent-600); color: white;
  border: none; border-radius: var(--radius);
  padding: 10px 18px;
  font-family: var(--font-base); font-size: 0.9rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; transition: all 0.15s;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.22);
}
.btn-primary:hover { background: var(--color-accent-700); transform: translateY(-1px); color: white; }
.btn-secondary {
  background: white; border: 1px solid var(--color-border);
  color: var(--color-text); border-radius: var(--radius);
  padding: 9px 14px; font-size: 0.86rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s; text-decoration: none;
  font-family: var(--font-base);
}
.btn-secondary:hover { border-color: var(--color-accent-400); color: var(--color-accent-700); background: var(--color-accent-50); }
.btn-danger {
  background: var(--color-danger); color: white;
  border: none; border-radius: var(--radius);
  padding: 10px 18px; font-size: 0.9rem; font-weight: 600;
  font-family: var(--font-base);
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s;
}
.btn-danger:hover { background: #dc2626; }

/* ============ PANELS ============ */
.panel {
  background: white; border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 22px 24px;
  margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-title { font-size: 1.05rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 10px; color: var(--color-text); }

/* ============ TABLE ============ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--color-border); background: white; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th {
  text-align: left; font-weight: 600; font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: 12px 16px;
  background: var(--color-bg-soft);
  border-bottom: 1px solid var(--color-border);
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--color-border-soft); vertical-align: middle; }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: var(--color-bg-soft); cursor: pointer; }
.table tbody tr:last-child td { border-bottom: none; }

/* ============ PILLS ============ */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.74rem; font-weight: 600;
  padding: 3px 10px; border-radius: 100px;
  font-family: var(--font-mono); letter-spacing: 0.02em;
}
.pill.active, .pill.success { background: var(--color-success-soft); color: var(--color-success); }
.pill.warning { background: var(--color-warning-soft); color: var(--color-warning-text); }
.pill.danger, .pill.urgent { background: var(--color-danger-soft); color: var(--color-danger); }
.pill.info { background: var(--color-info-soft); color: var(--color-info); }
.pill.accent { background: var(--color-accent-100); color: var(--color-accent-700); }
.pill.neutral { background: var(--color-bg-app); color: var(--color-text-muted); }

.exp-id-pill {
  font-family: var(--font-mono); font-size: 0.78rem;
  background: var(--color-bg-app); color: var(--color-text-muted);
  padding: 2px 8px; border-radius: 4px; font-weight: 600;
}

/* ============ FORM ============ */
.form-field { margin-bottom: 18px; }
.form-label { display: block; font-size: 0.86rem; font-weight: 600; margin-bottom: 6px; color: var(--color-text); }
.form-help { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 4px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  font-family: var(--font-base); font-size: 0.95rem; color: var(--color-text);
  background: white; transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--color-accent-500);
  box-shadow: 0 0 0 3px var(--color-accent-100);
}
.form-textarea { resize: vertical; min-height: 90px; }

/* ============ EMPTY STATE ============ */
.empty-state { text-align: center; padding: 48px 24px; color: var(--color-text-muted); }
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { margin: 0 0 8px; font-size: 1.1rem; color: var(--color-text); font-weight: 700; }
.empty-state p { margin: 0 0 16px; max-width: 380px; margin-left: auto; margin-right: auto; }

/* ============ USER MENU DROPDOWN ============ */
.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  padding: 6px;
  z-index: 1000;
  display: none;
}
.user-menu.open { display: block; }
.user-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  border: 0; background: none;
  font: inherit; font-size: 0.9rem;
  color: var(--color-text); text-decoration: none;
  border-radius: 8px;
  cursor: pointer; text-align: left;
}
.user-menu-item:hover { background: var(--color-bg-soft); }
.user-menu-item svg { color: var(--color-text-muted); flex-shrink: 0; }
.user-menu-danger { color: #dc2626; }
.user-menu-danger svg { color: #dc2626; }
.user-menu-divider { height: 1px; background: var(--color-border); margin: 4px 0; }

/* ── Topbar user: dos líneas (nombre / licencia) ── */
.user-name {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  line-height: 1;
}
.user-fullname {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
}
.user-licencia-label {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
