:root {
  color-scheme: dark;
  --bg: #070a12;
  --panel: #0d1320;
  --panel-strong: #111827;
  --panel-soft: #0b1220;
  --line: #263244;
  --line-soft: #1d2939;
  --text: #e5edf6;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --accent: #2563eb;
  --accent-2: #60a5fa;
  --accent-soft: #172554;
  --warn: #fbbf24;
  --danger: #f87171;
  --ok: #86efac;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  background: var(--bg);
}

.panel-heading h2,
.cycle-summary h2,
.message-panel__header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.month-picker,
.month-switch__step,
.month-switch__current,
.filter-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.month-switch__current:focus,
.search-box input:focus {
  border-color: var(--accent-2);
}

.error-banner {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border: 1px solid #7f1d1d;
  border-radius: 8px;
  background: #450a0a;
  color: #fecaca;
}

.desktop-workbench {
  display: grid;
  grid-template-columns: 280px minmax(390px, 1fr) 390px;
  height: 100vh;
  min-height: 620px;
}

.message-pane {
  min-height: 0;
  overflow: auto;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px;
}

.cycle-scroll {
  min-height: 0;
  overflow: auto;
}

.timeline-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 0;
}

.message-pane {
  background: var(--panel);
  padding: 14px;
}

.panel-heading,
.message-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.panel-heading span,
.message-panel__header span,
.cycle-card__meta,
.cycle-card__summary,
.event-card__meta,
.message-bubble header,
.search-results p {
  color: var(--muted);
}

.cycle-list {
  display: grid;
  gap: 8px;
}

.cycle-card,
.event-card,
.search-results button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-strong);
  text-align: left;
  cursor: pointer;
}

.cycle-card {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.cycle-card.is-selected,
.event-card.is-selected {
  border-color: var(--accent);
  background: #0b1f4d;
}

.cycle-card__title {
  font-weight: 800;
  line-height: 1.35;
}

.cycle-card__meta,
.cycle-card__summary {
  font-size: 12px;
  line-height: 1.45;
}

.cycle-card__summary {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.cycle-card__badges,
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cycle-card__badges span {
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #bfdbfe;
  font-size: 11px;
}

.date-nav {
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  margin: 0 0 14px;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.month-switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-2);
}

.month-switch__step {
  width: 28px;
  height: 28px;
  padding: 0;
  cursor: pointer;
}

.month-switch__current {
  min-width: 86px;
  height: 28px;
  padding: 0 10px;
  color: var(--accent-2);
  cursor: pointer;
  font-weight: 750;
}

.month-picker {
  position: absolute;
  right: 34px;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-grid--labels {
  margin-bottom: 4px;
  color: var(--muted-2);
  font-size: 11px;
  text-align: center;
}

.calendar-day {
  display: grid;
  place-items: center;
  min-height: 34px;
  padding: 4px 2px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: #182235;
  color: var(--text);
  cursor: pointer;
  text-align: center;
}

.calendar-day.is-empty {
  background: #0b1220;
  color: var(--muted-2);
}

.calendar-day--heat-1 {
  background: #0f2a1d;
}

.calendar-day--heat-2 {
  background: #14532d;
}

.calendar-day--heat-3 {
  background: #15803d;
}

.calendar-day--heat-4 {
  background: #22c55e;
  color: #04130a;
  font-weight: 800;
}

.calendar-day.is-in-cycle {
  border-color: #1d4ed8;
}

.calendar-day.is-selected {
  background: var(--accent);
  color: white;
}

.cycle-summary {
  z-index: 5;
  flex: 0 0 auto;
  display: block;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-width: 0 0 1px;
  border-radius: 0;
  background: var(--panel);
}

.cycle-summary p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.cycle-summary__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 100%;
}

.cycle-summary__header .eyebrow {
  margin: 0;
}

.cycle-summary__footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.cycle-summary__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
}

.cycle-summary__toggle {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  padding: 6px 9px;
  cursor: pointer;
}

.cycle-summary__text {
  white-space: pre-wrap;
}

.cycle-summary__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  text-align: right;
}

