@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,600;0,700;1,400&family=Plus+Jakarta+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --void:     #080E1A;
  --ink:      #0D1530;
  --slate:    #162448;
  --azure:    #1E3B7A;
  --gold:     #C9A84C;
  --amber:    #E8C97A;
  --gold-dim: #7A6328;
  --emerald:  #0D9E6E;
  --em-bg:    #E6F7F1;
  --coral:    #D94F3D;
  --co-bg:    #FDECEA;
  --warn:     #D08030;
  --wa-bg:    #FEF3E2;
  --paper:    #F6F4EF;
  --cream:    #FAFAF7;
  --white:    #FFFFFF;
  --border:   #E8E4DC;
  --border2:  #D4CFC5;
  --muted:    #9B9690;
  --dark:     #1A1714;
  --mid:      #4A4640;
  --sidebar-w: 264px;
  --radius:   10px;
  --shadow:   0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--paper);
  color: var(--dark);
  font-size: 13.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── SIDEBAR ────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--void);
  display: flex; flex-direction: column;
  z-index: 100; overflow: hidden;
  border-right: 1px solid rgba(201,168,76,.12);
}

/* Subtle grain texture overlay */
.sidebar::before {
  content: '';
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0;
}

/* Gold top stripe */
.sidebar::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), transparent);
  z-index: 1;
}

.sidebar > * { position: relative; z-index: 2; }

.sidebar-brand {
  padding: 28px 22px 22px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.sidebar-brand .brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dim) 100%);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--void);
  margin-bottom: 14px;
  box-shadow: 0 4px 12px rgba(201,168,76,.3);
}

.sidebar-brand .brand-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px; font-weight: 700;
  color: var(--white); letter-spacing: .5px; line-height: 1;
}

.sidebar-brand .brand-sub {
  font-size: 10px; color: var(--gold);
  text-transform: uppercase; letter-spacing: 2px;
  margin-top: 5px; font-weight: 500; opacity: .8;
}

.sidebar-nav { padding: 16px 0; flex: 1; overflow-y: auto; }

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 3px; }

.nav-section {
  padding: 14px 22px 5px;
  font-size: 9.5px; font-weight: 600;
  color: rgba(255,255,255,.2);
  text-transform: uppercase; letter-spacing: 2.5px;
}

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 22px; color: rgba(255,255,255,.55);
  text-decoration: none; font-size: 13px; font-weight: 400;
  position: relative; transition: all .18s ease;
  margin: 1px 10px; border-radius: 7px;
}

.nav-item::before {
  content: '';
  position: absolute; left: -10px; top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px; height: 60%;
  background: var(--gold); border-radius: 0 2px 2px 0;
  transition: transform .2s ease;
}

.nav-item:hover {
  color: var(--white);
  background: rgba(255,255,255,.06);
}

.nav-item.active {
  color: var(--white);
  background: rgba(201,168,76,.12);
  font-weight: 500;
}

.nav-item.active::before { transform: translateY(-50%) scaleY(1); }

.nav-icon { width: 16px; font-size: 13px; opacity: .7; flex-shrink: 0; }
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 16px 22px;
  border-top: 1px solid rgba(255,255,255,.05);
  display: flex; align-items: center; gap: 10px;
}

.sidebar-footer .avatar {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--void); font-weight: 600;
  flex-shrink: 0;
}

.sidebar-footer .user-name {
  font-size: 12px; color: rgba(255,255,255,.65);
  font-weight: 500;
}

.sidebar-footer .user-role {
  font-size: 10px; color: rgba(255,255,255,.25);
  text-transform: uppercase; letter-spacing: 1px;
}

/* ── MAIN CONTENT ────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 0 var(--border);
}

.topbar-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px; font-weight: 600;
  color: var(--ink); letter-spacing: .2px;
  display: flex; align-items: center; gap: 8px;
}

.topbar-actions { display: flex; gap: 10px; align-items: center; }

.page-body { padding: 28px 32px; flex: 1; }

/* ── CARDS ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow .2s ease, transform .2s ease;
}

.card:hover { box-shadow: var(--shadow-lg); }

.card-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--cream);
}

.card-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 15px; font-weight: 600;
  color: var(--ink); letter-spacing: .2px;
}

.card-body { padding: 20px; }

/* ── STAT CARDS ──────────────────────────────────────────────────────────── */
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
  transition: all .22s ease;
  cursor: default;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
}

