:root {
  --bg: #030712;
  --bg-gradient: linear-gradient(150deg, #030712, #0b1220 45%, #111827 80%);
  --surface: rgba(15, 23, 42, 0.92);
  --surface-strong: rgba(15, 23, 42, 0.98);
  --border: rgba(148, 163, 184, 0.25);
  --muted: #9ca3af;
  --text: #e5e7eb;
  --accent: #60a5fa;
  --accent-strong: #22c55e;
  --danger: #fb7185;
  --warning: #fbbf24;
  --focus-ring: rgba(96, 165, 250, 0.55);
  --radius: 18px;
  --shadow: 0 20px 60px rgba(2, 6, 23, 0.55);
  --font: "Space Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg-gradient);
  color: var(--text);
}

.page-loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #22c55e, #60a5fa);
  transform: scaleX(0);
  transform-origin: left center;
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
  z-index: 120;
  pointer-events: none;
}

.page-loader.htmx-request,
body.htmx-request .page-loader {
  transform: scaleX(1);
  opacity: 1;
}

a {
  color: var(--accent);
  transition: color 0.15s ease;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

main.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 140px;
  display: grid;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

details.card {
  overflow: visible;
}

details.card > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  outline: none;
}

details.card > summary::-webkit-details-marker {
  display: none;
}

details.card > summary .toggle-icon {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 10px;
  margin-left: 6px;
  color: var(--muted);
}

details.card[open] > summary .toggle-icon {
  transform: rotate(180deg);
}

.card:hover {
  border-color: rgba(148, 163, 184, 0.35);
  transform: translateY(-1px);
  box-shadow: 0 24px 72px rgba(2, 6, 23, 0.6);
}

.hero-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  background: linear-gradient(145deg, rgba(27, 40, 79, 0.85), rgba(15, 23, 42, 0.95));
}

.hero-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% -20%, rgba(96, 165, 250, 0.25), transparent 45%);
  pointer-events: none;
}

.hero-copy {
  position: relative;
  z-index: 1;
}

.hero-label {
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.hero-copy h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.03em;
}

.hero-text {
  margin-top: 10px;
  color: rgba(229, 231, 235, 0.9);
  line-height: 1.5;
}

.hero-metrics {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 16px;
}

.hero-metric {
  background: rgba(2, 6, 23, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 16px;
}

.hero-metric-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.hero-metric-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 1.3rem;
  font-weight: 600;
}

.hero-metric-value span {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.kpi {
  background: rgba(2, 6, 23, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px;
}

.kpi .label {
  font-size: 12px;
  color: var(--muted);
}

.kpi .value {
  font-size: 1.3rem;
  font-weight: 600;
  margin-top: 4px;
}

.progress {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  overflow: hidden;
  margin-top: 6px;
}
.progress.tiny {
  height: 6px;
  margin-top: 4px;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.action-item-wrap {
  position: relative;
  max-height: 130px;
  overflow: hidden;
  transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.22s ease, margin 0.22s ease;
}

.action-item-wrap.is-dismissing {
  opacity: 0;
  max-height: 0;
  margin: 0;
  transform: translateY(-6px);
  pointer-events: none;
}

.action-dismiss {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0.5;
  transition: opacity 0.15s, color 0.15s;
}

.action-dismiss:hover {
  opacity: 1;
  color: var(--text);
}

.action-dismiss:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.action-card {
  border-left: 4px solid var(--accent);
}

.list {
  display: grid;
  gap: 10px;
}

.meal-list {
  gap: 12px;
}

.meal-swipe-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  isolation: isolate;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  max-height: 120px;
  transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.22s ease, margin 0.22s ease;
}

.meal-swipe-wrapper:active {
  cursor: grabbing;
}

.meal-swipe-wrapper.is-removing {
  opacity: 0;
  max-height: 0;
  margin: 0;
  transform: translateY(-6px);
  pointer-events: none;
}

.meal-delete-bg {
  position: absolute;
  right: -88px;
  top: 0;
  bottom: 0;
  width: 88px;
  z-index: 2;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.95), rgba(220, 38, 38, 0.9));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  pointer-events: auto;
}

.meal-delete-bg:hover {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.98), rgba(239, 68, 68, 0.95));
}

.meal-delete-bg:active {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.98), rgba(185, 28, 28, 0.95));
}

.meal-item-content {
  position: relative;
  z-index: 1;
}

