:root {
  --dash-bg: #f6f7f9;
  --panel: #ffffff;
  --panel-border: #e5e8ed;
  --text: #263238;
  --muted: #6f7782;
  --green: #4aa060;
  --green-soft: #eaf6ee;
  --red: #b65b5b;
  --blue: #4f97d1;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--dash-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.page-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.45rem 1rem 2.5rem;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 13rem;
  padding: 1.5rem 1rem;
  background: #fff;
  border-right: 1px solid var(--panel-border);
}

.sidebar + .page-shell { padding-left: 14rem; }

h1 {
  color: #25312f;
  font-size: 1.85rem;
  line-height: 1.15;
  margin: 0 0 0.35rem;
}

h2 {
  color: #263238;
  font-size: 1.65rem;
  margin: 1.8rem 0 1rem;
}

.page-header, .controls-row, .section-heading-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.dashboard-kicker, .metric-note, .cash-helper, .metric-bar-label {
  color: var(--muted);
}

.privacy-pill {
  display: inline-flex;
  color: #52605d;
  background: #eef3f0;
  border: 1px solid #dce5df;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

.stale-warning {
  background: #fff7d6;
  border: 1px solid #efd37a;
  border-radius: 8px;
  color: #5f4a00;
  font-size: 0.9rem;
  line-height: 1.42;
  margin: 0.75rem 0 0.95rem;
  padding: 0.75rem 0.95rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(38, 50, 56, 0.06);
  padding: 1.35rem 1.45rem;
  margin: 1rem 0 1.35rem;
}

.panel-title {
  color: #263238;
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 1rem;
}

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

.metric-tile, .cash-card {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 1.2rem 0.85rem;
  background: #fff;
  min-width: 0;
  text-align: center;
}

.cash-card {
  display: flex;
  min-height: 8.6rem;
  flex-direction: column;
  justify-content: center;
}

.metric-label {
  color: #5f6872;
  font-size: 0.76rem;
  text-transform: uppercase;
  margin-bottom: 0.55rem;
  font-weight: 650;
}

.metric-value {
  color: #263238;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.12;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.metric-delta {
  display: inline-flex;
  margin-top: 0.45rem;
  padding: 0.12rem 0.42rem;
  border-radius: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.positive { color: var(--green); font-weight: 600; }
.negative { color: var(--red); font-weight: 600; }
.metric-delta.positive { background: var(--green-soft); }
.metric-delta.negative { background: #f9eeee; }

.metric-note {
  font-size: 0.78rem;
  line-height: 1.25;
  margin-top: 0.4rem;
}

.metric-bar {
  display: flex;
  height: 0.55rem;
  margin-top: 0.65rem;
  overflow: hidden;
  border-radius: 999px;
  background: #e9edf2;
}

.metric-bar-positions { background: #4f7a64; }
.metric-bar-cash { background: var(--blue); }
.metric-bar-label {
  font-size: 0.72rem;
  line-height: 1.25;
  margin-top: 0.32rem;
  font-variant-numeric: tabular-nums;
}

label, .sidebar-title {
  display: block;
  color: #5f6872;
  font-size: 0.86rem;
  margin-bottom: 0.35rem;
}

select, input {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  color: var(--text);
  background: #fff;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-weight: 650;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(39, 49, 61, 0.12);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
  transform: none;
  box-shadow: none;
}

.primary-button {
  width: 100%;
  color: #fff;
  background: #ff454f;
}

.secondary-button {
  color: #263238;
  background: #eef1f4;
}

.control-stack {
  display: grid;
  gap: 0.5rem;
  min-width: 12rem;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.toggle-row input {
  width: auto;
}

.data-status {
  color: #586174;
  line-height: 1.28;
  flex: 1;
}

.data-status strong { color: #245f7a; }
.data-status .note { color: #8a6471; font-size: 0.82rem; }

.table-section {
  margin-top: 1.8rem;
  border-top: 1px solid #d7dce2;
  padding-top: 1rem;
}

.table-toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.table-search { max-width: 24rem; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #fff;
}

.breakdown-stack {
  display: grid;
  gap: 1rem;
}

.breakdown-panel {
  background: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 1rem;
}

.breakdown-panel summary {
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.breakdown-metrics {
  margin-bottom: 1rem;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

th {
  color: #6f7782;
  background: #f8fafc;
  font-weight: 600;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  width: 100%;
  border: 0;
  border-radius: 4px;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.sort-button:hover {
  box-shadow: none;
  color: #263238;
  transform: none;
}

.sort-indicator::after {
  color: #9aa3ad;
  content: "";
  font-size: 0.72rem;
}

th[aria-sort="ascending"] .sort-indicator::after {
  color: #245f7a;
  content: "^";
}

th[aria-sort="descending"] .sort-indicator::after {
  color: #245f7a;
  content: "v";
}

tr[hidden], tbody[hidden] { display: none; }

.chart {
  min-height: 430px;
  background: #fff;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell { width: min(28rem, calc(100vw - 2rem)); }
.login-panel {
  background: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 1.5rem;
}
.login-form { display: grid; gap: 0.85rem; }
.login-form button { color: #fff; background: #ff454f; }

@media (max-width: 760px) {
  .sidebar { position: static; width: auto; border-right: 0; border-bottom: 1px solid var(--panel-border); }
  .sidebar + .page-shell { padding-left: 1rem; }
  .page-header, .controls-row, .section-heading-row, .table-toolbar { flex-direction: column; }
  .metric-grid, .cash-grid { grid-template-columns: 1fr; gap: 0.55rem; }
  .control-stack, .account-form, .table-search { width: 100%; max-width: none; }
  h1 { font-size: 1.55rem; }
}
