:root {
  --bg: #05070d;
  --panel: rgba(11, 16, 27, 0.82);
  --panel-strong: #0b1020;
  --line: rgba(77, 208, 255, 0.2);
  --text: #f7fbff;
  --muted: #89a3c1;
  --brand: #00a7ff;
  --accent: #8b5cf6;
  --danger: #ff5d8f;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(0, 167, 255, 0.12), transparent 28rem),
    radial-gradient(circle at 88% 10%, rgba(139, 92, 246, 0.12), transparent 30rem),
    linear-gradient(135deg, #030509 0%, #0b1020 48%, #030509 100%);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 24px;
  min-height: 100vh;
  padding: 28px;
}

.editor-panel,
.preview-panel {
  border: 1px solid rgba(93, 211, 255, 0.18);
  border-radius: 18px;
  background: rgba(5, 9, 18, 0.94);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

.editor-panel {
  position: sticky;
  top: 28px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow: auto;
  padding: 24px;
}

.panel-heading {
  margin-bottom: 24px;
}

.eyebrow,
.section-label {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

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

.panel-heading h1,
.preview-toolbar h2 {
  margin-bottom: 8px;
  font-size: clamp(1.65rem, 3vw, 2.6rem);
  letter-spacing: 0;
}

.panel-heading p:last-child {
  margin: 0;
  color: var(--muted);
}

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

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: #dbeafe;
  font-size: 0.92rem;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid rgba(112, 209, 255, 0.2);
  border-radius: 10px;
  outline: none;
  background: rgba(1, 8, 18, 0.76);
  color: var(--text);
  padding: 12px 13px;
  transition:
    border-color 120ms ease,
    background-color 120ms ease;
}

.field select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--brand) 50%),
    linear-gradient(135deg, var(--brand) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 52%,
    calc(100% - 12px) 52%;
  background-size:
    6px 6px,
    6px 6px;
  background-repeat: no-repeat;
}

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

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  background: rgba(2, 12, 26, 0.96);
}

.form-grid {
  display: grid;
  gap: 12px;
}

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

.items-list {
  display: grid;
  gap: 14px;
}

.item-editor {
  display: grid;
  gap: 12px;
  margin: 0;
  border: 1px solid rgba(0, 167, 255, 0.18);
  border-radius: 12px;
  background: rgba(0, 167, 255, 0.045);
  padding: 14px;
}

.item-editor legend {
  padding: 0 8px;
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.add-item-button,
.remove-item-button {
  min-height: 42px;
  border-radius: 10px;
  font-weight: 800;
}

.add-item-button {
  border: 1px solid rgba(0, 167, 255, 0.34);
  background: rgba(0, 167, 255, 0.1);
  color: var(--text);
}

.remove-item-button {
  border: 1px solid rgba(255, 93, 143, 0.26);
  background: rgba(255, 93, 143, 0.08);
  color: #ffd6e2;
}

.remove-item-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.action-bar {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.action-bar button {
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0 16px;
  color: var(--text);
  font-weight: 800;
}

.primary-button {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  box-shadow: 0 10px 22px rgba(0, 167, 255, 0.14);
}

.secondary-button {
  border-color: rgba(0, 167, 255, 0.34) !important;
  background: rgba(0, 167, 255, 0.1);
}

.ghost-button {
  border-color: rgba(255, 255, 255, 0.12) !important;
  background: rgba(255, 255, 255, 0.04);
  color: #c8d7ea !important;
}

.action-bar button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.preview-panel {
  min-width: 0;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid rgba(93, 211, 255, 0.16);
}

.preview-toolbar h2 {
  margin: 0;
  font-size: 1.35rem;
}

.preview-toolbar span {
  border: 1px solid rgba(0, 167, 255, 0.28);
  border-radius: 999px;
  padding: 8px 12px;
  color: #bde9ff;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.preview-frame {
  overflow: auto;
  padding: 28px;
}

.quote-document {
  position: relative;
  isolation: isolate;
  width: min(100%, 900px);
  min-height: 1272px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(0, 167, 255, 0.28);
  border-top: 4px solid var(--brand);
  background: #03070d;
  color: #eaf7ff;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.34);
}

.quote-grid {
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(0, 167, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 167, 255, 0.035) 1px, transparent 1px);
  background-size: 64px 64px;
}

.quote-header,
.quote-title-row,
.quote-meta,
.services-section,
.quote-bottom,
.quote-footer {
  padding-inline: 54px;
}

.quote-header {
  display: flex;
  justify-content: space-between;
  gap: 32px;
  padding-block: 42px 38px;
  border-bottom: 1px solid rgba(0, 167, 255, 0.16);
}

.brand-logo-text {
  display: inline-grid;
  color: var(--brand);
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
}

.brand-logo-text strong {
  color: #fff;
}

.brand-logo-text small {
  margin-top: 9px;
  color: var(--brand);
  font-size: 0.54rem;
  font-weight: 700;
  letter-spacing: 0.72em;
  text-transform: uppercase;
}

.brand-logo-image {
  max-width: 210px;
  max-height: 72px;
  object-fit: contain;
}

.contact-block {
  display: grid;
  gap: 7px;
  color: #8fbbef;
  font-size: 0.86rem;
  font-style: normal;
  text-align: right;
}

.contact-block strong {
  color: #d7f3ff;
}

.quote-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-block: 30px;
  border-bottom: 1px solid rgba(0, 167, 255, 0.14);
}