.cycle-summary__stats div {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
  white-space: nowrap;
}

.cycle-summary__stats strong {
  display: inline;
  font-size: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cycle-summary__stats span {
  color: var(--muted);
}

.event-scroll {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.filter-row {
  margin-bottom: 12px;
}

.filter-chip {
  padding: 7px 10px;
  cursor: pointer;
}

.filter-chip.is-active {
  border-color: var(--accent);
  background: var(--accent);
}

.timeline {
  display: grid;
  gap: 9px;
  padding-left: 12px;
  border-left: 2px solid #334155;
}

.event-card {
  --event-accent: var(--line);
  --event-border: var(--line);
  --event-bg: var(--panel-strong);
  position: relative;
  display: grid;
  gap: 6px;
  padding: 10px;
  border-color: var(--event-border);
  background: var(--event-bg);
}

.event-card::before {
  position: absolute;
  left: -18px;
  top: 18px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--event-accent);
  content: "";
}

.event-card.is-selected::before {
  background: var(--event-accent);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.event-card__top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.event-card__top span,
.event-card__amount {
  color: var(--warn);
}

.event-card__meta {
  color: var(--event-accent);
}

.event-card--promise {
  --event-accent: #86efac;
  --event-border: #166534;
  --event-bg: #0f2418;
}

.event-card--money-request {
  --event-accent: #fbbf24;
  --event-border: #92400e;
  --event-bg: #2b1f0b;
}

.event-card--outgoing-payment {
  --event-accent: #38bdf8;
  --event-border: #075985;
  --event-bg: #082333;
}

.event-card--incoming-payment {
  --event-accent: #34d399;
  --event-border: #047857;
  --event-bg: #08251f;
}

.event-card--my-demand {
  --event-accent: #c084fc;
  --event-border: #7e22ce;
  --event-bg: #211331;
}

.event-card--third-party-statement {
  --event-accent: #cbd5e1;
  --event-border: #475569;
  --event-bg: #141b27;
}

.event-card--status-update {
  --event-accent: #60a5fa;
  --event-border: #1d4ed8;
  --event-bg: #0b1d3a;
}

.event-card--dispute-or-accountability {
  --event-accent: #f87171;
  --event-border: #991b1b;
  --event-bg: #2a1114;
}

.event-card__title {
  font-weight: 750;
  line-height: 1.5;
}

.event-card__meta,
.event-card__amount {
  font-size: 12px;
}

.message-panel__header {
  margin-bottom: 10px;
}

.message-scope-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

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

.message-date-divider {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: center;
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.96);
}

.message-bubble {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-strong);
}

.message-bubble.is-source {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.message-bubble.is-sent {
  margin-left: 28px;
  background: #052e1a;
}

.message-bubble.is-received {
  margin-right: 28px;
  background: #0b1f4d;
}

.message-bubble header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 12px;
}

.message-bubble p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.65;
}

.empty-panel {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: var(--panel-soft);
}

.search-panel {
  display: grid;
  gap: 14px;
}

.search-box {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}

.search-results {
  display: grid;
  gap: 8px;
}

.search-results h3 {
  margin: 10px 0 0;
  font-size: 14px;
}

.search-results button {
  padding: 9px;
  line-height: 1.45;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.72);
}

