:root {
  --ink: #13212b;
  --muted: #68737d;
  --line: #dbe2e8;
  --paper: #ffffff;
  --soft: #f4f7fa;
  --orange: #ff5a00;
  --orange-dark: #d94b00;
  --blue-black: #13212b;
  --success: #0d7a45;
  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: #edf1f5;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  color: #fff;
  background: var(--blue-black);
  box-shadow: 0 6px 20px rgba(19, 33, 43, .18);
}

.topbar h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 2px;
  color: #ffb07c;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-mark {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
}

.brand-ring {
  position: absolute;
  inset: 4px;
  border: 5px solid #fff;
  border-right-color: var(--orange);
  border-bottom-color: var(--orange);
  border-radius: 50%;
  transform: rotate(-18deg);
}

.brand-bolt {
  position: absolute;
  left: 14px;
  top: 2px;
  width: 16px;
  height: 39px;
  background: linear-gradient(180deg, #ff7a00, #ff4b00);
  clip-path: polygon(70% 0, 22% 45%, 58% 45%, 20% 100%, 100% 35%, 62% 35%);
}

.icon-button {
  margin-left: auto;
  min-width: 46px;
  height: 38px;
  border-radius: 8px;
  color: #fff;
  background: var(--orange);
  font-weight: 800;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  font-size: 13px;
  font-weight: 800;
}

.top-actions a {
  color: #fff;
  text-decoration: none;
}

.top-actions a:hover {
  text-decoration: underline;
}

.top-actions + .icon-button {
  margin-left: 0;
}

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background: #edf1f5;
}