.quote-title-row h2 {
  margin: 0;
  color: #fff;
  font-size: 2.3rem;
  font-weight: 950;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.quote-code {
  border: 1px solid rgba(0, 167, 255, 0.32);
  background: rgba(0, 167, 255, 0.08);
  color: var(--brand);
  padding: 11px 20px;
  font-family: "Segoe UI Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 0.88rem;
  letter-spacing: 0.18em;
  white-space: nowrap;
}

.quote-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 44px;
  padding-block: 34px;
  border-bottom: 1px solid rgba(0, 167, 255, 0.11);
}

.quote-meta > div {
  border-top: 1px solid rgba(0, 167, 255, 0.28);
  padding-top: 14px;
}

.quote-meta h3 {
  margin-bottom: 6px;
  color: #fff;
  font-size: 1.08rem;
}

.quote-meta span,
.quote-meta dd {
  color: #8fbbef;
}

.inline-label {
  color: #fff;
  font-weight: 800;
}

.quote-meta > div:first-child span {
  display: block;
  margin-top: 7px;
}

.quote-meta dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.quote-meta dl div {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.quote-meta dt {
  color: #fff;
  font-weight: 800;
}

.quote-meta dd {
  margin: 0;
}

.services-section {
  padding-block: 34px 24px;
}

.service-table {
  display: grid;
  border: 1px solid rgba(0, 167, 255, 0.22);
}

[data-preview-items] {
  display: grid;
}

.service-row {
  display: grid;
  grid-template-columns: 40px minmax(140px, 190px) minmax(240px, 1fr) minmax(120px, auto);
  gap: 18px;
  align-items: start;
  padding: 20px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.045);
  color: #b5d9ff;
}

.service-row:first-child {
  border-top: 0;
}

.service-head {
  background: rgba(0, 167, 255, 0.09);
  color: #9bdcff;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.34em;
  text-transform: uppercase;
}

.service-row strong {
  color: #fff;
}

.service-row span:last-child strong {
  color: var(--brand);
  white-space: nowrap;
}

.quote-bottom {
  display: grid;
  grid-template-columns: 1fr minmax(230px, 290px);
  gap: 26px;
  align-items: start;
  padding-block: 24px 54px;
}

.terms-box {
  min-height: 132px;
  border: 1px solid rgba(0, 167, 255, 0.22);
  border-left: 3px solid var(--brand);
  background: rgba(0, 167, 255, 0.035);
  padding: 22px 24px;
}

.terms-box p:last-child {
  margin: 0;
  color: #a9d2ff;
}

.total-box {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(0, 167, 255, 0.24);
  background: linear-gradient(135deg, rgba(0, 167, 255, 0.1), rgba(139, 92, 246, 0.08));
  padding: 22px;
}

.total-box span {
  color: #fff;
  font-size: 0.9rem;
  font-weight: 950;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.total-box strong {
  color: var(--brand);
  font-size: 2rem;
  line-height: 1.1;
  text-align: right;
}

.quote-footer {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid rgba(0, 167, 255, 0.14);
  padding-block: 18px;
  color: rgba(111, 197, 255, 0.7);
  font-family: "Segoe UI Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.history-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(1, 5, 12, 0.78);
}

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

.history-modal {
  width: min(940px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  overflow: hidden;
  border: 1px solid rgba(93, 211, 255, 0.22);
  border-radius: 16px;
  background: #07101d;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.38);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid rgba(93, 211, 255, 0.16);
}

.history-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.history-list {
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding: 18px 20px 20px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  border: 1px solid rgba(0, 167, 255, 0.16);
  border-radius: 12px;
  background: rgba(0, 167, 255, 0.045);
  padding: 16px;
}

.history-item h3 {
  margin-bottom: 6px;
  font-size: 1rem;
}

.history-item p,
.history-item small,
.history-empty {
  margin: 0;
  color: #a9d2ff;
}

.history-item p + p,
.history-item small {
  display: block;
  margin-top: 4px;
}

.history-item strong {
  color: var(--brand);
}

.history-actions {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  gap: 8px;
}

.compact-button {
  min-height: 36px;
  border-radius: 9px;
  padding: 0 12px;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 800;
}

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

  .editor-panel {
    position: static;
    max-height: none;
  }
}

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

  .editor-panel,
  .preview-panel {
    border-radius: 14px;
  }

  .preview-frame {
    padding: 12px;
  }

  .quote-document {
    min-height: auto;
  }

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

  .quote-header,
  .quote-title-row,
  .quote-meta,
  .services-section,
  .quote-bottom,
  .quote-footer {
    padding-inline: 20px;
  }

  .quote-header,
  .quote-title-row,
  .quote-meta,
  .quote-bottom {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: flex-start;
  }

  .contact-block {
    text-align: left;
  }

  .quote-title-row h2 {
    font-size: 1.75rem;
  }

  .quote-code,
  .preview-toolbar span {
    white-space: normal;
  }

  .service-table {
    overflow: auto;
  }

  .service-row {
    min-width: 680px;
  }

  .quote-footer {
    position: static;
    flex-direction: column;
  }

  .history-item,
  .history-actions {
    grid-template-columns: 1fr;
  }

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

@media print {
  body {
    background: #03070d;
  }

  body * {
    visibility: hidden;
  }

  #quote-preview,
  #quote-preview * {
    visibility: visible;
  }

  #quote-preview {
    position: absolute;
    inset: 0 auto auto 0;
    width: 210mm;
    min-height: 297mm;
    border: 0;
    box-shadow: none;
  }

  @page {
    size: A4;
    margin: 0;
  }
}
