@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;500;600;700&display=swap');

:root {
  --miraki-blue: #0b3d91;
  --miraki-blue-soft: #e8f0fb;
  --miraki-orange: #e85d04;
  --miraki-orange-soft: #fff1e6;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #e6e8ee;
  --text: #1c2434;
  --muted: #6b7280;
  --success: #15803d;
  --danger: #b91c1c;
  --warning: #b45309;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--miraki-blue); text-decoration: none; }
a:hover { color: var(--miraki-orange); }

.brand-font {
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, #ffffff 0%, #f6f7f9 100%);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
}

.auth-card .logo-mark {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  background: var(--miraki-blue);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.auth-card h1 {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  color: var(--text);
}

.auth-card .subtitle {
  text-align: center;
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 0.95rem;
  line-height: 1.4;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
  background: var(--bg);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.sidebar .brand {
  padding: 6px 10px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.sidebar .brand h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--miraki-blue);
}

.sidebar .brand small {
  color: var(--muted);
  font-size: 0.82rem;
}

.nav-btn {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: #374151;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-btn:hover {
  background: #f3f4f6;
  color: var(--text);
}

.nav-btn.active {
  background: var(--miraki-blue-soft);
  color: var(--miraki-blue);
  border-color: transparent;
}

.main {
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--text);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--text);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.panel h3 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
  color: var(--text);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.metric {
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}

.metric .label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 6px;
}

.metric .value {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--miraki-blue);
}

.btn-miraki {
  background: var(--miraki-blue);
  border: 1px solid var(--miraki-blue);
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  padding: 9px 14px;
}

.btn-miraki:hover {
  background: #09327a;
  border-color: #09327a;
  color: #fff;
}

.btn-orange {
  background: var(--miraki-orange);
  border: 1px solid var(--miraki-orange);
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  padding: 9px 14px;
}

.btn-orange:hover {
  background: #cf5203;
  border-color: #cf5203;
  color: #fff;
}

.btn-ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: #374151;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 600;
}

.btn-ghost:hover {
  background: #f9fafb;
  color: var(--text);
}

.btn-outline-danger {
  background: #fff;
  border: 1px solid #f1a8a8;
  color: var(--danger);
  font-weight: 600;
  border-radius: 10px;
  padding: 9px 14px;
}

.btn-outline-danger:hover {
  background: #fef2f2;
  border-color: #ef4444;
  color: #991b1b;
}

.form-control, .form-select {
  background: #fff !important;
  border: 1px solid #d7dbe3 !important;
  color: var(--text) !important;
  border-radius: 10px !important;
  min-height: 44px;
  box-shadow: none !important;
}

.form-control:focus, .form-select:focus {
  border-color: var(--miraki-blue) !important;
  box-shadow: 0 0 0 3px rgba(11, 61, 145, 0.12) !important;
}

.form-control::placeholder {
  color: #9ca3af;
}

.form-label {
  color: #4b5563;
  font-weight: 600;
  font-size: 0.86rem;
  margin-bottom: 6px;
}

.password-field {
  position: relative;
}

.password-field .form-control {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  border-radius: 8px;
  cursor: pointer;
}

.password-toggle:hover {
  color: var(--miraki-blue);
  background: var(--miraki-blue-soft);
}

.table-wrap {
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.table {
  margin: 0;
  color: var(--text);
  --bs-table-bg: #fff;
  --bs-table-striped-bg: #fafbfc;
  --bs-table-hover-bg: #f3f6fb;
}

.table thead th {
  background: #f8f9fb;
  color: #4b5563;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  border-bottom-color: var(--line) !important;
}

.table td, .table th {
  border-color: var(--line) !important;
  vertical-align: middle;
  font-size: 0.92rem;
}

.badge-status {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.st-pendiente { background: #fff7ed; color: #c2410c; border-color: #ffedd5; }
.st-contactado { background: #eff6ff; color: #1d4ed8; border-color: #dbeafe; }
.st-en_seguimiento { background: #ecfeff; color: #0e7490; border-color: #cffafe; }
.st-convertido { background: #f0fdf4; color: #15803d; border-color: #dcfce7; }
.st-cerrado { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }

.modal-content {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 48px rgba(16, 24, 40, 0.12);
}

.modal-header, .modal-footer {
  border-color: var(--line);
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.btn-close {
  filter: none;
}

.alert {
  border-radius: 10px;
  border: 1px solid transparent;
}

.alert-warning {
  background: var(--miraki-orange-soft);
  border-color: #ffd8b5;
  color: #9a3412;
}

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast-item {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--miraki-blue);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.toast-item.error { border-left-color: var(--danger); }
.toast-item.success { border-left-color: var(--success); }

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.timeline {
  border-left: 2px solid var(--line);
  padding-left: 16px;
  margin-left: 6px;
}

.timeline-item {
  position: relative;
  margin-bottom: 14px;
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 16px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--miraki-orange);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
}

.text-secondary {
  color: var(--muted) !important;
}

/* Protecciones disuasorias para vendedor */
body.role-vendedor .no-export { display: none !important; }
body.role-vendedor .vendor-lock-table {
  user-select: none;
  -webkit-user-select: none;
}
@media print {
  body.role-vendedor .vendor-lock-table,
  body.role-vendedor #view-requests,
  body.role-vendedor #view-dashboard {
    display: none !important;
  }
  body.role-vendedor::after {
    content: "Datos no disponibles para impresión";
    display: block;
    padding: 40px;
    font-size: 1.2rem;
  }
}

.mobile-toggle { display: none; }

@media (max-width: 992px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: -300px;
    width: 260px;
    z-index: 1050;
    transition: left 0.25s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { left: 0; }
  .mobile-toggle { display: inline-flex; }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.35);
    z-index: 1040;
  }
  .sidebar-backdrop.show { display: block; }
}
