@import url('https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@latest/dist/tabler-icons.min.css');
:root {
  --bg: #F4F0FA;
  --surface: #FFFFFF;
  --surface-alt: #F9F8FE;
  --border: #E1D9F5;
  --border-strong: #CECBF6;
  --primary: #534AB7;
  --primary-hover: #453D9E;
  --primary-dark: #3C3489;
  --heading: #26215C;
  --text: #2C2A3D;
  --text-secondary: #6B6580;
  --success: #1F9D55;
  --success-hover: #188245;
  --danger: #C0392B;
  --danger-hover: #A5311F;
  --radius: 12px;
  --radius-sm: 8px;
  --mobile-topbar-height: 52px;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

h1, h2, h3 {
  color: var(--heading);
  font-weight: 500;
  margin: 0 0 0.75rem;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }

.page { max-width: 1000px; margin: 0 auto; padding: 1.5rem 2rem 3rem; }

/* Sidebar-навигация */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  align-self: flex-start;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar .logo {
  font-weight: 500;
  font-size: 1rem;
  color: var(--heading);
  padding: 0 0.5rem;
  margin-bottom: 1.5rem;
}
.logo-icon {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--primary-dark);
  color: var(--surface-alt);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.sidebar a {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.sidebar a i { font-size: 18px; width: 18px; text-align: center; }
.sidebar a:hover { background: var(--surface-alt); }
.sidebar a.active { background: #EEEDFE; color: var(--primary); }
.sidebar .spacer { flex: 1; }

.main-content { flex: 1; min-width: 0; }

/* Мобильная шапка (только на узких экранах) */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--mobile-topbar-height);
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  align-items: center;
  gap: 0.6rem;
  padding: 0 1rem;
  z-index: 1200;
}
.mobile-topbar button {
  background: none; border: none; padding: 0;
  font-size: 20px; color: var(--heading);
  display: flex; align-items: center; cursor: pointer;
}
.mobile-topbar .logo-icon {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--primary-dark);
  color: var(--surface-alt);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.mobile-topbar span { font-weight: 500; color: var(--heading); font-size: 0.95rem; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(38, 33, 92, 0.35);
  z-index: 1050;
}
.sidebar-overlay.visible { display: block; }

/* Карточки */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.card-narrow { max-width: 420px; margin: 3rem auto; }

/* Формы */
input[type="text"], input[type="email"], input[type="password"],
input[type="file"], select, textarea {
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  background: var(--surface-alt);
  color: var(--text);
  width: 100%;
  font-family: inherit;
}
label { font-weight: 500; font-size: 0.85rem; color: var(--heading); display: block; margin-top: 0.9rem; margin-bottom: 0.3rem; }

/* Кнопки */
.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}
.btn:hover { background: var(--primary-hover); }
.btn-block { width: 100%; text-align: center; margin-top: 1rem; }
.btn-success { background: var(--success); }
.btn-success:hover { background: var(--success-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; border: 0.5px solid var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn:disabled { background: #ccc; cursor: default; }

/* Разное */
.badge {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  padding: 0.1rem 0.5rem;
  font-size: 0.75rem;
  margin-left: 0.3rem;
}
.error-text { color: var(--danger); font-size: 0.85rem; }
.muted { color: var(--text-secondary); font-size: 0.85rem; }
.solution-box {
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  white-space: pre-wrap;
  font-size: 0.88rem;
  margin-top: 0.5rem;
}
img.task-image { max-width: 100%; border: 0.5px solid var(--border); border-radius: var(--radius-sm); margin: 0.5rem 0; }

.filters {
  background: var(--surface);
  border: 0.5px solid var(--border);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
}
.filters > * { flex: 1; min-width: 140px; }
.filters button.btn { flex: 0; }

/* Крупнее иконка мобильного меню */
.mobile-topbar button { font-size: 26px; }

/* Быстрые действия на кабинете — плитки вместо текстовых ссылок */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}
.action-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.6rem 1rem;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 16px;
  color: var(--primary);
  font-weight: 500;
  font-size: 0.9rem;
  text-align: center;
}
.action-tile:hover { background: var(--surface-alt); }
.action-tile i { font-size: 26px; }
.action-tile .badge { position: absolute; top: 0.7rem; right: 0.7rem; margin: 0; }

/* Иконки внутри обычных кнопок */
.btn i { margin-right: 0.4rem; vertical-align: -2px; }

/* Компактные иконочные кнопки (стрелочки, крестик в корзине конструктора) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
}
.icon-btn:hover { background: var(--surface-alt); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

/* Мобильная корзина-шторка конструктора (базовые правила, видны только внутри media query ниже) */
.mobile-cart-bar { display: none; }
.cart-close-btn { display: none; }

/* Планер: почасовая сетка (неделя/день) */
.hour-grid-wrap { display: flex; border: 0.5px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.hour-labels { width: 50px; flex-shrink: 0; border-right: 0.5px solid var(--border); }
.hour-header-spacer { height: 48px; box-sizing: border-box; border-bottom: 0.5px solid var(--border); }
.hour-label { height: 48px; font-size: 0.75rem; color: var(--text-secondary); text-align: right; padding-right: 6px; padding-top: 2px; box-sizing: border-box; border-top: 0.5px solid var(--border); }
.day-columns { flex: 1; display: flex; }
.day-col-outer { flex: 1; display: flex; flex-direction: column; border-left: 0.5px solid var(--border); }
.day-col-header { height: 48px; box-sizing: border-box; padding-top: 5px; text-align: center; font-size: 0.72rem; font-weight: 500; color: var(--heading); border-bottom: 0.5px solid var(--border); background: var(--surface-alt); line-height: 1.35; }
.day-col-header .weekday { display: block; color: var(--text-secondary); font-size: 0.65rem; }
.day-col-header .day-date { display: block; }
.day-col-header.today .weekday, .day-col-header.today .day-date { color: var(--primary); }
.day-col-body { flex: 1; display: flex; position: relative; }
.events-half { position: relative; width: 60%; cursor: pointer; background: var(--surface); border-right: 0.5px solid var(--border); }
.tasks-half { position: relative; width: 40%; background: var(--surface); padding: 4px; overflow-y: auto; }
.hour-line { position: absolute; left: 0; right: 0; border-top: 0.5px solid var(--border); }
.event-block { position: absolute; left: 3px; right: 3px; border-radius: 4px; padding: 3px 6px; font-size: 0.75rem; color: #fff; overflow: hidden; cursor: pointer; z-index: 2; }

.planner-task-item { background: var(--surface); border-radius: 4px; padding: 4px 6px; margin-bottom: 4px; font-size: 0.72rem; display: flex; align-items: flex-start; gap: 4px; cursor: pointer; border-left: 4px solid var(--border-strong); box-shadow: 0 0 0 0.5px var(--border); }
.planner-task-item.important { outline: 1.5px solid #7A1F2B; outline-offset: -1.5px; }
.planner-task-item.done .task-title { text-decoration: line-through; color: var(--text-secondary); }
.planner-task-item.compact { padding: 6px; justify-content: center; }
.planner-task-item.compact .task-title { display: none; }
.planner-task-item.compact .task-check { margin-top: 0; }
.task-check { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--text-secondary); flex-shrink: 0; margin-top: 1px; cursor: pointer; }
.task-check.checked { background: var(--success); border-color: var(--success); }
.task-title { flex: 1; }

/* Планер: месяц */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); border: 0.5px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.month-weekday { background: var(--surface-alt); padding: 0.5rem; text-align: center; font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; }
.month-day { min-height: 90px; border-top: 0.5px solid var(--border); border-left: 0.5px solid var(--border); padding: 0.4rem; background: var(--surface); cursor: pointer; }
.month-day.other-month { background: var(--bg); color: var(--text-secondary); }
.month-day.today .month-day-num { background: var(--primary); color: #fff; border-radius: 50%; padding: 0.1rem 0.45rem; }
.month-day-dots { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 0.4rem; }
.month-dot { width: 7px; height: 7px; border-radius: 50%; }

@media (max-width: 700px) {
  .mobile-topbar { display: flex; }

  .app-layout { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: 240px;
    padding-top: calc(var(--mobile-topbar-height) + 1.2rem);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1100;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .logo { display: none; }
  .sidebar .spacer { flex: 0 0 1.5rem; }

  .page { padding: calc(var(--mobile-topbar-height) + 1rem) 1rem 2rem; }

  h1 { font-size: 1.25rem; }
  h2 { font-size: 1rem; }

  .card { padding: 1rem; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters > * { width: 100%; }

  .constructor-layout { flex-direction: column; }

  .task-actions, .task-card-actions, .result-actions {
    flex-wrap: wrap;
  }

  .btn { padding: 0.6rem 1rem; }

  .month-day { min-height: 60px; font-size: 0.8rem; }

  .day-columns.week-mode {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .day-columns.week-mode .day-col-outer {
    flex: 0 0 150px;
    min-width: 150px;
    scroll-snap-align: center;
  }

  /* Корзина конструктора — bottom sheet */
  .cart-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    top: auto;
    width: 100%;
    background: var(--surface);
    border-top: 0.5px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 16px rgba(38, 33, 92, 0.15);
    padding: 1.2rem 1rem calc(1rem + env(safe-area-inset-bottom));
    max-height: 75vh;
    max-height: 75dvh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    z-index: 1150;
  }
  .cart-panel.open { transform: translateY(0); }
  .cart-panel .sheet-thumb { display: none; }

  .mobile-cart-bar {
    display: flex;
    position: fixed;
    left: 1rem; right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius);
    padding: 0.8rem 1.2rem;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(38, 33, 92, 0.25);
    z-index: 1120;
    border: none;
    cursor: pointer;
  }
  .mobile-cart-bar i { margin-right: 0.4rem; }

  .cart-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(38, 33, 92, 0.35);
    z-index: 1140;
  }
  .cart-overlay.visible { display: block; }

  .cart-close-btn {
    display: block;
    margin: 0 auto 0.8rem;
    width: 40px; height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    border: none;
  }
}

.added-item .preview { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }

/* Планер: верхняя панель (табы, навигация, категории) */
.planner-header { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.planner-tabs { display: flex; gap: 0.4rem; }
.planner-tabs button { padding: 0.45rem 0.9rem; border: 0.5px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); cursor: pointer; font-size: 0.85rem; color: var(--text-secondary); }
.planner-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.planner-nav { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.planner-nav button { width: 32px; height: 32px; border-radius: var(--radius-sm); border: 0.5px solid var(--border-strong); background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.planner-label { font-weight: 500; color: var(--heading); min-width: 160px; }
.planner-spacer { flex: 1; }
.category-legend { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.category-chip { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-secondary); }
.category-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.type-switch { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; }
.type-switch button { flex: 1; padding: 0.5rem; border: 0.5px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); cursor: pointer; font-size: 0.85rem; color: var(--text-secondary); }
.type-switch button.active { background: var(--primary); color: #fff; border-color: var(--primary); }