:root {
  --admin-bg: #f6f4fa;
  --admin-panel: rgba(255, 255, 255, 0.94);
  --admin-text: #1f2937;
  --admin-muted: #64748b;
  --admin-border: #e2e8f0;
  --admin-primary: #5f4a8b;
  --admin-primary-strong: #4f3c76;
  --admin-accent: #f28624;
  --admin-success: #157f58;
  --admin-danger: #b42318;
  --admin-warning: #b7791f;
  --admin-shadow: 0 18px 42px rgba(95, 74, 139, 0.11);
  font-family: "Plus Jakarta Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

body.admin-body {
  margin: 0;
  min-height: 100vh;
  color: var(--admin-text);
  background:
    radial-gradient(circle at 12% 0%, rgba(95, 74, 139, 0.14), transparent 28rem),
    linear-gradient(180deg, var(--admin-bg), #ffffff 38%, #f8fafc);
  overflow-x: hidden;
}

.admin-shell {
  min-height: 100vh;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(226, 232, 240, 0.86);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.admin-header-inner,
.admin-main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.admin-header-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto minmax(170px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 14px 0;
}

.admin-session {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
  min-width: 0;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: center;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.admin-brand img {
  width: auto;
  height: 44px;
}

.admin-brand strong {
  display: block;
  font-size: 0.9rem;
}

.admin-brand span,
.admin-eyebrow,
.muted {
  color: var(--admin-muted);
}

.admin-brand span {
  display: none;
  font-size: 0.75rem;
}

.admin-nav {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  display: none;
  grid-template-columns: 1fr;
  min-width: min(300px, calc(100vw - 24px));
  border: 1px solid var(--admin-border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--admin-shadow);
  padding: 10px;
  overflow: visible;
  z-index: 40;
}

.admin-nav.is-open {
  display: grid;
}

.admin-user-name {
  flex: 0 0 auto;
  color: var(--admin-muted);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.admin-logout-btn {
  flex: 0 0 auto;
}

.admin-menu-toggle {
  display: inline-flex;
  justify-self: end;
  width: 44px;
  min-width: 44px;
  min-height: 40px;
  height: 40px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.admin-logout-btn.icon-only {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 0.95rem;
}

.admin-nav a,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--admin-border);
  padding: 0 14px;
  color: var(--admin-text);
  background: #ffffff;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.admin-nav a:hover,
.btn:hover {
  border-color: rgba(95, 74, 139, 0.38);
  color: var(--admin-primary);
}

.btn.primary {
  border-color: var(--admin-primary);
  background: var(--admin-primary);
  color: #ffffff;
}

.btn.primary:hover {
  background: var(--admin-primary-strong);
  color: #ffffff;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  border-color: rgba(180, 35, 24, 0.22);
  color: var(--admin-danger);
}

.admin-main {
  padding: 28px 0 54px;
}

.auth-body {
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-shell {
  width: min(100%, 460px);
}

.auth-card {
  display: grid;
  gap: 18px;
  border: 1px solid var(--admin-border);
  border-radius: 22px;
  background: var(--admin-panel);
  box-shadow: var(--admin-shadow);
  padding: clamp(24px, 6vw, 38px);
}

.auth-logo {
  width: 180px;
  max-width: 70%;
  height: auto;
}

.auth-card h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3rem);
  letter-spacing: -0.05em;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.page-head h1 {
  margin: 4px 0 6px;
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  letter-spacing: 0;
}

.admin-eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card {
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  background: var(--admin-panel);
  box-shadow: var(--admin-shadow);
}

.card.pad {
  padding: 20px;
}

.dashboard-grid,
.form-grid,
.detail-grid {
  display: grid;
  gap: 16px;
}

.dashboard-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.company-grid {
  display: grid;
  gap: 18px;
}

.company-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 20px;
  background:
    radial-gradient(circle at 92% 0%, rgba(242, 134, 36, 0.18), transparent 24rem),
    linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.92));
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.1);
  padding: 24px;
}

.company-card-head {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
}

.company-card-head h2 {
  margin: 4px 0 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
  letter-spacing: -0.04em;
}

.company-logo {
  width: 98px;
  max-height: 82px;
  flex: 0 0 auto;
  object-fit: contain;
}

.company-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
}

