:root {
  --bg: #f3f5f7;
  --paper: #ffffff;
  --ink: #1c1f23;
  --brand: #111827;
  --accent: #eef2f7;
  --line: #d9dee7;
  --soft: #f8fafc;
  --muted: #6b7280;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}
body {
  margin: 0;
  font-family: "SF Pro Display", "Helvetica Neue", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 28%),
    linear-gradient(180deg, #fbfcfe 0%, var(--bg) 100%);
  color: var(--ink);
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(217, 222, 231, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar a { color: var(--muted); margin-left: 16px; text-decoration: none; }
.topbar a:hover { color: var(--ink); }
.container { max-width: 1360px; margin: 28px auto; padding: 0 20px 44px; }
.card {
  background: var(--paper);
  border: 1px solid rgba(217, 222, 231, 0.8);
  padding: 20px;
  border-radius: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.narrow { max-width: 480px; }
.eyebrow { margin: 0; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: #4b5563; }
.grid1, .grid2, .grid3, .grid4 { display: grid; gap: 8px; }
.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
input, textarea, select, button {
  padding: 12px 14px;
  font-size: 14px;
  border-radius: 14px;
}
input, textarea, select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}
textarea { min-height: 96px; resize: vertical; }
button {
  background: linear-gradient(180deg, #f9fbff, #eef3f9);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}
button:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08); }
.ghost-btn { background: rgba(255,255,255,0.88); }
.small-btn { padding: 8px 12px; font-size: 13px; }
.field-card {
  padding: 16px;
  border: 1px solid rgba(217, 222, 231, 0.8);
  border-radius: 20px;
  background: linear-gradient(180deg, #fff, #fbfdff);
}
.field-card label,
.card label { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.invoice-shell { padding: 24px; }
.phase-panel {
  display: none;
}
.phase-panel.is-active {
  display: block;
}
.phase-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}
.phase-summary-fields {
  margin-bottom: 18px;
}
.line-items-panel {
  padding: 18px;
  border: 1px solid rgba(217, 222, 231, 0.8);
  background: linear-gradient(180deg, #fff, #fbfdff);
  border-radius: 22px;
  margin: 20px 0;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.section-head.compact { align-items: center; }
.section-head h3 { margin: 4px 0 0; }
.panel-footer-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}
.line-card-list {
  display: grid;
  gap: 14px;
}
.line-card {
  border: 1px solid rgba(217, 222, 231, 0.82);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(248,250,252,0.96));
  padding: 16px;
}
.line-card-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  cursor: pointer;
}
.line-card-title {
  font-weight: 600;
}
.line-card-summary-meta {
  display: inline-flex;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}
.line-card-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 120px 2fr 100px 120px 120px 96px;
  gap: 12px;
  align-items: end;
}
.line-card.collapsed .line-card-grid {
  display: none;
}
.line-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.service-picker {
  min-width: 0;
}
.service-search {
  margin-bottom: 8px;
}
.inline-input, .inline-select {
  min-width: 96px;
  padding: 10px 12px;
  border-radius: 12px;
}
.service-select {
  min-height: 46px;
}
.number-input { min-width: 88px; }
.code-input { min-width: 72px; }
.taxable-cell { text-align: center; }
.compact-field { max-width: 120px; }
.amount-field {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.remove-field {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.line-total {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid rgba(217, 222, 231, 0.85);
  background: rgba(255,255,255,0.96);
  font-weight: 600;
}
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: #d7dee8;
  position: relative;
  display: inline-block;
  transition: background 140ms ease;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
  transition: transform 140ms ease;
}
.switch input:checked + span { background: #111827; }
.switch input:checked + span::after { transform: translateX(18px); }
.msg { padding: 8px; border-radius: 8px; }
.msg.success { background: #d4f3e0; }
.msg.error { background: #ffd9d9; }
.totals {
  margin-top: 18px;
  background: linear-gradient(180deg, #f7fafc, var(--accent));
  padding: 18px;
  border-radius: 20px;
  border: 1px solid rgba(217, 222, 231, 0.8);
}
.totals p { margin: 6px 0; }
@media (max-width: 900px) {
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .section-head,
  .topbar {
    display: block;
  }
  .line-card-grid {
    grid-template-columns: 1fr;
  }
  .line-card-summary {
    grid-template-columns: 1fr auto;
  }
  .line-card-summary-meta {
    grid-column: 1 / -1;
  }
  .phase-actions {
    flex-direction: column;
  }
  .phase-actions button {
    width: 100%;
  }
  .panel-footer-actions {
    justify-content: stretch;
  }
  .panel-footer-actions button {
    width: 100%;
  }
  .compact-field,
  .amount-field,
  .remove-field {
    max-width: none;
  }
  .topbar nav { margin-top: 10px; }
}
