:root {
  --primary-color: #5d59d9;
  --secondary-color: #9959d9;
  --text-dark: #1a1a1a;
  --text-light: #666;
  --bg-light: #f7f8ff;
  --white: #ffffff;
  --border-color: #e5e7eb;
  --danger: #dc2626;
}

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

body {
  font-family: "Urbanist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #f6f7fb 0%, #eef1ff 100%);
  color: var(--text-dark);
  min-height: 100vh;
  padding: 24px;
  overflow-x: hidden;
}

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

/* Evita que el contenido interno (tablas, flex) rompa el ancho del grid */
.layout > .card {
  min-width: 0;
}

.card {
  background: var(--white);
  border: 1px solid rgba(93, 89, 217, 0.12);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 6px 24px rgba(93, 89, 217, 0.08);
}

.card h1,
.card h2 {
  margin-bottom: 14px;
  font-size: 1.25rem;
  color: var(--primary-color);
}

.preview-title-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.preview-title-row h2 {
  margin-bottom: 0;
  min-width: 0;
}

.preview-title-row .btn-secondary {
  justify-self: end;
}

.section-title {
  font-size: 0.88rem;
  margin: 20px 0 10px;
  letter-spacing: 0.05em;
  color: #4b5563;
  text-transform: uppercase;
  font-weight: 700;
}

.field {
  margin-bottom: 12px;
}

label {
  display: block;
  font-size: 0.87rem;
  margin-bottom: 6px;
  color: #374151;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.93rem;
  font-family: inherit;
  background: #fff;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(93, 89, 217, 0.12);
}

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

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

button {
  border: none;
  border-radius: 9px;
  padding: 11px 16px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-color), #4440b8);
}

.btn-secondary {
  color: #fff;
  background: linear-gradient(135deg, var(--secondary-color), #7a47b8);
}

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
  border: 1px solid #fecaca;
  font-weight: 600;
}

.btn-reset {
  color: #374151;
  background: #fff;
  border: 1px solid var(--border-color);
  font-weight: 600;
}

.btn-reset:hover {
  background: #f9fafb;
  border-color: #d1d5db;
}

.preview-header {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--border-color);
  margin-bottom: 16px;
}

.preview-logo {
  width: auto;
  height: auto;
  max-width: 150px;
  max-height: 80px;
  object-fit: contain;
  display: none;
}

.preview-meta h3 {
  margin-bottom: 4px;
  color: var(--primary-color);
}

.muted {
  color: var(--text-light);
  font-size: 0.88rem;
}

.table-wrapper {
  margin-top: 10px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table {
  min-width: 520px;
}

.table-wrapper-with-toolbar {
  display: flex;
  flex-direction: column;
}

.table-wrapper-with-toolbar .table-scroll {
  flex: 1 1 auto;
  min-width: 0;
}

.table-toolbar {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-start;
  padding: 10px 12px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-light);
}

.btn-add-row {
  min-width: 200px;
  width: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 0;
  background: #fff;
}

th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

th {
  background: var(--bg-light);
  font-size: 0.85rem;
  color: #374151;
}

thead th:first-child {
  border-top-left-radius: 12px;
}

thead th:last-child {
  border-top-right-radius: 12px;
}

td input {
  padding: 8px;
  font-size: 0.88rem;
}

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

.summary {
  margin-top: 16px;
  margin-left: auto;
  width: min(360px, 100%);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.92rem;
}

.summary-row:last-child {
  border-bottom: none;
  font-weight: 700;
  background: var(--bg-light);
  color: #111827;
}

.preview-notes {
  margin-top: 16px;
  background: #fafaff;
  border: 1px solid rgba(93, 89, 217, 0.2);
  border-radius: 10px;
  padding: 12px;
  white-space: pre-line;
  font-size: 0.9rem;
  color: #374151;
}

.small {
  font-size: 0.8rem;
}

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

@media (max-width: 640px) {
  body {
    padding: 12px;
  }

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

  .actions {
    flex-direction: column;
  }

  .actions button {
    width: 100%;
  }

  th,
  td {
    padding: 8px 6px;
    font-size: 0.82rem;
  }

  td input {
    font-size: 0.8rem;
    padding: 6px;
  }
}
