* { box-sizing: border-box; }
:root {
  --bg: #f8fafc;
  --surface: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --weekend: #fef2f2;
  --today: #dbeafe;
}
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #334155;
  --weekend: #422f2f;
  --today: #1e3a8a;
}

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px;
}

button, input, select, textarea {
  font: inherit; color: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { background: var(--border); }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover { background: #2563eb; }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 8px;
}
.topbar .left, .topbar .right { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.topbar h1 { font-size: 16px; margin: 0 8px; font-weight: 600; }
.view-switch button.active { background: var(--primary); color: #fff; }

.filters {
  display: flex; gap: 6px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filters input, .filters select { min-width: 140px; }

.banner {
  background: var(--warning); color: #fff;
  padding: 6px 12px; text-align: center; font-size: 13px;
}

#calendar { padding: 8px; }

/* --- MONTH GRID --- */
.month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px; background: var(--border); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.month-grid .dow {
  background: var(--surface); padding: 6px; text-align: center;
  font-weight: 600; color: var(--muted); font-size: 12px;
}
.month-grid .day {
  background: var(--surface); min-height: 110px; padding: 4px;
  display: flex; flex-direction: column; gap: 2px;
  cursor: pointer; transition: background 0.15s;
}
.month-grid .day:hover { background: var(--bg); }
.month-grid .day.weekend { background: var(--weekend); }
.month-grid .day.today { background: var(--today); }
.month-grid .day.other-month { opacity: 0.4; }
.month-grid .day .num { font-weight: 600; font-size: 12px; color: var(--muted); }
.month-grid .day.today .num { color: var(--primary); }

/* --- WEEK / DAY --- */
.week-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
}
.week-grid .day-col {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; min-height: 300px;
  display: flex; flex-direction: column; gap: 4px;
}
.week-grid .day-col.today { border-color: var(--primary); border-width: 2px; }
.week-grid .day-col h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }

.day-view {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; max-width: 600px; margin: 0 auto;
}
.day-view h2 { margin-top: 0; }

/* --- TASK CARD --- */
.task {
  background: var(--primary); color: #fff;
  padding: 3px 6px; border-radius: 4px;
  font-size: 12px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-left: 3px solid rgba(0,0,0,0.2);
}
.task:hover { opacity: 0.85; }
.task.done { opacity: 0.5; text-decoration: line-through; }
.task.priority-high { box-shadow: inset 3px 0 0 var(--danger); }
.task.priority-low { opacity: 0.7; }
.task.overdue { animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 2px var(--danger); } }

.day-view .task {
  padding: 10px; margin-bottom: 6px; font-size: 14px;
  white-space: normal;
}

/* --- DIALOG --- */
dialog {
  border: none; border-radius: 12px; padding: 0;
  background: var(--surface); color: var(--text);
  max-width: 480px; width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
dialog::backdrop { background: rgba(0,0,0,0.4); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted); flex: 1;
}
dialog label input, dialog label select, dialog label textarea {
  color: var(--text); font-size: 14px;
}
dialog .row { display: flex; gap: 10px; }
dialog menu {
  display: flex; justify-content: flex-end; gap: 8px;
  margin: 12px 0 0; padding: 0; list-style: none;
}
dialog menu .danger { margin-right: auto; }

/* --- DRAG & DROP --- */
.day.drag-over { background: var(--today) !important; outline: 2px dashed var(--primary); }
.task[draggable="true"] { cursor: grab; }
.task.dragging { opacity: 0.4; }

/* --- RESPONSIVE --- */
@media (max-width: 1024px) {
  .month-grid .day { min-height: 80px; }
}
@media (max-width: 640px) {
  .topbar h1 { font-size: 14px; }
  .filters { flex-direction: column; }
  .filters input, .filters select { width: 100%; }
  .month-grid .day { min-height: 60px; font-size: 11px; }
  .week-grid { grid-template-columns: 1fr; }
}

#todayBtn {
  font-weight: 600;
  min-width: 140px;
  white-space: nowrap;
}
#todayBtn.is-today {
  color: var(--primary);
  border-color: var(--primary);
}

.task-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 0.95;
  margin-right: 2px;
}

/* Шапка должна быть relative для абсолютного позиционирования заголовка */
.topbar {
  position: relative;
}

.app-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: #3b82f6;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: opacity .15s, transform .1s;
}

.app-title:hover {
  opacity: .7;
}

.app-title:active {
  transform: translate(-50%, -50%) scale(0.96);
}

/* На узких экранах — прячем заголовок, чтобы не мешал кнопкам */
@media (max-width: 768px) {
  .app-title {
    display: none;
  }
}