.meal-item-content.item {
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.item {
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
}

.item strong {
  display: block;
  margin-bottom: 4px;
}

.priority-high {
  border-color: rgba(251, 113, 133, 0.6);
}

.priority-medium {
  border-color: rgba(251, 191, 36, 0.6);
}

.priority-low {
  border-color: rgba(34, 197, 94, 0.6);
}

.btn {
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.btn.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn:hover,
.btn:focus-visible {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(3, 7, 18, 0.95);
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  gap: 6px;
  z-index: 50;
}

.bottom-nav a {
  flex: 1;
  text-align: center;
  color: rgba(148, 163, 184, 0.9);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.12em;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 10px 6px;
  position: relative;
  transition: color 0.15s ease, transform 0.15s ease;
}

.bottom-nav a::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 18%;
  right: 18%;
  height: 2px;
  background: var(--accent);
  border-radius: 999px;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.2s ease;
}

.bottom-nav a:hover {
  color: #f8fafc;
  transform: translateY(-1px);
}

.bottom-nav a.active {
  color: #f8fafc;
}

.bottom-nav a.active::after {
  transform: scaleX(1);
}

.bottom-nav a .nav-emoji {
  font-size: 20px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.meta {
  font-size: 12px;
  color: var(--muted);
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.filters input,
.filters select {
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  padding: 8px;
  color: #e5e7eb;
}

.finance-row-action-form input,
.finance-row-action-form select {
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  padding: 6px 8px;
  color: #e5e7eb;
  font-size: 12px;
}

.finance-edit-cell .finance-edit-input {
  min-width: 150px;
  max-width: 220px;
}

.finance-edit-cell select.finance-edit-input {
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  padding: 6px 8px;
  color: #e5e7eb;
  font-size: 12px;
}

.finance-edit-cell .finance-payee-input {
  min-width: 180px;
}

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

.table-wrap {
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  margin-top: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  font-size: 13px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  padding: 10px;
  text-align: left;
}

.data-table th {
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.9);
  color: var(--muted);
  font-weight: 600;
}

.data-table tbody tr:hover {
  background: rgba(148, 163, 184, 0.1);
}

.positive {
  color: var(--accent-strong);
}

.negative {
  color: var(--danger);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  font-size: 11px;
  color: #cbd5e1;
}

.status-pill.good {
  border-color: rgba(34, 197, 94, 0.5);
  color: var(--accent-strong);
}

.status-pill.warn {
  border-color: rgba(251, 191, 36, 0.5);
  color: #fbbf24;
}

.status-pill.bad {
  border-color: rgba(251, 113, 133, 0.5);
  color: var(--danger);
}

.chat-output {
  background: rgba(3, 7, 18, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 14px;
  padding: 12px;
  min-height: 180px;
  max-height: 300px;
  overflow: auto;
}

.chat-message {
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
}

.chat-message.user {
  background: rgba(96, 165, 250, 0.25);
  border: 1px solid rgba(96, 165, 250, 0.6);
}

.chat-message.assistant {
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.chat-message.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(229, 231, 235, 0.8);
  animation: chatDotPulse 1s ease-in-out infinite;
}

.chat-typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.chat-typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes chatDotPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chat-form input {
  flex: 1;
  background: rgba(2, 6, 23, 0.8);
  color: #e5e7eb;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  padding: 10px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  font-size: 12px;
  color: var(--muted);
}
.status-chip.bad {
  border-color: rgba(251, 113, 133, 0.8);
  color: var(--danger);
}

.status-chip strong {
  color: #f8fafc;
  margin-right: 4px;
}

.account-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}


.split {
  display: grid;
  gap: 12px;
}
.split-3 {
  display: grid;
  gap: 12px;
}
@media (min-width: 860px) {
  .split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .split-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.session-grid {
  display: grid;
  gap: 12px;
}

.session-card {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.session-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.session-snippet {
  color: #d1d5db;
  margin: 0;
}

.session-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  font-size: 12px;
  color: #cbd5e1;
}

.tag-empty {
  border-style: dashed;
  color: #6b7280;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.85);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
  z-index: 60;
  overflow: auto;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-content {
  background: rgba(3, 7, 18, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 18px;
  padding: 28px;
  max-width: 960px;
  width: 100%;
  position: relative;
  box-shadow: 0 30px 80px rgba(2, 6, 23, 0.75);
  transform: translateY(14px) scale(0.985);
  transition: transform 0.2s ease;
}

.modal.open .modal-content {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-body {
  margin-top: 18px;
  background: rgba(2, 6, 23, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  padding: 18px;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.auto-refresh-indicator {
  position: fixed;
  bottom: 90px;
  right: 18px;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 8px rgba(5, 10, 26, 0.8);
  opacity: 0.5;
  transition: opacity 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  cursor: pointer;
  z-index: 50;
}

.auto-refresh-indicator[data-paused="true"] {
  background: var(--warning);
  opacity: 0.8;
}

.auto-refresh-indicator[data-holding="true"] {
  background: #60a5fa;
  opacity: 0.9;
}

html.is-refreshing body {
  opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
