:root {
  --bg-0: #edf3fb;
  --bg-1: #f7f9fc;
  --panel-bg: #ffffff;
  --line: #d9e2ef;
  --line-strong: #c3cfdf;
  --text: #17314e;
  --text-soft: #48617b;
  --brand: #0f4a8a;
  --brand-2: #1c7ed6;
  --success: #1a7f4b;
  --danger: #ad2d3d;
  --warning: #a56a00;
  --shadow: 0 14px 40px rgba(15, 54, 98, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% 0%, #dfeaf8 0%, var(--bg-1) 45%, var(--bg-0) 100%);
}

body.modal-open {
  overflow: hidden;
}

.app-shell {
  width: min(980px, 95vw);
  margin: 20px auto;
  display: block;
}

.left-panel {
  border-radius: 14px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-header {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.brand-logo {
  width: 132px;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.company-mini h1 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.company-mini p {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--text-soft);
}

.panel-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

label {
  font-size: 0.9rem;
  font-weight: 600;
}

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

select,
input[type="number"] {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text);
  background: #fff;
}

textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
  margin-bottom: 12px;
  line-height: 1.45;
  color: var(--text);
}

textarea:focus,
select:focus,
input:focus,
button:focus {
  outline: 2px solid #91bff0;
  outline-offset: 1px;
}

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

.btn {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 11px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background-color 0.14s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  color: #fff;
  box-shadow: 0 8px 18px rgba(19, 92, 167, 0.22);
}

.btn-success {
  background: linear-gradient(180deg, #28a867, var(--success));
  color: #fff;
  box-shadow: 0 8px 18px rgba(22, 128, 77, 0.2);
}

.btn-secondary {
  background: #eef3fa;
  border-color: var(--line-strong);
  color: var(--text);
}

.btn-outline {
  background: #fff;
  border-color: var(--brand);
  color: var(--brand);
}

.btn:hover {
  transform: translateY(-1px);
}

.tax-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.tax-header h2,
.status-block h2,
.recent-block h2 {
  margin: 0;
  font-size: 0.96rem;
}

.hint {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #c6d5e8;
  border-radius: 999px;
  transition: 0.2s;
}

.slider:before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: 0.2s;
}

.switch input:checked + .slider {
  background-color: #4e9ef0;
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}

.status-area {
  min-height: 58px;
  border: 1px dashed var(--line-strong);
  background: #f8fbff;
  border-radius: 10px;
  padding: 9px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.status-line {
  margin: 0;
}

.status-info {
  color: var(--text-soft);
}

.status-success {
  color: var(--success);
}

.status-warning {
  color: var(--warning);
}

.status-error {
  color: var(--danger);
}

.recent-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.recent-list li {
  margin: 0;
}

.recent-quote {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  padding: 9px 10px;
  cursor: pointer;
}

.recent-quote strong {
  display: block;
  color: var(--brand);
  font-size: 0.88rem;
}

.recent-quote span {
  font-size: 0.8rem;
  color: var(--text-soft);
}

.quote-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vw, 20px);
}

.quote-modal.is-hidden {
  display: none;
}

.quote-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 39, 66, 0.62);
  backdrop-filter: blur(2px);
}

.quote-modal-dialog {
  position: relative;
  width: min(1160px, 100%);
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: #f4f8fd;
  border: 1px solid #cfdced;
  box-shadow: 0 24px 48px rgba(8, 35, 64, 0.24);
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 1px solid #d8e3f1;
  color: var(--text-soft);
  font-size: 0.88rem;
}

.preview-toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.quote-modal-body {
  overflow: auto;
  padding: 14px;
}

.quote-paper {
  width: 210mm;
  min-height: 297mm;
  max-width: 100%;
  margin: 0 auto;
  padding: 16mm;
  background: #fff;
  border: 1px solid #d5dde8;
  box-shadow: 0 18px 30px rgba(10, 39, 71, 0.14);
}

