:root {
  --bg: #faf8f5;
  --bg-warm: #f5f0ea;
  --text: #1a1816;
  --text-secondary: #6b6560;
  --text-tertiary: #9e9590;
  --accent: #c8553a;
  --accent-soft: #c8553a18;
  --border: #e8e2da;
  --border-light: #f0ebe5;
  --card: #ffffff;
  --alive: #3a8c6e;
  --alive-soft: #3a8c6e15;
  --danger: #c83a3a;
  --danger-soft: #c83a3a12;
  --warning: #c8953a;
  --warning-soft: #c8953a12;
  --radius: 12px;
  --radius-sm: 6px;
  --radius-lg: 16px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg); color: var(--text);
  font-family: Newsreader, Georgia, 'Times New Roman', serif;
  font-optical-sizing: auto; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility; min-height: 100vh;
}
::selection { background: var(--accent-soft); color: var(--accent); }

.nav {
  position: fixed; top: 0; left: 0; width: 100%; z-index: 100;
  padding: 1.25rem 2rem;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s ease;
}
.nav.scrolled { border-bottom-color: var(--border); }
.logo {
  font-family: 'DM Mono', monospace; font-size: 1.3rem; font-weight: 400;
  color: var(--text); text-decoration: none; letter-spacing: -0.02em;
}
.logo .dot { color: var(--accent); }

.container { max-width: 900px; margin: 0 auto; padding: 7rem 2rem 4rem; }

.page-header { margin-bottom: 2.5rem; }
.page-title {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 300; letter-spacing: -0.02em; margin-bottom: 0.25rem;
}
.page-subtitle {
  font-family: 'DM Mono', monospace; font-size: 0.8rem; color: var(--text-tertiary);
}

.summary {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem; margin-bottom: 2.5rem;
}
.summary-card {
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 1.25rem 1.5rem;
}
.summary-label {
  font-family: 'DM Mono', monospace; font-size: 0.62rem;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-tertiary); margin-bottom: 0.5rem;
}
.summary-value {
  font-size: 2rem; font-weight: 300; letter-spacing: -0.03em;
}
.summary-secondary {
  font-family: 'DM Mono', monospace; font-size: 0.75rem;
  color: var(--text-tertiary); margin-top: 0.25rem;
}

.status-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.25rem; }
.status-row {
  display: flex; align-items: center; gap: 0.5rem;
  font-family: 'DM Mono', monospace; font-size: 0.75rem; color: var(--text-secondary);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.s-active { background: var(--alive); }
.status-dot.s-cancelled { background: var(--danger); }
.status-dot.s-flagged { background: var(--warning); }
.status-dot.s-other { background: var(--text-tertiary); }

.cat-bars { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.25rem; }
.cat-bar-row {
  display: flex; align-items: center; gap: 0.75rem;
  font-family: 'DM Mono', monospace; font-size: 0.7rem; color: var(--text-secondary);
}
.cat-bar-label { min-width: 80px; text-align: right; }
.cat-bar-track {
  flex: 1; height: 6px; background: var(--border-light);
  border-radius: 3px; overflow: hidden;
}
.cat-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.4s ease; }
.cat-bar-amount { min-width: 50px; font-size: 0.65rem; color: var(--text-tertiary); }

.controls { display: flex; gap: 0.75rem; margin-bottom: 1rem; align-items: center; }
.search-input {
  flex: 1; font-family: 'DM Mono', monospace; font-size: 0.8rem;
  padding: 0.6rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); outline: none; transition: border-color 0.2s ease;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-tertiary); }
.sort-select {
  font-family: 'DM Mono', monospace; font-size: 0.75rem;
  padding: 0.6rem 2rem 0.6rem 0.75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card);
  color: var(--text-secondary); cursor: pointer; outline: none;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%239e9590' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.75rem center;
  transition: border-color 0.2s ease;
}
.sort-select:focus { border-color: var(--accent); }

.categories { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.cat-pill {
  font-family: 'DM Mono', monospace; font-size: 0.7rem;
  padding: 0.4rem 0.8rem; border-radius: 20px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-secondary); cursor: pointer; transition: all 0.2s ease;
}
.cat-pill:hover, .cat-pill.active {
  border-color: var(--accent); color: var(--accent); background: var(--accent-soft);
}

