:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --ink: #111827;
  --muted: #64748b;
  --line: #d8e0e8;
  --navy: #0f172a;
  --teal: #0f766e;
  --blue: #2563eb;
  --rose: #e11d48;
  --amber: #d97706;
  --green: #16a34a;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.08), transparent 220px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1680px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar,
.status-strip,
.workspace {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand,
.top-actions,
.calendar-toolbar,
.panel-heading,
.dialog-header,
.dialog-actions,
.dialog-actions > div {
  display: flex;
  align-items: center;
}

.brand {
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  color: white;
  background: var(--navy);
  box-shadow: var(--shadow);
}

.brand p,
.panel-heading p,
.calendar-toolbar p,
.dialog-header p,
.status-tile p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0;
}

.brand h1,
.panel-heading h2,
.calendar-toolbar h2,
.dialog-header h2 {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.15;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.tool-button,
.primary-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 800;
  line-height: 1;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border-color 120ms ease;
}

.tool-button {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  border-color: var(--line);
}

.cloud-button.is-cloud-live {
  color: #ffffff;
  background: var(--navy);
  border-color: var(--navy);
}

.cloud-button.has-cloud-error {
  color: #ffffff;
  background: var(--amber);
  border-color: var(--amber);
}

.primary-button {
  color: #ffffff;
  background: var(--teal);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.24);
}

.danger-button {
  color: #ffffff;
  background: var(--rose);
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.icon-button.ghost {
  background: transparent;
}

.tool-button:hover,
.primary-button:hover,
.danger-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.tool-button:focus-visible,
.primary-button:focus-visible,
.danger-button:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.status-tile {
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
}

.status-tile span {
  display: block;
  margin-bottom: 4px;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
}

.status-tile.danger span {
  color: var(--rose);
}

.status-tile.hot span {
  color: var(--amber);
}

.status-tile.warm span {
  color: var(--blue);
}

.status-tile.calm span {
  color: var(--green);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(520px, 1fr) minmax(280px, 340px);
  gap: 14px;
  align-items: start;
}

.agenda-panel,
.calendar-panel,
.day-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.06);
}

.agenda-panel,
.day-panel {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
}

.panel-heading,
.calendar-toolbar {
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.agenda-groups,
.day-list {
  padding: 12px;
}

.agenda-group + .agenda-group {
  margin-top: 14px;
}

.agenda-group h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.payment-item {
  position: relative;
  display: grid;
  grid-template-columns: 8px 1fr;
  gap: 12px;
  min-height: 96px;
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.payment-item:last-child {
  margin-bottom: 0;
}

.payment-accent {
  width: 8px;
  background: var(--blue);
}

.payment-item.category-card .payment-accent {
  background: var(--navy);
}

.payment-item.category-utility .payment-accent {
  background: var(--amber);
}

.payment-item.category-rent .payment-accent {
  background: var(--teal);
}

.payment-item.category-subscription .payment-accent {
  background: var(--blue);
}

.payment-item.category-tax .payment-accent {
  background: #9333ea;
}

.payment-item.category-vendor .payment-accent {
  background: #0891b2;
}

.payment-item.category-support .payment-accent {
  background: #ca8a04;
}

.payment-item.category-other .payment-accent {
  background: #7c3aed;
}

.payment-body {
  min-width: 0;
  padding: 12px 12px 12px 0;
}

.payment-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.payment-title {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
}

.payment-subtitle,
.payment-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.payment-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}

.status-pill {
  flex: 0 0 auto;
  color: var(--ink);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.payment-item.phase-overdue .status-pill {
  color: #ffffff;
  background: var(--rose);
}

.payment-item.phase-today .status-pill {
  color: #ffffff;
  background: var(--amber);
}

.payment-item.phase-soon .status-pill {
  color: #ffffff;
  background: var(--blue);
}

.payment-item.phase-paid .status-pill,
.payment-item.phase-done .status-pill {
  color: #ffffff;
  background: var(--green);
}

.payment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.small-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  font-size: 12px;
  font-weight: 850;
}

.small-action.pay {
  color: #ffffff;
  background: var(--teal);
  border-color: var(--teal);
}

.small-action[disabled] {
  cursor: default;
  opacity: 0.58;
}

.calendar-panel {
  overflow: hidden;
}

.calendar-toolbar {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  text-align: center;
}

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

.weekdays {
  padding: 10px 10px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0;
}

.calendar-grid {
  gap: 8px;
  padding: 10px;
}

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px;
  color: var(--ink);
  background: #ffffff;
  text-align: left;
}

