/* MoneyTree — base design system */

/* ----------------------------------------------------------------
   Tokens
   ---------------------------------------------------------------- */
:root {
  --accent:         #F59E0B;
  --accent-dim:     #D97706;

  --bg-page:        #161616;
  --bg-card:        #1E1E1E;
  --bg-surface:     #252525;
  --bg-input:       #2A2A2A;

  --text-primary:   #F0EDE8;
  --text-secondary: #AAAAAA;
  --text-muted:     #555555;

  --border:         #2A2A2A;
  --border-active:  #3A3A3A;

  --radius:         0.5rem;
  --radius-lg:      0.75rem;
}

/* ----------------------------------------------------------------
   Reset / base
   ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; overflow-x: hidden; }

body {
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  line-height: 1.6;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

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

img { display: block; max-width: 100%; }

/* ----------------------------------------------------------------
   Typography
   ---------------------------------------------------------------- */
h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

.eyebrow {
  font-size: 0.75rem;
  font-weight: 300;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ----------------------------------------------------------------
   Layout helpers
   ---------------------------------------------------------------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* longhand on purpose — .container and .section are combined on
   almost every page (class="container section"); a `padding: 3rem 0`
   shorthand here would silently zero out .container's left/right
   padding since both rules have equal specificity and this one comes
   later in the cascade (found 2026-09-21 chasing a mobile-edge-
   touching bug — it wasn't the nav, it was every page). */
.section { padding-top: 3rem; padding-bottom: 3rem; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }

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

/* ----------------------------------------------------------------
   Nav
   ---------------------------------------------------------------- */
.nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text-primary);
  text-decoration: none;
  flex-shrink: 0;
}

.nav-logo span { color: var(--accent); }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 32px;
  height: 32px;
  margin-left: auto;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex: 1;
  min-width: 0;
}

.nav-links {
  display: flex;
  gap: 1rem;
  list-style: none;
  flex: 1;
}

