/* Oracle */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --border: #e4e7ec;
  --text: #111827;
  --text-muted: #6b7280;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --negative: #dc2626;
  --negative-soft: #fef2f2;
  --fresh: #fef9c3;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --leftbar: 240px;
  --rightbar: 280px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-alt: #1e222a;
    --border: #2a2f39;
    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --brand: #818cf8;
    --brand-soft: #23264a;
    --negative: #f87171;
    --negative-soft: #3a1d1f;
    --fresh: #3d3a12;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

/* the page itself never scrolls, the three panes under the top bar each
   scroll on their own so the top bar always stays put */
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

h1, h2 {
  margin: 0;
  font-weight: 600;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 18px;
}

a {
  color: inherit;
}

button {
  font: inherit;
}

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

.small {
  font-size: 12px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.node:focus-visible,
.twisty:focus-visible,
.tile:focus-visible,
button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* top bar, full width across the three panes */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
}

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

.brand > .material-symbols-outlined {
  font-size: 22px;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 9px;
  padding: 6px;
}

.status.error {
  color: var(--negative);
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

button.primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
}

button.primary:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary .material-symbols-outlined {
  font-size: 18px;
}

button.spinning .material-symbols-outlined {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.switch input {
  accent-color: var(--brand);
  margin: 0;
}

/* panes */

.panes {
  display: grid;
  grid-template-columns: var(--leftbar) minmax(0, 1fr) var(--rightbar);
  min-height: 0;
}

.leftbar,
.canvas,
.rightbar {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.leftbar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px 24px;
}

.canvas {
  padding: 20px 24px 48px;
}

.rightbar {
  background: var(--surface);
  border-left: 1px solid var(--border);
}

/* tree */

.tree,
.tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.noderow {
  display: flex;
  align-items: center;
  gap: 2px;
}

.twisty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}

.twisty:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.twisty .material-symbols-outlined {
  font-size: 20px;
  transition: transform 0.15s ease;
}

.branch.folded .twisty .material-symbols-outlined {
  transform: rotate(-90deg);
}

.branch.folded > .children {
  display: none;
}

.node {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

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

.node.selected {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.node.root {
  font-weight: 600;
}

.nodeicon {
  font-size: 20px;
  color: var(--text-muted);
}

.node.selected .nodeicon {
  color: var(--brand);
}

.nodelabel {
  flex: 1;
}

.badge {
  min-width: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.badge:empty {
  display: none;
}

.node.selected .badge {
  background: var(--surface);
  border-color: transparent;
  color: var(--brand);
}

/* the guide line runs under the twisty so the children sit under the label */
.children {
  margin: 2px 0 0 12px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.children li + li {
  margin-top: 2px;
}

/* canvas */

.canvashead {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.headicon {
  font-size: 24px;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 10px;
  padding: 8px;
}

.headtitle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
  font-size: 12px;
  border-radius: 999px;
  padding: 1px 9px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 16px;
}

.empty {
  color: var(--text-muted);
  padding: 20px 4px;
}

.empty.error {
  color: var(--negative);
}

/* overview tiles */

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

.tile {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
}

.tile:hover {
  border-color: var(--brand);
}

.tilehead {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tileicon {
  font-size: 20px;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 8px;
  padding: 6px;
}

.tilelabel {
  flex: 1;
  font-weight: 600;
}

.tilecount {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* chips */

.chips,
.totals {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.totals {
  margin-bottom: 12px;
}

.totalslabel {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 2px;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

.chip .code {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.chip .amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chip.negative {
  background: var(--negative-soft);
  border-color: transparent;
}

.chip.negative .amount {
  color: var(--negative);
}

/* profile table */

.tablewrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  white-space: nowrap;
}

td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.name {
  font-weight: 600;
  white-space: nowrap;
}

td.muted {
  white-space: nowrap;
}

/* pools */

.poolgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.pool {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.poolhead {
  display: flex;
  align-items: center;
  gap: 8px;
}

.poolhead .material-symbols-outlined {
  color: var(--brand);
  font-size: 20px;
}

.poolname {
  font-weight: 600;
  flex: 1;
}

/* two boxes side by side that never break a number, a reserve too long to
   share the row takes one of its own */
.reserves {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}

.reserve {
  flex: 1 1 0;
  min-width: max-content;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}

.reserve .code {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.reserve .big {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rates {
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rates strong {
  font-variant-numeric: tabular-nums;
}

.poolfoot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* a row or pool posted again since the last read */

.fresh {
  animation: fresh 2.5s ease-out;
}

@keyframes fresh {
  from { background-color: var(--fresh); }
}

/* narrower screens drop the empty right bar first */

@media (max-width: 1100px) {
  .panes {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .rightbar {
    display: none;
  }
}

/* phones put the tree in a strip above the canvas */

@media (max-width: 640px) {
  .topbar {
    padding: 10px 16px;
  }

  .status {
    order: 3;
    width: 100%;
  }

  button.primary {
    padding: 7px 9px;
  }

  .buttonlabel {
    display: none;
  }

  .panes {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .leftbar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .tree,
  .branch,
  .children,
  .branch.folded > .children {
    display: flex;
    gap: 4px;
  }

  .noderow,
  .children {
    margin: 0;
    padding: 0;
    border: none;
  }

  .children li + li {
    margin-top: 0;
  }

  .twisty {
    display: none;
  }

  .node {
    white-space: nowrap;
  }

  .canvas {
    padding: 16px 16px 40px;
  }
}
