/* ============================================
   FACTURA GENIAL - STYLES
   ============================================ */

:root {
  --bg-app: #0f1117;
  --bg-panel: #1a1d27;
  --bg-section: #1e2130;
  --bg-input: #252838;
  --bg-input-hover: #2d3147;
  --border: #2e3248;
  --border-light: #3a3f5c;
  --accent: #6c63ff;
  --accent-hover: #7c74ff;
  --accent-glow: rgba(108, 99, 255, 0.25);
  --accent2: #00d4aa;
  --text-primary: #e8eaf6;
  --text-secondary: #8892b0;
  --text-muted: #5a6080;
  --success: #00d4aa;
  --warning: #ffb347;
  --danger: #ff5e7d;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --font-ui: 'Inter', sans-serif;
  --font-display: 'Outfit', sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* the panels handle their own scroll */
}

/* ===== HEADER ===== */
.app-header {
  background: linear-gradient(135deg, #12141f 0%, #1a1d2e 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  max-width: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent), #9c27b0);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.logo-icon svg {
  width: 20px;
  height: 20px;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.logo-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

/* Buttons */
.btn-primary,
.btn-secondary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-primary svg,
.btn-secondary svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5855d6);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #6861df);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-input-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

/* ===== MAIN LAYOUT ===== */
.app-main {
  display: flex;
  flex: 1;
  height: calc(100vh - 62px);
  overflow: hidden;
}

/* ===== FORM PANEL ===== */
.panel-form {
  width: 420px;
  min-width: 380px;
  max-width: 480px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.panel-form::-webkit-scrollbar {
  width: 5px;
}

.panel-form::-webkit-scrollbar-track {
  background: transparent;
}

.panel-form::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 10px;
}

.form-container {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* FORM SECTIONS */
.form-section {
  background: var(--bg-section);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.form-section:hover {
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.08);
  border-color: var(--border-light);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(108, 99, 255, 0.05), transparent);
}

.section-icon {
  font-size: 1.1rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border-radius: 7px;
}

.section-header h2 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.3px;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  padding: 9px 11px;
  transition: all 0.2s;
  width: 100%;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  background: var(--bg-input-hover);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238892b0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
}

.form-group select option {
  background: var(--bg-input);
}

.form-group textarea {
  resize: vertical;
  min-height: 70px;
  line-height: 1.5;
}

/* DOC TYPE BUTTONS */
.doc-type-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-type-btn {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.doc-type-btn input[type="radio"] {
  display: none;
}

.doc-type-btn span {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-input);
  transition: all 0.2s;
  cursor: pointer;
}

.doc-type-btn:hover span {
  border-color: var(--accent);
  color: var(--accent);
}

.doc-type-btn input[type="radio"]:checked+span {
  background: linear-gradient(135deg, var(--accent), #5855d6);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
}

/* STYLE GROUP */
.style-group {
  display: flex;
  gap: 8px;
}

.style-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-input);
  cursor: pointer;
  transition: all 0.2s;
}

.style-btn input[type="radio"] {
  display: none;
}

.style-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.style-btn:has(input:checked) {
  background: linear-gradient(135deg, var(--accent), #5855d6);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
}

/* TOGGLE */
.toggle-group {
  padding: 2px 0;
}

.toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 4px 0;
}

.toggle-label span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  display: none;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 50px;
  transition: all 0.25s;
  cursor: pointer;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.25s;
}

.toggle-switch input:checked+.toggle-slider {
  background: linear-gradient(135deg, var(--accent), #5855d6);
  border-color: var(--accent);
}

.toggle-switch input:checked+.toggle-slider::after {
  left: calc(100% - 17px);
  background: white;
}

/* COLOR INPUTS */
.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  transition: all 0.2s;
}

.color-input-wrap:hover {
  border-color: var(--border-light);
}

.color-input-wrap input[type="color"] {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 4px;
  padding: 0;
}

.color-input-wrap span {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: monospace;
}

/* LOGO UPLOAD */
.logo-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-input);
  text-align: center;
}

.logo-upload-area:hover {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.05);
}

.logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.logo-placeholder svg {
  width: 32px;
  height: 32px;
}

.logo-placeholder span {
  font-size: 0.85rem;
}

.logo-placeholder small {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.btn-remove-logo {
  background: rgba(255, 94, 125, 0.15);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 5px;
  padding: 4px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-remove-logo:hover {
  background: var(--danger);
  color: white;
}

/* ITEMS */
.item-row {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  position: relative;
  transition: all 0.2s;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.item-row:hover {
  border-color: var(--border-light);
}

.item-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.item-num {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(108, 99, 255, 0.15);
  padding: 2px 8px;
  border-radius: 20px;
}

.item-numbers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.item-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  display: block;
  margin-bottom: 4px;
}

.item-input {
  background: var(--bg-section);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 8px 10px;
  width: 100%;
  outline: none;
  transition: all 0.2s;
}

.item-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.item-total-display {
  background: rgba(0, 212, 170, 0.1);
  border: 1px solid rgba(0, 212, 170, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent2);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.btn-remove-item {
  background: rgba(255, 94, 125, 0.15);
  border: none;
  color: var(--danger);
  border-radius: 5px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: all 0.2s;
}

.btn-remove-item:hover {
  background: var(--danger);
  color: white;
}

.btn-add-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px;
  background: rgba(108, 99, 255, 0.08);
  border: 1.5px dashed var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 4px;
}

.btn-add-item svg {
  width: 18px;
  height: 18px;
}

.btn-add-item:hover {
  background: rgba(108, 99, 255, 0.15);
  transform: translateY(-1px);
}

/* ===== PREVIEW PANEL ===== */
.panel-preview {
  flex: 1;
  background: #111320;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* inner .preview-scroller scrolls */
  min-width: 0;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: #14172b;
  border-bottom: 1px solid var(--border);
}

.preview-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.preview-label svg {
  width: 15px;
  height: 15px;
  color: var(--accent2);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls button {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.zoom-controls button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

#zoomLevel {
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
  font-weight: 600;
}

.preview-scroller {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 30px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
  /* Critical: allow content to overflow so scroll appears */
  min-height: 0;
}

.preview-scroller::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.preview-scroller::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 10px;
}

.preview-page-wrap {
  /* zoom is applied via JS (wrap.style.zoom) which respects layout flow */
  flex-shrink: 0;
}

/* ===== INVOICE PAPER ===== */
.invoice-paper {
  width: 794px;
  /* A4 at 96dpi */
  min-height: 1123px;
  background: white;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 4px 20px rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  overflow: hidden;
  color: #111;
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-size: 13px;
  position: relative;
}

/* ===== INVOICE CONTENT STYLES ===== */

/* --- HEADER CLASSIC --- */
.inv-header-classic {
  text-align: center;
  padding: 22px 40px 14px;
  border-bottom: 2px solid #1a3a5c;
}

.inv-header-modern {
  padding: 0;
  display: flex;
  align-items: stretch;
}

.inv-header-modern .inv-hm-left {
  background: #1a3a5c;
  color: white;
  padding: 28px 32px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.inv-header-modern .inv-hm-right {
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  background: linear-gradient(135deg, #f8f9fc, #eef0f8);
  min-width: 220px;
}

.inv-header-minimal {
  padding: 28px 40px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #ddd;
}

/* Company name */
.inv-company-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 2px;
  font-family: 'Arial Black', 'Arial', sans-serif;
}

.inv-company-sub {
  font-size: 12px;
  color: #444;
}

.inv-company-name-light {
  color: white;
}

.inv-company-sub-light {
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
}

.inv-doc-type {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #1a3a5c;
  margin-top: 8px;
  text-transform: uppercase;
}

.inv-doc-type-light {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #1a3a5c;
}

.inv-logo-img {
  max-height: 70px;
  max-width: 180px;
  object-fit: contain;
  margin-bottom: 8px;
}

/* DOC INFO BAR */
.inv-doc-info-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 7px 40px;
  background: #f0f3f8;
  border-bottom: 1px solid #d0d8ea;
  font-size: 12px;
}

.inv-doc-info-bar span {
  color: #333;
}

.inv-doc-info-bar strong {
  color: #1a3a5c;
  font-weight: 700;
}

/* CLIENT INFO */
.inv-client-section {
  padding: 12px 40px 10px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.inv-client-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 2px 0;
  font-size: 13px;
  line-height: 1.55;
}

.inv-client-label {
  font-weight: 700;
  white-space: nowrap;
  color: #111;
  min-width: 110px;
}

.inv-client-value {
  color: #222;
}

/* ITEMS TABLE */
.inv-table-wrap {
  padding: 10px 40px;
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.inv-table th {
  padding: 9px 10px;
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  border: 1px solid #999;
  vertical-align: middle;
  line-height: 1.3;
}

.inv-table th:first-child {
  text-align: left;
}

.inv-table td {
  padding: 9px 10px;
  border: 1px solid #bbb;
  vertical-align: top;
  line-height: 1.45;
}

.inv-table td:not(:first-child) {
  text-align: center;
}

.inv-table tbody tr:nth-child(even) {
  background: #f9f9f9;
}

.inv-table tfoot td {
  border: none;
  padding: 4px 10px;
}

/* TOTALS */
.inv-totals-wrap {
  display: flex;
  justify-content: flex-end;
  padding: 4px 40px 10px;
}

.inv-totals-table {
  font-size: 13px;
  min-width: 240px;
}

.inv-totals-table tr td {
  padding: 3px 10px;
  color: #222;
}

.inv-totals-table .label-col {
  text-align: right;
  font-weight: 600;
}

.inv-totals-table .val-col {
  text-align: right;
  font-weight: 600;
}

.inv-totals-table .total-row td {
  font-weight: 800;
  font-size: 14px;
  color: #1a3a5c;
  border-top: 2px solid #1a3a5c;
  padding-top: 7px;
}

/* PAYMENT BOX */
.inv-payment-box {
  margin: 8px 40px 20px;
  border: 1.5px solid;
  border-radius: 2px;
  padding: 11px 16px;
  text-align: center;
  font-size: 12px;
  line-height: 1.65;
}

.inv-payment-title {
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.8px;
  margin-bottom: 5px;
  text-transform: uppercase;
}

/* NOTES */
.inv-notes {
  margin: 0 40px 20px;
  font-size: 11.5px;
  color: #555;
  font-style: italic;
  border-top: 1px solid #e0e4f0;
  padding-top: 10px;
  line-height: 1.5;
}

/* VALIDITY */
.inv-validity {
  margin: 0 40px 8px;
  font-size: 11px;
  color: #888;
  text-align: right;
}

/* WATERMARK BOAT */
.inv-watermark {
  position: absolute;
  bottom: 80px;
  right: -10px;
  opacity: 0.04;
  pointer-events: none;
  width: 340px;
}

/* DIVIDER */
.inv-divider {
  margin: 2px 40px;
  border: none;
  border-top: 1px solid #dce2f0;
}

/* ===== PRINT STYLES ===== */
@media print {
  body {
    background: white !important;
    overflow: visible !important;
  }

  .app-header,
  .panel-form,
  .preview-toolbar,
  .zoom-controls {
    display: none !important;
  }

  .app-main {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .panel-preview {
    display: block !important;
    flex: none !important;
    overflow: visible !important;
  }

  .preview-scroller {
    overflow: visible !important;
    padding: 0 !important;
    display: block !important;
  }

  .preview-page-wrap {
    transform: none !important;
  }

  .invoice-paper {
    width: 100% !important;
    min-height: auto !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  @page {
    margin: 10mm;
    size: A4 portrait;
  }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .app-main {
    flex-direction: column;
    height: auto;
    overflow: auto;
  }

  .panel-form {
    width: 100%;
    max-width: 100%;
    min-width: unset;
  }

  .panel-preview {
    min-height: 500px;
  }

  .preview-page-wrap {
    zoom: 0.5;
  }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.invoice-paper {
  animation: fadeIn 0.3s ease;
}