.sub-list { display: flex; flex-direction: column; gap: 1rem; }
.sub-card {
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 1.25rem 1.5rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.sub-card:hover { border-color: var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.sub-card.flagged {
  border-left: 4px solid var(--warning);
  background: linear-gradient(90deg, #c8953a06 0%, transparent 40%);
}
.sub-card.is-cancelled .cost-amount { text-decoration: line-through; opacity: 0.5; }

.sub-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.sub-name { font-size: 1.1rem; font-weight: 400; }
.sub-badge {
  font-family: 'DM Mono', monospace; font-size: 0.62rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0.25rem 0.6rem; border-radius: 4px; white-space: nowrap;
}
.sub-badge.active, .sub-badge.likely-active { color: var(--alive); background: var(--alive-soft); }
.sub-badge.cancelled { color: var(--danger); background: var(--danger-soft); }
.sub-badge.likely-cancelled { color: var(--warning); background: var(--warning-soft); }
.sub-badge.unknown, .sub-badge.paused { color: var(--text-tertiary); background: var(--bg-warm); }

.cost-line { font-family: 'DM Mono', monospace; margin-bottom: 0.35rem; }
.cost-amount { font-size: 1.05rem; font-weight: 500; color: var(--text); }
.cost-cycle { font-size: 0.8rem; color: var(--text-tertiary); }

.sub-meta {
  font-family: 'DM Mono', monospace; font-size: 0.7rem; color: var(--text-tertiary);
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
}
.sub-meta .sep { color: var(--border); user-select: none; }

.flagged-msg {
  font-family: 'DM Mono', monospace; font-size: 0.7rem;
  color: var(--warning); margin-top: 0.5rem; display: none;
}
.sub-card.flagged .flagged-msg { display: block; }

.evidence-section { overflow: hidden; max-height: 0; transition: max-height 0.3s ease; }
.evidence-section.open { max-height: 200px; padding-top: 0.75rem; margin-top: 0.5rem; border-top: 1px solid var(--border-light); }
.evidence-text {
  font-family: 'DM Mono', monospace; font-size: 0.75rem;
  color: var(--text-secondary); line-height: 1.5;
}
.ev-toggle {
  font-family: 'DM Mono', monospace; font-size: 0.7rem;
  color: var(--text-tertiary); cursor: pointer;
  background: none; border: none; padding: 0;
  display: inline-flex; align-items: center; gap: 0.3rem;
  transition: color 0.2s ease; margin-top: 0.5rem;
}
.ev-toggle:hover { color: var(--accent); }
.ev-toggle .chev { display: inline-block; transition: transform 0.2s ease; font-size: 0.6rem; }
.ev-toggle.open .chev { transform: rotate(90deg); }

.sub-actions {
  display: flex; gap: 0.5rem; margin-top: 0.75rem;
  padding-top: 0.75rem; border-top: 1px solid var(--border-light);
}
.act-btn {
  font-family: 'DM Mono', monospace; font-size: 0.7rem;
  padding: 0.5rem 0.85rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: transparent;
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.15s ease; min-height: 36px;
}
.act-btn:hover { border-color: var(--text-secondary); }
.act-btn.danger { border-color: var(--danger); color: var(--danger); }
.act-btn.danger:hover { background: var(--danger-soft); }
.act-btn.warn { border-color: var(--warning); color: var(--warning); }
.act-btn.warn:hover { background: var(--warning-soft); }
.act-btn.muted { border-color: transparent; color: var(--text-tertiary); }
.act-btn.muted:hover { border-color: var(--border); color: var(--text-secondary); }

.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(26,24,22,0.4); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.15s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-card {
  background: var(--card); border-radius: var(--radius-lg);
  padding: 2rem; max-width: 400px; width: calc(100% - 2rem);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  transform: scale(0.95); transition: transform 0.15s ease;
}
.modal-overlay.open .modal-card { transform: scale(1); }
.modal-title { font-size: 1.1rem; font-weight: 400; margin-bottom: 0.75rem; }
.modal-body {
  font-family: 'DM Mono', monospace; font-size: 0.8rem;
  color: var(--text-secondary); line-height: 1.6; margin-bottom: 1.5rem;
}
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; }
.modal-btn {
  font-family: 'DM Mono', monospace; font-size: 0.75rem;
  padding: 0.6rem 1.25rem; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.15s ease; min-height: 44px;
  border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
}
.modal-btn:hover { border-color: var(--text-secondary); }
.modal-btn.m-danger { background: var(--danger); color: white; border-color: var(--danger); }
.modal-btn.m-danger:hover { opacity: 0.9; }
.modal-btn.m-warn { background: var(--warning); color: white; border-color: var(--warning); }
.modal-btn.m-warn:hover { opacity: 0.9; }

.toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
  font-family: 'DM Mono', monospace; font-size: 0.75rem;
  padding: 0.75rem 1.25rem; border-radius: var(--radius);
  background: var(--text); color: var(--bg);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease; z-index: 300;
}
.toast.show { opacity: 1; }

.footer {
  max-width: 900px; margin: 0 auto; padding: 3rem 2rem;
  border-top: 1px solid var(--border); display: flex; justify-content: center;
}
.footer-text { font-family: 'DM Mono', monospace; font-size: 0.7rem; color: var(--text-tertiary); }

.loading {
  display: flex; justify-content: center; padding: 4rem;
  flex-direction: column; align-items: center; gap: 1rem;
}
.loading-dots { display: flex; gap: 6px; }
.loading-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-tertiary);
  animation: breathe 1.5s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes breathe { 0% { opacity: 0.3; } 50% { opacity: 1; } 100% { opacity: 0.3; } }
.loading-label {
  font-family: 'DM Mono', monospace; font-size: 0.75rem; color: var(--text-tertiary);
}

.empty { text-align: center; padding: 4rem 2rem; }
.empty-title { font-size: 1.2rem; font-weight: 300; color: var(--text-secondary); margin-bottom: 0.5rem; }
.empty-text { font-family: 'DM Mono', monospace; font-size: 0.75rem; color: var(--text-tertiary); }
.empty-text a { color: var(--accent); text-decoration: none; }
.empty-text a:hover { text-decoration: underline; }

.fade-in { animation: fadeIn 0.4s ease-out both; }
.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.1s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.2s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 700px) {
  .nav { padding: 1rem 1.5rem; }
  .container { padding: 5.5rem 1.25rem 3rem; }
  .summary { grid-template-columns: 1fr; }
  .controls { flex-direction: column; }
  .search-input, .sort-select { width: 100%; }
  .sub-card { padding: 1rem 1.25rem; }
  .sub-header { flex-wrap: wrap; gap: 0.5rem; }
  .sub-actions { flex-direction: column; }
  .act-btn { width: 100%; min-height: 44px; text-align: center; }
  .modal-card {
    position: fixed; bottom: 0; left: 0; right: 0;
    max-width: none; width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
  }
  .modal-overlay.open .modal-card { transform: translateY(0); }
}