  @import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');

  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    font-family: 'DM Sans', sans-serif;
    background: #0f1117;
    color: #e0e0e0;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 64px 20px 40px;
  }

  h1 { font-size: 1.6rem; font-weight: 700; color: #fff; margin-bottom: 6px; letter-spacing: -0.02em; }
  .subtitle { font-size: 0.85rem; color: #888; margin-bottom: 32px; }

  .container { width: 100%; max-width: 680px; }

  .drop-zone {
    border: 2px dashed #2a2d37; border-radius: 12px; padding: 28px 20px;
    text-align: center; cursor: pointer; transition: all 0.2s ease;
    position: relative; background: #16181f; margin-bottom: 20px;
  }
  .drop-zone:hover, .drop-zone.dragover { border-color: #4a7cff; background: #1a1f2e; }
  .drop-zone.loaded { border-color: #34d399; background: #141f1b; }
  .drop-zone-label { font-weight: 600; font-size: 0.9rem; color: #ccc; margin-bottom: 4px; }
  .drop-zone-hint { font-size: 0.75rem; color: #666; }
  .drop-zone.loaded .drop-zone-hint { color: #34d399; }
  .drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

  .parsed-data {
    display: none;
    background: #16181f;
    border: 1px solid #2a2d37;
    border-radius: 12px;
    margin-bottom: 20px;
    /* Lock to exact same height as PDF preview panel */
    height: calc(100vh - 100px);
    min-height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    flex-direction: column;
    overflow: hidden;
  }
  .parsed-data.visible { display: flex; }

  /* Fixed top — customer, IDs, description, total, breakdown, lineitems label */
  .pd-header {
    flex-shrink: 0;
    padding: 20px 20px 0;
  }

  /* Middle — grows to fill remaining space, line items scroll inside */
  .pd-lineitems {
    flex: 1;
    min-height: 0;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
  }

  /* The actual scrolling list — fills pd-lineitems exactly */
  .line-items-body {
    background: #12141a; border: 1px solid #1e2029; border-top: none;
    border-radius: 0 0 8px 8px; padding: 8px 0;
    flex: 1;
    min-height: 0;
    overflow-y: scroll;
  }

  /* Fixed bottom — totals, SC fields, submit button */
  .pd-footer {
    flex-shrink: 0;
    padding: 12px 20px 16px;
    border-top: 1px solid #1e2029;
  }

  /* Pinned footer — submit button always visible */
  .parsed-data-footer {
    padding: 0 20px 16px;
    flex-shrink: 0;
  }

  /* Line items wrapper — fixed, doesn't stretch */
  .parsed-data-lineitems {
    flex-shrink: 0;
    padding: 0 20px;
  }

  .field-group { margin-bottom: 14px; }
  .field-label { font-size: 0.75rem; font-weight: 600; color: #888; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
  .field-value {
    background: #1e2029; border: 1px solid #2a2d37; border-radius: 8px;
    padding: 10px 12px; font-size: 0.85rem; color: #e0e0e0; font-family: inherit;
  }
  .field-value.editable { width: 100%; outline: none; border-color: #3a3d47; }
  .field-value.editable:focus { border-color: #4a7cff; }
  input.field-value.editable { height: 40px; }
  select.field-value.editable { height: 40px; cursor: pointer; -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
  }

  .field-row { display: flex; gap: 12px; }
  .field-row .field-group { flex: 1; }

  .field-value.readonly { color: #aaa; background: #191b22; }

  /* ── Header bar: customer + portal + ATF ── */
  .header-bar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #2a2d37;
  }
  .header-left { display: flex; align-items: center; gap: 10px; }
  .customer-name { font-weight: 700; font-size: 1.05rem; color: #fff; }
  .customer-name.not-found { color: #888; font-weight: 500; }

  .portal-badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 6px;
    font-size: 0.68rem; font-weight: 600; white-space: nowrap;
  }
  .portal-badge.sc { background: #1a2a3a; color: #60a5fa; }
  .portal-badge.other { background: #2a2a1a; color: #fbbf24; }
  .portal-badge.none { background: #2a2d37; color: #666; }

  .header-right { display: flex; align-items: center; gap: 8; }
  .atf-label { font-size: 0.7rem; color: #666; font-weight: 500; }

  /* ATF toggle switch */
  .atf-toggle {
    position: relative; display: inline-block; width: 40px; height: 22px;
    cursor: pointer;
  }
  .atf-toggle input { opacity: 0; width: 0; height: 0; }
  .atf-slider {
    position: absolute; inset: 0; background: #2a2d37; border-radius: 11px;
    transition: background 0.2s ease;
    border: 1px solid #3a3d47;
  }
  .atf-slider::before {
    content: ''; position: absolute; width: 16px; height: 16px;
    left: 2px; bottom: 2px; background: #666;
    border-radius: 50%; transition: transform 0.2s ease, background 0.2s ease;
  }
  .atf-toggle input:checked + .atf-slider { background: #1a3a1a; border-color: #34d399; }
  .atf-toggle input:checked + .atf-slider::before { transform: translateX(18px); background: #34d399; }

  /* ── Compact ID strip ── */
  .id-strip {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    margin-bottom: 14px; padding: 8px 12px;
    background: #12141a; border-radius: 8px;
    font-size: 0.75rem; border: 1px solid #1e2029;
  }
  .id-item { display: flex; align-items: center; gap: 4px; }
  .id-label { color: #555; font-weight: 600; text-transform: uppercase; font-size: 0.65rem; }
  .id-value { color: #aaa; font-family: monospace; font-weight: 500; letter-spacing: 0.02em; }
  .id-strip .pathway-wrapper { margin-left: auto; }
  .pathway-inline {
    background: #1e2029; border: 1px solid #3a3d47; border-radius: 6px;
    padding: 2px 10px; color: #e0e0e0; font-size: 0.75rem;
    font-weight: 500; cursor: pointer; font-family: inherit;
    -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%23666' d='M5 7L1 3h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 8px center; padding-right: 24px;
    height: 26px;
  }

  /* ── Collapsible section ── */
  .collapsible-header {
    display: flex; align-items: center; gap: 6px;
    cursor: pointer; margin-bottom: 4px; user-select: none;
  }
  .collapsible-label { font-size: 0.7rem; font-weight: 600; color: #555; text-transform: uppercase; letter-spacing: 0.05em; }
  .collapsible-arrow { font-size: 0.6rem; color: #444; transition: transform 0.2s; }
  .collapsible-arrow.open { transform: rotate(180deg); }

  .description-box {
    background: #12141a; border: 1px solid #1e2029; border-radius: 8px;
    padding: 6px 12px; font-size: 0.78rem; line-height: 1.5; color: #888;
    max-height: 24px; overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    white-space: nowrap; text-overflow: ellipsis;
  }
  .description-box.expanded {
    max-height: 200px; padding: 10px 12px;
    white-space: pre-wrap; text-overflow: unset; overflow-y: auto;
  }

  /* ── Grand total card ── */
  .grand-total-card {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; margin-bottom: 14px;
    background: linear-gradient(135deg, #1a1e2e 0%, #16181f 100%);
    border: 1px solid #2a2d47; border-radius: 10px;
  }
  .grand-total-label { font-size: 0.75rem; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }
  .grand-total-value { font-size: 1.3rem; font-weight: 700; color: #fff; font-family: monospace; letter-spacing: -0.02em; }

  /* ── Breakdown bar ── */
  .breakdown-bar {
    display: flex; height: 6px; border-radius: 3px; overflow: hidden;
    background: #1e2029; gap: 1px; margin-bottom: 4px;
  }
  .breakdown-bar-seg { border-radius: 1px; opacity: 0.8; }

  /* ── Breakdown chips ── */
  .breakdown-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
  .breakdown-chip {
    display: flex; align-items: center; gap: 5px;
    padding: 4px 8px; border-radius: 6px; font-size: 0.72rem; font-weight: 500;
  }
  .breakdown-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
  .breakdown-chip-label { color: #888; }
  .breakdown-chip-value { font-weight: 600; font-family: monospace; }

  /* ── Collapsible line items ── */
  .line-items-header {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; padding: 8px 12px; user-select: none;
    background: #12141a; border: 1px solid #1e2029;
    border-radius: 8px; transition: border-radius 0.2s;
  }
  .line-items-header.open { border-radius: 8px 8px 0 0; }
  .line-items-header-left { display: flex; align-items: center; gap: 8px; }
  .line-items-count { font-size: 0.65rem; color: #444; font-weight: 500; }
  /* Legacy (kept for backward compat with section-title uses) */
  .section-title {
    font-size: 0.9rem; font-weight: 700; color: #fff;
    margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid #2a2d37;
  }
  .customer-badge {
    display: inline-block; padding: 3px 10px; border-radius: 6px;
    font-size: 0.75rem; font-weight: 600;
  }
  .customer-badge.configured { background: #1a3a1a; color: #34d399; }
  .customer-badge.detected { background: #2a2a1a; color: #fbbf24; }
  .customer-badge.unknown { background: #2a2d37; color: #888; }

  .pathway-tag {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 0.7rem; font-weight: 600; margin-left: 8px;
  }
  .pathway-tag.ready { background: #1a3a1a; color: #34d399; }
  .pathway-tag.pending { background: #3a2a1a; color: #fbbf24; }

  .line-items-section {
    margin-bottom: 14px;
  }
  .line-item-row {
    display: flex; gap: 6px; align-items: center;
    padding: 5px 12px; font-size: 0.78rem;
    border-bottom: 1px solid #1a1c24;
  }
  .line-item-row:last-child { border-bottom: none; }
  .line-item-type { width: 44px; color: #555; font-weight: 600; text-transform: uppercase; font-size: 0.62rem; flex-shrink: 0; }
  .line-item-desc { flex: 1; color: #999; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.76rem; }
  .line-item-amount { width: 72px; text-align: right; color: #ccc; font-weight: 500; font-family: monospace; font-size: 0.78rem; flex-shrink: 0; }

  .totals-row {
    display: flex; gap: 8px; align-items: center; padding-top: 8px;
    border-top: 1px solid #2a2d37; margin-top: 8px; font-size: 0.8rem;
  }
  .totals-label { flex: 1; text-align: right; color: #888; font-weight: 600; text-transform: uppercase; font-size: 0.7rem; }
  .totals-amount { width: 90px; text-align: right; color: #e0e0e0; font-weight: 600; }

  .btn {
    width: 100%; padding: 14px; border: none; border-radius: 10px;
    font-family: inherit; font-size: 0.95rem; font-weight: 600;
    cursor: pointer; transition: all 0.2s ease; margin-bottom: 10px;
  }
  .btn-primary { background: #4a7cff; color: #fff; }
  .btn-primary:hover:not(:disabled) { background: #5d8bff; transform: translateY(-1px); }
  .btn-primary:disabled { background: #2a2d37; color: #555; cursor: not-allowed; }

  .status {
    margin-top: 0; padding: 14px 18px; border-radius: 10px;
    font-size: 0.82rem; line-height: 1.5; display: none;
  }
  .status.success { display: block; background: #141f1b; border: 1px solid #1a3d2a; color: #34d399; }
  .status.error { display: block; background: #1f1417; border: 1px solid #3d1a1a; color: #f87171; }
  .status.warning { display: block; background: #1f1c14; border: 1px solid #3d351a; color: #fbbf24; }

  .suggest-list {
    display: none;
    position: absolute;
    left: 0; right: 0; top: 100%;
    background: #1e2029;
    border: 1px solid #3a3d47;
    border-radius: 0 0 8px 8px;
    z-index: 10;
    max-height: 140px;
    overflow-y: auto;
  }
  .suggest-list.visible { display: block; }
  .suggest-item {
    padding: 8px 12px;
    font-size: 0.83rem;
    color: #ccc;
    cursor: pointer;
    transition: background 0.1s;
  }
  .suggest-item:hover { background: #2a2d37; color: #fff; }

  .override-row { display: flex; gap: 12px; align-items: flex-end; }
  .override-row .field-group { flex: 1; }
  .override-row .field-group:last-child { flex: 0 0 auto; }

  /* ── Fixed top-right toolbar ── */
  .top-toolbar {
    position: fixed;
    top: 14px;
    right: 20px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 6px;
    background: #16181f;
    border: 1px solid #2a2d37;
    border-radius: 10px;
    padding: 5px 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    transition: all 0.2s ease;
  }

  /* Drop zone as small icon in toolbar */
  .toolbar-drop {
    position: relative;
    width: 32px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s ease;
    color: #555;
  }
  .toolbar-drop:hover { background: #1e2029; color: #888; }
  .toolbar-drop.loaded { color: #34d399; }
  .toolbar-drop svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .toolbar-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

  .toolbar-filename {
    font-size: 0.7rem;
    color: #666;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
  }
  .toolbar-filename.loaded { color: #34d399; }

  .toolbar-sep {
    width: 1px;
    height: 18px;
    background: #2a2d37;
    flex-shrink: 0;
  }

  .toolbar-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #555;
    cursor: pointer;
    width: 30px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
  }
  .toolbar-btn:hover { background: #1e2029; color: #e0e0e0; border-color: #2a2d37; }
  .toolbar-btn.active { color: #60a5fa; }
  .toolbar-btn.hidden { display: none; }
  .toolbar-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

  /* ── Top-left page title ── */
  .top-title {
    position: fixed;
    top: 14px;
    left: 20px;
    z-index: 100;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
    pointer-events: none;
    transition: color 0.2s ease;
  }
  .top-title span {
    color: #555;
    font-weight: 500;
  }

  /* ── Mode toggle (Proposal / Invoice) ── */
  .mode-toggle {
    display: flex;
    align-items: center;
    background: #12141a;
    border: 1px solid #2a2d37;
    border-radius: 7px;
    padding: 2px;
    gap: 0;
    flex-shrink: 0;
  }
  .mode-toggle-btn {
    border: none;
    border-radius: 5px;
    padding: 3px 10px;
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
    background: transparent;
    color: #555;
    letter-spacing: 0.02em;
    white-space: nowrap;
  }
  .mode-toggle-btn.active-proposal {
    background: #1a2a3a;
    color: #60a5fa;
  }
  .mode-toggle-btn.active-invoice {
    background: #1a2e1a;
    color: #34d399;
  }
  .mode-toggle-btn:not(.active-proposal):not(.active-invoice):hover {
    color: #aaa;
  }

  /* ── Split-panel layout ── */
  .split-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
    max-width: 680px;
    transition: max-width 0.35s ease;
  }
  .split-wrapper.split-active {
    max-width: 100%;
    gap: 0;
    justify-content: center;
  }
  .split-wrapper.split-active.split-reversed {
    flex-direction: row-reverse;
  }

  /* Each half — centers content within its 50vw column */
  .split-half {
    flex: 0 0 50%;
    display: flex;
    justify-content: center;
    padding: 0 24px;
  }
  .split-half.left { justify-content: flex-end; }
  .split-half.right { justify-content: flex-start; }

  /* In single-column mode, form-half takes full width */
  .split-wrapper:not(.split-active) .split-half {
    flex: 1;
    padding: 0;
  }

  /* Form panel — always present */
  .form-panel {
    flex: 1;
    min-width: 0;
    max-width: 680px;
    width: 100%;
  }

  /* PDF preview panel */
  .pdf-preview-panel {
    display: none;
    width: 100%;
    max-width: 600px;
    background: #16181f;
    border: 1px solid #2a2d37;
    border-radius: 12px;
    overflow: hidden;
    position: sticky;
    top: 60px;
    max-height: calc(100vh - 100px);
    transition: opacity 0.3s ease;
  }
  .pdf-preview-panel.visible { display: flex; flex-direction: column; }

  .pdf-preview-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: #12141a;
    border-bottom: 1px solid #2a2d37;
    flex-shrink: 0;
  }
  .pdf-preview-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pdf-preview-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }
  .pdf-preview-scroll canvas {
    width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
    display: block;
  }
  .pdf-page-label {
    font-size: 0.65rem;
    color: #444;
    text-align: center;
    margin-top: 4px;
  }

  /* Responsive: stack vertically on narrow screens */
  @media (max-width: 1000px) {
    .split-wrapper.split-active {
      flex-direction: column !important;
      max-width: 680px;
      align-items: center;
    }
    .split-half {
      flex: none !important;
      width: 100%;
      padding: 0;
      justify-content: center !important;
    }
    .pdf-preview-panel {
      position: relative;
      top: 0;
      max-height: 50vh;
      max-width: 100%;
    }
  }
