:root {
  --ink: #1b1f24;
  --muted: #64707d;
  --line: #d8dee6;
  --paper: #ffffff;
  --canvas: #f4f6f8;
  --panel: #ffffff;
  --primary: #17685f;
  --primary-strong: #0f4f48;
  --accent: #bd4b3f;
  --soft: #e8f3f1;
  --shadow: 0 18px 44px rgba(28, 35, 42, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 0;
  cursor: pointer;
}

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

.workspace {
  padding: 28px;
  overflow: auto;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

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

.app-brand img {
  width: min(260px, 36vw);
  max-height: 82px;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
}

h2 {
  margin-bottom: 16px;
  font-size: 1rem;
}

.doc-mode {
  display: flex;
  gap: 8px;
  padding: 5px;
  background: #e6ebef;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.doc-mode label {
  min-height: 36px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 700;
}

.doc-mode label:has(input:checked) {
  color: #ffffff;
  background: var(--primary);
}

.doc-mode input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

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

.panel {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(20, 26, 32, 0.04);
}

.span-2 {
  grid-column: span 2;
}

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

.panel-heading h2 {
  margin-bottom: 0;
}

.grid-2,
.grid-3,
.totals-grid {
  display: grid;
  gap: 14px;
}

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

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

.totals-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 16px 0;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 104, 95, 0.14);
}

.ghost-button,
.preview-actions button {
  min-height: 38px;
  padding: 0 13px;
  color: #ffffff;
  background: var(--primary);
  border-radius: 6px;
  font-weight: 800;
}

.ghost-button {
  color: var(--primary);
  background: var(--soft);
}

.ghost-button:hover,
.preview-actions button:hover {
  filter: brightness(0.95);
}

.line-items {
  display: grid;
  gap: 9px;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 86px 120px 40px;
  gap: 8px;
}

.icon-button {
  width: 40px;
  height: 40px;
  color: #ffffff;
  background: var(--accent);
  border-radius: 6px;
  font-size: 1.35rem;
  line-height: 1;
}

.preview-shell {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px;
  overflow: auto;
  background: #dfe5ea;
  border-left: 1px solid var(--line);
}

.preview-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.document-preview {
  position: relative;
  min-height: calc(100vh - 82px);
  padding: 30px;
  background: var(--paper);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.document-preview::before {
  content: "";
  position: absolute;
  inset: 180px 32px 160px;
  background: url("dominican-servidesk-logo.png") center / contain no-repeat;
  opacity: 0.06;
  pointer-events: none;
}

.document-preview > * {
  position: relative;
  z-index: 1;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  padding-bottom: 20px;
  border-bottom: 4px solid var(--primary);
}

.receipt-header {
  padding-bottom: 14px;
  border-bottom: 2px solid #2f343a;
  text-align: center;
}

.receipt-logo {
  width: min(320px, 90%);
  max-height: 92px;
  object-fit: contain;
  margin: 0 auto 8px;
}

.receipt-header p {
  margin: 0 0 6px;
  color: #3c444c;
  font-size: 0.85rem;
}

.receipt-header h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 900;
  text-transform: uppercase;
}

.receipt-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 28px;
  padding: 14px 0;
  border-bottom: 1px solid #2f343a;
}

.receipt-meta p {
  margin: 0;
  color: #343b43;
  font-size: 0.86rem;
  line-height: 1.35;
}

.preview-logo {
  display: block;
  width: min(290px, 100%);
  max-height: 86px;
  object-fit: contain;
  object-position: left center;
  margin-bottom: 12px;
}

.brand-block h3 {
  margin: 0 0 8px;
  font-size: 1.45rem;
}

.brand-block p,
.meta-block p,
.preview-section p {
  margin: 0 0 5px;
  color: var(--muted);
  line-height: 1.45;
}

.doc-badge {
  display: inline-block;
  min-width: 138px;
  padding: 8px 12px;
  color: #ffffff;
  background: var(--primary);
  border-radius: 6px;
  text-align: center;
  font-weight: 900;
  text-transform: uppercase;
}

.receipt-header .doc-badge {
  min-width: 170px;
  color: #ffffff;
  background: #245a9a;
}

.preview-section {
  margin-top: 22px;
}

.preview-section h4 {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--primary-strong);
  text-transform: uppercase;
  letter-spacing: 0;
}

.service-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 18px;
}

.service-summary p {
  padding-bottom: 7px;
  border-bottom: 1px solid #edf0f3;
}

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

.items-table th,
.items-table td {
  padding: 8px 7px;
  border-bottom: 1px solid #2f343a;
  text-align: left;
}

.items-table th {
  color: #20262c;
  font-size: 0.78rem;
  text-transform: uppercase;
  border-top: 1px solid #2f343a;
}

.items-table td:nth-child(n+2),
.items-table th:nth-child(n+2),
.totals-table td:nth-child(2) {
  text-align: right;
}

.totals-table {
  width: min(100%, 310px);
  margin: 18px 0 0 auto;
  border-collapse: collapse;
}

.totals-table td {
  padding: 7px 0;
}

.totals-table .grand-total td {
  padding-top: 12px;
  color: #111820;
  border-top: 2px solid #2f343a;
  font-size: 1.15rem;
  font-weight: 900;
}

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

  .preview-shell {
    position: static;
    height: auto;
    border-left: 0;
  }
}

@media (max-width: 720px) {
  .workspace,
  .preview-shell {
    padding: 14px;
  }

  .topbar,
  .panel-heading,
  .preview-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .app-brand img {
    width: min(100%, 330px);
  }

  .form-grid,
  .grid-2,
  .grid-3,
  .totals-grid,
  .service-summary,
  .receipt-meta {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .line-row {
    grid-template-columns: 1fr 72px 96px 40px;
  }

  .document-preview {
    padding: 20px;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .workspace,
  .preview-actions {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .preview-shell {
    height: auto;
    padding: 0;
    overflow: visible;
    background: #ffffff;
    border: 0;
  }

  .document-preview {
    min-height: auto;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
  }
}
