:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --paper: #f5f9fc;
  --panel: #ffffff;
  --brand: #1d4ed8;
  --brand-strong: #1e40af;
  --accent: #22d3ee;
  --danger: #b42318;
  --soft: #eff6ff;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="jobsite"] {
  --ink: #172033;
  --muted: #5e687a;
  --line: #d6deea;
  --paper: #f7f9fc;
  --panel: #ffffff;
  --brand: #1d4f91;
  --brand-strong: #153764;
  --accent: #b85c2b;
  --danger: #a33b34;
  --soft: #eaf1f9;
  --shadow: 0 12px 30px rgba(28, 55, 91, 0.1);
}

[data-theme="contrast"] {
  --ink: #050505;
  --muted: #333333;
  --line: #6b6b6b;
  --paper: #ffffff;
  --panel: #ffffff;
  --brand: #004b8d;
  --brand-strong: #002b52;
  --accent: #8a3300;
  --danger: #8f0000;
  --soft: #eeeeee;
  --shadow: none;
}

[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f4f7f6;
  --muted: #b9c6c2;
  --line: #344640;
  --paper: #111816;
  --panel: #18231f;
  --brand: #4ab89c;
  --brand-strong: #70d4bb;
  --accent: #e08b55;
  --danger: #ef7870;
  --soft: #21312b;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}

[data-theme="paper"] {
  --ink: #27231d;
  --muted: #766b5e;
  --line: #ded2c2;
  --paper: #fbf7ef;
  --panel: #fffdf8;
  --brand: #5d6f3c;
  --brand-strong: #3f4d28;
  --accent: #9b4d2f;
  --danger: #9a3833;
  --soft: #f1eadf;
  --shadow: 0 12px 30px rgba(78, 55, 32, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

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

button,
.file-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-weight: 700;
  cursor: pointer;
}

.primary {
  color: #fff;
  background: var(--brand);
}

.primary:active {
  background: var(--brand-strong);
}

.secondary {
  color: var(--brand-strong);
  background: var(--soft);
}

.danger {
  color: #fff;
  background: var(--danger);
}

.text-button {
  min-height: auto;
  padding: 0;
  color: var(--brand);
  background: transparent;
}

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  color: #fff;
  background: var(--accent);
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.full-width {
  width: 100%;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem 0 1.25rem;
}

.brand-block {
  max-width: 720px;
}

.topbar h1,
.panel-heading h2,
.onboarding h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.05;
}

.brand-block > p:last-child {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 0.3rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-actions,
.record-tools,
.onboarding-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.app-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 0.45rem;
  margin-bottom: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 94%, var(--soft));
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.nav-tab {
  flex: 0 0 auto;
  min-height: 40px;
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  color: var(--muted);
  background: transparent;
}

.nav-tab.active {
  color: #fff;
  background: var(--brand);
}

.view-panel {
  display: none;
}

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

.notice {
  border: 1px solid var(--line);
  border-left: 6px solid var(--accent);
  border-radius: 8px;
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  background: var(--panel);
}

.backup-status {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.dashboard-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--panel), var(--soft));
  box-shadow: var(--shadow);
}

.dashboard-intro h2 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.dashboard article,
.entry-panel,
.records-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dashboard article {
  padding: 1rem;
}

.dashboard span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
}

.dashboard strong {
  display: block;
  margin-top: 0.35rem;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.dashboard small {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-weight: 700;
}

.dashboard-grid,
.more-grid,
.materials-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 1rem;
  margin-top: 1rem;
}

.more-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.quick-actions {
  margin-bottom: 1rem;
}

.quick-action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.action-tile {
  display: grid;
  gap: 0.25rem;
  align-content: center;
  min-height: 86px;
  text-align: left;
}

.action-tile strong,
.action-tile span {
  display: block;
}

.action-tile span {
  color: currentColor;
  font-size: 0.86rem;
  opacity: 0.8;
}

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

.entry-panel,
.records-panel,
.tool-panel {
  padding: 1rem;
}

.tool-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.entry-panel label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.compact-form {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 0.9rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.quote-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(86px, 120px) auto;
  gap: 0.65rem;
}

.quote-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.quote-summary span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  color: var(--muted);
  background: var(--paper);
  font-weight: 800;
}

.quote-summary strong {
  display: block;
  margin-top: 0.25rem;
  color: var(--ink);
  font-size: 1.1rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.button-row button {
  flex: 1 1 150px;
}

.voice-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 1rem;
  padding: 0.8rem;
  background: var(--soft);
}

.voice-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.65rem;
}

.voice-actions button {
  flex: 1;
}

.voice-status {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  color: var(--ink);
  background: var(--panel);
}

textarea {
  resize: vertical;
}

.records-panel {
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.75rem;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: var(--soft);
  font-size: 0.8rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.amount {
  text-align: right;
}

.type-pill {
  display: inline-block;
  min-width: 74px;
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.type-income {
  background: var(--brand);
}

.type-expense {
  background: var(--accent);
}

.delete-button {
  min-height: 36px;
  padding: 0.4rem 0.6rem;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, var(--panel));
}

.edit-button {
  min-height: 36px;
  padding: 0.4rem 0.6rem;
  color: var(--brand-strong);
  background: var(--soft);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

.empty-state {
  display: none;
  margin: 0;
  padding: 1.5rem;
  color: var(--muted);
  text-align: center;
}

.empty-state.visible {
  display: block;
}

.item-list {
  display: grid;
  gap: 0.6rem;
}

.item-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  background: var(--paper);
}

.job-card {
  display: grid;
  gap: 0.55rem;
}

.item-card strong,
.report-card strong {
  display: block;
}

.item-card span,
.report-card span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.thumb {
  display: block;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 0.5rem;
  object-fit: cover;
}

.reports-summary {
  display: grid;
  gap: 0.65rem;
}

.report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem;
  background: var(--paper);
}

