/* ==========================================================================
   ESTILOS DE LA APLICACIÓN WEB: FACTURAS Y PRESUPUESTOS RÁPIDOS
   ========================================================================== */

:root {
  --bg-app: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-card-solid: #1e293b;
  --bg-card-hover: rgba(51, 65, 85, 0.6);
  --bg-input: #0b1120;
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: #38bdf8;
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: rgba(59, 130, 246, 0.15);
  
  --success: #10b981;
  --success-hover: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.4);

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(147, 51, 234, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
}

/* ==========================================================================
   HEADER SUPERIOR
   ========================================================================== */
.app-header {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 1750px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.brand-logo-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-main);
}

.brand-icon-box {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-actions-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ==========================================================================
   LAYOUT PRINCIPAL
   ========================================================================== */
.app-main {
  flex: 1;
  max-width: 1750px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 30px;
  display: grid;
  grid-template-columns: 580px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 1300px) {
  .app-main {
    grid-template-columns: 500px 1fr;
  }
}

@media (max-width: 1080px) {
  .app-main {
    grid-template-columns: 1fr;
  }
  .mobile-hidden {
    display: none !important;
  }
}

/* ==========================================================================
   PANEL EDITOR
   ========================================================================== */
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card-section {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s;
}

.card-section:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.section-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title svg {
  color: var(--primary);
}

/* Formularios y campos */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-control {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.88rem;
  padding: 8px 12px;
  transition: all 0.2s;
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

select.form-control {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  appearance: none;
}

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

/* ==========================================================================
   EDITOR DE CONCEPTOS / LÍNEAS
   ========================================================================== */
.items-list-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.items-header-row {
  display: grid;
  grid-template-columns: minmax(110px, 1.4fr) 48px 68px 48px 58px 66px 46px;
  gap: 6px;
  padding: 0 8px 4px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  align-items: center;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(110px, 1.4fr) 48px 68px 48px 58px 66px 46px;
  gap: 6px;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  transition: border-color 0.2s;
  width: 100%;
  box-sizing: border-box;
}

.item-col {
  min-width: 0;
}

.item-col-desc {
  min-width: 0;
  width: 100%;
}

.item-row .form-control {
  padding: 6px 4px;
  font-size: 0.82rem;
  text-align: center;
}

textarea.item-input-desc {
  min-height: 36px;
  height: 36px;
  padding: 7px 8px !important;
  text-align: left !important;
  resize: none;
  overflow-y: hidden;
  line-height: 1.35;
  box-sizing: border-box;
  font-size: 0.82rem;
}

select.item-input-vat {
  padding: 6px 14px 6px 4px !important;
  background-position: right 3px center;
  font-size: 0.8rem;
  text-align: left !important;
}

.item-row:hover {
  border-color: rgba(255, 255, 255, 0.25);
}

.item-mobile-label {
  display: none;
}

.item-total-preview {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-col-actions {
  display: flex;
  gap: 2px;
  justify-content: flex-end;
}

.item-row .btn-icon {
  width: 22px;
  height: 26px;
  padding: 0;
}

@media (max-width: 680px) {
  .items-header-row {
    display: none;
  }
  .item-row {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
  }
  .item-col-desc {
    grid-column: 1 / -1;
  }
  .item-row .form-control {
    text-align: left;
    padding: 8px 10px;
  }
  .item-col-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    margin-top: 4px;
  }
  .item-row .btn-icon {
    width: 28px;
    height: 28px;
  }
  .item-mobile-label {
    display: block;
    font-size: 0.72rem;
    margin-bottom: 2px;
  }
}

/* ==========================================================================
   BOTONES
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.18s ease;
  text-decoration: none;
  font-family: inherit;
  line-height: 1.2;
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(51, 65, 85, 0.7);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: rgba(71, 85, 105, 0.9);
}

.btn-outline {
  background: transparent;
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.btn-icon.disabled, .btn-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ==========================================================================
   PANEL DE VISTA PREVIA
   ========================================================================== */
.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 76px;
  height: calc(100vh - 100px);
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  gap: 12px;
}

.preview-toolbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.preview-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-presets-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-preset-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s;
}

.color-preset-btn:hover {
  transform: scale(1.18);
}

.color-picker-input {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
}

.preview-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 40px;
  display: flex;
  justify-content: center;
}

.preview-scroll-area::-webkit-scrollbar {
  width: 8px;
}
.preview-scroll-area::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* ==========================================================================
   MODALES PERSONALIZADOS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  padding: 20px;
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalPop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.modal-card.modal-lg {
  max-width: 680px;
}

.modal-card.modal-confirm {
  max-width: 440px;
}

@keyframes modalPop {
  from {
    transform: scale(0.94) translateY(8px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

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

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-primary {
  background: var(--primary-light);
  color: var(--primary);
}

.icon-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
}

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

.btn-close-modal:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
  max-height: 75vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: rgba(15, 23, 42, 0.4);
}

/* Lista de clientes y tarjetas de historial */
.client-card-item, .history-card-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.client-card-name {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 2px;
}

.client-card-details {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}

.client-card-actions, .history-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.history-type-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.badge-factura { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.badge-presupuesto { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge-proforma { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.badge-rectificativa { background: rgba(239, 68, 68, 0.2); color: #f87171; }

.history-number {
  font-weight: 700;
  font-size: 0.88rem;
}

.history-date {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.history-client-name {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.history-card-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.history-total {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
}

/* ==========================================================================
   TOASTS
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  background: #1e293b;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  max-width: 380px;
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.22s ease;
}

.toast-item.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success { border-left: 4px solid var(--success); }
.toast-success .toast-icon { color: var(--success); }

.toast-error { border-left: 4px solid var(--danger); }
.toast-error .toast-icon { color: var(--danger); }

.toast-warning { border-left: 4px solid var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }

.toast-info { border-left: 4px solid var(--primary); }
.toast-info .toast-icon { color: var(--primary); }

.toast-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  margin-left: auto;
}

/* ==========================================================================
   UTILIDADES
   ========================================================================== */
.d-none { display: none !important; }
.text-muted { color: var(--text-muted); }
.mb-3 { margin-bottom: 12px; }
.font-mono { font-family: 'Consolas', 'Courier New', monospace; }

.logo-upload-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-preview-thumb {
  position: relative;
  width: 90px;
  height: 50px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-preview-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.btn-remove-logo {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.spin-animation {
  animation: spin 1s linear infinite;
}

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

.btn-toggle-view-mobile {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

@media (max-width: 1080px) {
  .btn-toggle-view-mobile {
    display: inline-flex;
  }
}
