:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --panel: #fffaf1;
  --ink: #1c241f;
  --muted: #69726d;
  --line: #ded6c8;
  --accent: #256f52;
  --accent-dark: #153f30;
  --gold: #d59a2b;
  --shadow: 0 18px 55px rgba(39, 31, 20, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #fff6dd 0, transparent 32rem), var(--bg);
  color: var(--ink);
}

a { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 18rem 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  padding: 1.5rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.7);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 1rem;
  background: var(--accent-dark);
  color: #fff;
  font-weight: 800;
}

.brand small,
.user-card small,
.platform-row small,
.muted {
  display: block;
  color: var(--muted);
}

.nav {
  display: grid;
  gap: 0.35rem;
}

.nav a {
  padding: 0.85rem 1rem;
  border-radius: 0.9rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
}

.nav a.active,
.nav a:hover {
  background: #efe5d4;
  color: var(--ink);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: auto;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
}

.avatar {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  background: #e4dac9;
}

.main {
  padding: 2rem;
}

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

.topbar h1,
.auth-panel h2,
.panel h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 0.75rem;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.15rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.button.secondary {
  background: #e7dece;
  color: var(--ink);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.notice,
.auth-panel,
.panel,
.metric-card {
  border: 1px solid var(--line);
  border-radius: 1.4rem;
  background: rgba(255, 250, 241, 0.86);
  box-shadow: var(--shadow);
}

.notice {
  margin-bottom: 1rem;
  padding: 1rem;
  color: #724713;
  background: #fff1c7;
}

.notice.success {
  color: var(--accent-dark);
  background: #dceee6;
}

.auth-panel {
  display: grid;
  place-items: center;
  min-height: 10rem;
  padding: 1.5rem;
  text-align: center;
}

.content {
  display: grid;
  gap: 1.25rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1rem;
}

.metric-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.metric-card {
  padding: 1.25rem;
}

.metric-card span {
  color: var(--muted);
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-top: 0.8rem;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.panel-grid,
.connection-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.panel {
  padding: 1.25rem;
}

.wide-panel {
  overflow-x: auto;
}

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

.platform-list {
  display: grid;
  gap: 0.75rem;
}

.platform-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-radius: 1rem;
  background: #f3ebde;
}

.dark-panel {
  background: linear-gradient(135deg, var(--accent-dark), #1d5b42);
  color: #fff;
}

.dark-panel .eyebrow,
.dark-panel p {
  color: #dceee6;
}

.connection-card {
  position: relative;
  min-height: 14rem;
}

.status {
  display: inline-flex;
  margin-bottom: 1.25rem;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  background: #e7dece;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.status.connected {
  background: #dceee6;
  color: var(--accent-dark);
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  background: #dceee6;
  color: var(--accent-dark);
  font-size: 0.75rem;
  font-weight: 800;
}

.badge.danger {
  background: #f7d9d0;
  color: #8f2b16;
}

.pnl-panel table td:last-child,
.total-row td:last-child {
  text-align: right;
  font-weight: 800;
}

.total-row td {
  border-top: 2px solid var(--ink);
  color: var(--ink);
  font-weight: 900;
}

.pnl-total {
  display: grid;
  gap: 0.5rem;
  background: linear-gradient(135deg, #fffaf1, #dceee6);
}

.pnl-total span {
  color: var(--muted);
  font-weight: 800;
}

.pnl-total strong {
  font-size: clamp(2rem, 6vw, 3.5rem);
}

.plain-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
}

.expense-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  align-items: end;
}

.expense-form label {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-weight: 800;
}

.expense-form input,
.expense-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  padding: 0.8rem 0.9rem;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
}

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

.form-actions,
.table-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.link-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.link-button.danger {
  color: #8f2b16;
}

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

th,
td {
  padding: 0.9rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

code {
  border-radius: 0.35rem;
  padding: 0.1rem 0.3rem;
  background: #eadfce;
}

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

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .topbar,
  .platform-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .panel-grid,
  .connection-grid,
  .expense-form {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 560px) {
  .main,
  .sidebar {
    padding: 1rem;
  }

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

  .topbar-actions {
    width: 100%;
    flex-direction: column;
  }

  .button {
    width: 100%;
  }
}