.cycle-detail-modal {
  display: grid;
  gap: 14px;
  width: min(720px, 100%);
  max-height: min(78vh, 780px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
}

.cycle-detail-modal header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.cycle-detail-modal h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.cycle-detail-modal p {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
  white-space: pre-wrap;
}

.mobile-shell {
  display: none;
}

.mobile-date-toggle,
.mobile-date-drawer,
.mobile-date-backdrop {
  display: none;
}

@media (max-width: 920px) {
  .desktop-workbench {
    display: none;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    min-height: auto;
    padding: 12px;
  }

  .topbar__tools {
    width: 100%;
    justify-content: stretch;
  }

  .global-search {
    width: 100%;
    flex: 1;
  }

  .topbar__tools button,
  .status-pill {
    display: none;
  }

  .mobile-shell {
    --mobile-date-toggle-height: 42px;
    display: block;
    padding-bottom: 58px;
  }

  .mobile-date-toggle {
    position: sticky;
    top: 0;
    z-index: 32;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: var(--mobile-date-toggle-height);
    padding: 8px 12px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(13, 19, 32, 0.98);
    color: var(--text);
    cursor: pointer;
    backdrop-filter: blur(10px);
  }

  .mobile-date-toggle span {
    color: var(--muted);
    font-size: 12px;
  }

  .mobile-date-toggle strong {
    color: var(--accent-2);
    font-size: 14px;
  }

  .mobile-date-backdrop.is-open {
    position: fixed;
    inset: 0;
    z-index: 36;
    display: block;
    border: 0;
    background: rgba(2, 6, 23, 0.6);
  }

  .mobile-date-drawer {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 40;
    display: none;
    max-height: min(72vh, 430px);
    overflow: auto;
    padding: 10px 12px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(13, 19, 32, 0.99);
    box-shadow: 0 18px 56px rgba(0, 0, 0, 0.42);
  }

  .mobile-date-drawer.is-open {
    display: block;
  }

  .mobile-date-close {
    float: right;
    min-height: 28px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
  }

  .mobile-page {
    padding: 12px;
  }

  .date-nav {
    position: sticky;
    top: 0;
    margin: -12px -12px 14px;
    padding: 10px 12px;
    background: rgba(13, 19, 32, 0.98);
    backdrop-filter: blur(10px);
  }

  .mobile-date-drawer .date-nav {
    position: relative;
    top: auto;
    margin: 0;
    padding: 0;
    border-bottom: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .date-nav .panel-heading {
    margin-bottom: 8px;
  }

  .calendar-grid {
    gap: 3px;
  }

  .calendar-day {
    min-height: 32px;
  }

  .mobile-page .cycle-summary {
    position: sticky;
    top: var(--mobile-date-toggle-height);
    z-index: 20;
    margin: -12px -12px 0;
    background: rgba(13, 19, 32, 0.98);
    backdrop-filter: blur(10px);
  }

  .mobile-page .message-date-divider {
    top: var(--mobile-date-toggle-height);
  }

  .mobile-tabs {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--line);
    background: rgba(13, 19, 32, 0.98);
  }

  .mobile-tabs button {
    min-height: 52px;
    border: 0;
    background: transparent;
    color: var(--muted);
  }

  .mobile-tabs button.is-active {
    color: var(--accent-2);
  }

  .cycle-summary__stats {
    text-align: left;
  }

  .cycle-summary__stats div {
    justify-content: flex-start;
  }

  .message-bubble.is-sent,
  .message-bubble.is-received {
    margin-right: 0;
    margin-left: 0;
  }
}

@media (max-width: 430px) {
  .topbar h1,
  .panel-heading h2,
  .cycle-summary h2,
  .message-panel__header h2 {
    font-size: 16px;
  }

  .mobile-page {
    padding: 10px;
  }

  .mobile-shell {
    --mobile-date-toggle-height: 40px;
  }

  .mobile-page .cycle-summary {
    margin: -10px -10px 0;
  }

  .date-nav {
    margin: -10px -10px 12px;
    padding: 9px 10px;
  }

  .mobile-date-toggle {
    padding: 7px 10px;
  }

  .mobile-date-drawer {
    padding: 9px 10px 10px;
  }

  .mobile-date-drawer .date-nav {
    margin: 0;
    padding: 0;
  }

  .date-nav .panel-heading {
    margin-bottom: 7px;
  }

  .month-switch {
    gap: 4px;
  }

  .month-switch__step {
    width: 26px;
    height: 26px;
  }

  .month-switch__current {
    min-width: 78px;
    height: 26px;
    padding: 0 8px;
  }

  .calendar-grid--labels {
    margin-bottom: 3px;
  }

  .calendar-day {
    min-height: 30px;
    padding: 3px 1px;
  }

  .cycle-card,
  .event-card,
  .message-bubble {
    border-radius: 9px;
  }
}

