:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --ink: #1d2528;
  --muted: #667076;
  --line: #ded8cf;
  --line-strong: #c9c0b4;
  --green: #1f7a64;
  --green-dark: #135b4b;
  --coral: #c85c42;
  --amber: #b7791f;
  --blue: #2d6cdf;
  --shadow: 0 16px 40px rgba(29, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(31, 122, 100, 0.12), transparent 44%),
    linear-gradient(315deg, rgba(45, 108, 223, 0.1), transparent 42%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.login-error {
  margin: 0;
  border: 1px solid rgba(200, 92, 66, 0.35);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(200, 92, 66, 0.08);
  color: var(--coral);
  font-size: 13px;
  font-weight: 750;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.section-heading h2,
.empty-state h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions,
.form-actions,
.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-panel {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--amber);
}

.sync-panel[data-state="synced"] .sync-dot {
  background: var(--green);
}

.sync-panel[data-state="saving"] .sync-dot,
.sync-panel[data-state="pending"] .sync-dot {
  background: var(--amber);
}

.sync-panel[data-state="error"] .sync-dot {
  background: var(--coral);
}

.current-user {
  color: var(--green-dark);
}

.icon-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
  white-space: nowrap;
}

.icon-button:hover {
  border-color: var(--green);
  color: var(--green-dark);
}

.icon-button.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.icon-button.primary:hover {
  background: var(--green-dark);
  color: #fff;
}

.icon-button.danger {
  border-color: rgba(200, 92, 66, 0.45);
  color: var(--coral);
}

.icon-button.danger:hover {
  border-color: var(--coral);
}

.file-button {
  position: relative;
  overflow: hidden;
}

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

.full-width {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
}

.filter-band {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 11px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 100, 0.14);
}

.record-list {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.record-card {
  width: 100%;
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  background: transparent;
  text-align: left;
}

.record-card:hover,
.record-card.active {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 8px 22px rgba(29, 37, 40, 0.06);
}

.record-thumb {
  width: 68px;
  height: 68px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(31, 122, 100, 0.15), rgba(200, 92, 66, 0.12)),
    var(--surface);
  object-fit: cover;
  border: 1px solid var(--line);
}

.record-title {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-subtitle,
.record-stats {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.record-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  background: rgba(45, 108, 223, 0.1);
  color: #2855a6;
  font-size: 12px;
  font-weight: 800;
}

.empty-list {
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.editor-panel {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 26px;
}

.empty-state {
  min-height: calc(100vh - 140px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  text-align: center;
}

.empty-state p {
  max-width: 540px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.empty-visual {
  position: relative;
  width: min(360px, 80vw);
  height: 190px;
}

.photo-stack {
  position: absolute;
  width: 190px;
  height: 130px;
  border: 8px solid #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stack-a {
  left: 8px;
  top: 35px;
  transform: rotate(-7deg);
  background: linear-gradient(135deg, #1f7a64 0%, #8cc0a8 48%, #f3ddba 100%);
}

.stack-b {
  left: 86px;
  top: 5px;
  transform: rotate(4deg);
  background: linear-gradient(135deg, #2d6cdf 0%, #7bb3d8 52%, #fff0c2 100%);
}

.stack-c {
  right: 2px;
  top: 52px;
  transform: rotate(10deg);
  background: linear-gradient(135deg, #c85c42 0%, #e9a36e 48%, #f7f4ef 100%);
}

.record-form {
  display: grid;
  gap: 22px;
  min-width: 0;
}

.hidden {
  display: none !important;
}

.form-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.title-input {
  min-height: 56px;
  border: 0;
  border-bottom: 2px solid var(--line-strong);
  border-radius: 0;
  padding: 6px 0;
  background: transparent;
  font-size: clamp(24px, 4vw, 42px);
  font-weight: 900;
}

.title-input:focus {
  box-shadow: none;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(250px, 360px) minmax(0, 1fr);
  gap: 20px;
}

.media-panel,
.field-panel,
.research-section,
.profit-calculator-section,
.variant-section,
.competitor-section,
.metrics-strip,
.notes-grid {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(29, 37, 40, 0.04);
}

.media-panel,
.field-panel,
.research-section,
.profit-calculator-section,
.variant-section,
.competitor-section {
  padding: 16px;
}

.photo-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.photo-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.photo-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(31, 122, 100, 0.18), transparent 46%),
    linear-gradient(315deg, rgba(200, 92, 66, 0.14), transparent 48%),
    #f3eee7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

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

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

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

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  padding: 14px;
}

.metrics-strip input[readonly] {
  color: var(--green-dark);
  font-weight: 850;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 14px;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

.compact-heading {
  margin-bottom: 10px;
}

.research-grid {
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}

.research-note {
  margin-top: 14px;
}

.profit-calculator-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 16px;
  align-items: start;
}

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

.attribute-grid {
  grid-template-columns: repeat(4, minmax(110px, 1fr));
}

.logistics-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}

.logistics-summary div {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
}

.logistics-summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.logistics-summary strong {
  color: var(--green-dark);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.profit-fields {
  min-width: 0;
}

.calculator-grid {
  grid-template-columns: repeat(3, minmax(140px, 1fr));
}

.profit-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.result-card {
  min-height: 82px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.result-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-card strong {
  color: var(--ink);
  font-size: 19px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.result-card strong.positive {
  color: var(--green-dark);
}

.result-card strong.negative {
  color: var(--coral);
}

.preset-note {
  margin: -4px 0 14px;
  border: 1px solid rgba(31, 122, 100, 0.2);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(31, 122, 100, 0.07);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.45;
}

.variant-table-wrap,
.competitor-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.variant-table,
.competitor-table {
  width: 100%;
  border-collapse: collapse;
}

.variant-table {
  min-width: 1280px;
}

.competitor-table {
  min-width: 1060px;
}

.variant-table th,
.competitor-table th {
  padding: 8px 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: left;
}

.variant-table td,
.competitor-table td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.variant-table input,
.competitor-table input,
.competitor-table textarea {
  min-width: 130px;
}

.variant-table .name-cell {
  min-width: 220px;
}

.variant-table .number-cell {
  min-width: 112px;
}

.variant-result {
  min-width: 92px;
  padding-top: 10px;
  color: var(--ink);
  font-weight: 900;
}

.variant-result.positive {
  color: var(--green-dark);
}

.variant-result.negative {
  color: var(--coral);
}

.empty-table-cell {
  padding: 22px 10px !important;
  color: var(--muted);
  text-align: center;
}

.competitor-table textarea {
  min-height: 76px;
}

.competitor-table .wide-cell {
  min-width: 220px;
}

.row-remove {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(200, 92, 66, 0.38);
  border-radius: 8px;
  background: #fff;
  color: var(--coral);
  font-weight: 900;
}

.row-remove:hover {
  border-color: var(--coral);
}

@media (max-width: 1000px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 360px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .record-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }

  .profit-calculator-grid {
    grid-template-columns: 1fr;
  }

  .calculator-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .attribute-grid,
  .logistics-summary {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .form-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    padding: 16px;
  }

  .topbar-actions,
  .form-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .icon-button {
    padding-inline: 10px;
  }

  .editor-panel {
    padding: 16px;
  }

  .editor-grid,
  .research-grid,
  .calculator-grid,
  .attribute-grid,
  .logistics-summary,
  .notes-grid,
  .metrics-strip,
  .two-cols {
    grid-template-columns: 1fr;
  }

  .profit-results {
    grid-template-columns: 1fr;
  }

  .title-input {
    font-size: 26px;
  }
}
