:root {
  --bg: #f4f0e8;
  --panel: rgba(255, 251, 246, 0.88);
  --panel-strong: #fffaf4;
  --warm: #f7e6d9;
  --ink: #192229;
  --muted: #62727c;
  --line: rgba(25, 34, 41, 0.12);
  --accent: #bf5b36;
  --accent-strong: #8d3f25;
  --shadow: 0 24px 64px rgba(25, 34, 41, 0.12);
  --radius: 28px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(191, 91, 54, 0.18), transparent 24%),
    radial-gradient(circle at bottom right, rgba(98, 114, 124, 0.12), transparent 20%),
    linear-gradient(180deg, #fbf7f1 0%, var(--bg) 100%);
}

body.portal-only-mode .app-shell {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1180px;
  margin: 0 auto;
}

body.portal-only-mode .sidebar,
body.portal-only-mode .portal-admin-panel {
  display: none;
}

body.portal-only-mode .main-area {
  min-height: calc(100vh - 48px);
}

body.portal-only-mode .topbar-actions {
  justify-content: flex-end;
}

body.portal-only-mode #seedDemoButton,
body.portal-only-mode #resetDatabaseButton {
  display: none;
}

body.portal-only-mode #portalPanel .content-grid {
  grid-template-columns: minmax(0, 1fr);
}

body.portal-only-mode .portal-client-panel {
  max-width: 980px;
  margin: 0 auto;
}

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

button {
  border: none;
  border-radius: 999px;
  padding: 0.95rem 1.25rem;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, color 180ms ease, opacity 180ms ease;
}

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

.primary {
  background: var(--ink);
  color: white;
}

.secondary {
  background: rgba(191, 91, 54, 0.15);
  color: var(--accent-strong);
}

.ghost {
  background: rgba(25, 34, 41, 0.06);
  color: var(--ink);
}

.compact {
  padding: 0.75rem 1rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  min-height: 100vh;
  padding: 24px;
}

.sidebar,
.main-area {
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.sidebar {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand-block {
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo {
  display: block;
  width: min(220px, 100%);
  height: auto;
}

.main-area {
  padding: 28px;
}

.eyebrow,
.section-kicker,
.paper-label {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
}

.brand-block h1,
.topbar h2 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.intro,
.muted {
  color: var(--muted);
  line-height: 1.6;
}

.nav-tabs {
  display: grid;
  gap: 10px;
}

.tab-button {
  text-align: left;
  border-radius: 18px;
  padding: 0.95rem 1rem;
  background: transparent;
  color: var(--ink);
}

.tab-button.active {
  background: rgba(191, 91, 54, 0.15);
  color: var(--accent-strong);
}

.status-card,
.panel {
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(25, 34, 41, 0.08);
  border-radius: 24px;
  padding: 20px;
}

.pilot-banner {
  background: linear-gradient(135deg, rgba(191, 91, 54, 0.16), rgba(255, 245, 236, 0.92));
  border: 1px solid rgba(191, 91, 54, 0.2);
  border-radius: 24px;
  padding: 20px;
}

.pilot-banner h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
  line-height: 1.1;
}

.pilot-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.warm-panel {
  background: linear-gradient(180deg, rgba(247, 230, 217, 0.85), rgba(255, 251, 246, 0.95));
}

.steps {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
  line-height: 1.7;
}

.topbar,
.section-heading,
.row,
.inline-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.portal-link-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px dashed rgba(25, 34, 41, 0.14);
  background: rgba(255, 255, 255, 0.8);
}

.portal-link-box code {
  display: block;
  margin-top: 6px;
  font-size: 0.82rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  color: var(--accent-strong);
}

.import-warning {
  color: var(--accent-strong);
}

.topbar {
  margin-bottom: 24px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.compact-filter {
  display: grid;
  gap: 6px;
  min-width: 220px;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.metric-card {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(25, 34, 41, 0.08);
  background: rgba(255, 255, 255, 0.78);
}

.metric-card strong {
  font-size: 1.4rem;
  line-height: 1;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-bar,
.auth-session {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(25, 34, 41, 0.08);
}

.auth-bar input {
  min-width: 220px;
  border: 1px solid rgba(25, 34, 41, 0.12);
  background: rgba(255, 255, 255, 0.9);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tab-panel {
  display: none;
  animation: rise 220ms ease;
}

.tab-panel.active {
  display: block;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 420px);
  gap: 18px;
  margin-bottom: 18px;
}

.hero-stats,
.dashboard-grid,
.content-grid,
.invoice-layout {
  display: grid;
  gap: 18px;
}

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

.metric {
  padding: 20px;
  border-radius: 22px;
  background: var(--panel-strong);
  border: 1px solid rgba(25, 34, 41, 0.08);
  display: grid;
  gap: 8px;
}

.metric span {
  color: var(--muted);
  font-size: 0.85rem;
}

.metric strong {
  font-size: 2rem;
  letter-spacing: -0.04em;
}

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

.single-column {
  grid-template-columns: 1fr;
}

.client-detail-panel {
  margin-top: 18px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.summary-list,
.stack-list {
  display: grid;
  gap: 12px;
}

.record-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(244, 240, 232, 0.7);
  border: 1px solid rgba(25, 34, 41, 0.08);
  display: grid;
  gap: 6px;
}

.record-card h4,
.invoice-paper h3,
.section-heading h3,
.section-heading h4 {
  margin: 0;
}

.record-meta {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.client-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  cursor: pointer;
}

.client-list-item.active {
  padding: 10px;
  margin: -10px;
  border-radius: 16px;
  background: rgba(191, 91, 54, 0.08);
}

.client-list-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.client-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.client-list-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.client-list-item .status-pill {
  padding: 0.24rem 0.55rem;
  font-size: 0.74rem;
}

.invoice-list-item {
  display: grid;
  gap: 6px;
}

.invoice-list-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  border-radius: 999px;
  padding: 0.32rem 0.7rem;
  background: rgba(191, 91, 54, 0.12);
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: capitalize;
}

.compact-note {
  max-width: 42ch;
  margin: 0;
}

#portalPanel .panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(255, 249, 242, 0.92));
}

.portal-mobile-shell {
  gap: 16px;
}

.portal-entry-grid {
  align-items: end;
}

.portal-readonly-field input[readonly] {
  color: var(--ink);
  font-weight: 600;
  background: rgba(244, 240, 232, 0.72);
}

#portalPanel .record-card {
  background: rgba(255, 255, 255, 0.88);
}

#portalPanel .record-card h4 {
  line-height: 1.35;
}

