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

[hidden] {
  display: none !important;
}

:root {
  --primary: #e8732f;
  --primary-dark: #c95f22;
  --primary-light: #fde9d9;
  --primary-soft: #fff3e6;
  --success: #2f9e63;
  --success-light: #e0f5e9;
  --danger: #d64545;
  --danger-light: #fde7e7;
  --warning: #d98a1f;
  --warning-light: #fdf0d5;
  --purple: #7c3aed;
  --bg: #faf6f0;
  --surface: #ffffff;
  --text: #3c3228;
  --text-muted: #8a7d6d;
  --border: #eee4d8;
  --sidebar-bg: #2f211a;
  --sidebar-text: #d9c9b8;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(60,50,40,.08), 0 1px 2px rgba(60,50,40,.05);
  --shadow-lg: 0 16px 40px rgba(60,50,40,.18);
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px;
  background: linear-gradient(180deg, #38281f, var(--sidebar-bg));
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  transition: transform .25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #f2a65a);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
  font-size: 17px;
  box-shadow: 0 4px 10px rgba(232,115,47,.35);
}

.brand-logo img {
  width: 100%;
  height: 100%;
  border-radius: 11px;
  object-fit: cover;
  display: block;
}

.logo-preview-img {
  max-height: 80px;
  max-width: 200px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,.08);
  background: #fff;
  padding: 4px;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.nav {
  padding: 12px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  overflow-y: auto;
}

.nav-section {
  padding: 16px 14px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(217,201,184,.45);
  font-weight: 700;
}

.nav-section:first-child {
  padding-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 14px;
  cursor: pointer;
  border-radius: 10px;
  text-align: left;
  font-family: inherit;
  transition: background .15s, color .15s;
}

.nav-item:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.nav-item.active {
  background: linear-gradient(135deg, var(--primary), #e8732f);
  color: #fff;
  box-shadow: 0 4px 12px rgba(232,115,47,.3);
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,.08);
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  margin-left: 230px;
  padding: 0 24px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.topbar h1 {
  font-size: 22px;
  font-weight: 700;
}

.topbar-right {
  margin-left: auto;
}

.date-info {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* ---------- Cards / Dashboard ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  transition: box-shadow .15s, transform .15s;
}

.card:hover {
  box-shadow: 0 8px 20px rgba(60,50,40,.08);
}

.card-stat {
  border-top: 3px solid transparent;
}

.card-stat .stat-label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}

.card-stat .stat-value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
}

.card-stat .stat-sub {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 4px;
}

.card-stat .stat-icon {
  font-size: 30px;
}

.stat-green { color: var(--success); }
.stat-blue { color: var(--primary); }
.stat-orange { color: var(--warning); }
.stat-purple { color: var(--purple); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.panel h2 {
  font-size: 17px;
  margin-bottom: 14px;
  color: var(--text);
}

/* ---------- Toolbar & buttons ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  font-family: inherit;
}

.btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(232,115,47,.3);
}

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--primary-soft); box-shadow: none; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b93333; box-shadow: 0 4px 12px rgba(214,69,69,.3); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #237d4d; box-shadow: 0 4px 12px rgba(47,158,99,.3); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-sm + .btn-sm { margin-left: 6px; }

.input, .select, .textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .full { grid-column: 1 / -1; }

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--primary-soft);
}

tbody tr:hover { background: #fbf6ef; }

.text-right { text-align: right; }
.text-center { text-align: center; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-paid { background: var(--success-light); color: var(--success); }
.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-cancelled { background: var(--danger-light); color: var(--danger); }

.actions-cell { text-align: right; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 10px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(47,33,26,.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 30px 16px;
  z-index: 100;
  overflow-y: auto;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  box-shadow: var(--shadow-lg);
  animation: slideDown .2s ease;
}

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

.modal-header h2 { font-size: 18px; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

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

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  font-size: 14px;
}

.toast[hidden] { display: none; }

/* ---------- Factura (documento) ---------- */
.invoice-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px;
  background: #fff;
  max-width: 720px;
  margin: 0 auto;
}

.invoice-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
}

.invoice-company h3 { font-size: 20px; color: var(--primary); }

.invoice-meta { text-align: right; font-size: 14px; color: var(--text-muted); }
.invoice-meta strong { color: var(--text); }

.invoice-client {
  margin-bottom: 24px;
  padding: 14px 16px;
  background: var(--bg);
  border-radius: 10px;
}