.doc-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-bottom: 2px solid #d7e0ec;
  padding-bottom: 12px;
}

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

.doc-brand img {
  width: 125px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.doc-brand h2 {
  margin: 0 0 4px;
  font-size: 1.08rem;
}

.doc-brand p {
  margin: 0;
  font-size: 0.76rem;
  color: #425f7d;
  line-height: 1.35;
}

.doc-title-wrap {
  text-align: right;
}

.doc-title {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.08em;
  color: #0f4a8a;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
  margin-bottom: 14px;
}

.meta-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfdff;
}

.meta-box strong {
  display: block;
  margin-bottom: 5px;
  font-size: 0.74rem;
  color: #446485;
}

.meta-box span {
  font-size: 0.9rem;
  font-weight: 600;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.items-table thead th {
  background: #f0f5fb;
  color: #375676;
  border: 1px solid #d4deea;
  padding: 7px 6px;
  text-align: left;
}

.items-table tbody td {
  border: 1px solid #dbe4f0;
  padding: 7px 6px;
  vertical-align: top;
}

.items-table td.num,
.items-table th.num {
  text-align: right;
  white-space: nowrap;
}

.items-table td.center,
.items-table th.center {
  text-align: center;
}

.item-name {
  font-weight: 600;
  margin-bottom: 2px;
}

.item-desc {
  color: #4d6883;
}

.unmatched-row {
  background: #fff8f0;
}

.unmatched-pill {
  display: inline-block;
  margin-top: 4px;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.68rem;
  background: #ffe8ce;
  color: #8a4c00;
}

.totals-wrap {
  margin-top: 12px;
  margin-left: auto;
  width: min(320px, 100%);
}

.totals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.totals-table td {
  border: 1px solid #dbe4f0;
  padding: 8px;
}

.totals-table td:last-child {
  text-align: right;
  font-weight: 600;
}

.totals-table tr:last-child td {
  background: #eef5fd;
  font-size: 1rem;
  color: #0f4a8a;
}

.terms {
  margin-top: 14px;
  border-top: 1px solid #dbe4f0;
  padding-top: 10px;
  font-size: 0.8rem;
  color: #445f7b;
  line-height: 1.45;
}

.terms h3 {
  margin: 0 0 7px;
  color: #2f4f71;
  font-size: 0.85rem;
}

.terms p {
  margin: 0 0 4px;
}

.doc-footer {
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px dashed #cad7e8;
  text-align: center;
  color: #436080;
  font-size: 0.84rem;
  font-weight: 600;
}

.no-script {
  width: min(1100px, 95vw);
  margin: 12px auto;
  color: var(--danger);
}

@media (max-width: 1180px) {
  .quote-paper {
    width: 100%;
    min-height: auto;
    padding: 8mm;
  }

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

@media (max-width: 760px) {
  .app-shell {
    width: min(98vw, 980px);
    margin: 8px auto;
  }

  .left-panel {
    padding: 12px;
    border-radius: 12px;
  }

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

  .preview-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .preview-toolbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .preview-toolbar-actions .btn {
    flex: 1;
  }

  .quote-modal {
    padding: 0;
  }

  .quote-modal-dialog {
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: 0;
  }

  .quote-modal-body {
    padding: 10px;
  }
}

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

  body {
    background: #fff;
    margin: 0;
  }

  .app-shell,
  .quote-modal-backdrop,
  .preview-toolbar {
    display: none !important;
  }

  .quote-modal,
  .quote-modal.is-hidden,
  .quote-modal-dialog,
  .quote-modal-body {
    display: block !important;
    position: static !important;
    margin: 0;
    padding: 0;
    width: 100%;
    max-height: none;
    box-shadow: none;
    background: #fff;
    border: 0;
    overflow: visible;
  }

  .quote-paper {
    width: 210mm;
    min-height: 297mm;
    border: 0;
    box-shadow: none;
    margin: 0;
    padding: 12mm;
  }
}
