:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #111820;
  --muted: #66727d;
  --line: #dce2e7;
  --line-strong: #c7d0d8;
  --accent: #0e7c66;
  --accent-dark: #075b4b;
  --accent-soft: #e2f3ee;
  --buy: #d75454;
  --buy-soft: #fbeaea;
  --sell: #079b78;
  --sell-soft: #e1f5ef;
  --warning: #a86413;
  --warning-soft: #fff4df;
  --shadow: 0 12px 36px rgba(25, 38, 49, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  background: rgba(244, 246, 248, 0.94);
  border-bottom: 1px solid rgba(199, 208, 216, 0.8);
  backdrop-filter: blur(18px);
}

.brand-lockup,
.profile-actions,
.profile-heading-actions,
.history-actions,
.action-group {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
}

.brand-name {
  font-size: 17px;
  font-weight: 760;
}

.profile-actions {
  gap: 8px;
  min-width: 0;
}

.profile-select {
  width: min(180px, 31vw);
  height: 40px;
  padding: 0 32px 0 12px;
  overflow: hidden;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  text-overflow: ellipsis;
}

.icon-button,
.text-button,
.secondary-button,
.primary-button,
.danger-button {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-weight: 680;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 40px;
  padding: 0;
  place-items: center;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
  font-size: 22px;
}

.text-button {
  padding: 0 10px;
  color: var(--accent-dark);
  background: transparent;
}

.text-button.compact {
  min-height: 36px;
}

.secondary-button,
.primary-button,
.danger-button {
  padding: 0 16px;
}

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

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

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-dark);
}

.danger-button {
  color: #b43e3e;
  background: #fff;
  border-color: #efc4c4;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 28px 24px calc(48px + env(safe-area-inset-bottom));
}

.profile-heading,
.section-heading,
.history-header,
.modal-header,
.selection-toolbar,
.panel-actions,
.split-actions,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.profile-heading {
  gap: 18px;
  margin-bottom: 20px;
}

.profile-heading-actions {
  flex: 0 0 auto;
  gap: 6px;
}

.profile-heading h1,
.section-heading h2,
.history-header h2,
.modal-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.profile-heading h1 {
  margin-top: 4px;
  font-size: 28px;
  line-height: 1.2;
}

.current-price-form,
.current-price-control {
  display: flex;
  align-items: center;
}

.current-price-form {
  gap: 10px;
  margin: -4px 0 16px;
}

.current-price-form > label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.current-price-control {
  height: 40px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
}

.current-price-control span {
  padding-left: 11px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.current-price-control input {
  width: 118px;
  height: 38px;
  padding: 0 10px 0 7px;
  color: var(--ink);
  background: transparent;
  border: 0;
  font-weight: 720;
}

.eyebrow,
.step-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.metrics-band {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(25, 38, 49, 0.04);
}

.metric {
  min-width: 0;
  padding: 18px 20px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric span {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 650;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 21px;
  line-height: 1.2;
}

.metric small {
  margin-top: 7px;
  overflow-wrap: anywhere;
  font-size: 11px;
  line-height: 1.35;
}

.positive {
  color: var(--sell) !important;
}

.negative {
  color: var(--buy) !important;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 3px;
  margin-bottom: 18px;
  padding: 3px;
  background: #e7ebee;
  border-radius: 8px;
}

.tab-button {
  min-height: 40px;
  padding: 0 18px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
}

.tab-button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(25, 38, 49, 0.12);
}

.state-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 12px 14px;
  color: #6f480a;
  background: var(--warning-soft);
  border: 1px solid #ecd7aa;
  border-radius: 7px;
  font-size: 13px;
}

.recognition-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.78fr) minmax(430px, 1.22fr);
  gap: 18px;
  align-items: start;
}

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

