/* ==========================================================================
   RIQSIY COTIZADOR - DESIGN SYSTEM & STYLES
   Estética Minimalista Apple / Inter / Monocromática de Alta Gama
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --bg-app: #F5F5F7;
  --bg-card: #FFFFFF;
  --text-main: #1D1D1F;
  --text-muted: #6E6E73;
  --text-subtle: #86868B;
  --border-light: #E5E5EA;
  --border-subtle: #F2F2F7;
  --accent: #000000;
  --accent-hover: #2C2C2E;
  --accent-blue: #0071E3;
  --accent-green: #34C759;
  --accent-amber: #FF9500;
  --accent-red: #FF3B30;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 36px rgba(0,0,0,0.12);
}

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

body {
  font-family: var(--font-sans);
  color: var(--text-main);
  background: var(--bg-app);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Tipografía */
h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  line-height: 1.2;
}

.btn-primary {
  background: #000000;
  color: #FFFFFF;
}
.btn-primary:hover {
  background: #2C2C2E;
}

.btn-secondary {
  background: #FFFFFF;
  color: var(--text-main);
  border-color: var(--border-light);
}
.btn-secondary:hover {
  background: #F5F5F7;
  border-color: #D1D1D6;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  color: var(--text-main);
  background: rgba(0,0,0,0.04);
}

.btn-danger {
  background: #FFF0F0;
  color: var(--accent-red);
  border-color: #FFD2D0;
}
.btn-danger:hover {
  background: var(--accent-red);
  color: #FFFFFF;
}

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

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
  border-radius: var(--radius-md);
}

/* Inputs y Formularios */
.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}

.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-main);
  background: #FFFFFF;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  border-color: #000000;
  box-shadow: 0 0 0 1px #000000;
}

.form-control[readonly], .form-control:disabled {
  background: #F2F2F7;
  color: var(--text-muted);
  cursor: not-allowed;
}

textarea.form-control {
  resize: vertical;
  min-height: 60px;
}

.input-with-action {
  display: flex;
  gap: 8px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  letter-spacing: -0.01em;
}

