:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-2: #fafafa;
  --ink: #202124;
  --muted: #68707a;
  --border: #dfe3e7;
  --border-strong: #c9d0d7;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --blue: #2563eb;
  --amber: #d97706;
  --red: #dc2626;
  --critical: #991b1b;
  --green: #138a53;
  --shadow: 0 8px 22px rgba(32, 33, 36, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-width: 0;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

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

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: calc(14px + env(safe-area-inset-top)) 22px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  line-height: 1.3;
  letter-spacing: 0;
}

.position-form {
  display: grid;
  grid-template-columns: minmax(110px, 140px) minmax(110px, 140px) minmax(92px, 118px) auto auto;
  gap: 10px;
  align-items: end;
}

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

input,
select {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

button {
  border: 0;
  cursor: pointer;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 40px;
  min-height: 40px;
  height: 40px;
  padding: 0 13px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
}

button:hover {
  border-color: var(--accent);
}

button svg {
  width: 17px;
  height: 17px;
}

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

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

.secondary-button {
  background: #eef7f5;
  border-color: #badbd5;
  color: var(--accent-dark);
  font-weight: 700;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.icon-button.small {
  width: 31px;
  height: 31px;
}

.workspace {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 1540px;
  margin: 0 auto;
  padding: 16px max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  flex: 1;
}

.watch-panel,
.tool-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.watch-panel {
  min-height: 420px;
  padding: 12px;
  align-self: start;
  position: sticky;
  top: 92px;
}

.analysis-panel {
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}

.watchlist {
  display: grid;
  gap: 8px;
  padding-top: 10px;
}

.watch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(58px, max-content);
  gap: 6px 10px;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 7px;
  text-align: left;
  min-width: 0;
  width: 100%;
  align-items: center;
  overflow: hidden;
}

.watch-row.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.watch-symbol {
  font-weight: 800;
  font-size: 15px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.watch-cost,
.watch-alert {
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.status-bar {
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: #eef2f5;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #3d4752;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.status-bar.warning {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.metric {
  display: grid;
  gap: 5px;
  min-height: 78px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

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

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

.metric strong.support-range {
  font-size: 18px;
  line-height: 1.25;
}

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 0 10px;
}

.chart-toolbar p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.alert-count {
  min-width: 88px;
  height: 32px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
  border: 1px solid var(--border-strong);
}

.alert-count.neutral {
  background: #f3f4f6;
  color: #4b5563;
}

.alert-count.hot {
  background: #fef2f2;
  color: var(--critical);
  border-color: #fecaca;
}

.chart-stack {
  display: grid;
  gap: 10px;
}

.chart {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.price-chart {
  height: clamp(360px, 42vh, 520px);
}

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

.small-chart {
  height: clamp(180px, 22vh, 240px);
}

.lower-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.tool-panel {
  min-height: 170px;
}

.alerts-list,
.events-list,
.ai-summary {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.alert-item,
.event-item {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel-2);
}

.alert-title,
.event-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
  margin-bottom: 5px;
  min-width: 0;
}

.alert-title span:first-child,
.event-title span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.alert-item.notice {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.alert-item.warning {
  border-color: #fed7aa;
  background: #fff7ed;
}

.alert-item.danger {
  border-color: #fecaca;
  background: #fef2f2;
}

.alert-item.critical {
  border-color: #fca5a5;
  background: #fff1f2;
}

.badge {
  flex: none;
  min-width: 46px;
  text-align: center;
  font-size: 11px;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 999px;
  background: #e5e7eb;
  color: #374151;
}

.badge.critical,
.badge.danger {
  background: #fee2e2;
  color: var(--critical);
}

.badge.warning {
  background: #ffedd5;
  color: #9a3412;
}

.badge.notice {
  background: #dbeafe;
  color: #1d4ed8;
}

.alert-detail,
.event-detail {
  color: #4b5563;
  font-size: 13px;
  line-height: 1.45;
}

.event-link {
  color: var(--blue);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.event-link:hover {
  text-decoration: underline;
}

.ai-panel {
  margin-top: 12px;
}

.ai-summary {
  color: #374151;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-line;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  color: var(--muted);
  padding: 14px 2px;
  text-align: center;
  font-size: 13px;
}

.footer-note {
  padding: 10px max(18px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

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

.negative {
  color: var(--red);
}

@media (max-width: 1020px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .position-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(108px, 0.6fr) auto auto;
  }

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

  .watch-panel {
    position: static;
    min-height: auto;
  }

  .watchlist {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    position: static;
    padding: calc(12px + env(safe-area-inset-top)) 12px 12px;
  }

  .eyebrow {
    font-size: 11px;
  }

  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 14px;
  }

  input,
  select,
  button {
    height: 44px;
    min-height: 44px;
  }

  .icon-button {
    width: 44px;
  }

  .workspace {
    gap: 12px;
    padding: 12px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  }

  .position-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
  }

  .position-form label:nth-of-type(3) {
    grid-column: 1 / 2;
  }

  .position-form .primary-button {
    grid-column: 2 / 3;
    width: 100%;
  }

  .position-form .icon-button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .watch-panel {
    padding: 10px;
  }

  .watchlist {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 1px 2px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .watch-row {
    flex: 0 0 178px;
    scroll-snap-align: start;
  }

  .status-bar {
    min-height: 42px;
    padding: 8px 10px;
    align-items: flex-start;
  }

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

  .metric {
    min-height: 72px;
    padding: 10px;
  }

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

  .metric strong.support-range {
    font-size: 15px;
  }

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

  .chart-toolbar {
    align-items: flex-start;
  }

  .chart-toolbar p {
    font-size: 12px;
  }

  .alert-count {
    height: 30px;
    min-width: 76px;
    font-size: 12px;
  }

  .indicator-row,
  .lower-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .price-chart {
    height: clamp(320px, 58vh, 460px);
  }

  .small-chart {
    height: 190px;
  }

  .panel-header {
    padding: 10px;
  }

  .alerts-list,
  .events-list,
  .ai-summary {
    padding: 10px;
  }

  .alert-item,
  .event-item {
    padding: 10px;
  }
}

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

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

  .position-form label {
    min-width: 0;
  }

  .position-form label:nth-of-type(1),
  .position-form label:nth-of-type(2) {
    grid-column: span 1;
  }

  .position-form label:nth-of-type(3),
  .position-form .primary-button,
  .position-form .icon-button {
    grid-column: 1 / -1;
  }

  .chart-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

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

  .watch-row {
    flex-basis: 168px;
  }
}

@media (max-width: 390px) {
  .workspace {
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

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

  .price-chart {
    height: 330px;
  }

  .small-chart {
    height: 176px;
  }

  .alert-title,
  .event-title {
    align-items: flex-start;
  }

  .badge {
    min-width: 40px;
  }
}