.company-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  border: 1px solid var(--admin-border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  padding: 16px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.05);
}

.kpi-card span {
  display: block;
  color: var(--admin-muted);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.25rem, 2.4vw, 1.7rem);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.kpi-card.kpi-paid {
  border-color: rgba(21, 127, 88, 0.22);
  background: linear-gradient(135deg, #ffffff, rgba(21, 127, 88, 0.1));
}

.kpi-card.kpi-paid strong {
  color: var(--admin-success);
}

.kpi-card.kpi-receivable,
.kpi-card.kpi-danger {
  border-color: rgba(180, 35, 24, 0.22);
  background: linear-gradient(135deg, #ffffff, rgba(180, 35, 24, 0.1));
}

.kpi-card.kpi-receivable strong,
.kpi-card.kpi-danger strong {
  color: var(--admin-danger);
}

.kpi-card.kpi-warning {
  border-color: rgba(183, 121, 31, 0.26);
  background: linear-gradient(135deg, #ffffff, rgba(183, 121, 31, 0.12));
}

.kpi-card.kpi-warning strong {
  color: var(--admin-warning);
}

.kpi-card.kpi-billed {
  border-color: rgba(95, 74, 139, 0.24);
  background: linear-gradient(135deg, #ffffff, rgba(95, 74, 139, 0.11));
}

.kpi-card.kpi-billed strong {
  color: var(--admin-primary);
}

.kpi-card.kpi-tax {
  border-color: rgba(37, 99, 235, 0.22);
  background: linear-gradient(135deg, #ffffff, rgba(37, 99, 235, 0.1));
}

.kpi-card.kpi-tax strong {
  color: #2563eb;
}

.section-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.48fr);
  gap: 16px;
  align-items: start;
}

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

.detail-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
}

.stack {
  display: grid;
  gap: 14px;
}

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

label {
  display: grid;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 800;
}

label.checkbox-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

label.checkbox-line input {
  width: auto;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--admin-text);
  background: #ffffff;
  font: inherit;
  font-size: 0.94rem;
}

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

textarea.auto-resize {
  min-height: 44px;
  overflow: hidden;
  resize: none;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--admin-primary);
  outline: 3px solid rgba(95, 74, 139, 0.16);
}

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

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--admin-muted);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  background: #eef2ff;
  color: var(--admin-primary);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: capitalize;
}

.status-pill.aprobado,
.status-pill.facturado {
  background: #e8f7ef;
  color: var(--admin-success);
}

.status-pill.rechazado,
.status-pill.vencido {
  background: #fff1f0;
  color: var(--admin-danger);
}

.status-pill.enviado {
  background: #fff8e7;
  color: var(--admin-warning);
}

.work-status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: none;
  white-space: nowrap;
}

.work-diseno {
  background: #eef2ff;
  color: #4f46e5;
}

.work-aprobacion {
  background: #fff7ed;
  color: #c2410c;
}

.work-cambios_cliente {
  background: #fff1f0;
  color: var(--admin-danger);
}

.work-aprobado {
  background: #e8f7ef;
  color: var(--admin-success);
}

.work-produccion {
  background: #eff6ff;
  color: #2563eb;
}

.work-terminado {
  background: #f0fdf4;
  color: #15803d;
}

.work-entregado {
  background: #ecfdf5;
  color: #047857;
}

.work-list {
  display: grid;
  gap: 16px;
}

.work-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  padding: 18px;
}

.work-card-main {
  display: grid;
  gap: 15px;
}