.portal-submit-bar {
  display: flex;
  justify-content: flex-start;
}

.portal-live-preview {
  gap: 12px;
  border: 1px solid rgba(25, 34, 41, 0.08);
  box-shadow: 0 14px 28px rgba(25, 34, 41, 0.06);
}

.portal-preview-line {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(25, 34, 41, 0.08);
}

.portal-preview-line h5 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
}

.portal-preview-line .portal-preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 0;
}

.portal-preview-line .portal-preview-meta span {
  font-weight: 600;
}

.portal-preview-formula,
.portal-preview-description {
  margin: 0;
}

.portal-preview-total-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(25, 34, 41, 0.08);
}

.portal-preview-total-row strong {
  text-align: right;
}

.portal-vof-line-actions {
  align-self: stretch;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.editor-form,
.sub-panel,
.items {
  display: grid;
  gap: 14px;
}

.sub-panel {
  padding: 16px;
  border-radius: 20px;
  background: rgba(244, 240, 232, 0.65);
}

.nested-panel {
  margin-top: -2px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(25, 34, 41, 0.08);
}

.logo-upload-preview {
  display: grid;
  gap: 10px;
  justify-items: start;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(25, 34, 41, 0.08);
}

.logo-upload-preview img,
.invoice-company-logo {
  max-width: 180px;
  max-height: 72px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.hidden {
  display: none;
}

.grid {
  display: grid;
  gap: 14px;
}

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

label {
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 600;
}

.checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0.92rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.98);
}

.checkbox-row input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

input,
select,
textarea {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.98);
  padding: 0.92rem 1rem;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(191, 91, 54, 0.22);
  border-color: rgba(191, 91, 54, 0.4);
}

textarea {
  resize: vertical;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) 110px 110px minmax(0, 1.1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.72);
}

.grow {
  min-width: 0;
}

.partner-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.invoice-layout {
  grid-template-columns: minmax(320px, 0.92fr) minmax(520px, 1.08fr);
  align-items: start;
}

.preview-column {
  display: grid;
  gap: 18px;
}

.invoice-paper {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: 44px 52px 42px;
  border-radius: 4px;
  background: #ffffff;
  box-shadow: 0 14px 30px rgba(25, 34, 41, 0.06);
  border: 1px solid rgba(25, 34, 41, 0.1);
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color: #1d252b;
}

.invoice-top,
.client-block,
.notes-block {
  margin-bottom: 32px;
}

.invoice-top {
  display: flex;
  justify-content: space-between;
  gap: 42px;
  align-items: start;
}

.invoice-meta {
  min-width: 254px;
  flex: 0 1 294px;
}

.invoice-title-block {
  margin-bottom: 14px;
}

.invoice-title {
  margin: 0;
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: #1a2228;
}

