:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #d7dee8;
  --text: #1f2937;
  --muted: #687386;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #15803d;
  --warning: #b45309;
  --shadow: 0 12px 30px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}

button:hover {
  border-color: #aab7ca;
}

button.primary,
#uploadAllBtn,
#selectFilesBtn {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

button.primary:hover,
#uploadAllBtn:hover,
#selectFilesBtn:hover {
  background: var(--primary-dark);
}

button.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.app-shell {
  width: min(1420px, calc(100% - 32px));
  margin: 24px auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.odoo-selector-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  color: var(--muted);
  border-color: var(--border);
  padding: 5px 10px;
}
.logout-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.odoo-selector-wrap label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.odoo-selector-wrap select {
  border: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  outline: none;
  padding: 0;
}

.topbar h1 {
  margin: 0 0 5px;
  font-size: 28px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.health-link {
  color: var(--primary);
  text-decoration: none;
}

.app-version {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted, #6b7280);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.tab {
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: #e7ecf3;
}

.tab.active {
  background: var(--panel);
  color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.layout.single {
  grid-template-columns: minmax(0, 1fr);
}

.left-pane,
.right-pane,
.form-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.left-pane {
  padding: 16px;
  position: sticky;
  top: 16px;
}

.right-pane {
  padding: 18px;
}

.drop-zone {
  min-height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  border: 2px dashed #9fb0c6;
  border-radius: 8px;
  background: var(--panel-soft);
  text-align: center;
}

.drop-zone.dragover {
  background: #e8f0ff;
  border-color: var(--primary);
}

.toolbar {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.process-panel {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.process-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.process-header h2 {
  margin: 0;
  font-size: 17px;
}

.process-header button {
  padding: 6px 9px;
  font-size: 13px;
}

.process-summary {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.process-log {
  display: grid;
  gap: 7px;
  max-height: 360px;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.process-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 2px 8px;
  padding: 8px 9px;
  border-left: 3px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
}

.process-item span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.process-item strong {
  min-width: 0;
  font-size: 13px;
  line-height: 1.3;
}

.process-item small {
  grid-column: 2;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.process-item.success {
  border-left-color: var(--success);
}

.process-item.warning {
  border-left-color: var(--warning);
}

.process-item.error {
  border-left-color: var(--danger);
}

.process-item.info {
  border-left-color: var(--primary);
}

h2,
h3 {
  margin: 0 0 12px;
}

.invoice-list {
  display: grid;
  gap: 8px;
}

.invoice-list.empty {
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 18px;
}

.invoice-item {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 4px;
  padding: 10px;
  background: var(--panel-soft);
}

.invoice-item.active {
  border-color: var(--primary);
  outline: 2px solid rgba(37, 99, 235, 0.16);
}

.invoice-item strong {
  overflow-wrap: anywhere;
}

.invoice-item small {
  color: var(--muted);
}

.status {
  width: fit-content;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  background: #e5e7eb;
  color: #374151;
}

.status.lista {
  background: #dcfce7;
  color: var(--success);
}

.status.subida_odoo {
  background: var(--success);
  color: #fff;
  font-weight: 600;
}

.status.subida_odoo::before {
  content: "✓ ";
}

.status.error {
  background: #fee2e2;
  color: var(--danger);
}

.status.subiendo {
  background: #dbeafe;
  color: var(--primary);
}

.status.enviado_gpt {
  background: #e0f2fe;
  color: #0369a1;
}

.status.pendiente_revision {
  background: #fef3c7;
  color: var(--warning);
}

.table-panel {
  margin-bottom: 18px;
}

.table-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.table-header p,
.empty-state p {
  margin: 0;
  color: var(--muted);
}

.empty-state {
  background: var(--panel-soft);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 18px;
}

.select-all {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.select-all input,
.invoice-select input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.invoice-card-list {
  display: grid;
  gap: 10px;
}

.invoice-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.invoice-card.active-card {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.14);
}

.invoice-card.uploaded-card {
  border-color: var(--success);
  border-left-width: 4px;
  background: #f0fdf4;
}

.invoice-card.uploaded-card.active-card {
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.18);
}

.invoice-card-main {
  display: grid;
  grid-template-columns:
    24px
    minmax(118px, 1.35fr)
    minmax(118px, 1.2fr)
    minmax(86px, 0.85fr)
    minmax(86px, 0.7fr)
    minmax(78px, 0.7fr)
    minmax(104px, 0.8fr)
    132px;
  gap: 8px;
  align-items: center;
  padding: 12px;
}

.invoice-select {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
}

.invoice-field {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.invoice-field span:first-child {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.invoice-field strong {
  min-width: 0;
  font-size: 14px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.invoice-file strong,
.invoice-partner strong {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.invoice-card-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: var(--panel-soft);
  border-top: 1px solid var(--border);
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  white-space: normal;
  justify-content: flex-end;
  min-width: 132px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button.primary {
  color: #fff;
}

.icon-button.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.message-cell {
  min-width: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.3;
}

.file-cell,
.partner-cell {
  font-weight: 600;
}

.amount-cell {
  white-space: nowrap;
}

.fiscal-pill {
  display: inline-block;
  width: max-content;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  background: #e5e7eb;
  color: #374151;
}

.fiscal-current {
  background: #dcfce7;
  color: var(--success);
}

.fiscal-previous {
  background: #fef3c7;
  color: var(--warning);
}

.fiscal-old,
.fiscal-future {
  background: #fee2e2;
  color: var(--danger);
}

.fiscal-unknown {
  background: #e5e7eb;
  color: #374151;
}

.form-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 16px;
}

.form-header p {
  margin: 3px 0 0;
  color: var(--muted);
}

.section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 42px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.lines {
  display: grid;
  gap: 10px;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(190px, 2fr) 82px 110px 100px 82px 82px minmax(130px, 1fr) 44px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.icon-danger {
  height: 38px;
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.message-box {
  display: none;
  margin-top: 14px;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  white-space: pre-line;
}

.message-box.show {
  display: block;
}

.message-box.error {
  border-color: #fecaca;
  background: #fff1f2;
  color: #991b1b;
}

.message-box.warning {
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.message-box.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

/* ── Overlay GPT ─────────────────────────────── */
.gpt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.gpt-overlay[hidden] { display: none; }

.gpt-overlay-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.3);
  padding: 2.5rem 2rem 2rem;
  width: min(480px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

.gpt-spinner {
  width: 56px;
  height: 56px;
}

.gpt-spinner-svg {
  width: 100%;
  height: 100%;
  animation: gpt-rotate 1.2s linear infinite;
}

.gpt-spinner-svg circle {
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 90, 150;
  stroke-dashoffset: 0;
  animation: gpt-dash 1.5s ease-in-out infinite;
}

@keyframes gpt-rotate { 100% { transform: rotate(360deg); } }
@keyframes gpt-dash {
  0%   { stroke-dasharray: 1, 150;  stroke-dashoffset: 0; }
  50%  { stroke-dasharray: 90, 150; stroke-dashoffset: -35px; }
  100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124px; }
}

.gpt-overlay-card h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text);
}

.gpt-step {
  margin: 0;
  font-size: 0.9rem;
  color: var(--primary);
  font-weight: 600;
  min-height: 1.4em;
}

.gpt-progress-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}

.gpt-progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.gpt-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.gpt-progress-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 36px;
  text-align: right;
}

.gpt-file-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.gpt-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
}

.gpt-file-item .gpt-file-name {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.gpt-file-icon { font-size: 1rem; flex-shrink: 0; }

.gpt-file-item.waiting  .gpt-file-icon::before { content: "⏳"; }
.gpt-file-item.sending  .gpt-file-icon::before { content: "📤"; }
.gpt-file-item.done     .gpt-file-icon::before { content: "✅"; }
.gpt-file-item.error    .gpt-file-icon::before { content: "❌"; }

.gpt-file-item.done   { border-color: #86efac; background: #f0fdf4; }
.gpt-file-item.error  { border-color: #fca5a5; background: #fef2f2; }
.gpt-file-item.sending { border-color: #93c5fd; background: #eff6ff; }

.gpt-note {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.gpt-stop-btn {
  margin-top: 14px;
  padding: 9px 18px;
  border: 1px solid var(--danger, #d33);
  border-radius: 8px;
  background: transparent;
  color: var(--danger, #d33);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.gpt-stop-btn:hover:not(:disabled) {
  background: var(--danger, #d33);
  color: #fff;
}

.gpt-stop-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
/* ──────────────────────────────────────────────── */

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: 160ms ease;
  pointer-events: none;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-backdrop.show {
  display: grid;
}

.result-modal {
  width: min(620px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.modal-backdrop.success .result-modal {
  border-top: 5px solid var(--success);
}

.modal-backdrop.warning .result-modal {
  border-top: 5px solid var(--warning);
}

.modal-backdrop.error .result-modal {
  border-top: 5px solid var(--danger);
}

.result-modal-header,
.result-modal-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}

.result-modal-header {
  border-bottom: 1px solid var(--border);
}

.result-modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.result-modal-header button {
  padding: 7px 10px;
}

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

.result-modal-body p {
  margin: 0 0 14px;
  color: var(--text);
}

.result-modal-body a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.result-details {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.result-details div {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-soft);
}

.result-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.result-details dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.result-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result-list li {
  display: grid;
  gap: 4px;
  padding: 10px 11px;
  border-left: 4px solid #cbd5e1;
  border-radius: 6px;
  background: var(--panel-soft);
}

.result-list li.success {
  border-left-color: var(--success);
}

.result-list li.error {
  border-left-color: var(--danger);
}

.result-list strong,
.result-list span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.result-list span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.result-list .result-meta {
  color: var(--text);
  font-weight: 500;
}

.result-error-summary {
  color: var(--danger);
  font-weight: 600;
  margin: 4px 0 0;
}

.partner-choice-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.partner-choice {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-soft);
}

.partner-choice input {
  width: 16px;
  height: 16px;
}

.partner-choice span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.partner-choice strong,
.partner-choice small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.partner-choice small {
  color: var(--muted);
}

.modal-inline-action {
  margin-top: 4px;
}

.result-modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .left-pane {
    position: static;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .line-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .right-pane {
    padding: 12px;
  }

  .invoice-card-main {
    grid-template-columns: 24px repeat(3, minmax(0, 1fr));
  }

  .table-actions {
    grid-column: 2 / -1;
    justify-content: flex-start;
  }

  .invoice-select {
    grid-row: span 2;
  }

  .table-actions .icon-button {
    flex: 0 0 38px;
  }

  .invoice-card-meta {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 16px, 1420px);
    margin: 12px auto;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .grid,
  .line-row {
    grid-template-columns: 1fr;
  }

  .invoice-card-main {
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 9px;
  }

  .invoice-field,
  .table-actions {
    grid-column: 2;
  }

  .invoice-select {
    grid-column: 1;
    grid-row: 1;
  }

  .table-actions {
    gap: 8px;
  }

  .table-actions .icon-button {
    flex-basis: 38px;
  }
}
