:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-2: #f0f4f1;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d8ded8;
  --primary: #2f6f68;
  --primary-dark: #245852;
  --accent: #b85c38;
  --danger: #b42318;
  --gold: #9c7a20;
  --shadow: 0 12px 30px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

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

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 18px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.65rem);
}

h2 {
  font-size: 1rem;
}

.status-text {
  color: var(--muted);
  margin: 4px 0 0;
  min-height: 1.25em;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-panel {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-panel span {
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.is-hidden {
  display: none !important;
}

.auth-gate {
  min-height: calc(100vh - 78px);
  display: grid;
  place-items: center;
  padding: 24px;
}

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

.auth-gate-panel h2 {
  font-size: 1.3rem;
}

.auth-gate-panel p {
  margin: 10px 0 18px;
  color: var(--muted);
}

body.cloud-locked main,
body.cloud-locked .tabs {
  display: none !important;
}

.tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
}

.tab.is-active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(31, 41, 51, 0.12);
}

main {
  min-height: calc(100vh - 78px);
}

.view {
  display: none;
}

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

#projectsView {
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
}

#projectsView.is-active {
  display: grid;
}

.project-rail {
  min-height: calc(100vh - 78px);
  border-right: 1px solid var(--line);
  background: #fbfaf6;
  padding: 18px;
}

.rail-header,
.panel-heading,
.button-row,
.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rail-header,
.panel-heading {
  justify-content: space-between;
}

.workspace {
  padding: 18px;
}

.compose-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(340px, 1.1fr);
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.full-panel {
  margin: 18px;
}

.workspace .full-panel {
  margin: 18px 0 0;
}

.settings-panel {
  max-width: 820px;
  margin: 18px;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.field span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 9px 10px;
  min-height: 40px;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(47, 111, 104, 0.25);
  border-color: var(--primary);
}

.field-row {
  align-items: end;
}

.field-row .field {
  flex: 1;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.file-button {
  border: 1px solid transparent;
  border-radius: 7px;
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

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

.secondary-button,
.file-button {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.danger-button {
  background: #fff4f2;
  border-color: #f5c2bc;
  color: var(--danger);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  background: var(--primary);
  color: #ffffff;
}

.file-button {
  display: inline-grid;
  align-items: center;
}

.file-button input {
  display: none;
}

.search-field {
  margin-bottom: 14px;
}

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

.project-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
  padding: 12px;
}

.project-card.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(47, 111, 104, 0.16);
}

.project-card strong,
.project-card span {
  display: block;
}

.project-card strong {
  overflow-wrap: anywhere;
}

.project-card span {
  color: var(--muted);
  font-size: 0.83rem;
  margin-top: 3px;
}

.project-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-top: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.project-meta span,
.cost-strip span,
.settings-tile span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.project-meta strong {
  overflow-wrap: anywhere;
  text-align: right;
}

.cost-strip,
.summary-strip,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.cost-strip div,
.summary-chip,
.settings-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.cost-strip strong,
.settings-tile strong {
  display: block;
  font-size: 1.25rem;
  margin-top: 2px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 14px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

.data-table th,
.data-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: left;
  font-weight: 750;
}

.data-table td:last-child,
.data-table th:last-child {
  width: 48px;
}

.data-table input,
.data-table select {
  min-height: 34px;
  padding: 6px 8px;
}

.line-cost {
  font-weight: 750;
  white-space: nowrap;
}

.remove-row {
  width: 34px;
  min-height: 34px;
  border: 1px solid #f5c2bc;
  border-radius: 7px;
  background: #fff4f2;
  color: var(--danger);
  font-weight: 800;
}

.inventory-tools {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.inventory-tools .field {
  margin-top: 0;
}

.summary-strip {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.summary-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.summary-chip::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  flex: 0 0 auto;
}

.summary-chip:nth-child(3n + 1)::before {
  background: var(--primary);
}

.summary-chip:nth-child(3n + 2)::before {
  background: var(--gold);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

@media (max-width: 980px) {
  .topbar,
  #projectsView.is-active,
  .compose-grid,
  .inventory-tools {
    display: block;
  }

  .tabs {
    margin-top: 12px;
    width: 100%;
  }

  .top-actions {
    justify-content: stretch;
    margin-top: 12px;
  }

  .auth-panel {
    justify-content: space-between;
    width: 100%;
  }

  .tab {
    flex: 1;
  }

  .project-rail {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace,
  .full-panel,
  .settings-panel {
    margin: 0;
    padding: 14px;
  }

  .compose-grid .panel + .panel {
    margin-top: 14px;
  }

  .inventory-tools > * + * {
    margin-top: 10px;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 14px;
  }

  .rail-header,
  .panel-heading,
  .button-row,
  .field-row {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .panel-heading > .button-row {
    width: 100%;
  }

  .button-row > button,
  .primary-button,
  .secondary-button,
  .danger-button,
  .file-button {
    flex: 1;
  }

  .cost-strip,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}