.work-summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.work-summary h2 {
  margin: 3px 0 4px;
  font-size: clamp(1.1rem, 2.5vw, 1.45rem);
}

.work-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.work-meta span {
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.78);
}

.work-meta strong {
  display: block;
  color: var(--admin-muted);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.work-form {
  display: grid;
  grid-template-columns: minmax(180px, 0.42fr) minmax(0, 1fr) minmax(180px, 0.45fr);
  gap: 12px;
  align-items: start;
}

.work-form textarea {
  min-height: 78px;
}

.work-image {
  display: grid;
  align-content: start;
}

.work-image-link,
.work-image-empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px solid var(--admin-border);
  border-radius: 14px;
  background: #ffffff;
  color: var(--admin-muted);
  font-weight: 800;
  overflow: hidden;
}

.work-image-link img {
  width: 100%;
  height: 100%;
  max-height: 240px;
  object-fit: cover;
}

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

.totals-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.totals-row.total {
  border-top: 1px solid var(--admin-border);
  padding-top: 12px;
  font-size: 1.18rem;
  font-weight: 900;
}

.alert {
  display: none;
  border-radius: 8px;
  border: 1px solid var(--admin-border);
  padding: 12px 14px;
  font-size: 0.9rem;
  font-weight: 700;
}

.alert.show {
  display: block;
}

.alert.error {
  border-color: rgba(180, 35, 24, 0.28);
  background: #fff1f0;
  color: var(--admin-danger);
}

.alert.success {
  border-color: rgba(21, 127, 88, 0.28);
  background: #e8f7ef;
  color: var(--admin-success);
}

.partida-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 110px 140px 130px 44px;
  gap: 10px;
  align-items: end;
  padding: 12px 0;
  border-bottom: 1px solid var(--admin-border);
}

.partida-row:last-child {
  border-bottom: 0;
}

.icon-btn {
  width: 40px;
  min-width: 40px;
  padding: 0;
}

