/* ==========================================================================
   Alfred Grafic — hoja de estilos principal
   ========================================================================== */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #1b2433;
  --muted: #7b869a;
  --line: #e5e9f2;
  --sidebar: #151d2e;
  --sidebar-soft: #1e2940;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0284c7;
  --info-soft: #e0f2fe;
  --purple: #7c3aed;
  --purple-soft: #f3e8ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin-top: 0; }
code { font-family: Consolas, "Courier New", monospace; font-size: .92em; background: #f1f4fa; padding: 2px 5px; border-radius: 4px; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.icon { vertical-align: -3px; flex: none; }

/* ---------- Utilidades ---------- */
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1.5rem; }
.text-right { text-align: right; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-green { color: var(--success); }
.text-amber { color: var(--warning); }
.text-purple { color: var(--purple); }

/* ---------- Estructura ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: none; background: var(--sidebar); color: #cbd3e3;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand strong { display: block; color: #fff; font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.brand small { color: #8692ab; font-size: 11px; }
.side-nav { padding: 14px 10px; flex: 1; overflow-y: auto; }
.nav-label {
  display: block; padding: 14px 12px 6px; color: #62708c;
  font-size: 10px; font-weight: 700; letter-spacing: 1.4px;
}
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: 8px; color: #b6c0d4; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--sidebar-soft); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(79,70,229,.35); }
.nav-button { width: 100%; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.sidebar-bottom { padding: 10px; border-top: 1px solid rgba(255,255,255,.07); }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 16px 28px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 19px; font-weight: 700; margin: 0; }
.topbar-title p { color: var(--muted); font-size: 12px; margin: 2px 0 0; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user-info { text-align: right; }
.topbar-user-info strong { display: block; font-size: 13px; }
.topbar-user-info span { color: var(--muted); font-size: 11px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary); display: grid; place-items: center; font-weight: 700;
}
.mobile-toggle { display: none; border: 0; background: none; font-size: 21px; cursor: pointer; }
.content { padding: 24px 28px 40px; flex: 1; }
.app-footer {
  padding: 14px 28px; border-top: 1px solid var(--line); color: var(--muted);
  font-size: 11px; display: flex; justify-content: space-between; background: var(--surface);
}

/* ---------- Login ---------- */
.auth-body { background: #0f1728; }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.auth-brand {
  background: radial-gradient(circle at 20% 20%, #312e81, #111827 65%);
  color: #e5e7eb; padding: 8vh 9%; display: flex; flex-direction: column; justify-content: center;
}
.auth-logo-wrap {
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; border-radius: 14px; padding: 16px 22px; margin-bottom: 26px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .28);
}
.auth-logo { display: block; width: 100%; max-width: 320px; height: auto; }
.auth-logo-mobile { display: none; }
.auth-brand p { color: #a5b4d4; max-width: 380px; }
.auth-features { list-style: none; padding: 0; margin: 22px 0 34px; }
.auth-features li { padding: 7px 0 7px 26px; position: relative; color: #d1d5db; }
.auth-features li::before { content: "✓"; position: absolute; left: 0; color: #a78bfa; font-weight: 700; }
.auth-brand small { color: #6b7a99; }
.auth-panel { display: grid; place-items: center; padding: 40px; background: #fff; }
.auth-card { width: 100%; max-width: 390px; }
.auth-card h1 { font-size: 25px; margin-bottom: 4px; }
.auth-card .muted { margin-bottom: 24px; }
.auth-help { margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted); }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0 18px; color: #475569; }

/* ---------- Tarjetas y grillas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header {
  padding: 15px 18px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.card-header h2 { font-size: 14px; font-weight: 700; margin: 0; }
.card-body { padding: 18px; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--line); }
.card-accent-purple { border-top: 3px solid var(--purple); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.table-responsive { overflow-x: auto; }

/* ---------- Métricas ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.icon-indigo { background: var(--primary-soft); color: var(--primary); }
.icon-red { background: var(--danger-soft); color: var(--danger); }
.icon-amber { background: var(--warning-soft); color: var(--warning); }
.icon-green { background: var(--success-soft); color: var(--success); }
.icon-purple { background: var(--purple-soft); color: var(--purple); }
.stat-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 21px; font-weight: 700; }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.mini-stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.mini-stat span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.mini-stat strong { font-size: 20px; }
.mini-stat small { display: block; color: var(--muted); }
.big-number { font-size: 30px; font-weight: 700; margin: 0; }
.big-number small { color: var(--muted); font-weight: 400; }

/* ---------- Alertas y mensajes ---------- */
.alert { display: flex; gap: 10px; align-items: center; padding: 13px 16px; border-radius: 10px; margin-top: 18px; }
.alert-danger { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; }
.alert a { color: #991b1b; font-weight: 600; }
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash { padding: 11px 15px; border-radius: 9px; font-size: 13px; border: 1px solid transparent; }
.flash-success { background: var(--success-soft); color: #166534; border-color: #bbf7d0; }
.flash-danger { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.flash-warning { background: var(--warning-soft); color: #92400e; border-color: #fde68a; }
.flash-info { background: var(--info-soft); color: #075985; border-color: #bae6fd; }
.flash-secondary { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.notice { background: var(--purple-soft); color: #5b21b6; border: 1px solid #e9d5ff; border-radius: 9px; padding: 11px 13px; font-size: 12px; margin-top: 12px; }

/* ---------- Tablas ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; color: var(--muted); font-size: 10px; text-transform: uppercase;
  letter-spacing: .6px; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid #f0f2f7; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-hover tbody tr:hover { background: #fafbff; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; font-size: 12px; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-secondary { background: #e9edf4; color: #475569; }
.badge-light { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }
.badge-success { background: var(--success-soft); color: #166534; }
.badge-warning { background: var(--warning-soft); color: #92400e; }
.badge-danger { background: var(--danger-soft); color: #991b1b; }
.badge-info { background: var(--info-soft); color: #075985; }
.badge-purple { background: var(--purple-soft); color: #5b21b6; }

/* ---------- Formularios ---------- */
.field { display: block; margin-bottom: 14px; }
[hidden] { display: none !important; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 5px; }
.check-field { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.check-field input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }
.check-field > span { display: inline; margin: 0; font-size: 13px; }
.field input, .field select, .field textarea,
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], select, textarea {
  width: 100%; border: 1px solid #d9dfeb; background: #fff; color: var(--ink);
  border-radius: 8px; padding: 9px 11px; font: inherit; font-size: 13px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus,
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
textarea { resize: vertical; }
.hint { display: block; color: var(--muted); font-size: 11px; margin-top: 5px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.filter-grid .field { margin: 0; }
.filter-actions { display: flex; gap: 8px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; padding: 16px 18px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.inline-form { display: flex; gap: 8px; align-items: center; }

/* ---------- Fotografías adjuntas ---------- */
.upload-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
.upload-card { border: 1px dashed #cbd5e1; border-radius: 10px; padding: 14px; background: #fbfcff; }
.upload-title { display: block; font-size: 12px; font-weight: 700; color: #334155; margin-bottom: 10px; }
.upload-preview { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.upload-preview img { width: 76px; height: 76px; object-fit: cover; border: 1px solid var(--line); border-radius: 8px; }
.upload-actual { font-size: 11px; color: var(--muted); }
.file-field input[type="file"], .item-table input[type="file"] {
  width: 100%; border: 1px solid #d9dfeb; background: #fff; border-radius: 8px;
  padding: 8px; font: inherit; font-size: 12px; max-width: 100%;
}
.file-field input[type="file"]::file-selector-button, .item-table input[type="file"]::file-selector-button {
  border: 0; background: #eef2ff; color: #4338ca; border-radius: 6px;
  padding: 5px 9px; margin-right: 8px; cursor: pointer; font-weight: 600;
}
.photo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.photo-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; background: #fff; }
.photo-card img { width: 100%; height: 170px; object-fit: cover; border-radius: 7px; }
.photo-card span { display: block; margin-top: 8px; font-size: 12px; font-weight: 600; color: #475569; }
.foto-preview img { width: 48px; height: 48px; object-fit: cover; margin-top: 6px; border: 1px solid var(--line); border-radius: 6px; }
.inline-form select { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px; padding: 9px 15px;
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: transform .1s, background .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.22); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; color: #475569; border-color: #d9dfeb; }
.btn-ghost:hover { background: #f8fafc; color: var(--ink); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger-ghost { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; }
.btn-block { width: 100%; margin-top: 6px; }

/* ---------- Detalles ---------- */
.detail-list { display: grid; grid-template-columns: 130px 1fr; gap: 9px 12px; margin: 0; font-size: 13px; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 0; font-weight: 500; }
.empty-state { text-align: center; padding: 38px 16px; color: var(--muted); }
.empty-state svg { color: #cbd5e1; }
.empty-state p { margin: 8px 0 0; font-size: 13px; }

/* ---------- Línea de tiempo y pasos ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0f2f7; font-size: 13px; }
.timeline li:last-child { border: 0; }
.timeline-date { background: var(--primary-soft); color: var(--primary); font-weight: 700; border-radius: 7px; padding: 5px 8px; font-size: 11px; white-space: nowrap; }
.timeline li.urgent .timeline-date { background: var(--danger-soft); color: var(--danger); }
.timeline small { color: var(--muted); }
.timeline .badge { margin-left: auto; }
.steps { display: flex; flex-wrap: wrap; gap: 6px; }
.step { font-size: 10px; padding: 4px 8px; border-radius: 20px; background: #f1f5f9; color: #94a3b8; }
.step.done { background: var(--success-soft); color: #166534; }

/* ---------- Barras de progreso ---------- */
.progress-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 18px; }
.legend-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 6px; }
.bar { height: 7px; background: #edf1f7; border-radius: 10px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 10px; background: var(--primary); }
.bar-1 { background: #94a3b8; }
.bar-2 { background: #0ea5e9; }
.bar-3 { background: #f59e0b; }
.bar-4 { background: #22c55e; }

/* ---------- Cotizaciones ---------- */
.quote-summary { margin-top: 16px; border-top: 1px dashed #d9dfeb; padding-top: 12px; }
.quote-summary > div { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.quote-summary .total { margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 15px; color: var(--primary); }
.item-table input { padding: 7px 9px; }
.item-table .sub { padding-top: 12px; font-weight: 600; }

/* ---------- Error ---------- */
.error-page { text-align: center; padding: 60px 20px; }
.error-code { font-size: 90px; font-weight: 800; color: #dfe4ef; line-height: 1; }
.error-page h2 { margin: 10px 0; }
.error-page p { color: var(--muted); margin-bottom: 22px; }

/* ---------- Documento imprimible A4 ---------- */
.print-body { background: #e9edf4; }
.no-print.print-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 26px; background: #fff; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.print-document {
  width: 210mm; min-height: 297mm; margin: 26px auto; padding: 16mm 15mm;
  background: #fff; box-shadow: 0 10px 40px rgba(15,23,42,.12); color: #111827; font-size: 12px;
}
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid #4f46e5; padding-bottom: 18px; }
.doc-logo { display: block; width: 130px; max-width: 100%; height: auto; object-fit: contain; margin-bottom: 10px; }
.doc-brand h1 { font-size: 17px; margin: 0 0 3px; }
.doc-brand p { font-size: 10px; color: #6b7280; margin: 0; line-height: 1.5; }
.doc-title { text-align: right; }
.doc-title span { font-size: 10px; letter-spacing: 2px; color: #6b7280; }
.doc-title h2 { font-size: 22px; margin: 2px 0; color: #4f46e5; }
.doc-title p { font-size: 10px; margin: 1px 0; color: #4b5563; }
.doc-client { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; margin: 20px 0; padding: 12px 14px; background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 6px; }
.doc-label { display: block; font-size: 9px; font-weight: 700; letter-spacing: 1px; color: #6b7280; margin-bottom: 3px; }
.doc-client strong { font-size: 12px; }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th { background: #4f46e5; color: #fff; font-size: 10px; text-transform: uppercase; padding: 9px 10px; text-align: left; }
.doc-table td { padding: 10px; border-bottom: 1px solid #e5e7eb; }
.doc-table tbody tr:nth-child(even) { background: #f9fafb; }
.doc-item-photo { margin-top: 6px; }
.doc-item-photo img { max-width: 72px; max-height: 56px; object-fit: cover; border: 1px solid #e5e7eb; border-radius: 3px; }
.doc-totals { display: grid; grid-template-columns: 1fr 260px; gap: 26px; margin-top: 20px; }
.doc-observations p { font-size: 11px; color: #4b5563; border: 1px dashed #d1d5db; border-radius: 5px; padding: 10px; min-height: 62px; }
.doc-amounts > div { display: flex; justify-content: space-between; padding: 5px 0; font-size: 11px; }
.doc-amounts .doc-total { margin-top: 8px; padding: 10px; background: #4f46e5; color: #fff; border-radius: 5px; font-size: 13px; font-weight: 700; }
.doc-footer { margin-top: 50px; text-align: center; color: #6b7280; font-size: 10px; }
.doc-footer-contact { margin-top: 3px; }
.signature-line { width: 260px; border-top: 1px solid #9ca3af; margin: 0 auto 8px; }
.doc-thanks { margin-top: 16px; color: #4f46e5; font-weight: 600; }

@page { size: A4; margin: 12mm; }
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-document { width: auto; min-height: 0; margin: 0; padding: 0; box-shadow: none; }
  .doc-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-amounts .doc-total, .doc-header { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-table tr, .doc-item-photo { break-inside: avoid; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-logo-mobile { display: block; margin-bottom: 26px; }
  .auth-logo-mobile img { display: block; width: 100%; max-width: 260px; height: auto; }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .mobile-toggle { display: block; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 18px; }
  .topbar { padding: 12px 18px; }
  .topbar-user-info { display: none; }
  .doc-client, .doc-totals { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ---------- Miniaturas del catálogo en el panel (la tienda usa tienda.css) ---------- */
.catalogo-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid #e5e7eb; }
.catalogo-vista { width: 100%; max-width: 260px; border-radius: 10px; border: 1px solid #e5e7eb; }
