/* RoMatt Money - YNAB 4 Classic & Compact Responsive Design */

:root {
  /* Default: YNAB 4 Classic Light Theme */
  --bg-app: #dfe4ea;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f2f6;
  --bg-header-card: #3d4752;
  --bg-header-card-active: #2f3640;
  --border-main: #ced6e0;
  --border-light: #e4e7eb;
  --text-main: #2f3542;
  --text-muted: #747d8c;
  --text-light: #f1f2f6;
  --accent: #0097e6;
  --accent-light: #e1f5fe;
  --success: #2ed573;
  --danger: #ff4757;
  --danger-bg: #ffeaa7;
  --overspent-pill: #ffdddd;
  --overspent-text: #c0392b;
  --active-month-border: #00a8ff;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: "SF Mono", Consolas, Monaco, monospace;
}

[data-theme="dark"] {
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-subtle: #182234;
  --bg-header-card: #1e293b;
  --bg-header-card-active: #0f172a;
  --border-main: #334155;
  --border-light: #243042;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-light: #f8fafc;
  --accent: #38bdf8;
  --accent-light: rgba(56, 189, 248, 0.15);
  --success: #10b981;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --overspent-pill: rgba(239, 68, 68, 0.25);
  --overspent-text: #f87171;
  --active-month-border: #38bdf8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header.app-header {
  background: #2f3640;
  color: #f1f2f6;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid #1e272e;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand .logo-icon {
  background: linear-gradient(135deg, #0097e6, #e056fd);
  color: #fff;
  font-weight: 900;
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 13px;
}

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

.user-toggle {
  display: flex;
  background: #1e272e;
  border-radius: 4px;
  padding: 2px;
}

.user-toggle button {
  background: transparent;
  border: none;
  color: #a4b0be;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
}

.user-toggle button.active {
  background: #0097e6;
  color: #fff;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Nav Tabs */
nav.app-nav {
  background: #353b48;
  display: flex;
  padding: 0 16px;
  border-bottom: 1px solid #2f3640;
  overflow-x: auto;
}

nav.app-nav button {
  background: transparent;
  border: none;
  color: #dcdde1;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}

nav.app-nav button.active {
  color: #fff;
  border-bottom-color: #00a8ff;
  background: rgba(255, 255, 255, 0.05);
}

/* YNAB 4 Timeline Ribbon */
.timeline-ribbon {
  background: #2f3640;
  display: flex;
  align-items: center;
  padding: 3px 12px;
  gap: 6px;
  border-bottom: 1px solid #1e272e;
  overflow-x: auto;
}

.timeline-year-pill {
  background: #1e272e;
  color: #f1f2f6;
  border-radius: 3px;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.timeline-months {
  display: flex;
  gap: 2px;
  flex: 1;
}

.timeline-month-tab {
  background: transparent;
  border: none;
  color: #ced6e0;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.1s ease;
}

.timeline-month-tab:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.timeline-month-tab.visible-month {
  background: #0097e6;
  color: #fff;
  font-weight: 700;
}

.timeline-month-tab.active-center {
  background: #00a8ff;
  color: #fff;
  box-shadow: inset 0 0 0 1px #fff;
}

.timeline-stepper-btn {
  background: #1e272e;
  color: #ced6e0;
  border: none;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

/* Budget View Area */
main.app-main {
  flex: 1;
  padding: 10px;
  width: 100%;
  overflow-x: auto;
}

/* 5-Month Header Cards Container */
.multi-month-headers-container {
  display: grid;
  grid-template-columns: 240px repeat(var(--month-count, 5), minmax(200px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
  align-items: stretch;
}

.month-summary-card {
  background: var(--bg-header-card);
  color: #f1f2f6;
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.month-summary-card.active-month {
  background: var(--bg-header-card-active);
  border: 2px solid var(--active-month-border);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.card-month-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #fff;
}

.card-calc-list {
  font-size: 10px;
  color: #ced6e0;
  text-align: right;
  line-height: 1.35;
  font-family: var(--font-mono);
}

.card-calc-list .clickable-income {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  color: #7bed9f;
}

.card-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  padding-top: 6px;
  text-align: center;
}

.card-rta {
  font-size: 14px;
  font-weight: 800;
  font-family: var(--font-mono);
}

.card-rta.zero { color: #2ed573; }
.card-rta.positive { color: #2ed573; }
.card-rta.negative { color: #ff4757; }

/* Grid Table */
.budget-grid-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-main);
  border-radius: 6px;
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

table.ynab-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}

table.ynab-grid th, table.ynab-grid td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--border-light);
  border-right: 1px solid var(--border-light);
  white-space: nowrap;
}

/* Category column (fixed width) */
table.ynab-grid .col-cat {
  width: 240px;
  text-align: left;
}

/* Month columns */
table.ynab-grid .col-num {
  width: 76px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
}

table.ynab-grid tr.month-subheaders th {
  background: var(--bg-subtle);
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  padding: 6px 6px;
  text-align: right;
  border-bottom: 2px solid var(--border-main);
}

table.ynab-grid tr.month-subheaders th.month-border-start {
  border-left: 2px solid var(--border-main);
}

table.ynab-grid tr.month-subheaders th.active-month-col {
  background: var(--accent-light);
  color: var(--accent);
}

/* Group Headers */
table.ynab-grid tr.group-row {
  background: #e8ecf1;
  font-weight: 700;
}
[data-theme="dark"] table.ynab-grid tr.group-row {
  background: #1e293b;
}

table.ynab-grid tr.group-row td {
  padding: 6px 8px;
  border-top: 1px solid var(--border-main);
  border-bottom: 1px solid var(--border-main);
}

.group-row .group-add-btn {
  opacity: 0;
  transition: opacity 0.15s ease;
  margin-left: 6px;
  padding: 1px 5px;
  font-size: 11px;
}

.group-row:hover .group-add-btn {
  opacity: 1;
}

.clickable-name {
  cursor: pointer;
}
.clickable-name:hover {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-style: dotted;
}

table.ynab-grid tr.category-row:hover {
  background: rgba(0, 151, 230, 0.04);
}

/* Category Inputs & Cells */
.compact-budget-input {
  background: transparent;
  border: 1px solid transparent;
  width: 100%;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 2px;
  color: var(--text-main);
  border-radius: 2px;
}

.compact-budget-input:hover {
  border-color: var(--border-main);
  background: var(--bg-surface);
}

.compact-budget-input:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.active-month-cell {
  background: rgba(0, 151, 230, 0.02);
}

.active-month-cell .compact-budget-input {
  border-color: rgba(0, 151, 230, 0.3);
}

.clickable-outflow {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
}
.clickable-outflow:hover {
  color: var(--accent);
}

/* Overspent Balance Pill */
.overspent-badge {
  background: var(--overspent-pill);
  color: var(--overspent-text);
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

/* Buttons & Badges */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 3px;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-primary { background: #0097e6; color: #fff; }
.btn-primary:hover { background: #00a8ff; }
.btn-secondary { background: #f1f2f6; color: #2f3542; border-color: #ced6e0; }
[data-theme="dark"] .btn-secondary { background: #334155; color: #f8fafc; border-color: #475569; }
.btn-sm { padding: 3px 6px; font-size: 11px; }

.badge-owner {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  text-transform: uppercase;
}
.badge-matt { background: #dff9fb; color: #0984e3; }
.badge-rosie { background: #ffeaec; color: #e84393; }

/* Login Modal / Screen */
.login-screen-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-main);
  border-radius: 8px;
  width: 100%;
  max-width: 380px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.login-card h2 {
  font-size: 1.3rem;
  margin-bottom: 6px;
  text-align: center;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.form-control {
  background: var(--bg-surface);
  border: 1px solid var(--border-main);
  color: var(--text-main);
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 13px;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-main);
  border-radius: 6px;
  width: 100%;
  max-width: 500px;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
}

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}

.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-main);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Custom Context Menu */
.custom-context-menu {
  position: fixed;
  z-index: 10000;
  background: var(--bg-surface);
  border: 1px solid var(--border-main);
  border-radius: 6px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  min-width: 170px;
  padding: 4px 0;
  display: none;
}

.context-menu-item {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s;
}

.context-menu-item:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.context-menu-item.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.context-menu-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 0;
}

/* Inline Calculator Popover */
.calc-popover {
  position: absolute;
  z-index: 5000;
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  display: none;
  width: 220px;
}

.calc-popover-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.calc-display {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
  padding: 4px 6px;
  background: var(--bg-subtle);
  border-radius: 3px;
  text-align: right;
}

/* Floating Drill-down Modal */
.drilldown-dialog {
  max-width: 720px;
  width: 100%;
}

.drilldown-table-wrapper {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border-main);
  border-radius: 4px;
}

/* Register / Accounts View Layout */
.registers-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 12px;
}

.accounts-sidebar {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.account-section-header {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 800;
  margin: 10px 0 4px 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.account-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-main);
  margin-bottom: 3px;
  cursor: pointer;
  user-select: none;
}

.account-list-item:hover {
  border-color: var(--accent);
}

.account-list-item.active {
  border-color: var(--accent);
  background: var(--accent-light);
}

.account-list-item.closed-acc {
  opacity: 0.65;
  background: var(--bg-subtle);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .multi-month-headers-container {
    grid-template-columns: 1fr;
  }
  .registers-layout {
    grid-template-columns: 1fr;
  }
}