.nav-links a {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.nav-end {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

/* Project sub-navigation — one project's own Overview/Transactions/
   Budget/Rules/Tasks/Recurring tabs, shown on each of those pages.
   Same underline-on-hover/active language as .nav-links, smaller
   scale since it's a page-level tab strip, not the global nav. */
.project-subnav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.project-subnav a {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.625rem 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.project-subnav a:hover,
.project-subnav a.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.nav-user {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.nav-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.nav-avatar--fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 0.75rem;
  font-weight: 700;
}

.project-graph {
  position: relative;
  width: 100%;
  margin-top: 0.875rem;
}

.graph-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.graph-line {
  stroke: var(--border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.graph-hub {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(-50%, -50%);
}

.graph-node-wrap {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.graph-node {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1.5px solid var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.graph-node--fallback {
  background: var(--bg-input);
  color: var(--text-secondary);
}

.graph-node--account {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

.graph-node-label {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0.25rem 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-secondary);
  text-transform: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
  z-index: 20;
}

.graph-node-wrap:hover .graph-node-label {
  opacity: 1;
}

.graph-node-wrap .graph-node-label {
  left: 100%;
  margin-left: 0.5rem;
}

.graph-node-wrap--account .graph-node-label {
  left: auto;
  right: 100%;
  margin-left: 0;
  margin-right: 0.5rem;
}

.graph-node-role {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 0.25rem;
  white-space: nowrap;
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  text-transform: none;
}

@media (max-width: 860px) {
  .nav-toggle { display: flex; }

  .nav-menu {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }

  .nav-menu.is-open { display: flex; }

  .nav-links {
    flex-direction: column;
    gap: 0;
    width: 100%;
  }

  .nav-links a {
    display: block;
    padding: 0.875rem 1.25rem;
    border-bottom: none;
    border-left: 2px solid transparent;
  }

  .nav-links a:hover,
  .nav-links a.active {
    border-bottom-color: transparent;
    border-left-color: var(--accent);
    background: var(--bg-surface);
  }

  .nav-end {
    flex-direction: column;
    align-items: stretch;
    gap: 0.625rem;
    margin-left: 0;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
  }

  .nav-user { padding-bottom: 0.25rem; }
}

/* ----------------------------------------------------------------
   Cards
   ---------------------------------------------------------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.project-card {
  cursor: pointer;
}

.card--accent { border-color: var(--accent); }

/* ----------------------------------------------------------------
   Forms
   ---------------------------------------------------------------- */
.form-group { display: flex; flex-direction: column; gap: 0.375rem; }

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9375rem;
  padding: 0.625rem 0.875rem;
  width: 100%;
  transition: border-color 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-textarea { min-height: 100px; resize: vertical; }

.form-help {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-error {
  font-size: 0.8125rem;
  color: #EF4444;
}

/* ----------------------------------------------------------------
   Buttons
   ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  color: #0D0D0D;
  border-color: var(--accent);
}

.btn--primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); text-decoration: none; }

.btn--secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.btn--secondary:hover { background: var(--bg-input); text-decoration: none; }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn--ghost:hover { color: var(--text-primary); background: var(--bg-surface); text-decoration: none; }

.btn--danger { background: #EF4444; color: #fff; border-color: #EF4444; }
.btn--danger:hover { background: #DC2626; border-color: #DC2626; text-decoration: none; }

.btn--sm { font-size: 0.8125rem; padding: 0.375rem 0.875rem; }
.btn--lg { font-size: 1rem; padding: 0.875rem 1.75rem; }
.btn--full { width: 100%; }

/* ----------------------------------------------------------------
   Flash messages
   ---------------------------------------------------------------- */
.flash-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.flash--success { background: #14532d22; border-color: #16a34a55; color: #4ade80; }
.flash--error   { background: #7f1d1d22; border-color: #dc262655; color: #f87171; }
.flash--info    { background: #1e3a5f22; border-color: #3b82f655; color: #60a5fa; }
.flash--warning { background: #78350f22; border-color: #d9770655; color: #fbbf24; }

/* ----------------------------------------------------------------
   Auth page layout
   ---------------------------------------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
}

.auth-box {
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  margin-bottom: 0.25rem;
}

.auth-logo span { color: var(--accent); }

.auth-tagline {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

/* ----------------------------------------------------------------
   Spinner
   ---------------------------------------------------------------- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

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

/* ----------------------------------------------------------------
   Responsive table/card swap — same breakpoint as the nav collapse
   above, so "mobile" means one consistent width app-wide. Generic on
   purpose: any page that needs a table-on-desktop, cards-on-mobile
   swap can reuse these two classes.
   ---------------------------------------------------------------- */
.mobile-only { display: none; }

@media (max-width: 860px) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
}

/* ----------------------------------------------------------------
   Collapsible filter panel — mobile-only accordion (toggled via the
   .mobile-only button next to it); always fully expanded on desktop.
   Generic enough for any filter-heavy list page, not just Transactions.
   ---------------------------------------------------------------- */
.filter-toggle { display: none; }

@media (max-width: 860px) {
  .filter-panel { display: none; }
  .filter-panel.is-open { display: block; }
  .filter-toggle { display: flex; }
}

/* ----------------------------------------------------------------
   Tables
   ---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }

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

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

tr:hover td { background: var(--bg-surface); }

/* ----------------------------------------------------------------
   Badges
   ---------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.badge--green   { background: #14532d33; color: #4ade80; }
.badge--red     { background: #7f1d1d33; color: #f87171; }
.badge--amber   { background: #78350f33; color: #fbbf24; }
.badge--blue    { background: #1e3a5f33; color: #60a5fa; }
.badge--muted   { background: var(--bg-surface); color: var(--text-muted); }

/* ----------------------------------------------------------------
   Info buttons — small "i" trigger + click-toggled explanation
   popover, used throughout the app to explain non-obvious concepts
   (see backend/templates/_macros.html). Click-to-toggle, not hover —
   hover tooltips don't work on mobile, and this app is mobile-tested
   throughout.
   ---------------------------------------------------------------- */
.info-trigger {
  position: relative;
  display: inline-block;
  margin-left: 0.375rem;
  vertical-align: middle;
}

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-size: 0.6875rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  text-transform: none;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.info-btn:hover,
.info-btn[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
}

.info-popover {
  position: absolute;
  z-index: 50;
  top: calc(100% + 0.375rem);
  left: 0;
  width: max(260px, min(360px, 85vw));
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.5;
  text-transform: none;
  letter-spacing: normal;
}
