:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5eb;
  --text: #1a1d26;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --bar-track: #e8ebf0;
  --bar-fill: #2563eb;
  --error: #c62828;
  font-family: "IBM Plex Sans", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 max(1rem, calc((100vw - 1400px) / 2));
  position: sticky;
  top: 0;
  z-index: 10;
}

.tabs button,
.tabs a.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.95rem;
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-decoration: none;
}

.tabs button:hover,
.tabs a.tab:hover {
  color: var(--text);
  text-decoration: none;
}

.tabs button.active,
.tabs a.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.panel { display: none; }
.panel.active { display: block; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card strong { font-size: 1.7rem; font-weight: 650; }
.card p { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.9rem; }

.hardware-cards {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.metrics {
  margin: 0.9rem 0 0;
  display: grid;
  gap: 0.35rem;
}

.metrics > div {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.metrics dt {
  margin: 0;
  color: var(--muted);
}

.metrics dd {
  margin: 0;
}

.hint {
  margin: 0.9rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.file-list {
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  overflow-x: auto;
}

.file-list-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.45rem;
}

.file-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: max-content;
}

.file-list li {
  display: grid;
  grid-template-columns: 4.5rem auto;
  gap: 0.5rem;
  align-items: start;
  padding: 0.28rem 0;
  font-size: 0.82rem;
}

.file-size {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.file-path {
  white-space: nowrap;
}

.file-list-meta {
  margin: 0.45rem 0 0;
  font-size: 0.78rem;
}

.compact-table table {
  font-size: 0.82rem;
}

.compact-table th,
.compact-table td {
  padding: 0.4rem 0.5rem;
}

.bot-row,
.inspect-row {
  cursor: pointer;
}

.threefactor-row {
  cursor: pointer;
}

.bot-row:hover,
.bot-row.open,
.inspect-row:hover,
.inspect-row.open,
.threefactor-row:hover,
.threefactor-row.open {
  background: #f3f6fb;
}

.bot-detail td,
.inspect-detail td {
  background: #fafbfc;
  padding: 0.85rem 0.75rem 1rem;
}

.threefactor-detail td {
  background: #fafbfc;
  padding: 0.85rem 0.75rem 1rem;
}

.bot-detail-panels {
  display: grid;
  gap: 0.75rem;
}

.source-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}

.source-panel summary {
  cursor: pointer;
  font-weight: 600;
}

.source-panel .source-content {
  margin-top: 0.65rem;
  max-height: 55vh;
  overflow: auto;
}

.source-panel .source-log {
  white-space: pre;
  overflow-wrap: normal;
}

.source-note {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
}

.bar {
  height: 8px;
  background: var(--bar-track);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.75rem;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--bar-fill);
}

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

/* Strategies tab: denser tables, wrap naturally (no horizontal scroll) */
#panel-strategies .table-wrap {
  overflow-x: visible;
}

#panel-strategies .table-wrap:has(.bots-table) {
  max-width: 100%;
  overflow-x: hidden;
}

#panel-strategies .bots-table {
  table-layout: fixed;
  width: 100%;
}

#panel-threefactor-rebalances .threefactor-table {
  table-layout: fixed;
  width: 100%;
}

#panel-threefactor-rebalances .threefactor-table .threefactor-detail > td {
  overflow: hidden;
}

#panel-threefactor-rebalances .threefactor-table-wrap {
  max-width: 100%;
  overflow-x: hidden;
}

#panel-threefactor-rebalances table {
  font-size: 0.8125rem;
}

#panel-threefactor-rebalances th,
#panel-threefactor-rebalances td {
  padding: 0.42rem 0.55rem;
  vertical-align: top;
  line-height: 1.35;
}

#panel-threefactor-rebalances th {
  font-size: 0.72rem;
  line-height: 1.25;
}

#panel-threefactor-rebalances .mono {
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

#panel-threefactor-rebalances .bot-detail-panels {
  min-width: 0;
  max-width: 100%;
}

#panel-threefactor-rebalances .source-panel {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

#panel-threefactor-rebalances .source-panel summary {
  overflow: hidden;
  text-overflow: ellipsis;
}

#panel-threefactor-rebalances .source-panel .source-content {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  margin-top: 0.65rem;
  max-height: 55vh;
  overflow: auto;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}

#panel-threefactor-rebalances .threefactor-charts {
  margin-bottom: 0.9rem;
  font-size: 0.8125rem; /* match the table so summaries look like the per-file panels */
  line-height: 1.35;
}

#panel-threefactor-rebalances .threefactor-plot {
  width: 100%;
  min-height: 150px;
  max-height: 70vh;
  overflow-y: auto;
  margin-top: 0.65rem;
}

#panel-strategies .bots-table .bot-detail > td {
  overflow: hidden;
}

#panel-strategies .idle-strategies-table,
#panel-strategies .unused-configs-table,
#panel-strategies .backups-table {
  table-layout: fixed;
  width: 100%;
}

#panel-strategies .idle-strategies-table .inspect-detail > td,
#panel-strategies .unused-configs-table .inspect-detail > td,
#panel-strategies .backups-table .inspect-detail > td {
  overflow: hidden;
}

#panel-strategies .bot-detail-panels {
  min-width: 0;
  max-width: 100%;
}

#panel-strategies .source-panel {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

#panel-strategies .source-panel summary {
  overflow: hidden;
  text-overflow: ellipsis;
}

#panel-strategies .source-panel .source-content {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  margin-top: 0.65rem;
  max-height: 55vh;
  overflow: auto;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}

#panel-strategies table {
  font-size: 0.8125rem;
}

#panel-strategies th,
#panel-strategies td {
  padding: 0.42rem 0.55rem;
  vertical-align: top;
  line-height: 1.35;
}

#panel-strategies th {
  font-size: 0.72rem;
  line-height: 1.25;
}

#panel-strategies .mono {
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

#panel-strategies .bots-table th:last-child,
#panel-strategies .bots-table .ui-cell {
  width: 4.5rem;
  white-space: nowrap;
}

#panel-strategies .ui-link {
  font-size: 0.8125rem;
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

th, td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

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

tr:last-child td { border-bottom: 0; }

.status {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: #eef0f4;
  color: #374151;
  white-space: nowrap;
  font-size: 0.85rem;
}

.status-running_healthy,
.status-running { background: #e6f6ec; color: #17663a; }
.status-running_unhealthy,
.status-load_error { background: #fde8ea; color: #a11b28; }
.status-configured_stopped,
.status-stopped { background: #fff4e0; color: #8a5a00; }
.status-available { background: #e8f1ff; color: #1d4f91; }
.status-missing { background: #f3e8fb; color: #6b3d8a; }

.muted { color: var(--muted); }
.mono {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}
.error { color: var(--error); }

.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.plain-list li:last-child { border-bottom: 0; }

.log-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1rem;
}

.log-sources {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
}

.log-sources a.active { font-weight: 600; color: var(--text); }

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  max-height: 70vh;
  overflow: auto;
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

@media (max-width: 800px) {
  .log-layout { display: block; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tabs button,
  .tabs a.tab { white-space: nowrap; }
}

/* freqtrade_donch seasonality tab */
#panel-donch .donch-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

#panel-donch .donch-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

#panel-donch .donch-subtitle {
  font-weight: 400;
  font-size: 0.9rem;
  margin-left: 0.35rem;
}

#panel-donch .donch-note {
  margin: 0 0 0.9rem;
  font-size: 0.82rem;
}

#panel-donch .metric-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

#panel-donch .metric-toggle button {
  appearance: none;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

#panel-donch .metric-toggle button:last-child {
  border-right: 0;
}

#panel-donch .metric-toggle button:hover {
  color: var(--text);
}

#panel-donch .metric-toggle button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

#panel-donch .donch-grid {
  /* fixed two columns so entries fill row one and exits row two */
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 860px) {
  #panel-donch .donch-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

#panel-donch .donch-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.4rem;
  margin: 0 0 0.9rem;
  padding: 0.6rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

#panel-donch .donch-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

#panel-donch .donch-control-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-right: 0.15rem;
}

#panel-donch .donch-select {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.32rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

#panel-donch .donch-check,
#panel-donch .donch-inline-label {
  font-size: 0.8rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

#panel-donch .donch-candle-status {
  font-size: 0.8rem;
}

#panel-donch .donch-warnings {
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid #f5d38a;
  background: #fff8e6;
  border-radius: 8px;
  font-size: 0.82rem;
  color: #7c4a03;
}

#panel-donch .donch-warnings p {
  margin: 0.15rem 0;
}

#panel-donch .donch-wide {
  grid-column: 1 / -1;
}

#panel-donch .donch-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

#panel-donch .donch-card-head h3 {
  margin-bottom: 0;
}

#panel-donch .donch-daily-plot {
  min-height: 320px;
}

.update-button.secondary {
  background: var(--surface);
  color: var(--accent);
}

#panel-donch .donch-plot {
  width: 100%;
  min-height: 260px;
  margin-top: 0.5rem;
}

/* Manual update buttons */
.panel-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-toolbar-note {
  font-size: 0.82rem;
}

.update-button {
  appearance: none;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
}

.update-button:hover {
  filter: brightness(1.08);
}

.update-button:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Login page and sign-out */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem 1.6rem 1.7rem;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
}

.login-card .muted {
  margin: 0 0 1rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.login-form label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 0.5rem;
}

.login-form input {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.login-form input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.login-form .update-button {
  margin-top: 1rem;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
}

.login-error {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

.login-notice {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid #f5d38a;
  background: #fff8e6;
  border-radius: 8px;
  font-size: 0.8rem;
  color: #7c4a03;
  word-break: break-word;
}

.tabs .logout-form {
  margin-left: auto;
  display: flex;
  align-items: center;
}

.tabs .logout-button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}

.tabs .logout-button:hover {
  color: var(--text);
  border-color: var(--accent);
}
