:root {
  --primary-bg: #f3f4f6;
  --invoice-bg: #f0f0f0;
  --footer-bg: #ebebeb;
  --divider-color: #acacac;
  --text-main: #111827;
  --text-muted: #6b7280;
  --accent: #10b981;
  --border-color: #d1d5db;
  --sidebar-width: 320px;
  --item-spacing: 0px;
  --footer-pos: 70px;
}

* {
  box-sizing: border-box;
  font-family: "Inter", sans-serif;
}

body {
  background-color: var(--primary-bg);
  margin: 0;
  display: flex;
  min-height: 100vh;
}

/* Sidebar de Gestión */
.sidebar {
  width: var(--sidebar-width);
  background: #1c1c1c;
  color: white;
  padding: 25px;
  display: flex;
  flex-direction: column;
  gap: 25px;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

.sidebar h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #94a3b8;
  margin-bottom: 15px;
}
.sidebar-section {
  border-bottom: 1px solid #333;
  padding-bottom: 20px;
}

.sidebar-logo {
  width: 20px;
  margin-bottom: 8px;
  color: var(--accent);
}
.sidebar-logo svg {
  width: 100%;
  height: auto;
  display: block;
}
.sidebar-logo svg path {
  fill: currentColor;
}

.list-item {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.list-item:hover {
  background: rgba(255, 255, 255, 0.08);
}
.list-item.active {
  border: 1px solid var(--accent);
  background: rgba(16, 185, 129, 0.1);
}

.btn-sm-delete {
  color: #f87171;
  padding: 5px;
  opacity: 0.6;
  cursor: pointer;
  border: none;
  background: none;
}
.btn-sm-delete:hover {
  opacity: 1;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  margin-bottom: 5px;
  padding: 5px 0;
}
.section-header h3 {
  margin: 0;
}
.section-header:hover h3 {
  color: var(--accent);
}

.collapsible-menu {
  max-height: 0;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
}
.collapsible-menu.active {
  max-height: 500px;
  opacity: 1;
  margin-bottom: 15px;
  padding-top: 10px;
}

.btn-icon {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s;
  padding: 5px;
}
.section-header:hover .btn-icon,
.collapsible-menu.active + .section-header .btn-icon {
  color: var(--accent);
}
.collapsible-menu.active ~ .section-header .btn-icon i {
  transform: rotate(90deg);
}

/* Controles */
.control-group {
  margin-bottom: 15px;
}
.control-group label {
  display: block;
  font-size: 12px;
  color: #cbd5e1;
  margin-bottom: 8px;
}
.control-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.control-group input[type="color"] {
  width: 100%;
  height: 35px;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  padding: 2px;
}

/* Panel Principal */
.main-content {
  flex: 1;
  padding: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.toolbar {
  width: 800px;
  max-width: 100%;
  background: #ffffff;
  padding: 12px 20px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  border: 1px solid #e5e7eb;
}

.btn {
  cursor: pointer;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}
.btn-primary:hover {
  background: #0d9668;
  transform: translateY(-1px);
  box-shadow: 0 6px 12px -2px rgba(16, 185, 129, 0.3);
}

.btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #e5e7eb;
}
.btn-secondary:hover {
  background: #e5e7eb;
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.btn-outline {
  border: 1px solid #e5e7eb;
  background: white;
  color: var(--text-main);
}
.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* Lienzo de Factura */
.invoice-canvas {
  width: 800px;
  height: 1120px;
  background: var(--invoice-bg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  position: relative;
  color: var(--text-main);
  overflow: hidden;
}

.invoice-body {
  padding: 80px 70px 0px 70px;
  background: inherit;
}

.invoice-footer-section {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-top: 1px solid var(--divider-color);
  padding: 40px 70px var(--footer-pos) 70px;
  background: var(--footer-bg);
}

[contenteditable="true"] {
  outline: none;
  border-radius: 2px;
  transition: background 0.2s;
}
[contenteditable="true"]:hover {
  background: rgba(0, 0, 0, 0.03);
}
[contenteditable="true"]:focus {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

.header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 40px;
  align-items: flex-start;
}

.invoice-left-block h2 {
  font-size: 48px;
  margin: 0 0 32px 0;
  font-weight: 700;
  letter-spacing: -2px;
  line-height: 1; /* Font weight actualizado a 700 */
}

.bill-to {
  margin-bottom: 25px;
}
.bill-to-label {
  font-size: 11px;
  font-weight: 800;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 5px;
  display: block;
}
.bill-to-name {
  font-size: 20px;
  font-weight: 600;
} /* Font weight mantenida a 600 */

.meta-field {
  margin-bottom: 25px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.meta-label {
  font-size: 11px;
  font-weight: 800;
  color: #888;
  text-transform: uppercase;
}
.meta-value {
  font-size: 15px;
  font-weight: 700;
}

.sender-info {
  text-align: right;
}
.sender-info .sender-logo {
  width: 40px;
  margin-left: auto;
  margin-bottom: 32px;
  display: block;
}
.sender-info .sender-logo svg {
  width: 100%;
  height: auto;
  display: block;
}
.sender-info .sender-logo svg path {
  fill: #0f0f0f;
}

.sender-info .name {
  font-size: 20px;
  font-weight: 700;
  display: block;
  margin-bottom: 6px;
  line-height: 1.1;
}
.sender-info .title {
  color: var(--text-muted);
  font-size: 13px;
  display: block;
  margin-bottom: 6px;
  font-style: italic;
}
.sender-info .email {
  color: var(--text-muted);
  font-size: 12px;
  display: block;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  margin-top: 16px;
}
.items-table thead th {
  text-align: left;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--divider-color);
  font-size: 11px;
  font-weight: 800;
  color: #888;
  text-transform: uppercase;
}
.items-table td {
  padding: 0 0 var(--item-spacing) 0;
  vertical-align: top;
  position: relative;
  transition: padding 0.1s;
}
.items-table tbody tr:first-child td {
  padding-top: 24px !important;
}

.item-desc-main {
  font-weight: 700;
  font-size: 15px;
  display: block;
  margin-bottom: 4px;
}
.item-desc-sub {
  font-size: 13px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
}

.subitem-list {
  margin: 0;
  padding-left: 20px;
  list-style-type: disc;
  font-size: 12px;
  color: var(--text-muted);
}
.subitem-item {
  position: relative;
  padding: 1px 0;
  cursor: text;
}

.btn-add-subitem {
  font-size: 10px;
  color: var(--accent);
  background: none;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  margin-top: 10px;
  opacity: 0;
  transition: opacity 0.2s;
}
td:hover .btn-add-subitem {
  opacity: 0.6;
}
.btn-add-subitem:hover {
  opacity: 1 !important;
}

.item-price {
  text-align: right;
  font-weight: 700;
  font-size: 15px;
}

.row-actions {
  position: absolute;
  left: -40px;
  top: 10px;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
}
tr:hover .row-actions {
  opacity: 1;
}
.btn-row-del {
  border: none;
  background: #fee2e2;
  color: #ef4444;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 10px;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 40px;
}
.payment-info h3 {
  font-size: 11px;
  font-weight: 800;
  color: #888;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.payment-methods {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
  color: var(--text-main);
  line-height: 1.8;
}
.payment-methods li::before {
  content: "•";
  color: #888;
  margin-right: 8px;
}

.grand-total {
  color: var(--text-main);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}
.total-label {
  font-size: 11px;
  font-weight: 800;
  color: #888;
  text-transform: uppercase;
}

.invoice-watermark {
  position: absolute;
  right: 70px;
  bottom: 40px;
  pointer-events: none;
  opacity: 0.8; /* Un poco más de opacidad ya que el color es más claro */
}

.invoice-watermark svg {
  width: 28px;
  height: auto;
}

/* --- Mobile Styles --- */
.mobile-header {
  display: none;
  background: #1c1c1c;
  color: white;
  padding: 15px 20px;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 1001;
  border-bottom: 1px solid #333;
}

.mobile-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--accent);
}
.mobile-logo svg {
  width: 24px;
  height: auto;
}

.btn-menu {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
}

@media (max-width: 1024px) {
  body {
    flex-direction: column;
  }

  .mobile-header {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 57px; /* debajo del mobile header */
    width: 280px;
    height: calc(100vh - 57px);
    z-index: 1000;
    transition: left 0.3s ease;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
  }

  .sidebar.active {
    left: 0;
  }

  /* Contenedor principal sin scroll para que la toolbar sea sticky */
  .main-content {
    overflow-x: hidden;
    padding: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
  }

  .toolbar {
    position: sticky;
    top: 57px; /* Debajo del mobile header */
    left: 0;
    width: 100%;
    z-index: 100;
    background: #111827;
    padding: 15px;
    border-bottom: 1px solid #333;
    flex-wrap: wrap;
    gap: 10px;
  }

  .toolbar > div {
    width: 100%;
    justify-content: space-between;
  }

  /* Contenedor de la factura con scroll horizontal */
  .invoice-container {
    width: 100%;
    overflow-x: auto;
    padding: 15px;
    -webkit-overflow-scrolling: touch;
  }

  /* La factura mantiene su ancho fijo para no romper la estructura del PDF */
  .invoice-canvas {
    width: 800px;
    min-width: 800px;
    transform: scale(
      0.9
    ); /* Opcional: un ligero reescalado visual para que se vea mejor al abrir */
    transform-origin: top left;
  }
}

@media print {
  .mobile-header {
    display: none !important;
  }
  .sidebar {
    position: relative;
    left: 0;
    width: var(--sidebar-width);
    display: none !important;
  }
  .invoice-canvas {
    transform: none !important;
    margin: 0 !important;
    width: 800px !important;
  }
}

/* Login Styles */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #111827;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: #1c1c1c;
  padding: 40px;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  border: 1px solid #333;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.login-logo {
  width: 60px;
  height: 60px;
  margin: 0 auto 24px;
  color: var(--accent);
}

