:root {
  --bg: #eef3f9;
  --surface: #ffffff;
  --surface-soft: #f6f9fd;
  --ink: #07172e;
  --muted: #617089;
  --line: #d9e3ef;
  --blue: #1168b5;
  --blue-dark: #0a4f8f;
  --blue-soft: #e6f2ff;
  --green: #0f766e;
  --red: #b42318;
  --red-soft: #fff0ee;
  --shadow: 0 18px 50px rgba(12, 32, 64, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px;
  background: #07172e;
  color: white;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand span,
.scope-note {
  color: #b6c5d8;
  font-size: 13px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--blue);
  font-weight: 900;
}

.desktop-nav {
  display: grid;
  gap: 8px;
}

.nav-item,
.bottom-nav-item {
  border: 0;
  cursor: pointer;
  font-weight: 800;
}

.nav-item {
  text-align: left;
  border-radius: var(--radius);
  padding: 12px;
  color: #dbe8f8;
  background: transparent;
}

.nav-item.active,
.nav-item:hover {
  color: white;
  background: rgba(255, 255, 255, 0.12);
}

.scope-note {
  position: absolute;
  bottom: 20px;
  left: 20px;
}

.session-card {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
}

.session-card span {
  color: #b6c5d8;
  font-size: 12px;
}

.session-card .btn {
  justify-self: start;
}

.workspace {
  padding: 24px;
  padding-bottom: 92px;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: min(520px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  color: var(--ink);
}

.auth-brand span {
  color: var(--muted);
}

.checkbox-label {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px !important;
}

.checkbox-label input {
  width: auto !important;
}

.status-banner {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #bad8f4;
  border-radius: var(--radius);
  color: #24405f;
  background: #f7fbff;
  font-weight: 750;
}

.status-banner.success {
  border-color: #bfe3d5;
  color: var(--green);
  background: #ecfdf5;
}

.status-banner.warning {
  border-color: #ffd79a;
  color: #8a4b00;
  background: #fff7e8;
}

.page-header,
.record-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 8px;
  font-size: 32px;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 18px;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.header-actions,
.row-actions,
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.command-stack {
  display: grid;
  gap: 12px;
  justify-items: end;
  min-width: min(420px, 100%);
}

.next-action-callout {
  width: 100%;
  padding: 14px;
  border: 1px solid #bad8f4;
  border-radius: var(--radius);
  background: var(--blue-soft);
}

.next-action-callout span,
.action-question,
.summary-card span {
  display: block;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.next-action-callout strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

.btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--ink);
  background: white;
  font-weight: 850;
  cursor: pointer;
}

.btn.primary {
  color: white;
  border-color: var(--blue);
  background: var(--blue);
}

.btn.primary:hover {
  background: var(--blue-dark);
}

.btn.quiet {
  color: #24405f;
  background: var(--surface-soft);
}

.btn.small {
  min-height: 36px;
  padding: 8px 11px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 6px;
}

.prototype-switcher {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin: 14px 0;
  padding: 14px;
  border: 1px dashed #9fc3e8;
  border-radius: var(--radius);
  background: #f8fbff;
}

.prototype-switcher span {
  display: block;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.scenario-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.summary-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.summary-card strong {
  display: block;
  margin: 5px 0;
  font-size: 28px;
}

.summary-card p {
  margin: 0;
  font-size: 13px;
}

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.filter-chip,
.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  background: white;
  color: var(--muted);
  font-weight: 850;
  font-size: 13px;
}

.filter-chip.active,
.badge-info {
  color: var(--blue);
  border-color: #bad8f4;
  background: var(--blue-soft);
}

.filter-chip.quiet-filter {
  color: #6d7c91;
  background: #f4f7fb;
}

.badge-success {
  color: var(--green);
  border-color: #bfe3d5;
  background: #ecfdf5;
}

.badge-danger {
  color: var(--red);
  border-color: #ffd1cc;
  background: var(--red-soft);
}

.badge-warning {
  color: #8a4b00;
  border-color: #ffd79a;
  background: #fff7e8;
}

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

.record-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 160px 130px auto;
  gap: 16px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.estimate-row {
  grid-template-columns: minmax(0, 1fr) 120px 160px auto;
}

.alert-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.row-title {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 5px;
}

.row-main p,
.row-meta span,
.activity-item span,
.note-card span {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.row-meta {
  display: grid;
  gap: 4px;
}

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

.context-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.context-strip div,
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.context-strip div {
  padding: 13px;
}

.context-strip span,
.rail-card span,
.service-context span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
}

.main-column,
.right-rail {
  display: grid;
  align-content: start;
  gap: 16px;
}

.card {
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-heading.compact {
  align-items: start;
}

.large-text {
  color: var(--ink);
  font-size: 20px;
}

.action-panel {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--blue-soft);
}

.action-panel strong {
  display: block;
  margin: 5px 0;
  font-size: 24px;
}

.action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.rail-card strong {
  display: block;
  margin: 8px 0;
  font-size: 21px;
}

.service-card {
  overflow: hidden;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.service-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  background: var(--surface-soft);
}

.service-context {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.service-context div {
  padding: 14px;
}

.service-context div + div {
  border-left: 1px solid var(--line);
}

.line-list {
  display: grid;
}

.line-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 90px 100px;
  gap: 12px;
  align-items: center;
  padding: 14px;
  width: 100%;
  border: 0;
  color: inherit;
  text-align: left;
  background: white;
}

.line-row + .line-row {
  border-top: 1px solid var(--line);
}

.line-row-clickable {
  min-height: 60px;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.line-row-clickable:hover,
.line-row-clickable:focus-visible {
  outline: 0;
  background: #f8fbff;
  box-shadow: inset 4px 0 0 var(--blue);
}

.line-description,
.line-price {
  display: grid;
  gap: 3px;
}

.line-description small,
.line-price small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.line-price {
  justify-items: end;
}

.line-type {
  display: inline-flex;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 8px;
  color: var(--blue);
  background: var(--blue-soft);
  font-weight: 900;
  font-size: 12px;
}

.line-type-labor {
  color: #0a4f8f;
  background: #e6f2ff;
}

.line-type-part {
  color: #0f766e;
  background: #ecfdf5;
}

.line-type-fee {
  color: #8a4b00;
  background: #fff7e8;
}

.line-type-note {
  color: #526173;
  background: #f1f5f9;
}

.line-type-discount {
  color: #9f1d16;
  background: #fff0ee;
}

.line-type-sublet {
  color: #6d3aa8;
  background: #f3e8ff;
}

.total-line,
.grand-total {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.grand-total {
  margin-top: 6px;
  border-top: 2px solid var(--ink);
  border-bottom: 0;
  font-size: 22px;
}

.comm-grid {
  display: grid;
  gap: 18px;
}

.note-card,
.activity-item,
.placeholder-row {
  margin-top: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.placeholder-row p {
  margin: 5px 0 0;
}

.settings-list {
  display: grid;
  gap: 10px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.settings-row p {
  margin: 3px 0 0;
}

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

.bottom-nav {
  display: none;
}

.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 23, 46, 0.35);
  z-index: 20;
}

.slide-panel {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(440px, 100vw);
  z-index: 30;
  padding: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.line-edit-panel {
  width: min(600px, 100vw);
  overflow: auto;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}

.icon-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: white;
  font-weight: 850;
  cursor: pointer;
}

.panel-form {
  display: grid;
  gap: 14px;
}

.panel-form label {
  display: grid;
  gap: 7px;
  font-weight: 850;
}

.panel-context {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.panel-context span {
  color: var(--muted);
  font-size: 13px;
}

.panel-form select,
.panel-form input,
.panel-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px;
  color: var(--ink);
  background: white;
  font: inherit;
}

.panel-form input[readonly],
.panel-form textarea[readonly] {
  background: #fbfdff;
}

.line-editor-form {
  gap: 16px;
}

.line-editor-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.line-editor-section h3 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.customer-section {
  border-color: #b9d7f5;
  background: #f7fbff;
}

.staff-section {
  border-color: #d5dbe6;
  background: #f8fafc;
}

.staff-only-field > span::after {
  content: "Staff-only";
  display: inline-flex;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #475569;
  background: #e2e8f0;
  font-size: 11px;
  font-weight: 900;
}

.field-grid {
  display: grid;
  gap: 12px;
}

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

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

.future-actions .btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.remove-line-zone {
  border-color: #fecaca;
  background: #fff7f7;
}

.remove-line-zone p {
  margin: 0;
  color: var(--muted);
}

.remove-confirmation {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  background: #fff1f2;
}

.remove-confirmation span {
  color: var(--muted);
}

.btn.danger,
.btn.danger-outline {
  border-color: #fecaca;
  color: #991b1b;
  background: #fff5f5;
}

.btn.danger {
  color: white;
  background: #b91c1c;
}

.sticky-panel-actions {
  position: sticky;
  bottom: 0;
  margin-top: 4px;
  padding-top: 12px;
  background: linear-gradient(rgba(255, 255, 255, 0), var(--surface) 24%);
}

.empty-state {
  padding: 20px;
  border: 1px dashed #b9c9dc;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .workspace {
    padding: 14px;
    padding-bottom: 88px;
  }

  .bottom-nav {
    position: fixed;
    z-index: 15;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
    left: 0;
    right: 0;
    bottom: 0;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
  }

  .bottom-nav-item {
    min-height: 44px;
    border-radius: var(--radius);
    color: var(--muted);
    background: var(--surface-soft);
  }

  .bottom-nav-item.active {
    color: white;
    background: var(--blue);
  }

  .page-header,
  .record-header,
  .action-panel,
  .prototype-switcher,
  .service-header {
    align-items: stretch;
    flex-direction: column;
  }

  .scenario-buttons {
    justify-content: stretch;
  }

  .scenario-buttons .filter-chip {
    flex: 1 1 auto;
  }

  .header-actions,
  .row-actions {
    justify-content: stretch;
  }

  .header-actions .btn,
  .row-actions .btn,
  .action-panel .btn {
    width: 100%;
  }

  .record-row,
  .estimate-row,
  .alert-row,
  .detail-grid,
  .context-strip,
  .summary-grid,
  .service-context {
    grid-template-columns: 1fr;
  }

  .command-stack {
    justify-items: stretch;
  }

  .service-context div + div {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 26px;
  }

  .page-header,
  .record-header,
  .card {
    padding: 14px;
  }

  .line-row {
    grid-template-columns: 1fr;
    gap: 6px;
    min-height: 76px;
  }

  .line-price {
    justify-items: start;
  }

  .field-grid.two-col {
    grid-template-columns: 1fr;
  }

  .slide-panel {
    inset: auto 0 0 0;
    width: auto;
    max-height: 84vh;
    overflow: auto;
    border-radius: 18px 18px 0 0;
  }

  .line-edit-panel {
    width: auto;
    max-height: 88vh;
  }

  .sticky-panel-actions {
    padding-bottom: 76px;
  }
}
