:root {
  --app-bg: #0b1118;
  --panel: #111927;
  --panel-line: rgba(255,255,255,.10);
  --input: #0a1018;
  --paper: #ffffff;
  --ink: #07111f;
  --muted: #64748b;
  --line: #e4e7ec;
  --blue: #075f80;
  --gold: #c9973f;
  --green: #16803a;
  --red: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--app-bg);
  color: #f8fafc;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

.app-header {
  min-height: 76px;
  padding: 12px 22px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  background: rgba(7, 17, 31, .96);
  border-bottom: 1px solid var(--panel-line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}

.header-left { display: flex; align-items: center; gap: 14px; }
.header-left img { width: 190px; max-height: 54px; object-fit: contain; object-position: left center; }
.header-left strong { display: block; font-size: 15px; }
.header-left span { display: block; margin-top: 2px; color: #94a3b8; font-size: 12px; }

.header-actions { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

button {
  border: 0;
  border-radius: 11px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}

.primary { background: var(--gold); color: #07111f; }
.ghost { background: #182235; color: #e5e7eb; border: 1px solid var(--panel-line); }
.danger-ghost { background: #2a1414; color: #fecaca; border: 1px solid rgba(248,113,113,.25); }
.full-width { width: 100%; margin-top: 4px; }

.app-shell {
  display: grid;
  grid-template-columns: 390px minmax(760px, 1fr);
  gap: 24px;
  padding: 24px;
  align-items: start;
}

.form-panel, .history-panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 24px 80px rgba(0,0,0,.32);
}

.history-panel {
  display: none;
  grid-column: 1 / 2;
}

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

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

.history-header h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #cbd5e1;
}

.history-item {
  border: 1px solid var(--panel-line);
  background: #0a1018;
  border-radius: 14px;
  padding: 12px;
  margin-top: 12px;
}

.history-item strong {
  display: block;
  color: #fff;
  margin-bottom: 5px;
}

.history-item span {
  display: block;
  color: #94a3b8;
  font-size: 12px;
  margin-bottom: 9px;
}

.history-actions {
  display: flex;
  gap: 8px;
}

.history-actions button {
  padding: 8px 10px;
  font-size: 12px;
}

.form-section {
  border-bottom: 1px solid var(--panel-line);
  padding-bottom: 16px;
  margin-bottom: 17px;
}

.form-section:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }

.form-section h2 {
  margin: 0 0 13px;
  font-size: 14px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #cbd5e1;
}

.preset-tools {
  margin-top: 16px;
  border-top: 1px solid var(--panel-line);
  padding-top: 14px;
}

.preset-tools h3 {
  margin: 0 0 10px;
  color: #cbd5e1;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

label {
  display: block;
  font-size: 12px;
  color: #cbd5e1;
  margin-bottom: 11px;
}

input, select, textarea {
  width: 100%;
  margin-top: 6px;
  color: #f8fafc;
  background: var(--input);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  outline: none;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,151,63,.18);
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; align-items: end; }

.add-item { background: var(--blue); color: #fff; }

.notice-box {
  background: rgba(201,151,63,.10);
  border: 1px solid rgba(201,151,63,.25);
  color: #fde68a;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.45;
}

.small-hint {
  color: #94a3b8;
  font-size: 11.5px;
  line-height: 1.4;
}


.part-preset-wrap {
  display: none;
  background: rgba(7, 95, 128, .12);
  border: 1px solid rgba(7, 95, 128, .25);
  border-radius: 14px;
  padding: 12px;
  margin: 6px 0 12px;
}

.part-preset-wrap.active {
  display: block;
}

.preview-wrap { min-width: 0; }

.preview-label {
  color: #94a3b8;
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.invoice-page {
  width: 8.5in;
  min-height: 11in;
  margin: 0 auto;
  background: var(--paper);
  color: var(--ink);
  padding: .42in .52in;
  border-radius: 10px;
  box-shadow: 0 28px 90px rgba(0,0,0,.38);
  overflow: visible;
}

.invoice-master {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.invoice-master thead { display: table-header-group; }

.invoice-head-row th {
  padding: 0;
  text-align: left;
  font-weight: normal;
  background: #fff;
}

.invoice-top {
  display: grid;
  grid-template-columns: 1fr 245px;
  gap: 22px;
  align-items: start;
}

.invoice-brand img {
  width: 3.65in;
  height: 0.82in;
  object-fit: contain;
  object-position: left center;
  display: block;
}

.brand-meta { margin-top: .08in; }

.brand-meta p {
  margin: 1.5px 0;
  color: #334155;
  font-size: 12px;
  line-height: 1.2;
}

.invoice-meta { text-align: right; }

.invoice-meta h1 {
  margin: 0;
  font-size: 33px;
  letter-spacing: .28em;
  font-weight: 900;
  color: #07111f;
}

.status-badge {
  display: inline-block;
  margin: 12px 0 11px;
  padding: 6px 18px;
  border-radius: 999px;
  font-weight: 900;
  letter-spacing: .18em;
  transform: rotate(-4deg);
  font-size: 13px;
}

.status-badge.paid { border: 2px solid var(--green); color: var(--green); }
.status-badge.unpaid { border: 2px solid var(--red); color: var(--red); }

.invoice-meta p {
  margin: 5px 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  color: #334155;
  font-size: 12.2px;
}

.invoice-meta p span { font-weight: 800; }
.invoice-meta p strong { min-width: 108px; color: #07111f; }

.divider {
  height: 3px;
  background: linear-gradient(90deg, #07111f, #0f6f91, #c9973f);
  margin: .20in 0 .17in;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .36in;
  margin-bottom: .20in;
}

.info-grid h3,
.notes-box h3 {
  margin: 0 0 7px;
  font-size: 10.5px;
  letter-spacing: .14em;
  color: #64748b;
  text-transform: uppercase;
}

.info-grid p {
  margin: 3px 0;
  color: #1f2937;
  font-size: 12.5px;
}

.primary-line {
  color: #07111f !important;
  font-size: 14.5px !important;
  font-weight: 900;
}

.column-row th {
  color: #64748b;
  font-size: 9.6px;
  letter-spacing: .10em;
  text-transform: uppercase;
  padding: 0 6px 10px;
  text-align: left;
  border-bottom: 2px solid #d8dee8;
  background: #fff;
}

.column-row th:nth-child(1) { width: 30%; }
.column-row th:nth-child(2) { width: 32%; }
.column-row th:nth-child(3) { width: 11%; }
.column-row th:nth-child(4) { width: 12%; }
.column-row th:nth-child(5) { width: 15%; }
.column-row th:nth-child(6) { width: 8%; }

.invoice-master td {
  padding: 11px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  color: #1f2937;
  word-break: break-word;
  font-size: 11.6px;
}

.invoice-master td strong { color: #07111f; }

.num { text-align: right !important; }
.action-col { text-align: right !important; }

.remove-btn {
  background: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 11px;
}

.empty-row td { color: #94a3b8; font-style: italic; }

.lower-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 34px;
  margin-top: 28px;
  align-items: start;
  break-inside: avoid;
}

.notes-box p {
  margin: 0;
  color: #334155;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 13px;
}

.totals-card {
  border: 1px solid #d9dee8;
  border-radius: 15px;
  overflow: hidden;
  background: #fff;
}

.totals-card div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 16px;
  border-bottom: 1px solid #e5e7eb;
  color: #0f172a;
}

.totals-card div:last-child { border-bottom: 0; }
.totals-card span { color: #334155; }
.totals-card strong { color: #07111f; }

.totals-card .grand {
  background: #07111f;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
}

.totals-card .grand span,
.totals-card .grand strong { color: #fff; }

.disclaimer {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid #e4e7ec;
  color: #64748b;
  font-size: 10.5px;
  line-height: 1.45;
  break-inside: avoid;
}

.disclaimer strong { color: #334155; }

.invoice-footer {
  margin-top: 26px;
  padding-top: 12px;
  border-top: 1px solid #d8dee8;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  color: #64748b;
  font-size: 12px;
  break-inside: avoid;
}

@media (max-width: 1220px) {
  .app-shell { grid-template-columns: 1fr; }
  .form-panel, .history-panel { max-width: 8.5in; margin: 0 auto; width: 100%; }
  .history-panel { grid-column: auto; }
  .preview-wrap { overflow-x: auto; padding-bottom: 20px; }
}

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

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

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

  .app-shell {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .preview-wrap {
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .invoice-page {
    width: 8.5in !important;
    min-height: 11in !important;
    margin: 0 !important;
    padding: .34in .50in .36in .50in !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .invoice-master thead { display: table-header-group !important; }
  .invoice-master tbody { display: table-row-group !important; }

  .invoice-master tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .invoice-head-row th { background: #fff !important; }

  .invoice-brand img {
    width: 3.85in !important;
    height: 0.88in !important;
    object-fit: contain !important;
    object-position: left center !important;
  }

  .invoice-top {
    grid-template-columns: 1fr 2.35in !important;
    gap: .18in !important;
  }

  .invoice-meta h1 { font-size: 29px !important; }

  .divider { margin: .16in 0 .14in !important; }
  .info-grid { margin-bottom: .17in !important; }

  .column-row th {
    padding-top: 0 !important;
    padding-bottom: .075in !important;
    background: #fff !important;
  }

  .invoice-master td {
    padding-top: .078in !important;
    padding-bottom: .078in !important;
    font-size: 9.6pt !important;
  }

  .column-row th:nth-child(6),
  .invoice-master td:nth-child(6) {
    display: none !important;
  }

  .column-row th:nth-child(1) { width: 30% !important; }
  .column-row th:nth-child(2) { width: 34% !important; }
  .column-row th:nth-child(3) { width: 11% !important; }
  .column-row th:nth-child(4) { width: 12% !important; }
  .column-row th:nth-child(5) { width: 13% !important; }

  .lower-grid {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .invoice-footer { break-inside: avoid; }
}


/* V17 edit button styles */
.edit-btn {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 11px;
  margin-right: 4px;
  font-weight: 800;
}

.add-item.editing {
  background: #c9973f;
  color: #07111f;
}

.cancel-edit {
  margin-top: 8px;
}



/* =========================
   V18 iPhone/mobile responsive UI
   ========================= */

.service-editor-section {
  display: block;
}

.service-item-cards {
  display: grid;
  gap: 10px;
}

.service-item-card {
  background: #0a1018;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  padding: 12px;
}

.service-item-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.service-item-card-top strong {
  color: #fff;
  font-size: 13px;
  line-height: 1.3;
}

.service-item-card-top span {
  color: #fbbf24;
  font-weight: 900;
  white-space: nowrap;
}

.service-item-card p {
  color: #94a3b8;
  font-size: 12px;
  margin: 8px 0;
  line-height: 1.4;
}

.service-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.service-item-meta span {
  background: #111927;
  border: 1px solid rgba(255,255,255,.08);
  color: #cbd5e1;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
}

.service-item-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.edit-btn {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
  padding: 7px 9px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.add-item.editing {
  background: #c9973f;
  color: #07111f;
}

.cancel-edit {
  margin-top: 8px;
}

@media (max-width: 820px) {
  body {
    background: #07111f;
  }

  .app-header {
    position: sticky;
    top: 0;
    padding: 10px 12px;
    min-height: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .header-left {
    justify-content: flex-start;
  }

  .header-left img {
    width: 150px;
    max-height: 44px;
  }

  .header-left div strong {
    font-size: 14px;
  }

  .header-left div span {
    display: none;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
  }

  .header-actions button {
    padding: 10px 8px;
    font-size: 12px;
    border-radius: 10px;
  }

  .app-shell {
    display: block;
    padding: 12px;
  }

  .form-panel,
  .history-panel {
    border-radius: 16px;
    padding: 14px;
    width: 100%;
    max-width: none;
    margin-bottom: 14px;
  }

  .form-section {
    padding-bottom: 14px;
    margin-bottom: 14px;
  }

  .form-section h2 {
    font-size: 13px;
    margin-bottom: 10px;
  }

  .two-col,
  .three-col {
    grid-template-columns: 1fr;
    gap: 0;
  }

  label {
    font-size: 12px;
    margin-bottom: 10px;
  }

  input, select, textarea {
    font-size: 16px;
    padding: 12px;
    border-radius: 12px;
  }

  .full-width {
    min-height: 46px;
  }

  .preview-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 18px;
  }

  .preview-label {
    padding-left: 2px;
  }

  .invoice-page {
    width: 8.5in;
    transform: scale(.54);
    transform-origin: top left;
    margin: 0;
    min-height: 11in;
  }

  .preview-wrap::after {
    content: "";
    display: block;
    height: 0;
  }

  .action-col {
    min-width: 92px;
  }

  .column-row th:nth-child(6),
  .invoice-master td:nth-child(6) {
    width: 92px;
  }

  .edit-btn,
  .remove-btn {
    display: block;
    width: 100%;
    margin: 0 0 6px 0;
    font-size: 11px;
    padding: 7px 6px;
  }
}

@media (max-width: 430px) {
  .invoice-page {
    transform: scale(.48);
  }

  .header-actions {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media print {
  .service-editor-section,
  .service-item-cards,
  .service-item-card {
    display: none !important;
  }

  .invoice-page {
    transform: none !important;
  }
}
