:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #eef3f1;
  --line: #d7dee5;
  --text: #172026;
  --muted: #60707f;
  --accent: #176b58;
  --accent-strong: #0e4f40;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #b42318;
  --green: #15803d;
  --shadow: 0 8px 24px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  flex: 0 0 auto;
}

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

h1 {
  font-size: 1.35rem;
  line-height: 1.1;
}

h2 {
  font-size: 1.2rem;
}

h3 {
  font-size: 1rem;
}

.brand p,
.section-head p,
.muted,
.footer {
  color: var(--muted);
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.dot.ready {
  background: var(--green);
}

.dot.error {
  background: var(--red);
}

.app-shell {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  min-height: calc(100vh - 124px);
}

.sidebar {
  background: #e8edef;
  border-right: 1px solid var(--line);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

.nav-button,
.primary-button,
.secondary-button,
.chip,
.danger-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.nav-button {
  text-align: left;
  background: transparent;
  color: #34414c;
}

.nav-button:hover,
.nav-button.active {
  background: var(--surface);
  color: var(--accent-strong);
  border-color: var(--line);
}

.workspace {
  padding: 18px;
  min-width: 0;
}

.tool-view {
  display: none;
}

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

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

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

.tool-panel {
  padding: 14px;
  margin-bottom: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.compact-form .field-row {
  grid-template-columns: 150px minmax(130px, 1fr) 140px auto;
}

.wide-field {
  grid-column: span 2;
}

label {
  display: grid;
  gap: 6px;
  color: #3c4a55;
  font-size: 0.86rem;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #c8d1da;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfcfd;
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(23, 107, 88, 0.22);
  border-color: var(--accent);
}

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

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

.secondary-button {
  background: var(--surface);
  color: var(--accent-strong);
  border-color: #b8cbc5;
  font-weight: 700;
}

.secondary-button:hover {
  background: var(--surface-alt);
}

.danger-button {
  background: #fff5f2;
  color: var(--red);
  border-color: #f4c7be;
  min-height: 34px;
}

.button-row,
.quick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-row {
  margin-top: 12px;
}

.chip {
  min-height: 32px;
  background: #f7faf9;
  border-color: #d6e2de;
  color: #29423a;
  font-size: 0.88rem;
}

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

.result-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 14px;
  align-items: stretch;
}

.result-panel {
  min-height: 220px;
  padding: 14px;
  overflow: hidden;
}

.chart-panel {
  margin: 0;
  min-height: 320px;
  display: grid;
  place-items: start center;
  overflow: hidden;
  background: #fbfcfd;
  padding: 12px;
}

.chart-panel img {
  width: 100%;
  height: auto;
  max-height: 500px;
  object-fit: contain;
  display: block;
}

.block-title {
  margin: 14px 0 6px;
}

.empty-state {
  min-height: 180px;
  display: grid;
  align-content: center;
  gap: 8px;
  color: var(--muted);
}

.signal-grid,
.metric-grid,
.market-grid,
.access-grid {
  display: grid;
  gap: 12px;
}

.signal-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.metric-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.metric-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 4px;
}

.metric-value {
  font-weight: 800;
  font-size: 1.1rem;
}

.signal-up {
  color: var(--green);
}

.signal-down {
  color: var(--red);
}

.signal-neutral {
  color: var(--blue);
}

.text-output {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.5;
  margin: 0;
  color: #24323c;
  overflow-wrap: anywhere;
}

.watch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.watch-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  display: grid;
  gap: 10px;
}

.watch-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.watch-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.92rem;
}

.table th,
.table td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 9px 6px;
}

.table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.market-grid {
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
}

.heat-row,
.signal-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.heat-bar {
  height: 8px;
  border-radius: 8px;
  background: #dbe4ea;
  overflow: hidden;
}

.heat-fill {
  height: 100%;
  width: 50%;
  background: var(--blue);
}

.url-list {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.copy-line,
.url-pill {
  overflow-wrap: anywhere;
  background: #f2f6f5;
  border: 1px solid #d7e4df;
  border-radius: 8px;
  padding: 10px;
  color: #123d33;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

.loading {
  opacity: 0.7;
  pointer-events: none;
}

.footer {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.88rem;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-button {
    white-space: nowrap;
  }

  .field-row,
  .compact-form .field-row,
  .result-layout,
  .market-grid,
  .access-grid {
    grid-template-columns: 1fr;
  }

  .wide-field {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .status-strip {
    width: 100%;
    justify-content: flex-start;
    min-width: 0;
  }

  .workspace {
    padding: 12px;
  }

  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

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

  .chart-panel {
    min-height: 240px;
  }
}