@media (max-width: 820px) {
  .page-head,
  .detail-grid {
    display: grid;
  }

  .admin-header-inner {
    grid-template-columns: minmax(92px, 1fr) auto minmax(44px, 1fr);
    align-items: center;
    gap: 10px;
  }

  .admin-brand {
    gap: 8px;
  }

  .admin-brand img {
    height: 44px;
  }

  .admin-nav {
    top: calc(100% + 8px);
    left: auto;
  }

  .admin-nav.is-open {
    display: grid;
  }

  .admin-nav a,
  .admin-nav .btn {
    width: 100%;
    min-height: 38px;
    padding: 0 12px;
    font-size: 0.84rem;
    white-space: nowrap;
  }

  .admin-user-name {
    max-width: 92px;
    overflow: hidden;
    font-size: 0.72rem;
    text-overflow: ellipsis;
  }

  .dashboard-actions .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    overflow: visible;
    padding-bottom: 0;
  }

  .dashboard-actions .actions .btn {
    width: 100%;
    min-width: 0;
  }

  .company-card-head,
  .company-title-row,
  .compact-head {
    display: grid;
    justify-items: start;
  }

  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

  .partida-row label:first-child,
  .partida-row .line-total {
    grid-column: 1 / -1;
  }

  .work-card,
  .work-form,
  .work-meta {
    grid-template-columns: 1fr;
  }

  .work-summary {
    display: grid;
  }

  .responsive-table {
    min-width: 0;
  }

  .table-wrap {
    overflow: visible;
  }

  .estimate-sheet-wrap {
    overflow: visible;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr {
    display: block;
    width: 100%;
  }

  .responsive-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "number date"
      "client client"
      "project project"
      "status work"
      "total balance"
      "actions actions";
    gap: 8px 12px;
    border-bottom: 1px solid var(--admin-border);
    padding: 16px 14px;
  }

  .responsive-table td {
    display: block;
    border-bottom: 0;
    padding: 0;
    text-align: left;
    word-break: break-word;
  }

  .responsive-table td::before {
    content: none;
  }

  .responsive-table .doc-type {
    display: none;
  }

  .responsive-table .doc-number {
    grid-area: number;
    font-size: 1rem;
  }

  .responsive-table .doc-client {
    grid-area: client;
    color: var(--admin-text);
    font-size: 0.95rem;
    font-weight: 800;
  }

  .responsive-table .doc-project {
    grid-area: project;
    color: var(--admin-muted);
    font-size: 0.86rem;
  }

  .responsive-table .doc-date {
    grid-area: date;
    color: var(--admin-muted);
    font-size: 0.84rem;
    font-weight: 800;
    text-align: right;
    white-space: nowrap;
  }

  .responsive-table .doc-status {
    grid-area: status;
  }

  .responsive-table .doc-work {
    grid-area: work;
  }

  .responsive-table .doc-status .status-pill {
    width: 100%;
    justify-content: center;
  }

  .responsive-table .doc-work .work-status-pill {
    width: 100%;
  }

  .responsive-table .doc-total {
    grid-area: total;
  }

  .responsive-table .doc-balance {
    grid-area: balance;
    text-align: right;
  }

  .responsive-table .doc-total::before,
  .responsive-table .doc-balance::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--admin-muted);
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .responsive-table .doc-actions {
    display: grid;
    grid-area: actions;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 2px;
  }

  .responsive-table td .btn {
    width: 100%;
  }

  .preview-body .admin-header-inner {
    grid-template-columns: minmax(0, 1fr) auto minmax(42px, 1fr);
    gap: 8px;
  }

  .preview-body .admin-brand {
    width: auto;
  }

  .preview-body .admin-nav {
    display: none;
    width: auto;
  }

  .preview-body .admin-nav.is-open {
    display: grid;
  }

  .preview-body .admin-user-name {
    max-width: 112px;
    text-align: left;
  }

  .preview-session {
    display: grid;
    gap: 5px;
  }

  .preview-session .btn {
    width: auto;
    min-height: 30px;
    padding: 0 9px;
    font-size: 0.72rem;
  }
}

@media (max-width: 560px) {
  .admin-header-inner,
  .admin-main {
    width: min(100% - 20px, 1180px);
  }

  .actions {
    align-items: stretch;
  }

  .btn {
    width: 100%;
  }

  .admin-menu-toggle,
  .preview-menu-toggle,
  .admin-logout-btn.icon-only {
    width: 44px;
    min-width: 44px;
    flex: 0 0 44px;
  }

  .admin-logout-btn.icon-only {
    width: 32px;
    min-width: 32px;
    flex-basis: 32px;
  }

  .admin-nav .btn,
  .admin-nav a {
    width: 100%;
  }

  .admin-header-inner {
    width: min(100% - 14px, 1180px);
  }

  .admin-nav {
    max-width: none;
  }

  .admin-user-name {
    max-width: none;
  }

  .preview-body .admin-user-name {
    max-width: 88px;
  }
}

.preview-main {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.preview-header-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr);
  align-items: center;
}

.preview-session {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
  min-width: 0;
}

.preview-session .admin-user-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-brand {
  justify-self: center;
}

.preview-brand span {
  display: none;
}

.preview-brand img {
  height: 44px;
}

.preview-menu-toggle {
  justify-self: end;
  width: 44px;
  min-width: 44px;
  padding: 0;
}

.preview-nav {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  display: none;
  grid-template-columns: 1fr;
  min-width: min(280px, calc(100vw - 24px));
  border: 1px solid var(--admin-border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--admin-shadow);
  padding: 10px;
}

.preview-nav.is-open {
  display: grid;
}

.preview-nav a,
.preview-nav .btn {
  width: 100%;
}

