:root {
  --bg-color: #f0f4f8;
  --text-color: #1a202c;
  --card-bg: #ffffff;
  --border-color: #edf2f7;
  --input-border: #e2e8f0;
  --nav-bg: #fff;
  --text-muted: #718096;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #1a202c;
    --text-color: #f7fafc;
    --card-bg: #2d3748;
    --border-color: #4a5568;
    --input-border: #4a5568;
    --nav-bg: #2d3748;
    --text-muted: #a0aec0;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg-color); color: var(--text-color); min-height: 100vh; overflow-x: hidden; touch-action: manipulation; }
.hidden { display: none !important; }

/* Auth */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea, #764ba2); padding: 20px; }
.auth-box { background: #fff; padding: 32px; border-radius: 16px; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(0,0,0,.2); color: #1a202c; }
.auth-box h1 { font-size: 22px; text-align: center; margin-bottom: 20px; }
.hint { text-align: center; color: #718096; font-size: 14px; margin-bottom: 20px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button { flex: 1; padding: 10px; border: none; background: #edf2f7; border-radius: 8px; cursor: pointer; font-weight: 600; color: #4a5568; }
.tabs button.active { background: #667eea; color: #fff; }
#authForm { display: flex; flex-direction: column; gap: 10px; }
#authForm input { padding: 12px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 15px; }
#authForm button { padding: 12px; background: #667eea; color: #fff; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 15px; }
.error { color: #e53e3e; font-size: 14px; text-align: center; margin-top: 10px; min-height: 18px; }
.link-btn { display: block; margin: 16px auto 0; background: none; border: none; color: #718096; cursor: pointer; text-decoration: underline; font-size: 13px; }
.family-block { background: #f7fafc; padding: 14px; border-radius: 10px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.family-block h3 { font-size: 14px; color: #4a5568; }
.family-block input { padding: 10px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; }
.family-block button { padding: 10px; background: #48bb78; color: #fff; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; }

/* Header */
header { background: var(--nav-bg); padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.06); position: relative; z-index: 10; }
header h1 { font-size: 20px; }
.menu-container { position: relative; }
.menu-btn { background: none; border: none; font-size: 28px; line-height: 1; color: var(--text-muted); cursor: pointer; padding: 0 10px; }
.dropdown-menu { position: absolute; right: 0; top: 40px; background: var(--card-bg); border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.15); min-width: 220px; overflow: hidden; border: 1px solid var(--border-color); }
.dropdown-user { padding: 12px 16px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border-color); }
.dropdown-item { display: block; width: 100%; text-align: left; padding: 12px 16px; border: none; background: var(--card-bg); color: var(--text-color); font-size: 14px; cursor: pointer; border-bottom: 1px solid var(--border-color); }
.dropdown-item:hover { background: var(--border-color); }
.text-red { color: #e53e3e; }

.calendar-toggle { display: flex; gap: 8px; padding: 12px 20px; background: var(--nav-bg); border-bottom: 1px solid var(--border-color); }
.toggle-btn { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--input-border); background: var(--card-bg); color: var(--text-color); font-weight: 600; cursor: pointer; }
.toggle-btn.active { background: #667eea; color: #fff; border-color: #667eea; }

.invite-panel { background: rgba(102,126,234,.1); border-bottom: 1px solid var(--border-color); padding: 14px 24px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-color); }
.invite-code { font-family: monospace; font-weight: 700; font-size: 18px; letter-spacing: 2px; margin: 0 8px; }
.main-nav { display: flex; gap: 8px; padding: 16px 24px; background: var(--nav-bg); border-top: 1px solid var(--border-color); overflow-x: auto; }
.nav-btn { padding: 10px 18px; border: none; background: var(--border-color); color: var(--text-color); border-radius: 20px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.nav-btn.active { background: #667eea; color: #fff; }
main { max-width: 900px; margin: 0 auto; padding: 24px; padding-bottom: 120px; }

/* Filters & Switchers */
.filter-tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.filter-btn { padding: 8px 16px; border: 1px solid var(--input-border); border-radius: 20px; background: var(--card-bg); color: var(--text-muted); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.filter-btn.active { background: #667eea; color: #fff; border-color: #667eea; }
.view-switcher { display: flex; gap: 8px; margin-bottom: 16px; background: var(--border-color); padding: 4px; border-radius: 10px; }
.view-btn { flex: 1; padding: 8px; border: none; background: transparent; color: var(--text-color); border-radius: 8px; font-weight: 600; cursor: pointer; }
.view-btn.active { background: var(--card-bg); color: #667eea; box-shadow: 0 2px 4px rgba(0,0,0,.05); }

/* Calendar */
.timeline-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.timeline-header h2 { font-size: 20px; text-align: center; }
.nav-arrow { width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--card-bg); color: var(--text-color); font-size: 20px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.timeline-container { background: var(--card-bg); border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.06); overflow-x: auto; }
.timeline-grid { display: flex; min-width: max-content; }
.time-column { width: 60px; flex-shrink: 0; border-right: 1px solid var(--border-color); padding-top: 40px; }
.time-slot { height: 60px; text-align: right; padding-right: 8px; font-size: 12px; color: var(--text-muted); transform: translateY(-10px); }
.user-column { flex: 1; min-width: 150px; border-right: 1px solid var(--border-color); position: relative; }
.user-column-header { height: 40px; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; background: var(--border-color); border-bottom: 1px solid var(--border-color); position: sticky; top: 0; color: var(--text-color); }
.user-column-body { position: relative; background-image: linear-gradient(to bottom, var(--border-color) 1px, transparent 1px); background-size: 100% 60px; cursor: crosshair; }
.task-block { position: absolute; left: 4px; right: 4px; background: #ebf8ff; border-left: 4px solid #4299e1; border-radius: 4px; padding: 4px; font-size: 11px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.1); cursor: pointer; color: #1a202c; }
.task-block.done { opacity: 0.5; text-decoration: line-through; }
.task-block .task-time { font-weight: 700; display: block; margin-bottom: 2px; }

.month-container { background: var(--card-bg); border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.06); padding: 12px; }
.month-header { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-weight: 700; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(80px, auto); gap: 4px; }
.month-day { background: var(--bg-color); border-radius: 8px; padding: 4px; font-size: 12px; cursor: pointer; overflow: hidden; border: 1px solid var(--border-color); }
.month-day.other { opacity: 0.5; }
.month-day.today { border: 2px solid #667eea; }
.month-day-num { font-weight: 700; margin-bottom: 4px; text-align: right; }
.month-task-dot { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 2px 4px; border-radius: 4px; margin-bottom: 2px; font-size: 10px; background: #ebf8ff; color: #1a202c; border-left: 2px solid #4299e1; }

/* Forms */
.add-form { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
#taskTitle, #shopName, #taskDate { flex: 1 1 100%; width: 100%; }
.time-row { display: flex; gap: 10px; flex: 1 1 100%; width: 100%; }
#taskTime, #taskEndTime { flex: 1; min-width: 0; }
.add-form input, .add-form select { padding: 12px; border: 1px solid var(--input-border); background: var(--card-bg); color: var(--text-color); border-radius: 8px; font-size: 14px; box-sizing: border-box; -webkit-appearance: none; appearance: none; min-height: 46px; }
input[type="date"], input[type="time"] { text-align: left; display: flex; align-items: center; }
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
#taskPriority, #taskAssignee { flex: 1 1 calc(50% - 5px); width: calc(50% - 5px); }
.add-form button { flex: 1 1 100%; padding: 14px; background: #48bb78; color: #fff; border: none; border-radius: 8px; font-weight: 600; font-size: 16px; cursor: pointer; margin-top: 4px; }

/* Repeat Days Checkboxes (Красивые кнопки) */
.repeat-days { flex: 1 1 100%; display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0; }
.repeat-days label { 
  display: flex; align-items: center; justify-content: center; 
  width: 40px; height: 40px; border-radius: 50%; 
  background: var(--border-color); color: var(--text-color); 
  font-size: 13px; font-weight: 600; cursor: pointer; 
  transition: all 0.2s; user-select: none;
}
.repeat-days input { display: none; }
.repeat-days input:checked + span,
.repeat-days label:has(input:checked) { 
  background: #667eea; color: #fff; 
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #667eea;
}

/* Lists */
.list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.list li { background: var(--card-bg); padding: 14px 16px; border-radius: 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; box-shadow: 0 2px 8px rgba(0,0,0,.05); color: var(--text-color); position: relative; }
.list li.done .title, .list li.done .name { text-decoration: line-through; color: var(--text-muted); }
.list .title, .list .name { flex: 1; font-weight: 500; min-width: 120px; }
.list .meta { font-size: 13px; color: var(--text-muted); }
.list input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; }
.list .del { background: none; border: none; color: #e53e3e; font-size: 24px; cursor: pointer; padding: 0 4px; margin-left: auto; }
.list .assignee { background: var(--border-color); color: var(--text-muted); padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.skip-btn { background: #ed8936; color: white; border: none; border-radius: 6px; padding: 4px 8px; font-size: 12px; cursor: pointer; margin-left: 8px; }

/* Priorities */
.list li.priority-urgent { border-left: 4px solid #e53e3e; background: rgba(229, 62, 62, 0.1); }
.list li.priority-important { border-left: 4px solid #ed8936; background: rgba(237, 137, 54, 0.1); }
.list li.priority-not_urgent { border-left: 4px solid #48bb78; background: rgba(72, 187, 120, 0.1); }
.list li.priority-not_important { border-left: 4px solid #a0aec0; background: rgba(160, 174, 192, 0.1); }

.task-block.priority-urgent { background: #fed7d7; border-left-color: #e53e3e; }
.task-block.priority-important { background: #feebc8; border-left-color: #ed8936; }
.task-block.priority-not_urgent { background: #c6f6d5; border-left-color: #48bb78; }
.task-block.priority-not_important { background: #e2e8f0; border-left-color: #a0aec0; }

.month-task-dot.priority-urgent { background: #fed7d7; border-left-color: #e53e3e; }
.month-task-dot.priority-important { background: #feebc8; border-left-color: #ed8936; }
.month-task-dot.priority-not_urgent { background: #c6f6d5; border-left-color: #48bb78; }
.month-task-dot.priority-not_important { background: #e2e8f0; border-left-color: #a0aec0; }
