/* ========== TOKENS ========== */
:root {
  --sber-green: #21A038;
  --sber-green-dark: #1A8A2E;
  --sber-green-soft: #E8F5EC;
  --sber-green-100: #D4ECDA;
  --sber-ink: #0E1318;
  --sber-ink-2: #2A2F36;
  --muted: #6B7280;
  --muted-2: #9AA0A6;
  --line: #E6E8EB;
  --line-2: #F0F2F4;
  --bg: #F7F8FA;
  --bg-card: #FFFFFF;
  --weekend-bg: #FAFBFB;
  --today-ring: #21A038;

  /* Category palette — distinct hues, all readable on light bg */
  --c-country:     #C8102E;  /* красный — государственный */
  --c-production:  #6B7280;  /* серый — нейтральный, рабочий */
  --c-orthodox:    #8C5A2B;  /* охра — традиция */
  --c-muslim:      #1E7A52;  /* тёмно-зелёный исламский */
  --c-jewish:      #2E5BAA;  /* синий — небо */
  --c-business:    #0E1318;  /* почти чёрный — бизнес */
  --c-parents:     #E07A1F;  /* оранжевый — семья, тепло */
  --c-personal:    #B43DBE;  /* пурпурный — личное */
  --c-professions: #0F8FB8;  /* тил — профессии */
  --c-sber:        #21A038;  /* фирменный Сбер */
  --c-custom:      #5E5CE6;  /* индиго — пользовательское */

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(14,19,24,0.04), 0 1px 3px rgba(14,19,24,0.06);
  --shadow-md: 0 4px 16px rgba(14,19,24,0.08);
  --shadow-lg: 0 16px 48px rgba(14,19,24,0.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  color: var(--sber-ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ========== TOPBAR ========== */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 36px; height: 36px; flex: 0 0 auto; }
.brand-text { min-width: 0; }
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.view-tabs {
  display: inline-flex;
  gap: 4px;
  background: var(--line-2);
  padding: 4px;
  border-radius: 999px;
}
.view-tab {
  background: transparent;
  border: 0;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--sber-ink-2);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.view-tab:hover { color: var(--sber-ink); }
.view-tab.active {
  background: #fff;
  color: var(--sber-green);
  box-shadow: var(--shadow-sm);
}

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

.btn {
  border: 0;
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.12s ease;
  white-space: nowrap;
}
.btn-primary {
  background: var(--sber-green);
  color: #fff;
}
.btn-primary:hover { background: var(--sber-green-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-ghost {
  background: transparent;
  color: var(--sber-ink-2);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--line-2); border-color: var(--muted-2); }

/* ========== LEGEND ========== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #fff;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
}
.legend-chip .dot {
  width: 10px; height: 10px; border-radius: 999px; background: var(--c);
}
.legend-chip.off {
  opacity: 0.45;
  background: var(--line-2);
}
.legend-chip:hover { border-color: var(--muted-2); }

/* ========== VIEWS ========== */
.view { display: none; padding: 24px; max-width: 1640px; margin: 0 auto; }
.view.active { display: block; }

/* ========== MONTH VIEW ========== */
.view-month {
  display: none;
  grid-template-columns: 1fr 360px;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
  align-items: start;
}
.view-month.active { display: grid; }

.month-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.month-header h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.02em;
  font-weight: 800;
  min-width: 220px;
}
.nav-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  color: var(--sber-ink-2);
  transition: all 0.12s ease;
}
.nav-btn:hover { background: var(--sber-green-soft); border-color: var(--sber-green); color: var(--sber-green); }
.today-btn { margin-left: auto; }

.month-grid-head {
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--muted);
  padding: 0 4px;
}
.month-grid-head > div { padding: 6px 8px; }
.month-grid-head .we { color: var(--c-country); }

