:root {
  --ink: #18233b;
  --muted: #667085;
  --line: #d9dee8;
  --panel: #ffffff;
  --page: #f5f7fb;
  --navy: #002060;
  --blue: #1f5ea8;
  --green: #207567;
  --gold: #b8872f;
  --danger: #b42318;
  --soft-blue: #d3d9eb;
  --shadow: 0 18px 40px rgba(24, 35, 59, 0.12);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: #0d1f3f;
  color: #fff;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
  padding: 6px;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 20px;
}

.brand span {
  color: #c8d3e7;
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #d7deec;
  background: transparent;
  text-align: left;
  padding: 12px;
  border-radius: 6px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.nav-tab span {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

.nav-tab.active {
  background: #fff;
  color: var(--navy);
}

.sidebar-note {
  margin-top: auto;
  color: #c8d3e7;
  font-size: 13px;
  display: grid;
  gap: 7px;
  line-height: 1.35;
}

.sidebar-note strong {
  color: #fff;
  font-size: 14px;
}

.workspace {
  min-width: 0;
  padding: 26px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  font-size: 18px;
  margin-bottom: 0;
}

h3 {
  font-size: 15px;
}

.topbar-actions,
.inline-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

[data-action-scope][hidden] {
  display: none !important;
}

.primary-button,
.dark-button,
.ghost-button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.dark-button {
  background: var(--navy);
  color: #fff;
}

.ghost-button {
  background: #edf1f7;
  color: var(--ink);
  border: 1px solid var(--line);
}

.ghost-button.danger {
  color: var(--danger);
}

.small {
  padding: 8px 10px;
  font-size: 13px;
}

.session-user {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.logout-link {
  color: var(--danger);
}

.view {
  display: none;
  min-width: 0;
}

.view.active {
  display: block;
}

.quote-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.editor {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel,
.summary-panel,
.print-sheet {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
  min-width: 0;
}

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

.panel-heading span {
  color: var(--muted);
  font-size: 13px;
}

.field-grid {
  display: grid;
  gap: 14px;
}

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

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

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

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

.wide {
  grid-column: 1 / -1;
}

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

textarea {
  resize: vertical;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

.items-table th {
  background: var(--navy);
  color: #fff;
  text-align: left;
  padding: 10px;
  font-size: 13px;
}

.items-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  vertical-align: top;
}

.items-table input[type="number"] {
  min-width: 95px;
}

.items-table select {
  min-width: 150px;
}

.item-code {
  min-width: 90px;
}

.items-table .money-cell {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--danger);
  font-weight: 800;
}

.summary-panel {
  padding: 14px;
  display: grid;
  gap: 12px;
  position: sticky;
  top: 24px;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 13px;
  display: grid;
  gap: 4px;
}

.summary-card span {
  color: var(--muted);
  font-size: 13px;
}

.summary-card strong {
  font-size: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.summary-card.total {
  background: var(--soft-blue);
  border-color: #b9c2d7;
}

.payment-proof-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  display: grid;
  gap: 9px;
  background: #fff;
}

.payment-proof-card[hidden] {
  display: none;
}

.payment-proof-card h3,
.payment-proof-card p {
  margin: 0;
}

.payment-proof-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.payment-proof-card input[type="file"] {
  padding: 8px;
  font-size: 12px;
}

.proof-link {
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  word-break: break-word;
}

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

.quick-list button {
  width: 100%;
}

.print-sheet {
  margin-top: 18px;
  padding: 28px;
  max-width: 900px;
  overflow-x: auto;
}

.quote-print-head {
  display: grid;
  grid-template-columns: 1fr 290px;
  gap: 24px;
  align-items: start;
  border-bottom: 3px solid var(--navy);
  padding-bottom: 16px;
}

.print-company {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.print-company img {
  width: 80px;
  max-height: 70px;
  object-fit: contain;
}

.print-company strong {
  color: var(--navy);
  font-size: 18px;
}

.print-title {
  margin: 0 0 12px;
  color: var(--navy);
  text-align: right;
  font-size: 24px;
}

.status-pill {
  display: inline-flex;
  justify-content: center;
  min-width: 112px;
  border-radius: 999px;
  padding: 6px 10px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
}

.status-borrador { background: var(--gold); }
.status-emitida { background: var(--blue); }
.status-aceptada { background: var(--green); }
.status-pagada { background: #185c37; }
.status-cancelada { background: var(--danger); }

.print-meta {
  border-collapse: collapse;
  width: 100%;
}

.print-meta th,
.print-meta td,
.print-items th,
.print-items td,
.print-totals th,
.print-totals td {
  border: 1px solid #bfc7d5;
  padding: 8px;
}

.print-meta th {
  background: #edf1f7;
  text-align: left;
}

.client-box,
.comments-box {
  margin: 18px 0;
  border: 1px solid #bfc7d5;
}

.client-box h3,
.comments-box h3,
.terms-box h3 {
  background: var(--navy);
  color: #fff;
  margin: 0;
  padding: 8px 10px;
}

.client-box div,
.comments-box div,
.terms-box div {
  padding: 10px;
  line-height: 1.45;
}

.print-section-title {
  margin: 18px 0 8px;
  color: var(--navy);
  font-size: 15px;
}

.print-items {
  width: 100%;
  border-collapse: collapse;
}

.print-items th {
  background: var(--navy);
  color: #fff;
  text-align: left;
}

.print-items td:nth-child(n+2),
.print-items th:nth-child(n+2) {
  text-align: right;
  white-space: nowrap;
}

.print-items .num,
.print-items .money,
.print-totals td {
  text-align: right;
  white-space: nowrap;
}

.print-items td:first-child,
.print-items th:first-child {
  word-break: break-word;
}

.print-bottom {
  display: grid;
  grid-template-columns: 1fr 290px;
  gap: 24px;
  margin-top: 18px;
}

.print-totals {
  width: 100%;
  border-collapse: collapse;
}

.print-totals th {
  text-align: left;
}

.print-totals .grand th,
.print-totals .grand td {
  background: var(--soft-blue);
  font-size: 18px;
  font-weight: 800;
}

.thanks {
  text-align: center;
  font-weight: 800;
  color: var(--navy);
  margin: 18px 0 0;
}

.signature-line {
  margin-top: 22px;
  padding-top: 12px;
  border-top: 1px solid #bfc7d5;
  color: var(--ink);
  font-weight: 700;
}

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

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  background: #fff;
}

.list-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.list-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.catalog-form {
  display: grid;
  grid-template-columns: 130px minmax(360px, 1fr) 120px 190px 160px;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.admin-toolbar {
  margin-bottom: 14px;
}

.history-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 160px 160px auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

@media (max-width: 920px) {
  .history-filters {
    grid-template-columns: 1fr;
  }
}

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

.checkline input {
  width: auto;
}

dialog {
  width: min(680px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(13, 31, 63, 0.42);
}

.dialog-panel {
  padding: 18px;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

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

  .summary-panel {
    position: static;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .quick-list {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 18px;
  }

  .topbar,
  .panel-heading,
  .quote-print-head,
  .print-bottom {
    grid-template-columns: 1fr;
    display: grid;
  }

  .field-grid.two,
  .field-grid.three,
  .field-grid.four,
  .summary-panel,
  .catalog-form {
    grid-template-columns: 1fr;
  }

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

  h1 {
    font-size: 24px;
  }
}

@page {
  size: letter;
  margin: 10mm;
}

@media print {
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  html,
  body {
    background: #fff;
    width: auto;
    min-width: 0;
  }

  .sidebar,
  .topbar,
  .editor,
  .summary-panel,
  .view:not(.active) {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .quote-grid,
  .view.active {
    display: block;
    padding: 0;
    margin: 0;
    min-height: 0;
    width: 100%;
  }

  .print-sheet {
    display: block;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0 auto;
    max-width: 190mm;
    overflow: visible;
    padding: 0;
  }

  .quote-print-head,
  .print-bottom {
    break-inside: avoid;
  }

  .print-items,
  .print-meta,
  .print-totals {
    page-break-inside: avoid;
  }
}
