:root {
  color-scheme: dark;
  --bg: #0a0f14;
  --surface: #101820;
  --surface-2: #14202a;
  --line: #24323d;
  --text: #eef5f8;
  --muted: #8fa3ad;
  --accent: #43d6a0;
  --accent-2: #6aa8ff;
  --danger: #ff6b6b;
  --warn: #f3c969;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.is-hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

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

.login-panel .brand {
  margin-bottom: 2px;
}

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

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1218;
  color: var(--text);
  padding: 10px 11px;
  font: inherit;
}

.form-message {
  color: var(--warn);
  min-height: 20px;
  font-size: 13px;
}

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

.rail {
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  background: #0c1218;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 30px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 45px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #06100c;
  font-weight: 800;
}

.brand-text {
  font-weight: 700;
}

nav {
  display: grid;
  gap: 6px;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
}

nav a.active,
nav a:hover {
  background: var(--surface);
  color: var(--text);
}

main {
  padding: 28px;
  display: grid;
  gap: 18px;
}

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

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 10px;
  color: var(--muted);
  background: #0c1218;
  font-size: 13px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
}

.status-pill,
.panel,
.metric {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
}

.status-pill {
  padding: 9px 12px;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.ok {
  color: var(--accent);
}

.status-pill.warn {
  color: var(--warn);
}

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

.metric {
  padding: 16px;
  min-height: 110px;
  display: grid;
  align-content: space-between;
}

.metric span,
.panel-head span,
small {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 28px;
  line-height: 1.1;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
}

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

canvas {
  width: 100%;
  height: 220px;
  max-height: 220px;
  display: block;
}

.chart-canvas {
  height: 220px;
  max-height: 220px;
}

.reasoning {
  color: #c8d7dd;
  line-height: 1.55;
  max-height: 220px;
  overflow: auto;
}

.llm-decision {
  display: grid;
  gap: 12px;
}

.llm-decision pre {
  max-height: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.llm-rows {
  display: grid;
  gap: 8px;
}

.llm-row {
  display: grid;
  grid-template-columns: 80px auto 64px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.llm-row p {
  color: var(--muted);
  overflow-wrap: anywhere;
}

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

.market-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.market-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.market-card strong {
  font-size: 24px;
}

.kv {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.kv div {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 10px;
}

.kv span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.event-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.event {
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: #dbe7ec;
  font-size: 13px;
}

.operation-list {
  display: grid;
  gap: 10px;
}

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

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

.operation-card strong {
  font-size: 20px;
}

.pnl-positive {
  color: var(--accent);
}

.pnl-negative {
  color: var(--danger);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #1c2b35;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}

.tag.buy {
  color: var(--accent);
}

.tag.sell {
  color: var(--danger);
}

.tag.hold {
  color: var(--warn);
}

.segmented {
  display: flex;
  gap: 4px;
  background: #0c1218;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
}

.metric strong small {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
}

button {
  border: 0;
  border-radius: 6px;
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

button.selected {
  background: var(--surface-2);
  color: var(--text);
}

.primary-button {
  background: var(--accent);
  color: #06100c;
  font-weight: 800;
}

.user-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 140px auto;
  gap: 8px;
  margin-bottom: 12px;
}

.table-wrap.compact table {
  min-width: 420px;
}

pre {
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #070b0f;
  color: #b8c7ce;
  overflow: auto;
  max-height: 360px;
  font-size: 12px;
  line-height: 1.45;
}

.log-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.log-view {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #070b0f;
  color: #b8c7ce;
  overflow: auto;
  max-height: 460px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.log-line {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 8px;
  padding: 5px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.log-level {
  color: var(--muted);
  font-weight: 800;
}

.log-line.error .log-level,
.log-line.error .log-message {
  color: var(--danger);
}

.log-line.warning .log-level,
.log-line.warning .log-message {
  color: var(--warn);
}

.log-line.info .log-level {
  color: var(--accent-2);
}

.log-line.debug {
  color: var(--muted);
}

.inline-control {
  min-width: 120px;
}

.decision-list {
  display: none;
}

.decision-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
  display: grid;
  gap: 9px;
}

.decision-item header,
.decision-meta,
.row-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.decision-item header {
  justify-content: space-between;
}

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

.decision-item p {
  color: #c8d7dd;
  line-height: 1.45;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  margin-right: 7px;
  background: var(--muted);
}

.status-dot.ok {
  background: var(--accent);
}

.status-dot.off {
  background: var(--danger);
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.modal-panel {
  width: min(440px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  display: grid;
  gap: 14px;
}

.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
}

.password-field button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.modal-actions {
  justify-content: flex-end;
}

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

  .rail {
    position: sticky;
    z-index: 10;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  .brand {
    margin-bottom: 10px;
  }

  nav {
    grid-auto-flow: column;
    overflow-x: auto;
    justify-content: start;
  }

  main {
    padding: 18px 12px 28px;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    justify-content: start;
  }

  .metrics-grid,
  .grid.two,
  .user-form {
    grid-template-columns: 1fr;
  }

  .llm-row {
    grid-template-columns: 1fr auto;
  }

  .llm-row p {
    grid-column: 1 / -1;
  }

  .diary-table {
    display: none;
  }

  .decision-list {
    display: grid;
    gap: 10px;
  }

  .log-line {
    grid-template-columns: 1fr;
  }

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