.month-grid {
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(112px, 1fr);
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  gap: 1px;
}
.day {
  background: #fff;
  padding: 8px 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  position: relative;
  cursor: pointer;
  transition: background 0.12s ease;
}
.day:hover { background: #FBFCFD; }
.day.weekend { background: var(--weekend-bg); }
.day.other-month { background: #FAFAFB; }
.day.other-month .day-num { color: var(--muted-2); }
.day.today .day-num {
  background: var(--sber-green);
  color: #fff;
  border-radius: 999px;
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.day.holiday .day-num { color: var(--c-country); font-weight: 700; }

.day-num { font-weight: 600; font-size: 13px; color: var(--sber-ink); padding: 2px; }
.day-events { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.day-event {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 6px;
  background: var(--c-bg, #F0F2F4);
  color: var(--c-fg, var(--sber-ink));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 3px solid var(--c, var(--muted));
  cursor: pointer;
}
.day-event.imp-3 { font-weight: 700; }
.day-event-more { font-size: 10.5px; color: var(--muted); padding: 0 6px; font-weight: 600; }

.month-side {
  grid-column: 2;
  grid-row: 2 / span 2;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 18px;
  position: sticky;
  top: 130px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}
.month-side h3 { margin: 0 0 12px; font-size: 14px; font-weight: 700; }
.side-event {
  border-left: 3px solid var(--c);
  padding: 8px 10px;
  background: var(--c-bg);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.side-event:hover { transform: translateX(2px); }
.side-event-date { font-size: 11px; color: var(--muted); font-weight: 600; }
.side-event-title { font-weight: 600; font-size: 13px; margin-top: 1px; }
.side-event-note { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.35; }

/* ========== GANTT VIEW ========== */
.gantt-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.gantt-title { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.gantt-zoom { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.gantt-zoom input { accent-color: var(--sber-green); }

.gantt-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.gantt-scroll {
  overflow-x: auto;
  overflow-y: visible;
  position: relative;
}
.gantt-months {
  display: grid;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: #fff; z-index: 4;
}
.gantt-month-cell {
  font-weight: 700;
  font-size: 13px;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  letter-spacing: -0.01em;
}
.gantt-month-cell.alt { background: #FAFBFB; }

.gantt-days {
  display: grid;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 38px; background: #fff; z-index: 3;
}
.gantt-day-cell {
  font-size: 10px;
  color: var(--muted);
  padding: 4px 0;
  text-align: center;
  border-right: 1px solid var(--line-2);
  font-weight: 500;
}
.gantt-day-cell.we { color: var(--c-country); background: #FFF5F6; }
.gantt-day-cell.first-of-month { border-left: 2px solid var(--line); }

.gantt-body {
  position: relative;
  display: grid;
  grid-auto-rows: 30px;
  background-image:
    linear-gradient(to right, var(--line-2) 1px, transparent 1px);
}

.gantt-row {
  position: relative;
  border-bottom: 1px solid var(--line-2);
  height: 30px;
}
.gantt-row.row-cat-label {
  background: var(--cat-bg);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-weight: 700;
  font-size: 11px;
  color: var(--c);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  height: 26px;
}
.gantt-row.row-cat-label .label-pill {
  position: sticky;
  left: 12px;
  background: var(--cat-bg);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--c);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.gantt-row.row-cat-label .label-pill .dot { width: 8px; height: 8px; border-radius: 999px; background: var(--c); }

.gantt-bar {
  position: absolute;
  top: 4px;
  height: 22px;
  border-radius: 6px;
  background: var(--c);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 0 8px;
  display: flex;
  align-items: center;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 3px solid rgba(0,0,0,0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  z-index: 1;
}
.gantt-bar.long-range {
  /* For long-range bars, allow label to be readable from any scroll position by removing clipping */
  overflow: visible;
}
.gantt-bar.long-range > .bar-label-inner {
  position: sticky;
  left: 12px;
  display: inline-block;
  padding-right: 8px;
  background: linear-gradient(90deg, var(--c) 0%, var(--c) 92%, transparent 100%);
  border-radius: 0 4px 4px 0;
  max-width: calc(100vw - 80px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.gantt-bar:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); z-index: 5; }
.gantt-bar.imp-3 { box-shadow: 0 0 0 2px rgba(33,160,56,0.15); }
.gantt-bar.point {
  padding-left: 22px;
  background: var(--c) !important;
}
.gantt-bar.point::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.95);
}

.gantt-weekend-stripe {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(200,16,46,0.04);
  pointer-events: none;
}
.gantt-today-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--sber-green);
  z-index: 6;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(33,160,56,0.2);
}

/* ========== CALENDARS VIEW ========== */
.cat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}
.cat-tab {
  background: #fff;
  border: 1px solid var(--line);
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--sber-ink-2);
  transition: all 0.12s ease;
}
.cat-tab:hover { border-color: var(--muted-2); }
.cat-tab.active {
  background: var(--c);
  border-color: var(--c);
  color: #fff;
}
.cat-tab .dot { width: 8px; height: 8px; border-radius: 999px; background: var(--c); }
.cat-tab.active .dot { background: rgba(255,255,255,0.85); }
.cat-tab .count {
  font-size: 11px;
  background: rgba(0,0,0,0.06);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
}
.cat-tab.active .count { background: rgba(255,255,255,0.25); }

.cat-content {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
}
.cat-event-row {
  display: grid;
  grid-template-columns: 200px 1fr auto;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.1s ease;
  align-items: center;
}
.cat-event-row:hover { background: var(--line-2); }
.cat-event-row + .cat-event-row { border-top: 1px solid var(--line-2); }
.cat-event-date {
  font-weight: 700;
  font-size: 13px;
  color: var(--c);
  display: flex;
  align-items: center;
  gap: 8px;
}
.cat-event-date .dot { width: 10px; height: 10px; border-radius: 999px; background: var(--c); flex: 0 0 auto; }
.cat-event-main .title { font-weight: 600; font-size: 14px; }
.cat-event-main .note { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.cat-event-imp {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--line-2);
  color: var(--muted);
}
.cat-event-imp.imp-3 { background: var(--sber-green-soft); color: var(--sber-green-dark); }
.cat-event-imp.imp-2 { background: #FFF7E6; color: #B5651D; }

.cat-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ========== MODAL ========== */
.modal {
  position: fixed; inset: 0;
  background: rgba(14,19,24,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  animation: fadein 0.15s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal[hidden] { display: none; }
.modal-panel {
  background: #fff;
  border-radius: 16px;
  width: min(560px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideup 0.18s ease;
}
@keyframes slideup { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 8px;
}
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.icon-btn {
  background: transparent; border: 0; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px;
  font-size: 22px; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--line-2); color: var(--sber-ink); }

.form { padding: 8px 22px 22px; display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; }
.form label > span {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.form input[type="text"], .form input[type="date"], .form select, .form textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
  width: 100%;
  font-family: inherit;
}
.form input:focus, .form select:focus, .form textarea:focus {
  border-color: var(--sber-green);
  box-shadow: 0 0 0 3px var(--sber-green-soft);
}
.form .row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form .row > label { min-width: 0; }
.form .row > label[hidden], .form [hidden] { display: none !important; }
.modal-actions { display: flex; align-items: center; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); margin-top: 4px; padding: 14px 0 0; }

/* ========== RESPONSIVE ========== */
@media (max-width: 1100px) {
  .view-month.active { grid-template-columns: 1fr; }
  .month-side { position: static; max-height: none; grid-row: auto; grid-column: 1; }
}
@media (max-width: 720px) {
  .topbar { grid-template-columns: 1fr; gap: 10px; padding: 12px; }
  .view-tabs { justify-self: stretch; overflow-x: auto; }
  .topbar-actions { justify-content: flex-start; flex-wrap: wrap; }
  .view { padding: 14px; }
  .month-header h2 { font-size: 22px; min-width: 0; }
  .month-grid { grid-auto-rows: minmax(80px, 1fr); }
  .day-event { font-size: 10.5px; padding: 2px 4px; }
  .form .row { grid-template-columns: 1fr; }
  .cat-event-row { grid-template-columns: 1fr; gap: 6px; }
}

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }
