:root {
  color-scheme: dark;
  --bg: #050607;
  --sidebar: #080c0d;
  --panel: #0c1112;
  --panel-2: #0f1516;
  --line: #1d292b;
  --line-strong: #2d3d40;
  --text: #d8e4e1;
  --muted: #82948f;
  --faint: #52615e;
  --accent: #61e6ad;
  --accent-soft: rgba(97, 230, 173, 0.12);
  --warn: #f1bf67;
  --bad: #ff7474;
  --user: #e7fff0;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.auth-shell {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-form {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  display: grid;
  gap: 14px;
  max-width: 400px;
  padding: 24px;
  width: 100%;
}

.auth-form label {
  color: var(--muted);
  display: grid;
  gap: 6px;
}

.auth-error {
  color: var(--bad);
  margin: 0;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  position: relative;
}

@supports (height: 100dvh) {
  .chat-shell {
    height: 100dvh;
  }
}

.chat-shell .empty-state {
  display: grid;
  inset: 58px 0 0;
  place-content: center;
}

.chat-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 58px;
  padding: 10px 18px;
}

.history-controls {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: center;
  min-height: 44px;
  padding: 5px 18px;
  flex: 0 0 auto;
}

.history-controls button {
  min-height: 28px;
}

.account-bar {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Cascadia Mono", "Consolas", "SFMono-Regular", monospace;
  font-size: 13px;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  background: #07100d;
  border: 1px solid var(--line);
  color: var(--accent);
  cursor: pointer;
  min-height: 34px;
  padding: 0 12px;
}

button:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

