* {
  box-sizing: border-box;
}

:root {
  --bg: #0e1116;
  --surface: #151a23;
  --surface-2: #1c2330;
  --border: #263042;
  --border-hover: #34405a;
  --text: #e9edf3;
  --muted: #8b95a7;
  --accent: #ff7a59;
  --accent-hover: #ff8f72;
  --accent-soft: rgba(255, 122, 89, 0.16);
  --accent-ink: #1c0f08;
  --red: #ff5d5d;
  --red-soft: rgba(255, 93, 93, 0.14);
  --green: #43d17c;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}

a:hover {
  color: var(--accent-hover);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}

.btn:hover {
  background: #232c3c;
}

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

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

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--surface-2);
}

.btn-danger {
  background: var(--red);
  color: #fff;
}

.btn-danger:hover {
  background: #ff7373;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--red);
}

.btn-danger-ghost:hover {
  background: var(--red-soft);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.spacer {
  flex: 1;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-hover);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 16px;
  flex: 1;
  min-width: 0;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field input,
.select-btn {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field input::placeholder {
  color: #5b6577;
}

.field input:hover,
.select-btn:hover {
  border-color: var(--border-hover);
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.grid-num {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.grid-num:hover {
  border-color: var(--border-hover);
  background: #232c3c;
}

.grid-num.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.grid-month {
  padding: 9px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.grid-month:hover {
  border-color: var(--border-hover);
  background: #232c3c;
}

.grid-month.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.alert {
  background: var(--red-soft);
  color: #ff9c9c;
  border: 1px solid rgba(255, 93, 93, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1100px 500px at 50% -120px, rgba(255, 122, 89, 0.09), transparent),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 34px 32px;
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.auth-logo svg {
  width: 30px;
  height: 30px;
}

.auth-card h1 {
  margin: 0 0 20px;
  font-size: 22px;
}

.auth-switch {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

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

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
}

.topbar-brand svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-user > svg {
  width: 18px;
  height: 18px;
}

.cal-wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 24px 48px;
}

.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 14px 0 18px;
}

.cal-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.view-toggle {
  display: inline-flex;
  gap: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.view-btn {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.view-btn:hover {
  color: var(--text);
}

.view-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.cal-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  min-width: 190px;
  text-align: center;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.wd {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 6px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.cal-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 104px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s;
}

.cal-cell:hover {
  border-color: var(--border-hover);
}

.cal-cell.out {
  background: transparent;
  border-color: transparent;
}

.cal-cell.out .cal-daynum {
  color: #454f63;
}

.cal-cell.today {
  border-color: var(--accent);
  background: rgba(255, 122, 89, 0.06);
}

.cal-daynum {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.cal-cell.today .cal-daynum {
  background: var(--accent);
  color: var(--accent-ink);
}

.cal-chips {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.chip {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--accent-soft);
  color: #ffb49d;
  border: none;
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s, color 0.15s;
}

.chip:hover {
  background: var(--accent);
  color: var(--accent-ink);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.72);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.overlay.open {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  box-shadow: var(--shadow);
  animation: modal-pop 0.18s ease;
}

.modal-sm {
  max-width: 380px;
}

@keyframes modal-pop {
  from {
    transform: scale(0.96) translateY(6px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.modal h2 {
  margin: 0 0 18px;
  font-size: 19px;
}

.confirm-text {
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.5;
  margin: 0 0 20px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14px;
  box-shadow: var(--shadow);
  max-width: 320px;
  animation: toast-in 0.2s ease;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.error {
  border-left-color: var(--red);
}

.toast.hide {
  opacity: 0;
  transform: translateX(12px);
}

@keyframes toast-in {
  from {
    transform: translateX(16px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.year-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.mini-month {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  transition: border-color 0.15s;
}

.mini-month:hover {
  border-color: var(--border-hover);
}

.mini-title {
  display: block;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
  transition: color 0.15s;
}

.mini-title:hover {
  color: var(--accent);
}

.mini-weekdays,
.mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.mini-wd {
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  padding: 2px 0;
}

.mini-cell {
  display: flex;
  justify-content: center;
}

.mini-daynum {
  position: relative;
  width: 100%;
  max-width: 26px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(9px, 2.6vw, 11.5px);
  color: var(--text);
  border-radius: 50%;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}

.mini-cell.out .mini-daynum {
  color: #454f63;
}

.mini-daynum.bd {
  cursor: pointer;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.mini-daynum.bd:hover {
  background: var(--accent);
  color: var(--accent-ink);
  transform: scale(1.1);
}

.mini-daynum.bd:hover .dot {
  background: var(--accent-ink);
}

.mini-cell:not(.out):hover .mini-daynum:not(.bd) {
  background: var(--surface-2);
}

.mini-cell.today .mini-daynum {
  background: var(--accent);
  color: var(--accent-ink);
}

.mini-cell.today .mini-daynum .dot {
  background: var(--accent-ink);
}

.mini-cell.today:hover .mini-daynum {
  background: var(--accent-hover);
}

.mini-daynum .dot {
  position: absolute;
  bottom: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.mini-daynum::after {
  content: attr(data-names);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #0a0d12;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 40;
}

.mini-daynum[data-names]:hover::after {
  opacity: 1;
}

.mini-cell:nth-child(7n + 1) .mini-daynum::after {
  left: 0;
  transform: none;
}

.mini-cell:nth-child(7n + 7) .mini-daynum::after {
  left: auto;
  right: 0;
  transform: none;
}

@media (max-width: 720px) {
  .year-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .mini-month {
    padding: 10px 8px;
  }

  .mini-weekdays,
  .mini-grid {
    gap: 1px;
  }

  .cal-grid,
  .cal-weekdays {
    gap: 4px;
  }

  .cal-cell {
    min-height: 74px;
    padding: 5px;
    border-radius: 9px;
  }

  .cal-daynum {
    width: 20px;
    height: 20px;
    font-size: 11px;
  }

  .chip {
    font-size: 10.5px;
    padding: 3px 5px;
  }

  .cal-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .cal-nav {
    flex-wrap: wrap;
    row-gap: 10px;
  }

  .cal-nav .icon-btn[title="Предыдущий месяц"],
  .cal-nav .icon-btn[title="Предыдущий год"] {
    order: 1;
  }

  .cal-title {
    order: 2;
    flex: 1;
    min-width: 0;
    font-size: 19px;
  }

  .cal-nav .icon-btn[title="Следующий месяц"],
  .cal-nav .icon-btn[title="Следующий год"] {
    order: 3;
  }

  .view-toggle {
    order: 4;
    width: 100%;
    justify-content: center;
  }

  #add-birthday {
    width: 100%;
  }

  .topbar-user > svg,
  .topbar-user > span {
    display: none;
  }
}