.login-card h2 {
  color: white;
  margin-bottom: 8px;
  font-size: 24px;
}
.login-card p {
  color: #94a3b8;
  font-size: 14px;
  margin-bottom: 32px;
}

.login-input-group {
  text-align: left;
  margin-bottom: 20px;
}
.login-input-group label {
  display: block;
  color: #cbd5e1;
  font-size: 13px;
  margin-bottom: 8px;
  font-weight: 600;
}
.login-input-group input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid #333;
  padding: 12px;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  transition: all 0.2s;
}
.login-input-group input:focus {
  border-color: var(--accent);
  outline: none;
  background: rgba(255, 255, 255, 0.08);
}

.login-error {
  color: #f87171;
  font-size: 13px;
  margin-top: 16px;
  font-weight: 600;
}
/* Toggle Switch */
.public-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #334155;
  transition: 0.4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
}

input:checked + .slider {
  background-color: var(--accent);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--accent);
}

input:checked + .slider:before {
  transform: translateX(14px);
}

.slider.round {
  border-radius: 20px;
}

.slider.round:before {
  border-radius: 50%;
}

.table-footer-actions {
  position: relative;
  margin-top: 15px;
  min-height: 32px;
  display: flex;
  justify-content: flex-start;
}

.btn-add-concept {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
  transform: translateY(5px);
}