button:disabled {
  color: var(--faint);
  cursor: wait;
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.brand-block {
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.brand {
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
}

.runtime {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics {
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.metric {
  border-right: 1px solid var(--line);
  padding: 12px 10px;
}

.metric:last-child {
  border-right: 0;
}

.metric span {
  color: var(--faint);
  display: block;
  font-size: 11px;
}

.metric strong {
  color: var(--text);
  display: block;
  font-size: 18px;
  margin-top: 2px;
}

.nav {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  padding: 12px;
}

.nav button {
  width: 100%;
}

.side-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  overflow: hidden;
}

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

.panel-head span {
  color: var(--accent);
  font-weight: 700;
}

.panel-head button {
  min-height: 28px;
  padding: 0 8px;
}

.panel-body {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.panel-toolbar {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  margin-bottom: 10px;
}

input,
select,
textarea {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  outline: none;
}

input {
  min-height: 34px;
  padding: 0 10px;
  width: 100%;
}

select {
  min-height: 34px;
  padding: 0 10px;
  width: 100%;
}

textarea {
  min-height: 72px;
  padding: 10px;
  resize: vertical;
  width: 100%;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
}

.panel-summary {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
}

.memory-list,
.routine-list,
.event-list,
.record-list {
  display: grid;
  gap: 8px;
}

.finance-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 12px;
}

.status-view,
.activity-status {
  display: grid;
  gap: 10px;
}

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

.finance-card {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px;
}

.status-card {
  background: var(--panel);
  border: 1px solid var(--line);
  min-width: 0;
  padding: 10px;
}

.finance-card span {
  color: var(--faint);
  display: block;
  font-size: 11px;
}

.finance-card strong,
.status-card strong {
  color: var(--text);
  display: block;
  font-size: 15px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.status-card span {
  color: var(--faint);
  display: block;
  font-size: 11px;
}

.record {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px;
}

.record-head {
  color: var(--accent);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.record-body {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.record-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.record-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.record-controls button {
  min-height: 28px;
  padding: 0 8px;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.commandbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 64px;
  padding: 12px 18px;
}

.command-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.command-subtitle,
.activity-line {
  color: var(--muted);
  font-size: 12px;
}

.transcript {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px 26px;
  scroll-behavior: smooth;
}

.message {
  background: rgba(12, 17, 18, 0.56);
  border-left: 2px solid var(--line-strong);
  box-shadow: inset 0 0 0 1px rgba(45, 61, 64, 0.38);
  margin: 0 0 14px;
  max-width: 980px;
  padding: 10px 12px;
}

.message.user {
  border-color: var(--user);
  background: rgba(231, 255, 240, 0.035);
}

.message.agent {
  border-color: var(--accent);
  background: rgba(97, 230, 173, 0.045);
}

.message.error {
  border-color: var(--bad);
  background: rgba(255, 116, 116, 0.05);
}

.meta {
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 10px;
  margin-bottom: 6px;
}

.content {
  max-height: 46vh;
  overflow: auto;
  padding-right: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

.trace {
  max-width: 980px;
  margin-top: 10px;
}

.trace details {
  background: var(--panel);
  border: 1px solid var(--line);
  margin-top: 8px;
  max-height: 360px;
  overflow: auto;
}

.trace summary {
  cursor: pointer;
  padding: 8px 10px;
}

.trace pre,
.json-block {
  border-top: 1px solid var(--line);
  color: var(--muted);
  margin: 0;
  overflow-x: auto;
  padding: 10px;
  white-space: pre-wrap;
}

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

.fail {
  color: var(--bad);
}

.pending {
  color: var(--warn);
}

.composer {
  border-top: 1px solid var(--line);
  background: var(--bg);
  display: grid;
  flex: 0 0 auto;
  gap: 10px;
  grid-template-columns: 1fr auto;
  padding: 12px 18px 16px;
  z-index: 2;
}

.composer button {
  min-width: 96px;
}

.empty-state {
  align-self: center;
  color: var(--faint);
  justify-self: center;
  pointer-events: none;
  position: absolute;
  text-align: center;
}

.empty-state div {
  color: var(--accent);
  font-size: 24px;
  font-weight: 700;
}

.empty-state p {
  margin: 6px 0 0;
}

.main:has(.message) .empty-state {
  display: none;
}

* {
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--line-strong);
}

::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-bottom: 1px solid var(--line);
    border-right: 0;
    max-height: 54vh;
    min-height: 0;
  }

  .side-panel {
    max-height: 34vh;
  }

  .main {
    height: auto;
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .metrics {
    grid-template-columns: 1fr 1fr 1fr;
  }

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

  .commandbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

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

  .composer button {
    width: 100%;
  }
}

.finance-page {
  overflow: auto;
}

.finance-shell {
  display: grid;
  gap: 14px;
  min-height: 100vh;
  padding: 18px;
}

.finance-topbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 64px;
  padding-bottom: 14px;
}

.finance-title {
  color: var(--accent);
  font-size: 20px;
  font-weight: 700;
}

.finance-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

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

.finance-actions a {
  align-items: center;
  background: #07100d;
  border: 1px solid var(--line);
  color: var(--accent);
  display: inline-flex;
  min-height: 34px;
  padding: 0 12px;
  text-decoration: none;
}

.finance-actions a:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.finance-filters {
  align-items: end;
  display: flex;
  gap: 12px;
}

.finance-filters label,
.budget-form label,
.import-form label {
  color: var(--muted);
  display: grid;
  gap: 6px;
  min-width: 180px;
}

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

.finance-stat-card,
.finance-section,
.budget-row {
  background: var(--panel);
  border: 1px solid var(--line);
}

.finance-stat-card {
  min-height: 88px;
  padding: 12px;
}

.finance-stat-card span {
  color: var(--faint);
  display: block;
  font-size: 12px;
}

.finance-stat-card strong {
  color: var(--text);
  display: block;
  font-size: 20px;
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.finance-dashboard {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.finance-section {
  min-width: 0;
  padding: 14px;
}

.section-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 10px;
}

.section-head h2 {
  color: var(--text);
  font-size: 15px;
  margin: 0;
}

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

.chart-layout {
  align-items: center;
  display: grid;
  gap: 16px;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 240px;
}

.pie-chart {
  align-items: center;
  aspect-ratio: 1;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--muted);
  display: flex;
  justify-content: center;
  width: 220px;
}

.legend-list,
.budget-list {
  display: grid;
  gap: 8px;
}

.legend-row {
  align-items: center;
  border-bottom: 1px solid rgba(45, 61, 64, 0.5);
  display: grid;
  gap: 8px;
  grid-template-columns: auto 1fr auto auto;
  padding: 7px 0;
}

.legend-dot {
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.legend-row strong {
  color: var(--text);
  font-weight: 600;
}

.legend-row em {
  color: var(--muted);
  font-style: normal;
  min-width: 48px;
  text-align: right;
}

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

.import-section {
  display: grid;
  gap: 10px;
}

.import-form {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(280px, 1fr) auto;
}

.import-actions {
  display: flex;
  gap: 8px;
}

.import-result {
  display: grid;
  gap: 10px;
}

.import-summary {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 8px 14px;
}

.table-wrap.compact {
  max-height: 220px;
}

.budget-row {
  padding: 10px;
}

.budget-row.over {
  border-color: var(--bad);
}

.budget-line {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.budget-line strong {
  color: var(--accent);
}

.budget-line span,
.budget-meta,
.budget-hint,
.empty-inline {
  color: var(--muted);
  font-size: 12px;
}

.budget-bar {
  background: #060909;
  border: 1px solid var(--line);
  height: 9px;
  margin: 8px 0;
  overflow: hidden;
}

.budget-bar span {
  background: linear-gradient(90deg, var(--accent), var(--warn));
  display: block;
  height: 100%;
}

.budget-row.over .budget-bar span {
  background: var(--bad);
}

.table-wrap {
  max-height: 440px;
  overflow: auto;
}

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

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

th {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  color: var(--text);
}

.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.expense-row .num {
  color: var(--warn);
}

.income-row .num {
  color: var(--accent);
}

@media (max-width: 1100px) {
  .finance-overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .finance-dashboard {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .finance-shell {
    padding: 12px;
  }

  .finance-topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .finance-overview,
  .budget-form,
  .import-form,
  .chart-layout {
    grid-template-columns: 1fr;
  }

  .pie-chart {
    justify-self: center;
    width: min(220px, 70vw);
  }
}