.meta-row,
.total-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid rgba(25, 34, 41, 0.13);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 20px;
  border-top: 1px solid rgba(25, 34, 41, 0.13);
  border-bottom: 1px solid rgba(25, 34, 41, 0.13);
}

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

th,
td {
  padding: 14px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(25, 34, 41, 0.08);
  vertical-align: top;
  font-variant-numeric: tabular-nums;
}

th {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #60707a;
  font-weight: 700;
}

td {
  font-size: 0.97rem;
}

th:first-child,
td:first-child {
  padding-left: 0;
}

th:last-child,
td:last-child {
  padding-right: 0;
}

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

tbody tr:last-child td {
  border-bottom: none;
}

.totals {
  margin: 24px 0 28px auto;
  max-width: 352px;
}

.totals-sheet {
  margin-top: 28px;
}

.grand {
  font-size: 1.14rem;
  border-bottom: none;
}

.invoice-paper .paper-label {
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
}

.invoice-paper h3 {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.invoice-party {
  max-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.invoice-company-logo {
  margin: 16px 0 0;
}

.client-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.invoice-party .paper-label,
.client-block .paper-label {
  margin: 0;
}

.party-details {
  margin-top: 18px;
}

.invoice-party h3,
.client-block h3 {
  margin: 0;
  padding-bottom: 6px;
}

.invoice-address {
  margin: 0 0 8px;
  white-space: pre-line;
  width: 100%;
  overflow-wrap: anywhere;
}

.invoice-meta-copy {
  margin: 0;
  width: 100%;
}

.invoice-paper .muted {
  color: #60707a;
  line-height: 1.55;
}

.invoice-address {
  white-space: pre-line;
}

.invoice-meta-copy {
  font-size: 0.98rem;
  white-space: pre-line;
}

.meta-line {
  display: block;
  margin-bottom: 2px;
  white-space: normal;
}

.invoice-paper .meta-row span,
.invoice-paper .total-row span {
  color: #4b5a63;
  flex: 0 0 auto;
}

.invoice-paper .meta-row strong,
.invoice-paper .total-row strong {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.invoice-paper .notes-block {
  margin-top: 22px;
}

.client-block {
  max-width: 340px;
}

.notes-block {
  border-top: 1px solid rgba(25, 34, 41, 0.1);
  padding-top: 18px;
}

.empty-state {
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

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

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

  .hero-panel,
  .dashboard-grid,
  .content-grid,
  .invoice-layout {
    grid-template-columns: 1fr;
  }

  .invoice-paper {
    width: 100%;
  }
}

@media (max-width: 760px) {
  .app-shell,
  .sidebar,
  .main-area {
    padding: 16px;
    border-radius: 22px;
  }

  .panel,
  .status-card {
    padding: 16px;
  }

  .two-up,
  .item-row,
  .hero-stats {
    grid-template-columns: 1fr;
  }

  .invoice-top {
    flex-direction: column;
  }

  .invoice-meta,
  .totals,
  .invoice-party,
  .client-block {
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  .topbar,
  .section-heading,
  .row,
  .inline-actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions,
  .quick-actions,
  .record-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .auth-bar input {
    min-width: 0;
    width: 100%;
  }

  #portalPanel input,
  #portalPanel select,
  #portalPanel textarea,
  #portalPanel button {
    font-size: 16px;
  }

  #portalPanel .panel,
  #portalPanel .sub-panel {
    padding: 14px;
  }

  #portalPanel .section-heading h3,
  #portalPanel .section-heading h4 {
    line-height: 1.25;
  }

  #portalPanel .compact-note,
  #portalPanel .muted,
  #portalPanel .record-meta {
    max-width: none;
    font-size: 0.96rem;
    line-height: 1.55;
  }

  #portalPanel .record-card {
    gap: 8px;
    padding: 14px;
    border-radius: 16px;
  }

  #portalPanel .vof-line-row {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  #portalPanel .portal-submit-bar {
    position: sticky;
    bottom: 10px;
    z-index: 5;
    padding-top: 6px;
  }

  #portalPanel .portal-preview-total-row {
    align-items: flex-start;
  }

  #portalPanel .portal-entry-grid {
    grid-template-columns: 1fr;
  }

  #portalLoginSubmitButton,
  #portalSubmitButton,
  #portalAddVofLineButton,
  #portalLogoutButton {
    width: 100%;
    justify-content: center;
  }
}

@media print {
  body {
    background: white;
  }

  body * {
    visibility: hidden;
  }

  #invoicePreview,
  #invoicePreview * {
    visibility: visible;
  }

  .invoice-paper {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    padding: 0;
    margin: 0;
    border: none;
    box-shadow: none;
    background: white;
    font-size: 11pt;
  }

  @page {
    size: A4;
    margin: 14mm;
  }
}
