:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d1b16;
  --muted: #8a8476;
  --line: #e6e0d3;
  --accent: #e8572a;
  --accent-ink: #fff;
  --accent-soft: #fde9e1;
  --danger: #c0392b;
  --radius: 18px;
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

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

#app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 40px) 56px;
}

/* Top bar */

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 26px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.year {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
}

.year strong {
  min-width: 64px;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.account {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.account__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn--primary:hover {
  background: #d14a20;
}

.btn--ghost {
  border-color: var(--line);
  background: var(--card);
}

.btn--ghost:hover {
  border-color: var(--ink);
}

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

.btn--block {
  width: 100%;
  margin-top: auto;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--line);
}

.icon-btn--danger:hover {
  background: #f8dcd8;
  color: var(--danger);
}

.alert {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #fbe3df;
  color: var(--danger);
  font-weight: 600;
}

/* Months grid */

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  transition: opacity 0.2s;
}

.grid--loading {
  opacity: 0.55;
  pointer-events: none;
}

.month {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 240px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.month--current {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.month__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.month__head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.month--current .month__head h2 {
  color: var(--accent);
}

.month__count {
  color: var(--muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.month__empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.events {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.event {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px 6px 6px;
  border-radius: 12px;
}

.event:hover {
  background: var(--bg);
}

.event__day {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: none;
  width: 40px;
  padding: 4px 0;
  border-radius: 10px;
  background: var(--accent-soft);
  line-height: 1.1;
}

.event__day b {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.event__day small {
  color: var(--muted);
  font-size: 11px;
}

.event__title {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
  font-size: 15px;
}

.event__actions {
  display: flex;
  flex: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.event:hover .event__actions,
.event:focus-within .event__actions {
  opacity: 1;
}

@media (hover: none) {
  .event__actions {
    opacity: 1;
  }
}

.event--past .event__day {
  background: var(--line);
}

.event--past .event__title {
  color: var(--muted);
}

.event--editing {
  padding: 8px;
  background: var(--bg);
}

/* Forms */

.add-form,
.event-form {
  display: flex;
  gap: 6px;
}

.add-form {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.event-form {
  flex-wrap: wrap;
  width: 100%;
}

.add-form select,
.event-form select {
  flex: none;
  width: 82px;
}

.add-form input,
.event-form input {
  flex: 1;
  min-width: 0;
}

.add-form select,
.add-form input,
.event-form select,
.event-form input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 14px;
}

.add-form :is(select, input):focus,
.event-form :is(select, input):focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.add-form .btn {
  width: 38px;
  padding: 0;
  font-size: 20px;
}

.event-form__actions {
  display: flex;
  gap: 6px;
  width: 100%;
}

/* Auth callback */

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  max-width: 420px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  text-align: center;
}

.auth-card h1 {
  margin-top: 0;
}

.auth-card p {
  color: var(--muted);
}

/* Responsive */

@media (max-width: 1180px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .year {
    grid-row: 2;
    grid-column: 1 / -1;
    justify-self: center;
  }
}

@media (max-width: 560px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .month {
    min-height: 0;
  }

  .brand p {
    display: none;
  }
}