.status-badge {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  color: var(--brand-strong);
  background: var(--soft);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: capitalize;
}

.status-scheduled,
.status-sent {
  color: #075985;
  background: #e0f2fe;
}

.status-in-progress {
  color: #0f766e;
  background: #ccfbf1;
}

.status-waiting {
  color: #92400e;
  background: #fef3c7;
}

.status-open,
.status-draft,
.status-unpaid,
.status-partial {
  color: var(--brand-strong);
  background: var(--soft);
}

.status-accepted,
.status-paid,
.status-done {
  color: #166534;
  background: #dcfce7;
}

.status-declined {
  color: #991b1b;
  background: #fee2e2;
}

.status-canceled {
  color: #475569;
  background: #e2e8f0;
}

.attention-list,
.activity-list {
  display: grid;
  gap: 0.65rem;
}

.attention-item,
.activity-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.8rem;
  background: var(--paper);
}

.attention-item {
  border-left: 5px solid #f59e0b;
  font-weight: 800;
}

.attention-item.good {
  border-left-color: #16a34a;
}

.activity-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem;
}

.activity-item span {
  color: var(--muted);
}

.panel-copy {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.45;
}

.stacked-actions {
  display: grid;
  gap: 0.65rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.setup-grid label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.detail-dialog {
  width: min(760px, calc(100% - 2rem));
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.detail-summary article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.8rem;
  background: var(--paper);
}

.detail-summary span,
.detail-section p {
  color: var(--muted);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  margin-top: 1rem;
}

.detail-section h3 {
  margin: 0 0 0.75rem;
}

.timeline-list {
  display: grid;
  gap: 0.6rem;
}

.timeline-list article {
  border-left: 4px solid var(--brand);
  padding: 0.2rem 0 0.2rem 0.75rem;
}

.timeline-list strong,
.timeline-list span {
  display: block;
}

dialog:not([open]) {
  display: none;
}

.onboarding,
.settings-dialog {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 2rem));
  border: 0;
  border-radius: 8px;
  padding: 1.25rem;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
}

.onboarding::backdrop,
.settings-dialog::backdrop {
  background: rgba(10, 20, 17, 0.55);
}

.onboarding p,
.settings-dialog p {
  color: var(--muted);
}

.settings-dialog label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.color-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.color-settings input[type="color"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.2rem;
  background: var(--panel);
  cursor: pointer;
}

.settings-links,
.app-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

a {
  color: var(--brand-strong);
  font-weight: 700;
}

.settings-links {
  margin: 1rem 0;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding: 1rem 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.legal-page {
  max-width: 820px;
  line-height: 1.55;
}

.legal-page h1 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 6vw, 3.2rem);
}

.legal-page h2 {
  margin-top: 1.5rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  display: none;
  max-width: min(420px, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  color: var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.toast.show {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.toast button {
  min-height: 34px;
  padding: 0.35rem 0.55rem;
}

.onboarding-actions {
  justify-content: stretch;
}

.onboarding-actions > * {
  flex: 1 1 150px;
}

.small-warning {
  margin-bottom: 0;
  font-size: 0.92rem;
}

@media (max-width: 900px) {
  .topbar,
  .workspace,
  .dashboard-grid,
  .more-grid,
  .materials-layout {
    grid-template-columns: 1fr;
    display: grid;
  }

  .top-actions,
  .record-tools {
    justify-content: stretch;
  }

  .top-actions > *,
  .record-tools > * {
    flex: 1 1 145px;
  }

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

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

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

@media (max-width: 560px) {
  .app-shell {
    padding-bottom: 5.5rem;
  }

  .topbar {
    align-items: stretch;
  }

  .top-actions > * {
    flex: 1;
  }

  .app-nav {
    position: fixed;
    inset: auto 0 0 0;
    border-width: 1px 0 0;
    border-radius: 0;
    margin: 0;
    justify-content: space-around;
  }

  .nav-tab {
    flex: 1 1 auto;
    min-width: 74px;
    padding: 0.5rem 0.4rem;
    font-size: 0.78rem;
  }

  .dashboard-intro {
    align-items: stretch;
    flex-direction: column;
  }

  .quick-action-grid {
    grid-template-columns: 1fr;
  }

  .color-settings {
    grid-template-columns: 1fr;
  }

  .setup-grid,
  .detail-summary,
  .form-row,
  .quote-add-row,
  .quote-summary {
    grid-template-columns: 1fr;
  }

  .dashboard {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 0.75rem;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 105px minmax(0, 1fr);
    gap: 0.75rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  td.amount {
    text-align: left;
  }

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

  .row-actions button {
    flex: 1;
  }
}

@media print {
  body {
    background: #fff;
  }

  .top-actions,
  .entry-panel,
  .notice,
  .delete-button,
  .edit-button,
  .record-tools {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .workspace {
    display: block;
  }

  .records-panel,
  .dashboard article {
    box-shadow: none;
  }
}