.badge-draft { background: #E5E5EA; color: #1D1D1F; }
.badge-sent { background: #E1F0FF; color: #0071E3; }
.badge-approved { background: #E4F9E8; color: #288C43; }
.badge-rejected { background: #FFE8E7; color: #D70015; }

/* ==========================================================================
   VISTAS Y NAVEGACIÓN
   ========================================================================== */

.view-section {
  display: none;
}
.view-section.active {
  display: block;
}

/* Pantalla Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F5F5F7;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
  padding: 40px 32px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

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

/* App Header */
.app-header {
  background: #FFFFFF;
  border-bottom: 1px solid var(--border-light);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-brand-area {
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #000000;
  cursor: pointer;
}

.app-badge-tag {
  font-size: 10px;
  font-weight: 600;
  background: #000000;
  color: #FFFFFF;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.app-nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-tag {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 8px;
}

/* Layout Principal */
.app-container {
  max-width: 1200px;
  margin: 32px auto;
  padding: 0 24px;
}

/* Dashboard List View */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.metrics-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.metric-card {
  background: #FFFFFF;
  border-radius: var(--radius-md);
  padding: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

.metric-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.metric-val {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #000000;
}

.metric-sub {
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: 4px;
}

/* Filtros y Búsqueda */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}

.filter-group-left {
  display: flex;
  gap: 10px;
  flex: 1;
  min-width: 280px;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-input-wrapper input {
  padding-left: 36px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

/* Tabla de Cotizaciones */
.table-card {
  background: #FFFFFF;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-app {
  width: 100%;
  border-collapse: collapse;
}

.table-app th {
  background: #FAFAFC;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
}

.table-app td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  font-size: 13px;
}

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

.table-app tr:hover td {
  background: #FAFAFC;
}

.quote-title-cell {
  font-weight: 600;
  color: #000000;
}

.quote-client-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.table-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

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

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* ==========================================================================
   FORMULARIO CREADOR / EDITOR DE COTIZACIÓN
   ========================================================================== */

.editor-card {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  padding: 36px;
  margin-bottom: 40px;
}

.editor-section-header {
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 12px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.editor-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.editor-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

/* Items dinámicos en formulario */
.items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.items-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.items-table td {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.item-row {
  position: relative;
}

.btn-remove-item {
  background: none;
  border: none;
  color: #8E8E93;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.btn-remove-item:hover {
  color: var(--accent-red);
  background: #FFF0F0;
}

/* Autocomplete Suggestion Dropdown */
.autocomplete-wrapper {
  position: relative;
}

.suggestions-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #FFFFFF;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}

.suggestions-list.show {
  display: block;
}

.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover {
  background: #F5F5F7;
}

.suggestion-title {
  font-weight: 500;
  font-size: 13px;
  color: #000000;
}

.suggestion-desc {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.suggestion-price {
  font-size: 11px;
  font-weight: 600;
  color: #0071E3;
}

/* Totales Editor */
.editor-totals-wrapper {
  display: flex;
  justify-content: flex-end;
  margin-top: 24px;
}

.editor-totals-box {
  width: 300px;
}

.editor-total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
}

.editor-total-line.final {
  border-top: 1px solid var(--border-light);
  margin-top: 8px;
  padding-top: 16px;
  font-size: 18px;
  font-weight: 600;
}

/* Barra de acciones inferior del editor */
.editor-footer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border-light);
}

/* ==========================================================================
   VISTA DE IMPRESIÓN / DOCUMENTO A4 (Fiel al template original RIQSIY)
   ========================================================================== */

.print-preview-container {
  max-width: 900px;
  margin: 24px auto;
}

.print-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #FFFFFF;
  padding: 16px 24px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

/* Hoja A4 física en pantalla */
.a4-sheet {
  background: #FFFFFF;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-light);
  padding: 45mm 25mm 30mm 25mm;
  min-height: 297mm;
  box-sizing: border-box;
  color: #000000;
}

/* Estructura del documento dentro de la hoja A4 */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 50px;
}

.doc-brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.doc-meta {
  text-align: right;
}

.doc-type {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0;
}

.doc-number {
  font-size: 12px;
  color: #6E6E73;
  margin-top: 4px;
}

.doc-details-grid {
  display: flex;
  justify-content: space-between;
  margin-bottom: 50px;
  font-size: 12px;
  line-height: 1.6;
}

.doc-section-title {
  font-size: 10px;
  font-weight: 600;
  color: #6E6E73;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.doc-client-info p, .doc-meta-info p {
  margin: 0;
}

/* Tabla del documento A4 */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 40px;
}

.doc-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: #6E6E73;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-bottom: 12px;
  border-bottom: 1px solid #E5E5EA;
}

.doc-table th.num { text-align: right; }
.doc-table td {
  padding: 14px 0;
  border-bottom: 1px solid #F2F2F7;
  vertical-align: top;
  font-size: 12px;
}

.doc-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.doc-item-title {
  font-weight: 500;
  color: #000000;
  margin-bottom: 3px;
}

.doc-item-desc {
  font-size: 10px;
  color: #6E6E73;
  line-height: 1.4;
}

/* Totales Documento */
.doc-totals-container {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 50px;
}

.doc-totals-table {
  width: 260px;
  border-collapse: collapse;
}

.doc-totals-table td {
  border: none;
  padding: 4px 0;
  font-size: 12px;
}

.doc-totals-table .label { color: #6E6E73; }
.doc-totals-table .amount { text-align: right; font-variant-numeric: tabular-nums; }
.doc-totals-table .total-row td {
  padding-top: 14px;
  font-size: 18px;
  font-weight: 600;
  color: #000000;
}

.doc-footer {
  font-size: 9.5px;
  color: #86868B;
  line-height: 1.5;
  border-top: 1px solid #E5E5EA;
  padding-top: 18px;
}

/* ==========================================================================
   MODALES Y TOASTS
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-backdrop.show .modal-dialog {
  transform: translateY(0);
}

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

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

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

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}

.toast {
  background: #1D1D1F;
  color: #FFFFFF;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInToast 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-success { border-left: 4px solid var(--accent-green); }
.toast-error { border-left: 4px solid var(--accent-red); }
.toast-info { border-left: 4px solid var(--accent-blue); }

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

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 50%;
  border-top-color: currentColor;
  animation: spin 0.6s linear infinite;
}

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

/* ==========================================================================
   ESTILOS DE IMPRESIÓN (@media print)
   Garantiza exportación a PDF limpia en A4 idéntica a Index.html
   ========================================================================== */

@page {
  size: A4;
  margin: 0;
}

@media print {
  body {
    background: #FFFFFF !important;
    padding: 0 !important;
    margin: 0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app-header,
  .print-toolbar,
  .toast-container,
  .modal-backdrop,
  #view-login,
  #view-dashboard,
  #view-editor {
    display: none !important;
  }

  #view-print {
    display: block !important;
  }

  .print-preview-container {
    max-width: 100% !important;
    margin: 0 !important;
  }

  .a4-sheet {
    box-shadow: none !important;
    border: none !important;
    padding: 40mm 25mm 25mm 25mm !important;
    min-height: auto !important;
  }
}

/* Responsividad para móviles y pantallas pequeñas */
@media (max-width: 768px) {
  .app-header { padding: 0 16px; }
  .app-container { padding: 0 12px; margin: 16px auto; }
  .editor-grid-3, .editor-grid-2 { grid-template-columns: 1fr; gap: 12px; }
  .editor-card { padding: 20px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .a4-sheet { padding: 20px 15px; }
  .doc-details-grid { flex-direction: column; gap: 20px; }
  .doc-meta-info { text-align: left !important; }
}