.editor-main {
  width: min(1480px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.estimate-editor-layout {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) minmax(300px, 30vw);
  gap: 22px;
  align-items: start;
}

.editor-form-panel {
  display: grid;
  gap: 16px;
}

.live-preview-panel {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 106px);
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.live-preview-panel .estimate-sheet {
  width: 8.5in;
  height: 11in;
  min-height: 11in;
  margin: 0;
  display: none;
  transform: scale(var(--live-preview-scale, 0.42));
  transform-origin: top left;
}

.live-preview-panel .estimate-sheet.is-active-page {
  display: block;
}

.live-preview-spacer {
  width: calc(8.5in * var(--live-preview-scale, 0.42));
  height: calc(11in * var(--live-preview-scale, 0.42));
  margin: 0 auto;
  overflow: visible;
}

.live-preview-spacer .estimate-sheet {
  margin-bottom: 0;
}

.live-preview-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

.live-preview-page-label {
  min-width: 92px;
  color: var(--admin-muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.compact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.compact-head h2 {
  margin: 3px 0 0;
  font-size: 1.1rem;
}

.dashboard-actions,
.table-section {
  margin-bottom: 18px;
}

.table-section {
  margin-top: 18px;
}

.table-section-head {
  border-bottom: 1px solid var(--admin-border);
  padding: 18px 20px;
}

.table-section-head h2 {
  margin: 3px 0 0;
}

.inline-total {
  display: grid;
  gap: 2px;
  min-width: 150px;
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.86);
  padding: 9px 12px;
}

.inline-total span {
  color: var(--admin-muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.inline-total strong {
  font-size: 1rem;
}

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

.preview-controls {
  position: sticky;
  top: 92px;
}

.color-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
}

.color-row input[type="color"] {
  min-height: 42px;
  padding: 4px;
}

.estimate-sheet-wrap {
  overflow-x: auto;
  padding: 8px;
}

.preview-main .estimate-sheet-wrap {
  display: grid;
  justify-content: center;
  gap: 18px;
  overflow: visible;
}

.preview-main .estimate-sheet {
  zoom: var(--preview-sheet-scale, 1);
}

.estimate-sheet {
  --sheet-accent: #c99a16;
  --sheet-text: #252933;
  --sheet-muted: #626a78;
  --sheet-logo-size: 156px;
  width: 8.5in;
  height: 11in;
  min-height: 11in;
  margin: 0 auto;
  padding: 0.55in 0.62in;
  background: #ffffff;
  color: var(--sheet-text);
  box-shadow: 0 16px 44px rgba(15, 23, 42, 0.14);
  page-break-after: always;
  overflow: hidden;
}

.estimate-sheet:last-child {
  page-break-after: auto;
}

.sheet-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.8fr);
  gap: 42px;
  align-items: start;
}

.sheet-logo {
  width: var(--sheet-logo-size);
  max-width: 100%;
  height: auto;
  display: block;
}

.sheet-business-name {
  margin: 14px 0 0;
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 0;
}

.sheet-contact {
  display: grid;
  gap: 7px;
  margin: 16px 0 0;
  color: var(--sheet-muted);
  font-size: 0.9rem;
}

.sheet-contact span,
.sheet-lines span {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.sheet-contact i,
.sheet-lines i {
  width: 16px;
  color: var(--sheet-accent);
  text-align: center;
}

.sheet-divider {
  height: 12px;
  margin: 36px 0 40px;
  background:
    repeating-linear-gradient(
      90deg,
      var(--sheet-accent) 0 18px,
      transparent 18px 24px
    );
}

.sheet-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.8fr);
  gap: 42px;
  align-items: start;
}