.stat-card.navy::before { background: linear-gradient(90deg, var(--ink), var(--azure)); }
.stat-card.gold::before  { background: linear-gradient(90deg, var(--gold), var(--amber)); }
.stat-card.green::before { background: linear-gradient(90deg, var(--emerald), #3DD8A8); }
.stat-card.blue::before  { background: linear-gradient(90deg, var(--azure), #4A8FE8); }

.stat-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--muted); margin-bottom: 10px;
}

.stat-value {
  font-family: 'Cormorant Garamond', serif;
  font-size: 38px; font-weight: 700;
  color: var(--ink); line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-meta { font-size: 11px; color: var(--muted); margin-top: 8px; }

.stat-icon {
  position: absolute; right: 20px; top: 50%;
  transform: translateY(-50%);
  font-size: 36px; opacity: .06; color: var(--ink);
}

/* ── TABLAS ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table.data-table {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
}

.data-table thead th {
  background: var(--paper);
  padding: 10px 14px;
  text-align: left;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap; user-select: none;
}

.data-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--mid); vertical-align: middle;
  transition: background .12s ease;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td {
  background: #FDFCF9;
}

.data-table tbody tr.total-row td {
  background: var(--void); color: var(--white);
  font-weight: 600;
}

/* ── BADGES ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 9px; border-radius: 20px;
  font-size: 10.5px; font-weight: 600;
  letter-spacing: .3px;
}

.badge-ok    { background: var(--em-bg); color: var(--emerald); }
.badge-warn  { background: var(--wa-bg); color: var(--warn);    }
.badge-err   { background: var(--co-bg); color: var(--coral);   }
.badge-navy  { background: #EBF1FA;      color: var(--azure);   }
.badge-gold  { background: #FBF5E6;      color: #8A6A1C;        }

/* ── BOTONES ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 18px; border-radius: 8px; font-size: 13px;
  font-weight: 500; cursor: pointer; border: none;
  transition: all .16s ease; text-decoration: none;
  font-family: 'Plus Jakarta Sans', sans-serif;
  white-space: nowrap;
}

.btn-navy {
  background: var(--ink); color: var(--white);
  box-shadow: 0 2px 8px rgba(13,21,48,.2);
}
.btn-navy:hover { background: var(--azure); color: var(--white); box-shadow: 0 4px 12px rgba(13,21,48,.3); }

.btn-gold {
  background: var(--gold); color: var(--void); font-weight: 600;
  box-shadow: 0 2px 8px rgba(201,168,76,.3);
}
.btn-gold:hover { background: var(--amber); box-shadow: 0 4px 12px rgba(201,168,76,.4); }

.btn-outline {
  background: transparent; color: var(--ink);
  border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: var(--ink); background: var(--paper); }

.btn-danger { background: var(--coral); color: var(--white); }
.btn-danger:hover { background: #BF3A2A; }

.btn-sm { padding: 5px 12px; font-size: 11.5px; }

/* ── FORMULARIOS ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block; margin-bottom: 6px;
  font-size: 10.5px; font-weight: 600;
  color: var(--ink); text-transform: uppercase; letter-spacing: 1px;
}

.form-input {
  width: 100%; padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 13.5px;
  color: var(--dark); font-family: 'Plus Jakarta Sans', sans-serif;
  transition: all .16s ease; background: var(--cream);
}

.form-input:focus {
  outline: none; border-color: var(--gold);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(201,168,76,.12);
}

/* ── BUSCADOR ─────────────────────────────────────────────────────────────── */
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--cream); border: 1.5px solid var(--border);
  border-radius: 8px; padding: 7px 13px;
  transition: border-color .16s;
}

.search-box:focus-within { border-color: var(--gold); }

.search-box input {
  border: none; outline: none; background: transparent;
  font-size: 13px; color: var(--dark); width: 100%;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

/* ── TABS ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 20px; overflow-x: auto;
}

.tab-btn {
  padding: 10px 18px; font-size: 12.5px; font-weight: 500;
  color: var(--muted); border: none; background: transparent;
  cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1.5px; transition: all .16s; white-space: nowrap;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--ink); border-bottom-color: var(--gold); font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeUp .22s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── LOG TERMINAL ─────────────────────────────────────────────────────────── */
.log-terminal {
  background: var(--void); border-radius: 10px;
  padding: 18px; font-family: 'DM Mono', monospace;
  font-size: 12px; line-height: 1.8;
  height: 400px; overflow-y: auto; color: #9CB0C8;
  border: 1px solid rgba(255,255,255,.06);
}

.log-line  { padding: 1px 0; }
.log-start { color: #4EC994; font-weight: 500; }
.log-done  { color: #5EA8F5; font-weight: 500; }
.log-error { color: #F07070; }
.log-info  { color: #9CB0C8; }

/* ── STATUS DOT ───────────────────────────────────────────────────────────── */
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  display: inline-block;
}

.status-dot.online  { background: var(--emerald); box-shadow: 0 0 0 3px var(--em-bg); }
.status-dot.offline { background: #CCC; }
.status-dot.running { background: var(--gold); animation: pulse 1.4s infinite; }

@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(201,168,76,.5); }
  50%      { box-shadow: 0 0 0 5px rgba(201,168,76,0); }
}

/* ── BARRA DE PROGRESO ────────────────────────────────────────────────────── */
.progress-bar-wrap {
  background: var(--border); border-radius: 999px; height: 8px; overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ink), var(--azure));
  border-radius: 999px; transition: width .5s ease;
}

/* ── CHART WRAP ───────────────────────────────────────────────────────────── */
.chart-wrap { position: relative; }

/* ── GRIDS ────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 20px; }

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 860px)  { .grid-3,.grid-2 { grid-template-columns: 1fr; } }

/* ── LOGIN ────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex;
  background: var(--void);
  position: relative; overflow: hidden;
}

.login-bg-art {
  position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(201,168,76,.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(30,59,122,.5) 0%, transparent 50%),
    radial-gradient(ellipse at 60% 80%, rgba(13,21,48,.8) 0%, transparent 50%);
}

.login-left {
  flex: 1; display: flex; flex-direction: column;
  justify-content: center; padding: 60px;
  position: relative; z-index: 1;
}

.login-left-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(36px, 5vw, 56px);
  font-weight: 700; color: var(--white);
  line-height: 1.1; margin-bottom: 20px;
}

.login-left-title span { color: var(--gold); }

.login-left-desc {
  font-size: 15px; color: rgba(255,255,255,.45);
  max-width: 380px; line-height: 1.7;
}

.login-divider {
  width: 1px; background: rgba(255,255,255,.08);
  position: relative; z-index: 1;
}

.login-right {
  width: 460px; flex-shrink: 0;
  background: rgba(255,255,255,.03);
  backdrop-filter: blur(20px);
  border-left: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; justify-content: center;
  padding: 48px; position: relative; z-index: 1;
}

.login-card {
  width: 100%;
}

.login-logo {
  margin-bottom: 36px;
}

.login-logo-icon {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--void); margin-bottom: 16px;
  box-shadow: 0 6px 20px rgba(201,168,76,.35);
}

.login-logo-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 26px; font-weight: 700; color: var(--white);
  letter-spacing: .5px;
}

.login-logo-sub {
  font-size: 11px; color: var(--gold);
  text-transform: uppercase; letter-spacing: 2px; margin-top: 4px;
}

.login-form-label {
  display: block; margin-bottom: 6px;
  font-size: 10.5px; font-weight: 600;
  color: rgba(255,255,255,.45); text-transform: uppercase; letter-spacing: 1px;
}

.login-form-input {
  width: 100%; padding: 12px 14px;
  background: rgba(255,255,255,.06);
  border: 1.5px solid rgba(255,255,255,.12);
  border-radius: 8px; color: var(--white); font-size: 14px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  transition: all .16s ease;
}

.login-form-input::placeholder { color: rgba(255,255,255,.25); }

.login-form-input:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(255,255,255,.08);
  box-shadow: 0 0 0 3px rgba(201,168,76,.15);
}

.login-alert {
  background: rgba(217,79,61,.15);
  border: 1px solid rgba(217,79,61,.3);
  border-radius: 8px; padding: 10px 14px;
  color: #F5907E; font-size: 12.5px; margin-bottom: 16px;
}

.btn-login {
  width: 100%; padding: 13px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--amber) 100%);
  color: var(--void); font-weight: 700; font-size: 14px;
  border: none; border-radius: 8px; cursor: pointer;
  font-family: 'Plus Jakarta Sans', sans-serif;
  transition: all .18s ease; letter-spacing: .3px;
  box-shadow: 0 4px 16px rgba(201,168,76,.35);
}

.btn-login:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(201,168,76,.45);
}

/* ── MODAL ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(8,14,26,.7); backdrop-filter: blur(4px);
  z-index: 300; align-items: center; justify-content: center;
}

.modal-box {
  background: var(--white); border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
  overflow: hidden; width: 100%; max-width: 560px;
}

.modal-header {
  background: var(--ink); padding: 20px 24px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ── DIVIDERS & UTILS ─────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.mb-4  { margin-bottom: 16px; }
.mb-6  { margin-bottom: 24px; }
.mt-4  { margin-top: 16px; }
.gap-3 { gap: 12px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted  { color: var(--muted); }
.text-navy   { color: var(--ink); }
.text-gold   { color: var(--gold); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.fw-600 { font-weight: 600; }
.ff-serif { font-family: 'Cormorant Garamond', serif; }
.ff-mono  { font-family: 'DM Mono', monospace; }

/* Number formatting */
.num { font-family: 'DM Mono', monospace; font-size: .95em; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.2); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Page fade-in */
.page-body > * {
  animation: fadeUp .3s ease both;
}
.page-body > *:nth-child(2) { animation-delay: .05s; }
.page-body > *:nth-child(3) { animation-delay: .10s; }
.page-body > *:nth-child(4) { animation-delay: .15s; }

/* ── Barra de scroll superior de tablas ventas/compras ───────────── */
.vc-topbar::-webkit-scrollbar {
  height: 10px;
}
.vc-topbar::-webkit-scrollbar-track {
  background: var(--paper);
  border-radius: 5px;
}
.vc-topbar::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, var(--ink), var(--azure));
  border-radius: 5px;
  border: 2px solid var(--paper);
}
.vc-topbar::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(90deg, var(--azure), var(--gold));
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .page-body { padding: 16px; }
  .topbar { padding: 0 16px; }
  .login-left { display: none; }
  .login-right { width: 100%; }
  .grid-4,.grid-3,.grid-2 { grid-template-columns: 1fr; }
}