.table-footer-actions:hover .btn-add-concept {
  opacity: 0.6;
  transform: translateY(0);
}

.btn-add-concept:hover {
  opacity: 1 !important;
  background: rgba(16, 185, 129, 0.05);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.1);
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.loading-logo {
  width: 100px;
  height: auto;
  color: var(--accent);
  animation: pulse 2s infinite ease-in-out;
}

.loading-bar {
  width: 150px;
  height: 3px;
  background: #111;
  border-radius: 10px;
  overflow: hidden;
}

.loading-progress {
  width: 0%;
  height: 100%;
  background: var(--accent);
  animation: progress 1.5s infinite ease-in-out;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.05);
    opacity: 1;
  }
}

@keyframes progress {
  0% {
    width: 0%;
    left: 0;
  }
  50% {
    width: 100%;
    left: 0;
  }
  100% {
    width: 0%;
    left: 100%;
  }
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* Preview Mode Cleanups */
.is-preview * {
  cursor: default !important;
}

.is-preview [contenteditable="false"]:hover {
  background: transparent !important;
}

.is-preview .row-actions,
.is-preview .no-export,
.is-preview .btn-add-concept,
.is-preview .btn-add-subitem {
  display: none !important;
}

.invoice-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100%;
}

/* Floating Preview Actions */
.preview-actions {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
}

.is-preview .preview-actions {
  display: block !important;
}