.invoice-client h4 { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.invoice-client p { font-size: 15px; }

.invoice-total-box {
  margin-top: 20px;
  margin-left: auto;
  width: fit-content;
  min-width: 220px;
}

.invoice-total-box .row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.invoice-total-box .row.grand {
  border-top: 2px solid var(--text);
  font-size: 18px;
  font-weight: 700;
  padding-top: 10px;
  margin-top: 6px;
}

.status-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.print-hide { }
@media print {
  .sidebar, .topbar, .toolbar, .no-print { display: none !important; }
  .main { margin-left: 0; padding: 0; }
  body { background: #fff; }
  .invoice-preview { border: none; box-shadow: none; max-width: 100%; padding: 0; }
  .view { display: none !important; }
  .view.active { display: block !important; }
}

/* ---------- Reportes ---------- */
.report-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.bar-label { width: 90px; font-size: 13px; color: var(--text-muted); text-align: right; }
.bar-track { flex: 1; background: var(--border); border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #f2a65a); border-radius: 6px; min-width: 2px; }
.bar-value { width: 80px; font-size: 13px; font-weight: 600; text-align: left; }

/* ---------- Banner de bienvenida (dashboard) ---------- */
.welcome-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background:
    radial-gradient(600px 220px at 100% 0%, rgba(255,255,255,.22), transparent 60%),
    linear-gradient(135deg, #f2a65a, var(--primary) 55%, var(--primary-dark));
  color: #fff;
  border-radius: 16px;
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: 0 10px 24px rgba(232,115,47,.25);
}

.welcome-title { font-size: 20px; font-weight: 700; }
.welcome-sub { font-size: 14px; opacity: .92; margin-top: 4px; }

.welcome-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.welcome-actions .btn { background: #fff; color: var(--primary-dark); }
.welcome-actions .btn:hover { background: #fff5ec; box-shadow: 0 4px 12px rgba(0,0,0,.15); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 0 14px 30px; }
  .hamburger { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .invoice-head { flex-direction: column; gap: 12px; }
  .invoice-meta { text-align: left; }
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  background: var(--bg);
}

.login-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 48px 60px;
  background:
    radial-gradient(1100px 480px at 95% -5%, rgba(255,255,255,.2), transparent 60%),
    linear-gradient(135deg, #f6a25b 0%, var(--primary) 55%, var(--primary-dark) 100%);
  color: #fff;
}

.login-hero-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.login-hero .brand-logo {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 6px 16px rgba(0,0,0,.18);
}

.hero-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-dot { color: #ffe7c9; }

.hero-headline {
  font-size: 34px;
  line-height: 1.2;
  font-weight: 800;
  max-width: 460px;
}

.hero-tagline {
  font-size: 15px;
  max-width: 420px;
  opacity: .95;
  line-height: 1.6;
}

.hero-features {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
  max-width: 420px;
}

.hero-features li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  background: rgba(255,255,255,.13);
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.15);
}

.hf-icon {
  font-size: 16px;
  opacity: .95;
}

.hero-foot {
  margin-top: 26px;
  font-size: 12px;
  opacity: .75;
}

.login-card-wrap {
  width: 520px;
  min-width: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 28px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 36px 34px;
  width: 100%;
  max-width: 400px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.login-brand .brand-logo {
  width: 44px;
  height: 44px;
  font-size: 19px;
}

.login-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 6px 0 22px;
}

.login-store {
  text-align: center;
  color: var(--primary);
  font-weight: 600;
  font-size: 15px;
  margin: -12px 0 18px;
}

.login-tabs {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}

.login-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}

.login-tab.active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: var(--shadow);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}

.login-note {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.login-forgot {
  display: block;
  text-align: center;
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
  margin-top: 4px;
  font-weight: 600;
}

.login-forgot:hover {
  text-decoration: underline;
  color: var(--primary-dark);
}

.captcha-widget {
  display: none;
  justify-content: center;
  margin: 4px 0;
  min-height: 65px;
}

/* Pantalla de acceso pendiente */
#blocked-screen {
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1100px 480px at 95% -5%, rgba(255,255,255,.2), transparent 60%),
    linear-gradient(135deg, #f6a25b 0%, var(--primary) 55%, var(--primary-dark) 100%);
}

#blocked-screen .login-card {
  max-width: 420px;
}

.brand-user {
  font-size: 11px;
  color: var(--sidebar-text);
  opacity: .8;
}

.brand-store {
  font-size: 11px;
  color: #f2a65a;
  font-weight: 600;
  opacity: .95;
}

.permisos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.chk {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border, rgba(0,0,0,.06));
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ---------- Paginación y carga ---------- */
.paginacion {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 0 4px;
}

.pagina-info {
  font-size: 13px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 10px;
  border: 3px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Login responsive ---------- */
@media (max-width: 860px) {
  .login-hero { display: none; }
  .login-screen {
    padding: 20px;
    align-items: center;
    justify-content: center;
    background:
      radial-gradient(800px 400px at 100% 0%, rgba(255,255,255,.2), transparent 60%),
      linear-gradient(135deg, #f6a25b 0%, var(--primary) 55%, var(--primary-dark) 100%);
  }
  .login-card-wrap {
    width: 100%;
    min-width: 0;
    max-width: 420px;
    padding: 0;
    background: transparent;
  }
  .hero-headline { font-size: 28px; }
}