.section-heading,
.history-header {
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading h2,
.history-header h2,
.modal-header h2 {
  margin-top: 4px;
  font-size: 18px;
  line-height: 1.25;
}

.count-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.upload-target {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 156px;
  padding: 22px;
  place-items: center;
  align-content: center;
  gap: 7px;
  color: var(--accent-dark);
  background: var(--surface-soft);
  border: 1.5px dashed #9ab8b0;
  border-radius: 8px;
  font-weight: 740;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 160ms ease, background 160ms ease;
}

.upload-target.dragging {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.file-input-overlay {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-target small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.upload-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
}

.image-queue {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.image-item {
  display: grid;
  grid-template-columns: 24px 52px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 68px;
  padding: 8px 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.image-item.duplicate {
  background: #fff9ee;
  border-color: #ead5aa;
}

.image-item input[type="checkbox"],
.trade-check,
.check-label input {
  width: 19px;
  height: 19px;
  accent-color: var(--accent);
}

.image-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  object-position: top;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.image-meta {
  min-width: 0;
}

.image-meta strong,
.image-meta small {
  display: block;
}

.image-meta strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-meta small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.remove-image {
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 20px;
}

.panel-actions {
  gap: 10px;
  margin-top: 16px;
}

.panel-actions .primary-button {
  flex: 1;
}

.progress-wrap {
  margin-top: 16px;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  background: #e5eaed;
  border-radius: 3px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.progress-wrap p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  display: grid;
  min-height: 230px;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}

.empty-glyph {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  color: var(--muted);
  background: #edf0f2;
  border-radius: 50%;
  font-size: 17px;
  font-weight: 800;
}

.selection-toolbar {
  min-height: 42px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.recognition-warning {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 8px 0 12px;
  padding: 11px 12px;
  color: #6f480a;
  background: var(--warning-soft);
  border: 1px solid #ecd7aa;
  border-radius: 7px;
}

.recognition-warning strong,
.recognition-warning p {
  display: block;
  margin: 0;
}

.recognition-warning strong {
  font-size: 13px;
}

.recognition-warning p {
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.45;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.trade-list,
.history-list {
  display: grid;
  gap: 8px;
}

.trade-row {
  display: grid;
  grid-template-columns: 26px 58px minmax(0, 1fr) minmax(118px, auto) 38px;
  gap: 10px;
  align-items: center;
  min-height: 72px;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.trade-row.duplicate {
  background: #fff9ee;
  border-color: #ead5aa;
}

.trade-row.needs-review {
  border-color: #e4bd79;
}

.side-pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 760;
}

.side-pill.buy {
  color: var(--buy);
  background: var(--buy-soft);
}

.side-pill.sell {
  color: var(--sell);
  background: var(--sell-soft);
}

.trade-main,
.trade-time {
  min-width: 0;
}

.trade-main strong,
.trade-main small,
.trade-time span,
.trade-time small {
  display: block;
}

.trade-main strong {
  font-size: 15px;
}

.trade-main small,
.trade-time small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.trade-time {
  text-align: right;
}

.trade-time span {
  font-size: 12px;
  font-weight: 650;
}

.edit-trade,
.delete-trade {
  width: 36px;
  height: 36px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.status-badge {
  margin-top: 4px;
  padding: 0 6px;
  color: var(--warning);
  background: var(--warning-soft);
}

.batch-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 14px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.batch-summary div {
  padding: 0 12px;
  border-right: 1px solid var(--line);
}

.batch-summary div:first-child {
  padding-left: 0;
}

.batch-summary div:last-child {
  padding-right: 0;
  border-right: 0;
}

.batch-summary span,
.batch-summary strong {
  display: block;
}

.batch-summary span {
  color: var(--muted);
  font-size: 11px;
}

.batch-summary strong {
  margin-top: 5px;
  font-size: 14px;
}

.full-width {
  width: 100%;
  margin-top: 10px;
}

.history-header {
  margin-top: 2px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.history-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.history-selection-toolbar {
  margin-top: 14px;
}

.selected-history-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.history-empty {
  margin-top: 18px;
  background: var(--surface);
}

.history-list {
  margin-top: 16px;
}

.history-row {
  display: grid;
  grid-template-columns: 24px 70px minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) 42px;
  gap: 14px;
  align-items: center;
  min-height: 72px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.history-cell span,
.history-cell strong,
.history-cell small {
  display: block;
}

.history-cell span,
.history-cell small {
  color: var(--muted);
  font-size: 11px;
}

.history-cell strong {
  margin-top: 4px;
  font-size: 14px;
}

.modal {
  width: min(560px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow: auto;
  background: transparent;
  border: 0;
}

.modal::backdrop {
  background: rgba(13, 22, 29, 0.46);
  backdrop-filter: blur(5px);
}

.modal-card {
  padding: 22px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(10, 21, 28, 0.24);
}

.modal-header {
  align-items: flex-start;
  margin-bottom: 22px;
}

.modal-close {
  background: var(--surface-soft);
}

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

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

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

.form-section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.form-section-title span {
  font-size: 14px;
  font-weight: 760;
}

.form-section-title small,
.field-hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.field-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inline-action {
  min-height: 28px;
  padding: 0 7px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 0;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 124, 102, 0.12);
}

.full-span {
  grid-column: 1 / -1;
}

.modal-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.action-group {
  gap: 10px;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  color: #fff;
  background: #17222a;
  border-radius: 7px;
  box-shadow: 0 10px 30px rgba(12, 22, 29, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 900px) {
  .metrics-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric:nth-child(2),
  .metric:nth-child(4),
  .metric-total {
    border-right: 0;
  }

  .metric:nth-child(-n + 4) {
    border-bottom: 1px solid var(--line);
  }

  .metric-total {
    grid-column: 1 / -1;
  }

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

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    min-height: 104px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .brand-name {
    display: none;
  }

  .profile-actions {
    flex: 1;
    justify-content: flex-end;
  }

  .profile-select {
    width: min(180px, 47vw);
  }

  .profile-actions .compact {
    display: none;
  }

  .app-main {
    padding: 20px 14px calc(36px + env(safe-area-inset-bottom));
  }

  .profile-heading h1 {
    font-size: 24px;
  }

  .profile-heading-actions {
    align-items: flex-end;
    flex-direction: column;
  }

  .current-price-form {
    flex-wrap: wrap;
  }

  .metrics-band {
    margin-right: -14px;
    margin-left: -14px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .metric {
    min-height: 105px;
    padding: 15px 14px;
  }

  .metric strong {
    font-size: 18px;
  }

  .view-tabs {
    display: grid;
    width: 100%;
  }

  .state-notice {
    align-items: flex-start;
  }

  .recognition-warning {
    align-items: flex-start;
    flex-direction: column;
  }

  .tool-panel {
    padding: 17px 14px;
    border-radius: 7px;
    box-shadow: 0 5px 18px rgba(25, 38, 49, 0.06);
  }

  .trade-row {
    grid-template-columns: 24px 50px minmax(0, 1fr) 36px;
    gap: 8px;
  }

  .trade-time {
    grid-column: 3;
    text-align: left;
  }

  .edit-trade {
    grid-column: 4;
    grid-row: 1 / span 2;
  }

  .batch-summary div {
    padding: 0 8px;
  }

  .history-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .history-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .history-actions .secondary-button,
  .history-actions .danger-button {
    flex: 1;
    padding: 0 10px;
  }

  .history-selection-toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .selected-history-count {
    margin-left: 0;
  }

  .history-selection-toolbar .danger-button {
    margin-left: auto;
  }

  .history-row {
    grid-template-columns: 24px 58px minmax(0, 1fr) 36px;
    gap: 9px;
  }

  .history-row > .side-pill {
    grid-column: 2;
    grid-row: 1;
  }

  .history-price {
    grid-column: 3;
    grid-row: 1;
  }

  .history-time {
    grid-column: 3;
    grid-row: 2;
  }

  .history-amount {
    grid-column: 3;
    grid-row: 3;
  }

  .delete-trade {
    grid-column: 4;
    grid-row: 1 / span 3;
  }

  .modal {
    width: 100%;
    max-height: calc(100vh - env(safe-area-inset-top));
    margin: auto 0 0;
  }

  .modal-card {
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    border-radius: 8px 8px 0 0;
  }

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

  .form-section-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .full-span {
    grid-column: auto;
  }

  .split-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .action-group {
    width: 100%;
  }

  .action-group button {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
