:root {
  /* Verde de marca (Wasozky One), tomado del logo. --on-primary es un verde
     casi negro: da mucho mejor contraste sobre el verde que el blanco. */
  --primary: #7fb724;
  --primary-dark: #5f8f16;
  --primary-light: #eef8d6;
  --on-primary: #16220b;
  --link: #4a7010; /* mismo verde de marca pero oscurecido para buen contraste como texto */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --sidebar-bg: #10190a;
  --sidebar-text: #c8d6bd;
  --sidebar-active: #24331a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

#app { min-height: 100vh; }

a { color: var(--link); text-decoration: none; }
button { font-family: inherit; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f1a08 0%, #3d6014 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}
.login-card p.sub {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 13px;
}
.login-logo {
  width: 52px; height: 52px; border-radius: 12px;
  background: var(--primary);
  color: var(--on-primary); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; margin-bottom: 16px; overflow: hidden;
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  font-weight: 700; color: #fff; font-size: 15px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .dot {
  width: 32px; height: 32px; border-radius: 8px; background: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 13px;
  overflow: hidden; flex-shrink: 0;
}
.sidebar-brand .dot img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.sidebar nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sidebar a.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; color: var(--sidebar-text);
  margin-bottom: 2px; font-size: 13.5px; font-weight: 500;
}
.sidebar a.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar a.nav-item.active { background: var(--primary); color: var(--on-primary); font-weight: 700; }
.sidebar-footer {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 12.5px;
}
.sidebar-footer .user-name { color: #fff; font-weight: 600; }
.sidebar-footer button {
  margin-top: 8px; width: 100%; padding: 6px 8px; font-size: 12px;
  background: rgba(255,255,255,0.06); color: var(--sidebar-text); border: none; border-radius: 6px; cursor: pointer;
}
.sidebar-footer button:hover { background: rgba(255,255,255,0.12); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 0 24px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-size: 17px; margin: 0; }
.content { padding: 24px; flex: 1; min-width: 0; }

/* Botón "☰" para abrir el menú lateral en celular — oculto en escritorio */
.menu-toggle {
  display: none; background: none; border: none; font-size: 20px; line-height: 1;
  cursor: pointer; color: var(--text); padding: 4px 6px; margin: 0 -2px 0 -6px;
}
.sidebar-backdrop { display: none; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Celular / pantallas angostas ----------
   El menú lateral fijo de 230px no cabe en un teléfono junto con el contenido,
   así que ahí se convierte en un panel que se desliza por encima (oculto por
   defecto, se abre con el botón "☰"), en vez de compartir el ancho con .main. */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 100;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 10px 0 30px rgba(0,0,0,0.25); }
  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0; background: rgba(15,23,42,0.5); z-index: 90;
  }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
}

@media (max-width: 560px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 14px 16px; }
  .login-wrap { padding: 16px; }
  .login-card { padding: 28px 22px; max-width: 100%; }
  .field-row { flex-direction: column; gap: 0; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .search { min-width: 0; }
  .modal { padding: 18px; }
  .modal-backdrop { padding: 16px; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .invoice-box { padding: 18px; }
  .invoice-head, .invoice-parties { flex-direction: column; gap: 10px; }
  .invoice-meta { text-align: left; }
  .bar-row .label { width: 90px; font-size: 11.5px; }
  .bar-row .value { width: 74px; font-size: 11.5px; }
}

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; border: 1px solid var(--border);
}
.card h3 { margin: 0 0 4px; font-size: 13px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat { font-size: 26px; font-weight: 700; margin: 4px 0; }
.stat-sub { font-size: 12.5px; color: var(--text-muted); }

.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-header h3 { text-transform: none; font-size: 15px; color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: background .12s;
}
.btn:hover { background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--danger-light); }
.btn-danger:hover { background: var(--danger-light); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-icon { padding: 6px 8px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.error-msg { background: var(--danger-light); color: var(--danger); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; border-bottom: 1px solid var(--border); }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.table-wrap { overflow-x: auto; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; }
.search input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-success { background: var(--success-light); color: #15803d; }
.badge-danger { background: var(--danger-light); color: #b91c1c; }
.badge-warning { background: var(--warning-light); color: #b45309; }
.badge-muted { background: #f1f5f9; color: var(--text-muted); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow-y: auto; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); padding: 24px;
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Misc ---------- */
.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }

/* ---------- Charts (SVG hechos a mano) ---------- */
.chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; }
.chart-bar { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.chart-bar:hover { background: var(--primary-dark); }
.chart-labels { display: flex; gap: 4px; margin-top: 6px; }
.chart-labels span { flex: 1; text-align: center; font-size: 10px; color: var(--text-muted); }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .label { width: 130px; font-size: 12.5px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: #f1f5f9; border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--primary); height: 100%; border-radius: 6px; }
.bar-row .value { width: 90px; text-align: right; font-size: 12.5px; font-weight: 600; flex-shrink: 0; }

/* ---------- Factura imprimible ---------- */
.invoice-box { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px; max-width: 720px; margin: 0 auto; border: 1px solid var(--border); }
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.invoice-head h1 { font-size: 20px; margin: 0 0 2px; }
.invoice-meta { text-align: right; font-size: 13px; color: var(--text-muted); }
.invoice-parties { display: flex; justify-content: space-between; margin-bottom: 24px; gap: 20px; }
.invoice-parties h4 { margin: 0 0 6px; font-size: 11.5px; text-transform: uppercase; color: var(--text-muted); }
.invoice-totals { margin-left: auto; width: 100%; max-width: 260px; margin-top: 12px; }
.invoice-totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; }
.invoice-totals .row.total { font-size: 17px; font-weight: 700; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 10px; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
  .invoice-box { box-shadow: none; border: none; }
}

.login-error { display: none; }
