* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background-color: #16181d;
  background-image: url('/images/apartment.png');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: #e8e8ec;
}
a { color: #9fd3ff; text-decoration: none; cursor: pointer; }
.hidden { display: none !important; }
.dim { color: #888; font-size: 0.85em; }

/* Topbar */
#topbar {
  background: #1e2128;
  border-bottom: 1px solid #2c2f38;
}
#topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1300px;
  margin: 0 auto;
  padding: 10px 24px;
}

.brand { font-weight: 600; font-size: 1.1em; }
.topbar-right { display: flex; gap: 18px; align-items: center; }

/* Layout */
.view {
  padding: 24px;
  max-width: 1200px;
  margin: 25px auto;
  background: rgba(30, 33, 40, 0.85);
  border-radius: 10px;
}
#loginView {
  background: transparent;
}
.centered { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.card {
  background: #1e2128;
  border: 1px solid #2c2f38;
  border-radius: 10px;
  padding: 28px;
}
.login-card { width: 320px; display: flex; flex-direction: column; gap: 8px; }
.login-card h1 { font-size: 1.3em; margin: 0 0 12px; }
input, select, textarea, button {
  font-family: inherit;
  font-size: 1em;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #3a3e48;
  background: #14161b;
  color: #e8e8ec;
}
button {
  background: #3a5cff;
  border: none;
  cursor: pointer;
  font-weight: 600;
  padding: 9px 14px;
}
button:hover { background: #4b6bff; }
.error { color: #ff6b6b; margin-top: 6px; }

/* Toolbar / filters */
.toolbar {
  display: flex;
  gap: 40px;
  margin-bottom: 18px;
  background: #1e2128;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #2c2f38;
}
.filters { display: flex; gap: 14px; align-items: center; }
.filter-label { color: #999; font-size: 0.9em; }

/* Project table */
.project-table { width: 100%; border-collapse: collapse; }
.project-table th {
  text-align: left;
  padding: 10px 12px;
  color: #999;
  border-bottom: 1px solid #2c2f38;
  font-weight: 600;
  font-size: 0.85em;
  text-transform: uppercase;
}
.project-table td {
  padding: 12px;
  border-bottom: 1px solid #22252c;
}
.project-table tr { cursor: pointer; }
.project-table tr:hover td { background: #23262e; }
.project-table tr.completed td { opacity: 0.45; }
.status-pill {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.8em;
  font-weight: 600;
}
.status-active { background: #1f4d2b; color: #7be495; }
.status-suspended { background: #4d451f; color: #e4c86a; }
.status-completed { background: #333; color: #999; }

/* Project detail */
.project-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.project-header-right { display: flex; align-items: center; gap: 8px; }
.docs-panel { width: 100%; margin-bottom: 22px; }
.kanban-panel { width: 100%; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.panel-header h3 { margin: 0; }
.panel-header button { font-size: 0.85em; padding: 6px 10px; }

.doc-list-horizontal {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.doc-list-horizontal li {
  padding: 9px 14px;
  background: #1e2128;
  border: 1px solid #2c2f38;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
}
.doc-list-horizontal li:hover { background: #262a33; border-color: #3a5cff; }

/* Kanban */
.kanban-board { display: flex; gap: 14px; }
.kanban-col {
  flex: 1;
  background: #1a1c22;
  border: 1px solid #2c2f38;
  border-radius: 8px;
  padding: 10px;
  min-height: 200px;
}
.kanban-col h4 {
  margin: 0 0 10px;
  font-size: 0.8em;
  text-transform: uppercase;
  color: #888;
}
.kanban-card {
  border-radius: 7px;
  padding: 9px 10px;
  margin-bottom: 8px;
  font-size: 0.9em;
  border: 1px solid rgba(255,255,255,0.08);
}
.kanban-card .card-name { font-weight: 600; margin-bottom: 4px; }
.kanban-card .card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.kanban-card select {
  padding: 2px 4px;
  font-size: 0.8em;
  background: #2a2a2a;
  color: #e8e8ec;
  border-color: rgba(255,255,255,0.15);
}
.kanban-card select option {
  background: #2a2a2a;
  color: #e8e8ec;
}

.type-badge {
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 0.72em;
  font-weight: 700;
  color: #10121a;
}

/* Amber = green family */
.assignee-amber.shade-0 { background: #cfead6; }
.assignee-amber.shade-1 { background: #a9dcb6; }
.assignee-amber.shade-2 { background: #82c996; }
.assignee-amber.shade-3 { background: #5cb377; }
.name-amber { color: #1b5e20; }

/* Leeman = violet/magenta family */
.assignee-leeman.shade-0 { background: #ecd6f2; }
.assignee-leeman.shade-1 { background: #ddb3e8; }
.assignee-leeman.shade-2 { background: #cc8fdc; }
.assignee-leeman.shade-3 { background: #b968cf; }
.name-leeman { color: #8e0057; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-box {
  background: #1e2128;
  border: 1px solid #2c2f38;
  border-radius: 10px;
  padding: 20px;
  width: 380px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.editor-box { width: 78vw; height: 80vh; }
.editor-body {
  flex: 1;
  display: flex;
  gap: 0;
  min-height: 0;
  border: 1px solid #2c2f38;
  border-radius: 6px;
  overflow: hidden;
}
.editor-outline {
  width: 300px;
  flex-shrink: 0;
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  background: #17191f;
  border-right: 1px solid #2c2f38;
}
.editor-outline .outline-empty {
  color: #666;
  font-size: 0.85em;
  padding: 6px 8px;
}
.editor-outline li {
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.87em;
  color: #cfd2d8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.editor-outline li:hover { background: #23262e; }
.editor-outline li.outline-h1 { font-weight: 700; margin-top: 4px; }
.editor-outline li.outline-h2 { padding-left: 20px; color: #9aa0ab; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 600;
}
.modal-header a { font-size: 1.3em; color: #999; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; align-items: center; }
.modal-header-actions { display: flex; align-items: center; gap: 14px; }
.secondary-btn {
  background: #2c2f38;
  font-weight: 500;
  padding: 6px 12px;
  font-size: 0.85em;
}
.secondary-btn:hover { background: #383c47; }
.secondary-btn.active { background: #3a5cff; }

.editor-preview {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  background: #1b1d23;
  color: #e0e0e6;
  line-height: 1.55;
}
.editor-preview h1, .editor-preview h2, .editor-preview h3 {
  border-bottom: 1px solid #2c2f38;
  padding-bottom: 6px;
}
.editor-preview code {
  background: #14161b;
  padding: 2px 5px;
  border-radius: 4px;
  font-family: 'Cascadia Code', Consolas, monospace;
}
.editor-preview pre {
  background: #14161b;
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
}
.editor-preview pre code { background: none; padding: 0; }
.editor-preview table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}
.editor-preview th, .editor-preview td {
  border: 1px solid #383c47;
  padding: 8px 10px;
  text-align: left;
}
.editor-preview th { background: #23262e; }
.editor-preview blockquote {
  border-left: 3px solid #3a5cff;
  margin: 0;
  padding: 4px 14px;
  color: #aeb2bb;
}

#editorTextarea {
  flex: 1;
  width: 100%;
  height: 100%;
  resize: none;
  font-family: 'Cascadia Code', Consolas, monospace;
  line-height: 1.5;
  border: none;
  border-radius: 0;
}

/* Company page */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.summary-card {
  background: #1e2128;
  border: 1px solid #2c2f38;
  border-radius: 8px;
  padding: 14px 16px;
}
.summary-label { font-size: 0.8em; color: #9aa0ab; margin-bottom: 6px; }
.summary-value { font-size: 1.5em; font-weight: 600; }
.income-color { color: #7be495; }
.expense-color { color: #e4826a; }

/* Ledger detail */
.ledger-columns { display: flex; gap: 24px; }
.ledger-panel { flex: 1; }
.ledger-list { display: flex; flex-direction: column; gap: 8px; }
.ledger-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e2128;
  border: 1px solid #2c2f38;
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
}
.ledger-item:hover { border-color: #3a5cff; }
.ledger-item-left { display: flex; flex-direction: column; gap: 4px; }
.ledger-item-desc { font-size: 0.92em; }
.ledger-item-date { font-size: 0.78em; color: #888; }
.ledger-item-amount { font-weight: 600; white-space: nowrap; margin-left: 10px; }
.category-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72em;
  font-weight: 700;
  color: #10121a;
  margin-left: 8px;
}
.ledger-empty { color: #666; font-size: 0.88em; padding: 8px 2px; }

.danger-btn {
  background: transparent;
  border: 1px solid #7a2e2e;
  color: #ff8a8a;
  font-weight: 600;
}
.danger-btn:hover { background: #4d1f1f; }

/* Financial tracker */
.doc-list-horizontal li.ended { opacity: 0.45; }
.tx-debit { color: #e4826a; }
.tx-credit, .tx-payment { color: #7be495; }
.recurring-row td { background: rgba(255,255,255,0.045); }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88em;
  color: #cfd2d8;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: auto;
  padding: 0;
}

/* Wishlist */
.tab-btn {
  background: none;
  border: 1px solid #2c2f38;
  color: #9aa0ab;
  padding: 7px 14px;
  border-radius: 20px;
  font-weight: 500;
  font-size: 0.9em;
}
.tab-btn:hover { background: #23262e; color: #e8e8ec; }
.tab-btn.active { background: #3a5cff; border-color: #3a5cff; color: #fff; }
.cost-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75em;
  font-weight: 700;
  background: #2c2f38;
  color: #9aa0ab;
  margin-left: 8px;
}
.want-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72em;
  font-weight: 600;
  margin-left: 8px;
}
.want-meh { background: #23262e; color: #9aa0ab; }
.want-nice { background: #1f4d2b; color: #7be495; }
.want-kinda_need { background: #4d451f; color: #e4c86a; }
.want-thinking_about_it { background: #4a2a1f; color: #e4a68f; }
.want-send_help { background: #4d1f1f; color: #ff8a8a; }
.wishlist-item.done .ledger-item-desc { text-decoration: line-through; color: #666; }
.wishlist-item.done { opacity: 0.55; }
.wishlist-done-toggle { margin-right: 10px; }

/* Wishlist card grid */
.wishlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.wishlist-card {
  background: #1e2128;
  border: 1px solid #2c2f38;
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  position: relative;
}
.wishlist-card:hover { border-color: #3a5cff; }
.wishlist-card.done { opacity: 0.5; }
.wishlist-card.done .wishlist-card-name { text-decoration: line-through; color: #666; }
.wishlist-card-name {
  font-weight: 600;
  display: block;
  margin-bottom: 10px;
  padding-right: 26px;
}
.wishlist-card-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.wishlist-card-badges .cost-badge,
.wishlist-card-badges .want-badge { margin-left: 0; }
.wishlist-card-notes { font-size: 0.82em; color: #9aa0ab; }
.wishlist-card-done-toggle { position: absolute; top: 12px; right: 12px; }

/* Relationship rules */
.tier-badge {
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.72em;
  font-weight: 700;
  margin-right: 8px;
}
.tier-non_negotiable { background: #4d1f1f; color: #ff8a8a; }
.tier-important { background: #4d451f; color: #e4c86a; }
.tier-mindful { background: #1f4d2b; color: #7be495; }
.who-badge {
  font-size: 0.78em;
  font-weight: 700;
  margin-left: 8px;
}
.who-both { color: #9aa0ab; }
.rule-position {
  color: #666;
  font-size: 0.78em;
  margin-right: 8px;
  font-weight: 600;
}
.rule-unless {
  font-size: 0.82em;
  color: #9aa0ab;
  font-style: italic;
}
.rule-category-badge {
  background: #2c2f38;
  color: #9aa0ab;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 0.72em;
  margin-left: 8px;
}
.rule-category-badge.primary {
  background: #23304d;
  color: #9fc2ff;
}
.rule-textarea {
  width: 100%;
  resize: vertical;
  font-family: inherit;
  line-height: 1.4;
}

/* Maintenance log */
.maint-badge {
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.72em;
  font-weight: 700;
  margin-right: 8px;
}
.maint-overdue { background: #4d1f1f; color: #ff8a8a; }
.maint-due_soon { background: #4d451f; color: #e4c86a; }
.maint-ok { background: #1f4d2b; color: #7be495; }
.maint-none { background: #2c2f38; color: #9aa0ab; }
.maint-mark-done-btn {
  background: #23262e;
  border: 1px solid #2c2f38;
  color: #9fd3ff;
  font-size: 0.8em;
  padding: 6px 10px;
  font-weight: 500;
}
.maint-mark-done-btn:hover { background: #2c2f38; }
.maint-freq { color: #666; font-size: 0.78em; }
.maint-amount {
  color: #e4c86a;
  font-weight: 600;
  font-size: 0.85em;
  margin-left: 8px;
}

.tracker-columns { display: flex; gap: 20px; align-items: flex-start; }
.tracker-col-recurring { flex: 3 1 0; min-width: 0; }
.tracker-col-oneoff { flex: 2 1 0; min-width: 0; }
.tracker-card-btn { margin-top: 10px; width: 100%; }

/* Dropdown nav */
.brand { cursor: pointer; }
.nav-dropdowns { display: flex; gap: 4px; }
.nav-dropdown { position: relative; }
.nav-dropdown-btn {
  background: none;
  border: none;
  color: #9fd3ff;
  font-weight: 500;
  padding: 8px 10px;
  cursor: pointer;
}
.nav-dropdown-btn:hover { background: #23262e; border-radius: 6px; }
.nav-dropdown-btn .caret { font-size: 0.7em; margin-left: 3px; color: #777; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #1e2128;
  border: 1px solid #2c2f38;
  border-radius: 8px;
  min-width: 190px;
  padding: 6px;
  z-index: 100;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: #e8e8ec;
}
.nav-dropdown-menu a:hover { background: #262a33; }
.nav-soon {
  display: block;
  padding: 8px 10px;
  color: #666;
  font-size: 0.88em;
  cursor: default;
}
.nav-soon em {
  font-style: normal;
  font-size: 0.75em;
  background: #2c2f38;
  color: #9aa0ab;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 6px;
}

/* Dashboard */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}
.dashboard-card h3 { margin: 0 0 12px; }
.dashboard-card ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.dashboard-card a { color: #9fd3ff; }
.dashboard-card li.soon { color: #666; font-size: 0.9em; }
.dashboard-card li.soon em {
  font-style: normal;
  font-size: 0.75em;
  background: #2c2f38;
  color: #9aa0ab;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 6px;
}

/* ============================================================
   Mobile responsive pass
   Priority (genuinely designed for touch/small screens): login,
   Wishlist, Household Tracker, and future Shopping/Fitness pages.
   Everything else (BWG projects/kanban, Financial Tracker ledgers,
   Company summary) just needs to not break — horizontal scroll on
   wide tables is an acceptable, intentional tradeoff there, not a bug.
   ============================================================ */

html, body {
  max-width: 100%;
}

@media (max-width: 768px) {
  /* Topbar: wrap instead of overflowing */
  #topbar-inner {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
  }
  .brand { font-size: 0.95em; }
  .nav-dropdowns { flex-wrap: wrap; gap: 2px; }
  .nav-dropdown-btn { padding: 6px 8px; font-size: 0.92em; }
  .topbar-right { flex-wrap: wrap; gap: 10px; font-size: 0.9em; }

  /* Page shell */
  .view {
    padding: 14px;
    margin: 12px auto;
    border-radius: 8px;
  }

  /* Toolbars: wrap filters/buttons onto their own lines instead of
     squeezing or overflowing */
  .toolbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 12px;
  }
  /* Clear the margin-left:auto right-float so primary action buttons (Add
     Rule, Add Task, New Project, etc.) wrap naturally onto their own line
     instead of being squeezed against the filters. Deliberately NOT forcing
     width:100% here — that would also stretch small inline buttons like
     "Set as default" that sit next to a dropdown and shouldn't balloon. */
  .toolbar button[style*="margin-left"] {
    margin-left: 0 !important;
  }
  .filters { flex-wrap: wrap; gap: 8px; }

  /* Wide data tables (Projects, Company summary, Personal Projects,
     ledgers) — desktop-style bookkeeping tools by design. Rather than
     cram nine columns into a phone screen, let them scroll sideways
     as a contained unit instead of blowing out the whole page. */
  .project-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* BWG kanban board: stack columns instead of squeezing four
     side by side */
  .kanban-board {
    flex-direction: column;
  }
  .kanban-col { width: 100%; }

  /* Household Tracker: stack Recurring above One-offs instead of
     the 3:2 side-by-side split, which only makes sense at desktop width */
  .tracker-columns {
    flex-direction: column;
  }

  /* Financial Tracker ledger detail split similarly stacks */
  .ledger-columns {
    flex-direction: column;
  }

  /* Modals: fit the actual screen instead of a fixed desktop width */
  .modal-box {
    width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
  }
  .editor-box {
    width: 94vw;
    height: 88vh;
  }
  /* Doc editor: outline sits above the text instead of beside it —
     a fixed 300px sidebar would eat most of a phone-width modal */
  .editor-body {
    flex-direction: column;
  }
  .editor-outline {
    width: 100%;
    max-height: 120px;
    border-right: none;
    border-bottom: 1px solid #2c2f38;
  }

  /* Login: fit narrow phones without being edge-to-edge */
  .login-card {
    width: 90vw;
    max-width: 320px;
  }

  /* Touch targets: comfortable tap size everywhere */
  button, input, select, textarea {
    min-height: 42px;
  }
  .wishlist-done-toggle input,
  .maint-mark-done-btn {
    min-height: auto; /* these have their own sizing, don't force-inflate */
  }
}

@media (max-width: 420px) {
  .view { padding: 10px; }
  .modal-box { width: 94vw; padding: 16px; }
  .dashboard-grid { grid-template-columns: 1fr; }
}
