/* ============================================================
   NovaERP — Design System v1.0
   Complementa Tailwind CDN con tokens propios
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Variables ───────────────────────────────────────── */
:root {
  --sidebar-w: 260px;
  --topbar-h:  64px;
  --color-primary:   #6366f1;
  --color-primary-d: #4f46e5;
  --color-success:   #10b981;
  --color-warning:   #f59e0b;
  --color-danger:    #ef4444;
  --color-info:      #3b82f6;
  --sidebar-bg:      #0f172a;
  --sidebar-text:    #94a3b8;
  --sidebar-active:  #6366f1;
  --sidebar-hover:   #1e293b;
  --body-bg:         #f1f5f9;
  --card-bg:         #ffffff;
  --border-color:    #e2e8f0;
  --text-primary:    #0f172a;
  --text-muted:      #64748b;
  --shadow-card:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-lg:       0 10px 40px rgba(0,0,0,.12);
  --radius:          12px;
  --radius-sm:       8px;
  --transition:      all .2s ease;
}

/* ── Reset base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--body-bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: var(--transition);
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 1rem;
}

.page-content {
  padding: 1.75rem 2rem;
  flex: 1;
}

/* ── Sidebar Components ──────────────────────────────────── */
.sidebar-logo {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: .75rem;
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-logo h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -.02em;
}

.sidebar-logo span {
  display: block;
  font-size: .65rem;
  color: #64748b;
  letter-spacing: .05em;
  text-transform: uppercase;
  font-weight: 500;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem .75rem;
  overflow-y: auto;
}

.sidebar-section-title {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #475569;
  padding: .75rem .75rem .35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
  position: relative;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.nav-item.active {
  background: rgba(99,102,241,.15);
  color: #818cf8;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  height: 60%;
  width: 3px;
  background: var(--color-primary);
  border-radius: 0 4px 4px 0;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .8;
}

.nav-badge {
  margin-left: auto;
  background: #ef4444;
  color: white;
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .45rem;
  border-radius: 20px;
}

.sidebar-footer {
  padding: 1rem .75rem;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  cursor: pointer;
}

.sidebar-user:hover { background: var(--sidebar-hover); }

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-name {
  font-size: .8rem;
  font-weight: 600;
  color: #e2e8f0;
  line-height: 1.3;
}

.user-role {
  font-size: .7rem;
  color: #64748b;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body { padding: 1.5rem; }

/* ── KPI / Stat Cards ────────────────────────────────────── */
.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  padding: 1.4rem 1.5rem;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
  transform: translateY(-1px);
}

.kpi-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.kpi-icon svg { width: 22px; height: 22px; }

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -.03em;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: .3rem;
}

.kpi-label {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 20px;
  margin-top: .5rem;
}

.kpi-trend.up   { background: #d1fae5; color: #059669; }
.kpi-trend.down { background: #fee2e2; color: #dc2626; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
}

table.nova-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

table.nova-table thead tr {
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
}

table.nova-table thead th {
  padding: .85rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  white-space: nowrap;
}

table.nova-table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background .15s;
}

table.nova-table tbody tr:last-child { border-bottom: none; }
table.nova-table tbody tr:hover { background: #f8fafc; }

table.nova-table td {
  padding: 1rem;
  color: var(--text-primary);
  vertical-align: middle;
}

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .65rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green  { background: #d1fae5; color: #065f46; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-indigo { background: #e0e7ff; color: #3730a3; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover { background: var(--color-primary-d); }

.btn-secondary {
  background: #f1f5f9;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: #e2e8f0; }

.btn-success  { background: var(--color-success); color: white; }
.btn-danger   { background: var(--color-danger);  color: white; }
.btn-warning  { background: var(--color-warning); color: white; }

.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: .5rem; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}
.btn-ghost:hover { background: #f1f5f9; color: var(--text-primary); }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }

.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: .4rem;
}

.form-control {
  width: 100%;
  padding: .6rem .875rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-family: inherit;
  color: var(--text-primary);
  background: white;
  transition: var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.form-control::placeholder { color: #94a3b8; }

select.form-control { cursor: pointer; }

textarea.form-control {
  resize: vertical;
  min-height: 90px;
}

.form-control.error {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}

.form-hint {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .3rem;
}

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.025em;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: .875rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn .2s ease;
}

.modal {
  background: white;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .25s ease;
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-body   { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
}

/* ── Flash Messages ──────────────────────────────────────── */
.flash-message {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  padding: .875rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideInRight .3s ease;
  max-width: 380px;
  display: flex;
  align-items: center;
  gap: .75rem;
}

.flash-success { background: #d1fae5; color: #065f46; border-left: 4px solid #10b981; }
.flash-error   { background: #fee2e2; color: #991b1b; border-left: 4px solid #ef4444; }
.flash-warning { background: #fef3c7; color: #92400e; border-left: 4px solid #f59e0b; }
.flash-info    { background: #dbeafe; color: #1e40af; border-left: 4px solid #3b82f6; }

/* ── Search Bar ──────────────────────────────────────────── */
.search-global {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.search-global input {
  width: 100%;
  padding: .5rem .875rem .5rem 2.5rem;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  font-size: .875rem;
  background: #f8fafc;
  transition: var(--transition);
  outline: none;
}

.search-global input:focus {
  background: white;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}

.search-global .search-icon {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + .5rem);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  transition: background .15s;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
}

.search-result-item:hover { background: #f8fafc; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: .35rem;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: white;
  color: var(--text-muted);
  font-size: .8rem;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
}

.page-link:hover { background: #f1f5f9; color: var(--text-primary); }
.page-link.active { background: var(--color-primary); border-color: var(--color-primary); color: white; }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ── Charts ──────────────────────────────────────────────── */
.chart-container { position: relative; height: 260px; width: 100%; }

/* ── Loading ─────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Login Page ──────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  background: white;
  border-radius: 20px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 60px rgba(0,0,0,.4);
}

.auth-logo {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
}

/* ── Divider ─────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border-color);
  margin: 1.5rem 0;
}

/* ── Colors Icon Backgrounds ─────────────────────────────── */
.bg-primary-soft { background: #ede9fe; }
.bg-success-soft { background: #d1fae5; }
.bg-warning-soft { background: #fef3c7; }
.bg-danger-soft  { background: #fee2e2; }
.bg-info-soft    { background: #dbeafe; }
.text-primary-icon { color: #6366f1; }
.text-success-icon { color: #10b981; }
.text-warning-icon { color: #f59e0b; }
.text-danger-icon  { color: #ef4444; }
.text-info-icon    { color: #3b82f6; }

/* ── Animations ──────────────────────────────────────────── */
@keyframes fadeIn   { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp  { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes shimmer  { to { background-position: -200% 0; } }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .page-content { padding: 1.25rem 1rem; }
}

@media (max-width: 768px) {
  .page-header { flex-direction: column; align-items: flex-start; }
  .kpi-value { font-size: 1.4rem; }
}

/* ── Print ───────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #e2e8f0; }
}

/* ── Utility ─────────────────────────────────────────────── */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.glass { background: rgba(255,255,255,.1); backdrop-filter: blur(10px); }
.hover-lift { transition: transform .2s, box-shadow .2s; }
.hover-lift:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.12); }
