:root {
  color-scheme: light;
  --black: #11110f;
  --black-soft: #1b1a17;
  --gold: #d6b36a;
  --gold-deep: #a77d2f;
  --cream: #f7f3e8;
  --paper: #fffefb;
  --ink: #24211c;
  --muted: #746e64;
  --line: #ded7c7;
  --input: #fff7d8;
  --green: #2f7651;
  --red: #a83d35;
  --shadow: 0 12px 36px rgba(17, 17, 15, 0.14);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--cream);
  color: var(--ink);
}

body {
  min-width: 320px;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}

.brand-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  min-height: 68px;
  padding: 9px 16px;
  border-bottom: 1px solid rgba(214, 179, 106, 0.55);
  background: var(--black);
}

.brand-logo {
  width: 126px;
  height: 45px;
  object-fit: contain;
  object-position: left center;
}

.brand-copy {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 0;
}

.brand-copy strong {
  color: var(--gold);
  font-size: 16px;
}

.brand-copy a {
  color: #f5f1e8;
  font-size: 12px;
  text-decoration: none;
}

.content {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: 16px;
}

.loading-state,
.empty-state,
.access-state {
  display: grid;
  place-items: center;
  min-height: 55vh;
  padding: 32px 16px;
  text-align: center;
}

.loading-state p,
.empty-state p,
.access-state p {
  max-width: 420px;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--gold-deep);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

.page-heading h1,
.editor-heading h1 {
  overflow: hidden;
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-heading h1 {
  font-size: 18px;
}

.button {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--black);
  color: var(--gold);
  font-weight: 700;
}

.button:disabled {
  cursor: default;
  opacity: 0.48;
}

.button.secondary {
  border-color: var(--line);
  background: var(--paper);
  color: var(--ink);
}

.button.danger {
  border-color: #e8c0bc;
  background: #fff5f3;
  color: var(--red);
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-size: 20px;
}

.estimate-list,
.work-list,
.selected-list,
.price-list {
  display: grid;
  gap: 8px;
}

.estimate-row,
.work-row,
.selected-row,
.price-row {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
}

.estimate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px;
  color: var(--ink);
  text-align: left;
}

.estimate-main,
.work-main,
.selected-main,
.price-main {
  min-width: 0;
}

.estimate-title,
.work-name,
.selected-name,
.price-name {
  display: block;
  overflow: hidden;
  font-weight: 700;
  line-height: 1.3;
  text-overflow: ellipsis;
}

.estimate-meta,
.work-meta,
.selected-meta,
.price-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 10px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.estimate-total {
  align-self: center;
  color: var(--green);
  font-weight: 800;
  white-space: nowrap;
}

.status {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 6px;
  border-radius: 4px;
  background: #eee9dd;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.status.generated {
  background: #e0f0e6;
  color: var(--green);
}

.meta-panel {
  margin-bottom: 14px;
  border-top: 3px solid var(--gold-deep);
  background: var(--paper);
}

.meta-panel summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.meta-panel summary::-webkit-details-marker {
  display: none;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 12px 14px;
}

.field {
  display: grid;
  gap: 5px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.input,
.textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: none;
  background: var(--input);
  color: var(--ink);
}

.textarea {
  min-height: 76px;
  resize: vertical;
}

.input:focus,
.textarea:focus {
  border-color: var(--gold-deep);
  box-shadow: 0 0 0 2px rgba(214, 179, 106, 0.2);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin-bottom: 12px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ece6d9;
}

.segment {
  min-height: 38px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(17, 17, 15, 0.1);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}

.stage-strip {
  display: flex;
  overflow-x: auto;
  gap: 6px;
  margin: 0 -16px 12px;
  padding: 0 16px 5px;
  scrollbar-width: none;
}

.stage-strip::-webkit-scrollbar {
  display: none;
}

.stage-chip {
  min-height: 34px;
  flex: 0 0 auto;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stage-chip.active {
  border-color: var(--gold-deep);
  background: var(--black);
  color: var(--gold);
}

.work-row,
.price-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px;
}

.work-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.favorite-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #b7ae9e;
  font-size: 22px;
}

.favorite-button.active {
  color: var(--gold-deep);
}

.add-button {
  min-width: 42px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--gold-deep);
  border-radius: 5px;
  background: var(--paper);
  color: var(--gold-deep);
  font-weight: 800;
}

.add-button.added {
  border-color: #b7d6c3;
  background: #e8f3ec;
  color: var(--green);
}

.selected-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  color: var(--ink);
  text-align: left;
}

.selected-sum {
  align-self: center;
  color: var(--green);
  font-weight: 800;
  white-space: nowrap;
}

.sticky-total {
  position: sticky;
  z-index: 15;
  bottom: calc(58px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin: 14px -8px -2px;
  padding: 10px 12px;
  border: 1px solid var(--gold-deep);
  border-radius: 7px;
  background: var(--black);
  box-shadow: var(--shadow);
  color: #fff;
}

.total-copy span {
  display: block;
  color: #c9c0af;
  font-size: 11px;
}

.total-copy strong {
  display: block;
  margin-top: 2px;
  color: var(--gold);
  font-size: 18px;
}

.generate-button {
  min-height: 42px;
  padding: 8px 12px;
  border: 0;
  border-radius: 5px;
  background: var(--gold);
  color: var(--black);
  font-weight: 900;
}

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: calc(58px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: rgba(255, 254, 251, 0.96);
  backdrop-filter: blur(12px);
}

.bottom-nav[hidden] {
  display: none;
}

.editor-mode .sticky-total {
  bottom: calc(8px + env(safe-area-inset-bottom));
}

.nav-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.nav-button.active {
  color: var(--black);
  box-shadow: inset 0 3px 0 var(--gold-deep);
}

.modal[hidden],
.toast[hidden] {
  display: none;
}

.modal {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  align-items: end;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(17, 17, 15, 0.58);
}

.modal-sheet {
  position: relative;
  z-index: 1;
  width: min(100%, 620px);
  max-height: 88vh;
  margin: 0 auto;
  overflow-y: auto;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  border-radius: 8px 8px 0 0;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.modal-handle {
  width: 42px;
  height: 4px;
  margin: 0 auto 14px;
  border-radius: 2px;
  background: #d1c9bb;
}

.modal-title {
  margin: 0 0 4px;
  font-size: 18px;
}

.modal-subtitle {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.modal-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.toast {
  position: fixed;
  z-index: 120;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 16px;
  max-width: 520px;
  margin: auto;
  padding: 11px 13px;
  border-radius: 6px;
  background: var(--black-soft);
  box-shadow: var(--shadow);
  color: #fff;
  font-size: 13px;
  text-align: center;
}

.price-edit {
  min-width: 105px;
  min-height: 38px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--input);
  text-align: right;
}

.result-count {
  margin: 4px 0 10px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 480px) {
  .content { padding: 14px 12px; }
  .meta-grid,
  .modal-form { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
  .stage-strip { margin-right: -12px; margin-left: -12px; padding-right: 12px; padding-left: 12px; }
  .estimate-row { grid-template-columns: 1fr; }
  .estimate-total { justify-self: start; }
  .brand-logo { width: 116px; }
  .brand-copy strong { font-size: 15px; }
  .price-row { align-items: start; }
}
