:root {
  color-scheme: dark;
  --bg: #0d0f14;
  --surface: #151922;
  --surface-soft: #10151d;
  --surface-elevated: #1b2130;
  --surface-hover: #202838;
  --border: #2a3341;
  --border-strong: #3b4658;
  --text: #eef2f8;
  --muted: #98a6ba;
  --blue: #82a8ff;
  --blue-solid: #3f7bff;
  --blue-soft: rgba(72, 119, 255, 0.18);
  --green: #65d391;
  --green-soft: rgba(42, 157, 96, 0.16);
  --coral: #ff8a74;
  --coral-soft: rgba(255, 115, 91, 0.16);
  --gold: #f5c76f;
  --gold-soft: rgba(245, 199, 111, 0.16);
  --mint: #64d4c8;
  --mint-soft: rgba(78, 203, 190, 0.16);
  --violet: #b59cff;
  --violet-soft: rgba(156, 123, 255, 0.18);
  --shadow: 0 18px 52px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --focus: 0 0 0 3px rgba(130, 168, 255, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  scrollbar-color: var(--border-strong) var(--bg);
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

::selection {
  background: rgba(130, 168, 255, 0.32);
  color: var(--text);
}

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(180deg, #121824 0%, var(--bg) 42%, #090b10 100%);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto 16px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 1px solid rgba(130, 168, 255, 0.24);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
  color: var(--blue);
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 1.45rem;
  line-height: 1.1;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(21, 25, 34, 0.78);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.account-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  max-width: 220px;
  padding: 4px 10px 4px 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(21, 25, 34, 0.86);
  color: var(--text);
}

.account-badge span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--blue-solid);
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 900;
}

.account-badge strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.sync-status.is-success {
  border-color: rgba(21, 128, 61, 0.22);
  background: var(--green-soft);
  color: var(--green);
}

.sync-status.is-error {
  border-color: rgba(208, 79, 56, 0.22);
  background: var(--coral-soft);
  color: var(--coral);
}

.icon-button,
.text-button,
.primary-button,
.delete-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.text-button {
  padding: 0 14px;
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  font-weight: 700;
}

.text-button.quiet {
  background: transparent;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 8px;
  padding: 0 16px;
  background: var(--blue-solid);
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(63, 123, 255, 0.24);
}

.delete-button {
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 34px;
  padding: 0;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover,
.text-button:hover,
.delete-button:hover {
  background: var(--blue-soft);
  border-color: rgba(130, 168, 255, 0.24);
  color: var(--blue);
}

.primary-button:hover {
  transform: translateY(-1px);
  background: #5c8cff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

button:disabled:hover {
  transform: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}

.auth-view {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 120px);
  padding: 36px 0;
}

.auth-card {
  width: min(100%, 430px);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(21, 25, 34, 0.96);
  box-shadow: var(--shadow);
}

.auth-head {
  margin-bottom: 16px;
}

.auth-head h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.auth-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.auth-tab {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.auth-tab.is-active {
  border-color: var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}

.form-status {
  min-height: 20px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.form-status.is-error {
  color: var(--coral);
}

.sidebar {
  display: grid;
  gap: 12px;
}

.panel,
.calendar-surface {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(21, 25, 34, 0.94);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-heading.stacked {
  align-items: flex-start;
}

.panel h2 {
  font-size: 1rem;
  line-height: 1.25;
}

.panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  max-width: 100%;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

input,
select,
textarea,
.money-input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: #6f7f95;
}

input,
select,
textarea {
  padding: 9px 10px;
}

textarea {
  resize: vertical;
  min-height: 78px;
}

.money-input {
  display: flex;
  align-items: center;
  overflow: hidden;
}

.money-input > span {
  display: grid;
  place-items: center;
  align-self: stretch;
  width: 36px;
  border-right: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--muted);
}

.money-input input {
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.metric.wide {
  grid-column: 1 / -1;
  background: var(--blue-soft);
  border-color: rgba(130, 168, 255, 0.22);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.metric strong {
  display: block;
  min-width: 0;
  margin-top: 5px;
  color: var(--text);
  font-size: 1.16rem;
  overflow-wrap: anywhere;
}

.calendar-surface {
  overflow: hidden;
}

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

.weekday-row {
  min-height: 42px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.weekday-row span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.calendar-grid {
  min-height: min(70vh, 760px);
  grid-auto-rows: minmax(114px, 1fr);
}

.day-cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 9px;
  border: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  transition: background 150ms ease, box-shadow 150ms ease;
}

.day-cell:nth-child(7n) {
  border-right: 0;
}

.day-cell:nth-last-child(-n + 7) {
  border-bottom: 0;
}

.day-cell:hover {
  background: var(--surface-hover);
}

.day-cell.is-muted {
  background: #10141c;
  color: #66758b;
}

.day-cell.is-selected {
  box-shadow: inset 0 0 0 2px var(--blue);
}

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

.date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  margin-bottom: 7px;
}

.date-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: inherit;
  font-size: 0.88rem;
  font-weight: 900;
}

.day-total {
  min-width: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-stack {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.event-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-height: 26px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-left: 4px solid var(--blue);
  border-radius: 6px;
  background: var(--blue-soft);
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.2;
}

.event-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-amount {
  color: var(--muted);
  font-weight: 900;
  white-space: nowrap;
}

.more-events {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  padding: 1px 3px;
}

.event-chip[data-category="errand"] {
  border-left-color: var(--gold);
  background: var(--gold-soft);
}

.event-chip[data-category="food"] {
  border-left-color: var(--coral);
  background: var(--coral-soft);
}

.event-chip[data-category="work"] {
  border-left-color: var(--violet);
  background: var(--violet-soft);
}

.event-chip[data-category="payment"] {
  border-left-color: var(--green);
  background: var(--green-soft);
}

.event-chip[data-category="focus"] {
  border-left-color: var(--mint);
  background: var(--mint-soft);
}

.selected-list {
  display: grid;
  gap: 9px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 88px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
}

.plan-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.plan-item h3 {
  min-width: 0;
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.plan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.plan-notes {
  margin: 7px 0 0;
  color: #c0cad8;
  font-size: 0.82rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.money-positive {
  color: var(--green);
}

.money-negative {
  color: var(--coral);
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

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

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

  .day-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .account-badge {
    max-width: none;
    flex: 1 1 180px;
  }

  .toolbar {
    width: 100%;
    justify-content: space-between;
  }

  .auth-view {
    min-height: auto;
    padding: 20px 0;
  }

  .sidebar,
  .field-row {
    grid-template-columns: 1fr;
  }

  .calendar-grid {
    grid-auto-rows: minmax(100px, 1fr);
  }

  .day-cell {
    padding: 6px;
  }

  .event-chip {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .event-amount {
    font-size: 0.7rem;
  }
}

@media (max-width: 520px) {
  .weekday-row span {
    font-size: 0.68rem;
  }

  .calendar-grid {
    grid-auto-rows: minmax(86px, 1fr);
  }

  .date-number {
    width: 24px;
    height: 24px;
    font-size: 0.78rem;
  }

  .day-total {
    display: none;
  }
}