.login-card {
  width: min(100%, 420px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 34px rgba(19, 33, 43, .13);
}

.login-card img {
  width: 260px;
  max-width: 100%;
  display: block;
  margin-bottom: 18px;
}

.login-card h1 {
  margin: 0 0 18px;
  font-size: 24px;
}

.login-card form {
  display: grid;
  gap: 14px;
}

.login-error,
.login-ok {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.login-error {
  color: #8a1d1d;
  background: #ffecec;
}

.login-ok {
  color: #0d6b3f;
  background: #e9f8ef;
}

.admin-layout {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.admin-form,
.admin-row {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.admin-form {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}

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

.admin-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
  overflow: hidden;
}

.admin-details summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
}

.admin-details-title {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.admin-details-title strong,
.admin-details-title small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.admin-details-title small {
  color: var(--muted);
  font-size: 12px;
}

.admin-details .admin-row {
  margin: 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
}

.admin-row {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.admin-row label,
.admin-form label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 6px;
}

.signer-permissions-row {
  grid-template-columns: 180px minmax(220px, 1fr) auto;
}

.signer-checks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.admin-signature-preview {
  width: 86px;
  height: 42px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.signature-missing {
  color: var(--muted);
  font-size: 12px;
}

.footer-settings-form {
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr);
}

.footer-logo-editor {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(170px, 1fr) minmax(150px, 1fr) auto;
  grid-column: 1 / -1;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.admin-footer-logo-preview {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.sidebar,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.sidebar {
  position: sticky;
  top: 86px;
  height: calc(100vh - 104px);
  padding: 14px;
  overflow: auto;
}

.sidebar-head,
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h2 {
  margin: 0;
  font-size: 16px;
}

.primary,
.secondary {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

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

.secondary {
  color: var(--orange-dark);
  background: #fff1e8;
}

.small {
  min-height: 34px;
  padding-inline: 12px;
  font-size: 13px;
}

.search {
  display: block;
  margin: 14px 0;
}

label {
  display: grid;
  gap: 6px;
  color: #4b5660;
  font-size: 12px;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  font-size: 15px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 90, 0, .14);
}

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

.quote-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  text-align: left;
  background: #fff;
}

.quote-card.active {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 90, 0, .12);
}

.quote-card strong,
.quote-card span {
  display: block;
}

.quote-card strong {
  font-size: 14px;
}

.quote-card span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(390px, 1fr) minmax(420px, 800px);
  align-items: start;
  gap: 18px;
}

.quote-editor {
  display: grid;
  gap: 14px;
}

.panel {
  padding: 16px;
}

.status {
  color: var(--success);
  font-size: 12px;
  font-weight: 800;
}

.grid {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

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

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

.items-head,
.item-row {
  display: grid;
  grid-template-columns: 118px minmax(150px, 1fr) 70px 78px 120px 40px;
  gap: 8px;
  align-items: start;
}

.item-type-manager {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 130px auto;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.items-head {
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.items-editor {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.item-row textarea {
  min-height: 44px;
  padding-top: 10px;
}

.item-type-cell {
  display: grid;
  gap: 6px;
}

.item-unit-cell {
  display: grid;
  gap: 6px;
}

.custom-kind {
  display: none;
}

.custom-unit {
  display: none;
}

.item-row.custom-type .custom-kind {
  display: block;
}

.item-row.custom-unit-type .custom-unit {
  display: block;
}

.item-row.text-only {
  grid-template-columns: 160px minmax(0, 1fr) 40px;
}

.item-row.text-only [data-price-field] {
  display: none;
}

.item-row.text-only textarea {
  min-height: 78px;
}

.remove-item {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: #9d1c1c;
  background: #ffecec;
  font-size: 22px;
  line-height: 1;
}

.helper {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.quote-page {
  width: min(100%, 760px);
  min-height: 1075px;
  margin: 0 auto;
  padding: 22px 28px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 12px 34px rgba(19, 33, 43, .13);
}

.quote-doc-header {
  display: grid;
  gap: 8px;
}

.doc-top-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 26px;
  align-items: start;
}

.doc-logo img {
  width: 100%;
  max-width: 490px;
  height: auto;
  display: block;
  object-fit: contain;
}

.doc-title {
  padding: 12px 14px;
  border: 2px solid rgba(255, 90, 0, .75);
  border-radius: 8px;
  text-align: right;
}

.doc-title h2 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}

.doc-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  color: var(--muted);
  font-size: 10px;
}

.doc-meta strong {
  color: var(--ink);
}

.company-box {
  padding: 10px 16px;
  border: 1px solid rgba(19, 33, 43, .22);
  border-radius: 8px;
  background: rgba(255, 255, 255, .7);
}

.client-box {
  margin-top: 14px;
  padding: 12px 16px;
  border: 1px solid rgba(19, 33, 43, .22);
  border-radius: 8px;
}

.party.right {
  text-align: right;
}

.party-label {
  color: #111;
  font-size: 13px;
  font-weight: 700;
}

.party h3 {
  margin: 4px 0 9px;
  font-size: 17px;
}

.party p {
  margin: 0;
  color: #101820;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-line;
}

.company-box .party p {
  display: grid;
  gap: 2px;
  white-space: normal;
}

.company-name {
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

.client-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-top: 8px;
  font-size: 13px;
  align-items: start;
}

.client-detail-col {
  min-width: 0;
  padding: 0 16px;
  border-left: 1px solid rgba(19, 33, 43, .18);
}

.client-detail-col:first-child {
  padding-left: 0;
  border-left: 0;
}

.client-detail-col:last-child {
  padding-right: 0;
}

.client-detail-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  margin: 3px 0;
}

.client-detail-row strong {
  color: var(--ink);
  font-weight: 700;
}

.client-detail-row span {
  color: #101820;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.doc-table {
  width: 100%;
  margin-top: 18px;
  border-collapse: collapse;
  font-size: 10px;
}

.doc-table th {
  padding: 9px 6px;
  color: #fff;
  background: var(--orange);
  font-size: 8px;
  text-align: right;
  text-transform: uppercase;
}

.doc-table th:first-child,
.doc-table td:first-child {
  text-align: left;
}

.doc-table td {
  padding: 8px 6px;
  border-bottom: 1px solid #eef2f5;
  text-align: right;
  vertical-align: top;
}

.doc-table tr:nth-child(even) td {
  background: #f7fafc;
}

.item-desc {
  max-width: 245px;
}

.item-kind {
  display: block;
  margin-bottom: 3px;
  color: var(--orange-dark);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.text-only-doc {
  padding: 12px 10px !important;
  text-align: left !important;
  white-space: pre-line;
}

.doc-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 28px;
  margin-top: 18px;
}

.doc-bottom h3 {
  margin: 0 0 10px;
  font-size: 13px;
}

.doc-bottom p {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-line;
}

.totals {
  display: grid;
  gap: 8px;
  font-size: 11px;
}

.total-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.total-line strong {
  font-weight: 700;
}

.grand-total {
  margin-top: 5px;
  padding: 11px;
  background: #fff1e8;
  font-size: 13px;
  font-weight: 700;
}

.signature {
  margin-top: 32px;
  text-align: center;
}

.signature img {
  width: 220px;
  max-height: 118px;
  object-fit: contain;
  display: block;
  margin: 0 auto 4px;
}

.signature-empty {
  color: var(--muted);
  font-size: 11px;
  min-height: 54px;
}

.signature-line {
  width: 210px;
  height: 1px;
  margin: 8px auto 6px;
  background: var(--ink);
}

.signature strong {
  display: block;
  font-size: 11px;
}

.signature-role {
  margin-top: 2px;
  font-weight: 700;
}

.signature span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.doc-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px solid rgba(19, 33, 43, .16);
}

.doc-footer-company {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.doc-footer-contact {
  display: grid;
  justify-items: end;
  gap: 4px;
  color: #0b78ff;
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.doc-footer-contact span {
  overflow-wrap: anywhere;
}

.doc-footer-contact a {
  color: #0b78ff;
  text-decoration: none;
}

.doc-footer-logos {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.doc-footer-logos a,
.doc-footer-logo-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  text-decoration: none;
}

.doc-footer-logos img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

@media (max-width: 1180px) {
  .layout,
  .workspace {
    grid-template-columns: 1fr;
  }

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

  .quote-list {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar {
    flex-wrap: wrap;
  }

  .topbar h1 {
    font-size: 17px;
  }

  .top-actions {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .layout {
    padding: 12px;
  }

  .admin-layout {
    padding: 10px;
    gap: 12px;
  }

  .admin-form,
  .admin-row,
  .signer-permissions-row {
    grid-template-columns: 1fr;
  }

  .footer-settings-form,
  .footer-logo-editor {
    grid-template-columns: 1fr;
  }

  .admin-details summary {
    grid-template-columns: minmax(0, 1fr) 74px;
    gap: 8px;
    padding: 10px;
  }

  .admin-signature-preview {
    width: 72px;
    height: 36px;
  }

  .signer-checks {
    grid-template-columns: 1fr;
    max-height: 240px;
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

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

  .items-head {
    display: none;
  }

  .item-type-manager {
    grid-template-columns: 1fr;
  }

  .item-row {
    grid-template-columns: 1fr 1fr 40px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .item-row textarea {
    grid-column: 1 / -1;
  }

  .item-row [data-field="unitPrice"] {
    grid-column: 1 / 3;
  }

  .item-row.text-only {
    grid-template-columns: 1fr 40px;
  }

  .item-row.text-only textarea {
    grid-column: 1 / 2;
  }

  .quote-page {
    width: 100%;
    min-height: auto;
    padding: 16px;
  }

  .quote-doc-header {
    grid-template-columns: 1fr;
  }

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

  .doc-title {
    text-align: left;
  }

  .client-details {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .client-detail-col {
    padding: 0;
    border-left: 0;
  }

  .client-detail-row {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .doc-table {
    font-size: 9px;
  }

  .doc-table th,
  .doc-table td {
    padding: 7px 4px;
  }

  .party.right {
    text-align: left;
  }

  .doc-footer {
    grid-template-columns: 1fr;
  }

  .doc-footer-contact {
    justify-items: start;
    text-align: left;
  }

  .doc-footer-logos {
    justify-content: flex-start;
  }
}

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

  .no-print {
    display: none !important;
  }

  .layout,
  .workspace {
    display: block;
    padding: 0;
  }

  .quote-page {
    width: 210mm;
    min-height: auto;
    border: 0;
    box-shadow: none;
    padding: 9mm 11mm;
    font-family: Arial, Helvetica, sans-serif;
  }

  .quote-page,
  .quote-page * {
    font-synthesis: none;
    -webkit-font-smoothing: antialiased;
  }

  .quote-doc-header {
    display: grid;
    gap: 7px;
    align-items: start;
  }

  .doc-top-row {
    display: grid;
    grid-template-columns: 1fr 66mm;
    gap: 9mm;
    align-items: start;
  }

  .doc-logo img {
    width: 118mm;
    max-width: 100%;
  }

  .doc-title {
    padding: 10px 12px;
    border: 2px solid rgba(255, 90, 0, .75);
    border-radius: 8px;
    text-align: right;
  }

  .company-box {
    padding: 9px 13px;
    border: 1px solid rgba(19, 33, 43, .22);
    border-radius: 8px;
    background: transparent;
  }

  .client-box {
    margin-top: 6mm;
    padding: 9px 13px;
    border: 1px solid rgba(19, 33, 43, .22);
    border-radius: 8px;
  }

  .client-details {
    grid-template-columns: 1fr 1fr;
  }

  .client-detail-col {
    padding: 0 12px;
    border-left: 1px solid rgba(19, 33, 43, .18);
  }

  .client-detail-col:first-child {
    padding-left: 0;
    border-left: 0;
  }

  .doc-table {
    table-layout: fixed;
    page-break-inside: auto;
    break-inside: auto;
    font-size: 9.5px;
  }

  .doc-table th,
  .doc-table td {
    padding: 6px 5px;
  }

  .doc-table th:nth-child(1),
  .doc-table td:nth-child(1) {
    width: 34%;
  }

  .doc-table th:nth-child(2),
  .doc-table td:nth-child(2),
  .doc-table th:nth-child(3),
  .doc-table td:nth-child(3) {
    width: 10%;
  }

  .doc-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .doc-bottom {
    display: grid;
    grid-template-columns: 1fr 60mm;
    gap: 8mm;
    margin-top: 6mm;
  }

  .doc-footer {
    grid-template-columns: 1fr 58mm;
    gap: 8mm;
    margin-top: 6mm;
    padding-top: 3mm;
  }

  .doc-footer-logos img {
    width: 5mm;
    height: 5mm;
  }

  .signature {
    text-align: center;
  }

  .signature img {
    width: 55mm;
    max-height: 30mm;
    margin: 0 auto 2mm;
  }

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