.sheet-section-label {
  margin: 0 0 12px;
  color: var(--sheet-muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.sheet-client-name {
  margin: 0 0 8px;
  font-size: 1.08rem;
  font-weight: 900;
  text-transform: uppercase;
}

.sheet-lines {
  display: grid;
  gap: 6px;
  color: var(--sheet-muted);
  font-size: 0.92rem;
}

.sheet-title {
  margin: 0;
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0;
}

.sheet-number {
  margin: 5px 0 8px;
  color: var(--sheet-muted);
  font-weight: 700;
}

.sheet-table {
  margin-top: 44px;
  border-top: 3px solid var(--sheet-accent);
  border-bottom: 3px solid var(--sheet-accent);
}

.sheet-table table {
  border-collapse: collapse;
}

.sheet-table th {
  color: var(--sheet-accent);
  font-size: 0.88rem;
  letter-spacing: 0;
  text-align: center;
}

.sheet-table th,
.sheet-table td {
  border-bottom: 1px solid #d6d9df;
  padding: 15px 8px;
  text-align: center;
}

.sheet-table tr:last-child td {
  border-bottom: 0;
}

.sheet-table th:nth-child(2),
.sheet-table td:nth-child(2) {
  text-align: left;
}

.sheet-item-title {
  font-weight: 400;
  white-space: pre-line;
}

.sheet-footer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 48px;
  margin-top: 34px;
}

.sheet-notes h3,
.sheet-signature h3 {
  margin: 0 0 8px;
  font-size: 0.96rem;
}

.sheet-notes p,
.sheet-signature p {
  margin: 0;
  color: var(--sheet-muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.sheet-total-box {
  display: grid;
  gap: 9px;
  font-size: 0.95rem;
}

.sheet-total-row {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.sheet-total-row.grand {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 2px solid var(--sheet-accent);
  font-size: 1.1rem;
  font-weight: 900;
}

.sheet-signature {
  margin-top: 64px;
  text-align: right;
}

.sheet-signature-line {
  display: inline-block;
  width: 190px;
  border-top: 3px solid var(--sheet-accent);
  padding-top: 8px;
  color: var(--sheet-muted);
  font-weight: 800;
}

.sheet-bottom-note {
  margin-top: 48px;
  border-top: 1px solid #d6d9df;
  padding-top: 18px;
  color: var(--sheet-muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

.sheet-continuation-label {
  margin: 22px 0 0;
  color: var(--sheet-muted);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: right;
}

@media (max-width: 980px) {
  .estimate-editor-layout,
  .preview-layout {
    grid-template-columns: 1fr;
  }

  .live-preview-panel,
  .preview-controls {
    position: static;
    max-height: none;
  }

  .live-preview-panel .estimate-sheet {
    width: 8.5in;
    height: 11in;
    min-height: 11in;
    margin: 0 auto;
    display: none;
    transform: scale(var(--live-preview-scale, 0.42));
  }

  .live-preview-panel .estimate-sheet.is-active-page {
    display: block;
  }

  .live-preview-spacer {
    width: calc(8.5in * var(--live-preview-scale, 0.42));
    height: calc(11in * var(--live-preview-scale, 0.42));
    overflow: visible;
  }

  .preview-main {
    width: min(100% - 12px, 1280px);
    padding: 16px 0 40px;
  }

  .preview-main .estimate-sheet-wrap {
    padding: 0;
  }
}

@media (max-width: 760px) {
  .editor-main {
    width: min(100% - 20px, 1480px);
  }

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

  .sheet-table td,
  .sheet-table th {
    min-width: 96px;
  }
}

@media print {
  @page {
    size: letter;
    margin: 0;
  }

  body.admin-body {
    background: #ffffff;
  }

  .admin-header,
  .preview-controls {
    display: none;
  }

  .preview-main,
  .estimate-sheet-wrap {
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  .preview-layout {
    display: block;
  }

  .estimate-sheet {
    width: 8.5in;
    height: 11in;
    min-height: 11in;
    padding: 0.55in;
    box-shadow: none;
    zoom: 1;
  }

  .live-preview-panel .estimate-sheet {
    display: block;
  }

  .live-preview-pagination {
    display: none;
  }
}
