:root {
  --paper: #f6f2ea;
  --paper-strong: #fffaf1;
  --ink: #242321;
  --muted: #6d675c;
  --line: #d8cec0;
  --teal: #287c73;
  --teal-soft: #d7ebe6;
  --coral: #d85b43;
  --coral-soft: #f6d8cf;
  --gold: #b98d1f;
  --gold-soft: #f1e3ba;
  --blue: #4d5e9d;
  --blue-soft: #dbe1f4;
  --green: #287a4d;
  --red: #a54034;
  --shadow: 0 18px 40px rgba(52, 43, 33, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(90deg, rgba(36, 35, 33, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(36, 35, 33, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px, 28px 28px, auto;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Aptos", "Segoe UI", "Trebuchet MS", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1160px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 24px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 2px 14px;
}

.kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 34px;
  font-weight: 700;
}

h2 {
  margin-bottom: 2px;
  font-size: 18px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 4px;
  font-size: 16px;
}

.runtime-strip,
.tabs,
.panel-head,
.metric-grid,
.row-actions,
.trust-footer {
  display: flex;
  align-items: center;
}

.runtime-strip {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-strong);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.status-good {
  border-color: #a9d2c4;
  background: var(--teal-soft);
  color: var(--teal);
}

.status-warn {
  border-color: #e4c378;
  background: var(--gold-soft);
  color: #77580c;
}

.status-bad {
  border-color: #e0a89d;
  background: var(--coral-soft);
  color: var(--red);
}

.status-muted {
  color: var(--muted);
}

.tabs {
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.76);
}

.tab {
  min-height: 36px;
  padding: 8px 13px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.is-active {
  background: var(--ink);
  color: var(--paper-strong);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.workspace.has-side-panel {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) minmax(260px, 300px);
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.9);
  box-shadow: var(--shadow);
}

.market-panel,
.side-panel {
  padding: 14px;
}

.analyzer-panel {
  overflow: hidden;
}

.panel-head {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.sub-panel-head {
  display: grid;
  gap: 2px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.sub-panel-head h3 {
  margin-bottom: 0;
}

.sub-panel-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-head p,
.empty-copy,
.trust-footer {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.icon-button:hover,
.primary-button:hover,
.gift-row:hover,
.compact-item:hover {
  transform: translateY(-1px);
}

.search-box,
.alert-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-box input,
.alert-form input,
.alert-form select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.search-box input:focus,
.alert-form input:focus,
.alert-form select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(40, 124, 115, 0.14);
}

.gift-list,
.compact-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.gift-row,
.compact-item {
  width: 100%;
  min-height: 74px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 9px;
  text-align: left;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.gift-row.is-active {
  border-color: var(--ink);
  background: #fff8e7;
}

.gift-art {
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  object-fit: cover;
}

.row-copy {
  min-width: 0;
}

.row-title,
.metric-value,
.signal-title {
  font-weight: 900;
}

.row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.row-title span:first-child,
.compact-item strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.price-tag {
  flex: 0 0 auto;
  color: var(--gold);
  font-size: 12px;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-chip {
  min-height: 22px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.mini-chip.good {
  background: #dff0dc;
  color: var(--green);
}

.mini-chip.bad {
  background: var(--coral-soft);
  color: var(--red);
}

.mini-chip.warn {
  background: var(--gold-soft);
  color: #77580c;
}

.analyzer-card {
  display: grid;
  min-height: 640px;
  grid-template-rows: auto 1fr;
}

.analyzer-hero {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 16px;
  padding: 18px;
  background: #fff6df;
  border-bottom: 1px solid var(--line);
}

.analyzer-hero img {
  width: 132px;
  height: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  object-fit: cover;
}

.analyzer-title h2 {
  margin-bottom: 8px;
  font-size: 24px;
}

.signal-box {
  display: grid;
  gap: 7px;
  margin-top: 10px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fffdf8;
}

.signal-box[data-signal="interesting_growth"] {
  border-color: #a9d2c4;
  background: var(--teal-soft);
}

.signal-box[data-signal="overheat_risk"] {
  border-color: #e0a89d;
  background: var(--coral-soft);
}

.signal-box[data-signal="monitor_closely"] {
  border-color: #d6c16d;
  background: var(--gold-soft);
}

.signal-box[data-signal="avoid"] {
  border-color: #cdb7b0;
  background: #f4e5df;
}

.signal-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.signal-box p {
  margin-bottom: 0;
  color: var(--ink);
}

.analyzer-body {
  padding: 16px 18px 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
}

.metric {
  min-height: 80px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-value {
  display: block;
  margin-top: 7px;
  font-size: 18px;
}

.meter-stack {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.meter-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 56px;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.meter-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8dfd0;
}

.meter-fill {
  height: 100%;
  width: var(--value, 0%);
  border-radius: inherit;
  background: var(--teal);
}

.meter-fill.bad {
  background: var(--coral);
}

.meter-fill.warn {
  background: var(--gold);
}

.row-actions {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.primary-button,
.ghost-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 900;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.primary-button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper-strong);
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
}

.primary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
}

.analyzer-empty {
  min-height: 640px;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 24px;
  text-align: center;
}

.side-panel {
  display: none;
}

.side-panel.is-visible {
  display: block;
}

.compact-item {
  grid-template-columns: 1fr auto;
  min-height: 54px;
}

.compact-item small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.compact-item.is-event {
  grid-template-columns: 1fr;
}

.alert-form {
  display: grid;
  gap: 9px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  max-width: min(420px, calc(100% - 28px));
  transform: translate(-50%, 24px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper-strong);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.trust-footer {
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 2px 0;
}

.skeleton {
  min-height: 74px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.72), transparent),
    #e9dfd2;
  background-size: 180px 100%, auto;
  animation: shimmer 1.35s linear infinite;
}

@keyframes shimmer {
  from {
    background-position: -180px 0, 0 0;
  }
  to {
    background-position: calc(100% + 180px) 0, 0 0;
  }
}

@media (max-width: 980px) {
  .workspace,
  .workspace.has-side-panel {
    grid-template-columns: minmax(270px, 340px) minmax(0, 1fr);
  }

  .side-panel {
    grid-column: 1 / -1;
  }

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

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 16px, 560px);
    padding-top: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 30px;
  }

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

  .market-panel {
    display: block;
  }

  .market-panel.is-collapsed {
    display: none;
  }

  .workspace.has-side-panel .analyzer-panel {
    display: none;
  }

  .analyzer-card,
  .analyzer-empty {
    min-height: 0;
  }

  .analyzer-hero {
    grid-template-columns: 88px minmax(0, 1fr);
    padding: 14px;
  }

  .analyzer-hero img {
    width: 88px;
    height: 88px;
  }

  .analyzer-title h2 {
    font-size: 21px;
  }

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

  .meter-row {
    grid-template-columns: 88px minmax(0, 1fr) 48px;
  }

  .trust-footer {
    display: grid;
  }
}

@media (max-width: 420px) {
  .topbar {
    display: grid;
    gap: 10px;
  }

  .runtime-strip {
    justify-content: flex-start;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    flex: 1 0 auto;
  }

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