.day-cell:hover {
  border-color: #94a3b8;
}

.day-cell.is-empty {
  visibility: hidden;
}

.day-cell.is-selected {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.16);
}

.day-cell.is-today .day-number {
  color: #ffffff;
  background: var(--navy);
}

.day-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
}

.day-events {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
  min-width: 0;
}

.day-event {
  display: block;
  width: 100%;
  min-height: 22px;
  overflow: hidden;
  border-left: 4px solid var(--blue);
  border-radius: 5px;
  padding: 4px 6px;
  color: var(--ink);
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-event.phase-overdue,
.day-event.phase-today {
  color: #ffffff;
  background: var(--rose);
  border-left-color: #881337;
}

.day-event.phase-paid,
.day-event.phase-done {
  color: #ffffff;
  background: var(--green);
  border-left-color: #166534;
}

.day-more {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 126px;
  border: 1px dashed #b6c3d1;
  border-radius: var(--radius);
  padding: 18px;
  color: var(--muted);
  background: rgba(238, 243, 247, 0.55);
  font-size: 14px;
  font-weight: 750;
  text-align: center;
}

.obsidian-panel {
  margin: 0 12px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
}

.obsidian-panel.is-empty {
  display: none;
}

.obsidian-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.obsidian-head p,
.candidate-card p,
.source-chip {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
}

.obsidian-head h3 {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.2;
}

.obsidian-count {
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--navy);
  font-size: 14px;
  font-weight: 900;
}

.obsidian-actions,
.candidate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.obsidian-actions {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.candidate-list {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
}

.candidate-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #ffffff;
}

.candidate-card h4 {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 24px;
  overflow: hidden;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--surface-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payment-dialog,
.sync-dialog {
  width: min(720px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
}

.payment-dialog::backdrop,
.sync-dialog::backdrop {
  background: rgba(15, 23, 42, 0.52);
}

.payment-dialog form,
.sync-dialog form {
  padding: 18px;
}

.dialog-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field span,
.category-picker legend,
.reminder-picker legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  color: var(--ink);
  background: #ffffff;
}

.field textarea {
  resize: vertical;
}

.sync-state {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.4;
}

.sync-state p {
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.category-picker,
.reminder-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  border: 0;
  padding: 0;
}

.category-picker legend,
.reminder-picker legend {
  width: 100%;
  margin-bottom: 2px;
}

.category-picker label,
.reminder-picker label {
  position: relative;
  display: inline-flex;
}

.category-picker input,
.reminder-picker input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.category-picker span,
.reminder-picker label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 11px;
  color: var(--ink);
  background: #ffffff;
  font-size: 13px;
  font-weight: 850;
}

.category-picker input:checked + span,
.reminder-picker label:has(input:checked) {
  color: #ffffff;
  background: var(--navy);
  border-color: var(--navy);
}

.card-only.is-hidden,
#deletePayment.is-hidden,
.is-hidden {
  display: none;
}

.dialog-actions {
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 40px));
  transform: translateY(16px);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: #ffffff;
  background: var(--navy);
  box-shadow: var(--shadow);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.3;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(290px, 360px) 1fr;
  }

  .day-panel {
    position: static;
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 760px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .tool-button,
  .primary-button {
    width: 100%;
    padding: 0 10px;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .agenda-panel,
  .day-panel {
    position: static;
    max-height: none;
  }

  .calendar-grid {
    gap: 5px;
    padding: 8px;
  }

  .day-cell {
    min-height: 86px;
    padding: 6px;
  }

  .day-event {
    min-height: 18px;
    padding: 3px 5px;
    font-size: 10px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .brand h1,
  .panel-heading h2,
  .calendar-toolbar h2 {
    font-size: 19px;
  }

  .top-actions {
    grid-template-columns: 1fr;
  }

  .weekdays span {
    font-size: 10px;
  }

  .day-cell {
    min-height: 70px;
  }

  .day-number {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .day-events {
    gap: 3px;
    margin-top: 5px;
  }

  .day-event {
    border-left-width: 3px;
  }

  .day-event span {
    display: none;
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-actions > div {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
