:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-sans-strong: "Aptos", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", "Menlo", "Monaco", "Consolas", "Liberation Mono", monospace;
  --font-serif: Georgia, "Times New Roman", Times, serif;
  --bg: #eff3f8;
  --bg-accent: #f8fbff;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: #ffffff;
  --surface-soft: #f7f9fc;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --muted: #667085;
  --muted-strong: #475467;
  --primary: #0f62fe;
  --primary-strong: #0948bf;
  --primary-soft: rgba(15, 98, 254, 0.1);
  --success: #157347;
  --danger: #d92d20;
  --sidebar-bg: #0b1020;
  --sidebar-bg-soft: rgba(255, 255, 255, 0.06);
  --sidebar-text: #f8fafc;
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.12);
  --shadow-md: 0 16px 34px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 8px 18px rgba(15, 23, 42, 0.06);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(circle at 0% 0%, rgba(15, 98, 254, 0.08), transparent 28%),
    radial-gradient(circle at 100% 0%, rgba(16, 185, 129, 0.08), transparent 24%),
    linear-gradient(180deg, #f7faff 0%, #eff3f8 100%);
}

body.modal-open {
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.view-description,
.panel p,
.sidebar-note span,
.helper-copy {
  color: var(--muted);
}

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

.panel {
  background: var(--surface);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-xl);
  padding: 24px;
  animation: panel-in 0.35s ease;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel-head {
  margin-bottom: 18px;
}

.panel-head-split,
.inline-actions,
.header-actions,
.editor-toolbar,
.modal-actions,
.table-actions,
.total-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head-split,
.total-row,
.workspace-header {
  justify-content: space-between;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #fff;
  box-shadow: 0 14px 28px rgba(15, 98, 254, 0.26);
}

.secondary-button {
  background: linear-gradient(180deg, #ffffff 0%, #f2f6fb 100%);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08), var(--shadow-sm);
}

.ghost-button,
.icon-button {
  background: rgba(15, 23, 42, 0.05);
  color: var(--text);
}

.danger-button {
  background: linear-gradient(135deg, #f97066 0%, #d92d20 100%);
  color: #fff;
}

.small {
  padding: 10px 14px;
  border-radius: 12px;
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.3rem;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover,
.nav-link:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.icon-button:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  border-radius: 14px;
  padding: 13px 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(15, 98, 254, 0.45);
  box-shadow: 0 0 0 4px rgba(15, 98, 254, 0.12);
  background: #fff;
}

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

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

.form-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted-strong);
  font-size: 0.92rem;
}

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

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

.data-table {
  width: 100%;
  min-width: 800px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  text-align: left;
  padding: 16px 12px;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor-table input,
.editor-table select,
.editor-table textarea {
  min-width: 110px;
  padding: 10px 12px;
}

.line-item-copy {
  display: grid;
  gap: 8px;
  min-width: 260px;
}

.line-item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.line-item-ledger-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 12px;
  background: rgba(15, 98, 254, 0.06);
  box-shadow: inset 0 0 0 1px rgba(15, 98, 254, 0.09);
}

.line-item-ledger-field span {
  color: var(--primary-strong);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.line-item-ledger-field input {
  min-width: 124px;
  padding: 6px 8px;
  border: 1px solid rgba(15, 98, 254, 0.14);
  background: rgba(255, 255, 255, 0.88);
  color: var(--primary-strong);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
}

.line-item-copy textarea {
  min-height: 86px;
  resize: vertical;
  line-height: 1.55;
}

.row-total {
  font-weight: 700;
  white-space: nowrap;
}

.line-item-actions-cell {
  white-space: nowrap;
  width: 1%;
}

.line-item-action-stack {
  display: flex;
  align-items: center;
  gap: 10px;
}

.line-item-delete {
  width: 40px;
  height: 40px;
  padding: 0;
  background: linear-gradient(135deg, #fff4f2 0%, #ffe4e0 100%);
  color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(217, 45, 32, 0.14);
}

.line-item-delete svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

@media print {
  .line-item-meta {
    display: none !important;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.82rem;
  font-weight: 700;
  background: rgba(15, 98, 254, 0.1);
  color: var(--primary-strong);
}

.badge.success {
  background: rgba(21, 115, 71, 0.12);
  color: var(--success);
}

.badge.muted {
  background: rgba(71, 84, 103, 0.12);
  color: #475467;
}

.search-input {
  min-width: 280px;
}

.relation-quick-search {
  min-width: 220px;
}

.helper-copy {
  margin: 0 0 18px;
  font-size: 0.92rem;
}

.scope-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.scope-summary.compact {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.scope-card {
  padding: 14px 16px;
  border-radius: 16px;
  background: linear-gradient(180deg, #fbfdff 0%, #f4f7fb 100%);
  border: 1px solid rgba(15, 23, 42, 0.07);
}

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

.scope-card strong {
  margin-bottom: 6px;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.scope-card span {
  font-size: 1rem;
  color: var(--text);
}

#linkedDocumentBadge {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(15, 23, 42, 0.08);
}

#quoteConversionPanel .form-grid {
  grid-template-columns: minmax(0, 240px);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 11, 23, 0.5);
  backdrop-filter: blur(10px);
  z-index: 30;
}

.modal-card {
  width: min(760px, 100%);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  padding: 26px;
}

.modal-card-large {
  width: min(1120px, 100%);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

.lookup-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.logo-preview {
  margin-top: 18px;
  min-height: 112px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #fbfdff 0%, #f6f8fb 100%);
  color: var(--muted);
}

.logo-preview img {
  max-width: 190px;
  max-height: 96px;
  object-fit: contain;
}

.backup-entry-actions {
  margin-top: 14px;
}

.backup-entry-meta {
  display: block;
  color: var(--muted);
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  padding: 14px 16px;
  background: #101828;
  color: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-md);
}

.empty-state {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.preview-canvas {
  min-height: 70vh;
  max-height: 76vh;
  overflow: auto;
  padding: 18px;
  border-radius: 22px;
  background: linear-gradient(180deg, #f4f7fb 0%, #edf1f7 100%);
}

.preview-frame {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 24px 40px rgba(15, 23, 42, 0.12);
}

.print-root {
  display: none;
}

@media (max-width: 1024px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .panel,
  .modal-card {
    padding: 18px;
    border-radius: 22px;
  }

  .search-input {
    min-width: 0;
  }

  .modal {
    padding: 12px;
  }
}
