*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --sidebar-width: 170px;
  --time-gutter-width: 58px;
  --topbar-height: 56px;
  --cal-header-height: 40px;
  --slot-height: 48px;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ── App shell ──────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────── */

#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: 16px;
}

#sidebar-title {
  padding: 18px 16px 12px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#block-list {
  padding: 10px 10px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.pill-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.block-pill {
  flex: 1;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: grab;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  user-select: none;
  touch-action: none;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.block-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}

.pill-edit-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  padding: 0;
}

.pill-row:hover .pill-edit-btn {
  opacity: 1;
}

.pill-edit-btn:hover {
  background: var(--bg);
  color: var(--text);
}

#add-block-btn {
  margin: 10px 10px 0;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1.5px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}

#add-block-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(59, 130, 246, 0.04);
}

#sidebar-hint {
  margin: auto 16px 0;
  padding-top: 20px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.7;
  text-align: center;
}

/* ── Main area ──────────────────────────────────── */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Top bar ────────────────────────────────────── */

#top-bar {
  flex-shrink: 0;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

/* ── Nav dropdown ───────────────────────────────── */

#nav-dropdown {
  position: relative;
  flex-shrink: 0;
}

#nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  transition: background 0.12s;
  letter-spacing: 0.01em;
}

#nav-btn:hover {
  background: var(--bg);
}

#nav-chevron {
  color: var(--text-muted);
  transition: transform 0.18s;
  flex-shrink: 0;
}

#nav-dropdown.open #nav-chevron {
  transform: rotate(180deg);
}

#nav-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  overflow: hidden;
  z-index: 200;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  transition: background 0.12s;
}

.nav-item:hover {
  background: var(--bg);
}

.nav-item.active {
  font-weight: 700;
  color: var(--accent);
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.nav-item.active svg {
  opacity: 1;
  color: var(--accent);
}

/* ── Planner / todo control groups ─────────────── */

#planner-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

#todo-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.btn-secondary-sm {
  padding: 5px 12px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.btn-secondary-sm:hover {
  background: #f1f5f9;
  color: var(--text);
}

/* ── Planner view ───────────────────────────────── */

#planner-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ── Todo view (Google Tasks style) ────────────── */

#todo-view {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

/* Left sidebar */
#todo-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 0 16px;
  overflow-y: auto;
}

.todo-sidebar-section { flex: 1; }

#todo-lists {
  display: flex;
  flex-direction: column;
  padding: 0 8px;
}

.todo-list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 24px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background 0.12s;
  user-select: none;
}

.todo-list-row:hover { background: #f1f5f9; }

.todo-list-row.active {
  background: #e8f0fe;
  color: #1a73e8;
  font-weight: 700;
}

.todo-list-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}

.todo-list-row-name { flex: 1; }

.todo-list-row-count {
  font-size: 12px;
  color: #80868b;
  font-weight: 500;
}

.todo-list-row.active .todo-list-row-count { color: #1a73e8; }

#add-list-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 8px 0;
  padding: 9px 12px;
  border-radius: 24px;
  border: none;
  background: transparent;
  color: #80868b;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-align: left;
}

#add-list-btn:hover { background: #f1f5f9; color: var(--text); }

/* Main panel */
#todo-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 0 32px;
}

#todo-header {
  padding: 28px 24px 8px;
}

#todo-list-title {
  font-size: 22px;
  font-weight: 400;
  color: #202124;
  letter-spacing: 0;
}

/* Add task area */
#todo-add-area {
  padding: 0 24px 8px;
  flex-shrink: 0;
}

#todo-add-trigger {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: #80868b;
  font-family: inherit;
  border-radius: 8px;
  transition: background 0.12s;
  text-align: left;
}

#todo-add-trigger:hover { background: #f1f5f9; }

#todo-add-form {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

#todo-task-input {
  width: 100%;
  padding: 12px 16px 4px;
  border: none;
  outline: none;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: #202124;
  background: transparent;
}

#todo-task-note {
  width: 100%;
  padding: 4px 16px 10px;
  border: none;
  outline: none;
  font-size: 13px;
  font-family: inherit;
  color: #80868b;
  background: transparent;
}

#todo-form-actions {
  display: flex;
  gap: 8px;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
}

.btn-gtasks-primary {
  padding: 7px 16px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}

.btn-gtasks-primary:hover { background: #1557b0; }

.btn-gtasks-ghost {
  padding: 7px 16px;
  background: transparent;
  color: #1a73e8;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}

.btn-gtasks-ghost:hover { background: #e8f0fe; }

/* Tasks */
#todo-tasks-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px;
}

.todo-task {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid #f1f3f4;
  cursor: default;
  transition: background 0.1s;
  border-radius: 4px;
}

.todo-task:hover { background: #f8f9fa; }

.todo-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #dadce0;
  flex-shrink: 0;
  margin-top: 1px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  background: transparent;
}

.todo-checkbox:hover { border-color: #1a73e8; }

.todo-task.done .todo-checkbox {
  background: #1a73e8;
  border-color: #1a73e8;
}

.todo-checkbox svg { display: none; }
.todo-task.done .todo-checkbox svg { display: block; }

.todo-task-body { flex: 1; min-width: 0; }

.todo-task-text {
  font-size: 14px;
  color: #202124;
  line-height: 1.5;
  word-break: break-word;
  outline: none;
  cursor: text;
  white-space: pre-wrap;
}

.todo-task.done .todo-task-text {
  color: #80868b;
  text-decoration: line-through;
}

.todo-task-note-preview {
  font-size: 12px;
  color: #80868b;
  margin-top: 1px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.todo-task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.todo-task-list-chip {
  font-size: 11px;
  color: #80868b;
  background: #f1f3f4;
  border-radius: 10px;
  padding: 1px 7px;
}

.todo-delete-btn {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #80868b;
  font-size: 16px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 50%;
  transition: opacity 0.12s, background 0.12s;
  flex-shrink: 0;
}

.todo-task:hover .todo-delete-btn { opacity: 1; }
.todo-delete-btn:hover { background: #f1f3f4; color: #d93025; }

.todo-completed-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 8px 8px;
  font-size: 13px;
  font-weight: 500;
  color: #80868b;
  cursor: pointer;
  user-select: none;
  border-radius: 4px;
  transition: background 0.1s;
}

.todo-completed-header:hover { background: #f8f9fa; }

.todo-completed-chevron {
  transition: transform 0.2s;
}

.todo-completed-header.collapsed .todo-completed-chevron {
  transform: rotate(-90deg);
}

.todo-completed-tasks.hidden { display: none; }

#todo-tasks-body::-webkit-scrollbar { width: 5px; }
#todo-tasks-body::-webkit-scrollbar-track { background: transparent; }
#todo-tasks-body::-webkit-scrollbar-thumb { background: #dadce0; border-radius: 3px; }

/* ── Goals view ─────────────────────────────────── */

#goals-view {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
  position: relative;
}

#goals-canvas {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Empty state */
.goals-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}
.goals-empty-icon  { font-size: 40px; margin-bottom: 14px; }
.goals-empty-title { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.goals-empty-sub   { font-size: 13px; }

/* SVG connector lines */
.goals-svg {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  overflow: visible;
}

/* Center node */
.goals-center-node {
  position: absolute;
  transform: translate(-50%, -50%);
  background: var(--text);
  color: var(--surface);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 14px 24px;
  border-radius: 40px;
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

/* ── Area card ───────────────────────────────────── */

.goal-area-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: 4px solid var(--ac, var(--accent));
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s;
  z-index: 1;
}
.goal-area-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.10);
  z-index: 3;
}

.goal-area-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.goal-area-color-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  position: relative;
  transition: transform 0.12s;
}
.goal-area-color-dot:hover { transform: scale(1.2); }
.goal-area-color-input {
  position: absolute;
  width: 0; height: 0;
  opacity: 0;
  pointer-events: none;
}

.goal-area-title-input {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  min-width: 0;
}
.goal-area-title-input::placeholder { color: var(--text-muted); font-weight: 400; }

.goal-area-del-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 18px; line-height: 1;
  padding: 2px 5px; border-radius: 5px;
  opacity: 0; transition: opacity 0.1s;
  flex-shrink: 0;
}
.goal-area-card:hover .goal-area-del-btn { opacity: 1; }
.goal-area-del-btn:hover { color: #dc2626; background: #fee2e2; }

/* ── Items grid ──────────────────────────────────── */

.goal-items-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 6px 0;
}

.goal-item-card {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.goal-item-card:last-child { border-bottom: none; }

.goal-item-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.goal-item-bullet {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.goal-item-title {
  flex: 1;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  min-width: 0;
}
.goal-item-title::placeholder { color: var(--text-muted); font-weight: 400; }

.goal-item-del-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 15px; line-height: 1;
  padding: 1px 4px; border-radius: 4px;
  opacity: 0; transition: opacity 0.1s;
  flex-shrink: 0;
}
.goal-item-card:hover .goal-item-del-btn { opacity: 1; }
.goal-item-del-btn:hover { color: #dc2626; background: #fee2e2; }

.goal-item-notes {
  font-size: 13px;
  color: var(--text-muted);
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  resize: none;
  width: 100%;
  line-height: 1.5;
  min-height: 38px;
  overflow: hidden;
  padding-left: 15px;
}
.goal-item-notes::placeholder { color: #cbd5e1; }
.goal-item-notes:focus { color: var(--text); }

/* Add item button */
.goal-add-item-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 14px;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.goal-add-item-btn:hover {
  background: var(--bg);
  color: var(--accent);
}

#goals-view::-webkit-scrollbar { width: 5px; }
#goals-view::-webkit-scrollbar-track { background: transparent; }
#goals-view::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── Week navigation ────────────────────────────── */

#week-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#prev-week,
#next-week {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background 0.12s;
  flex-shrink: 0;
}

#prev-week:hover,
#next-week:hover {
  background: var(--bg);
}

#week-label {
  font-weight: 600;
  font-size: 13px;
  min-width: 168px;
  text-align: center;
  white-space: nowrap;
}

#today-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

#today-btn:hover {
  background: var(--bg);
  color: var(--text);
}


/* ── Time controls ──────────────────────────────── */

#time-controls {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

#time-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

#time-controls select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

#time-controls select:focus {
  border-color: var(--accent);
}

/* ── Calendar wrapper ───────────────────────────── */

#calendar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ── Calendar header (day names) ────────────────── */

#cal-header {
  flex-shrink: 0;
  height: var(--cal-header-height);
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

#time-gutter-header {
  width: var(--time-gutter-width);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

#day-headers {
  flex: 1;
  display: flex;
}


.day-header {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  letter-spacing: 0.02em;
  transition: color 0.15s;
}

.day-header:last-child {
  border-right: none;
}

.day-header.weekend {
  color: var(--accent);
}

.day-header.today {
  color: var(--text);
}

.day-header.today .day-date {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  margin-left: 3px;
}

/* ── Calendar body ──────────────────────────────── */

#cal-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  min-height: 0;
  padding-top: 10px;
}

/* ── Time gutter ────────────────────────────────── */

#time-gutter {
  width: var(--time-gutter-width);
  flex-shrink: 0;
  position: relative;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.time-label {
  position: absolute;
  right: 8px;
  font-size: 11px;
  color: var(--text-muted);
  transform: translateY(-50%);
  white-space: nowrap;
  user-select: none;
}

/* ── Day columns ────────────────────────────────── */

#day-columns {
  flex: 1;
  display: flex;
  position: relative;
}

.day-col {
  flex: 1;
  position: relative;
  border-right: 1px solid var(--border);
  /* Two-tone lines: light at :30, darker at :00. Pattern repeats every 2 slots (1 hour). */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent calc(var(--slot-height) - 1px),
    #dde3eb calc(var(--slot-height) - 1px),
    #dde3eb var(--slot-height),
    transparent var(--slot-height),
    transparent calc(var(--slot-height) * 2 - 1px),
    var(--border) calc(var(--slot-height) * 2 - 1px),
    var(--border) calc(var(--slot-height) * 2)
  );
  background-size: 100% calc(var(--slot-height) * 2);
  transition: background-color 0.1s;
}

.day-col:last-child {
  border-right: none;
}

.day-col.drop-hover {
  background-color: rgba(59, 130, 246, 0.06);
}

.day-col.today-col {
  background-color: rgba(59, 130, 246, 0.02);
}

.current-time-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #ef4444;
  border-radius: 1px;
  z-index: 10;
  pointer-events: none;
}

.current-time-line::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
}

/* ── Event blocks ───────────────────────────────── */

.event-block {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 6px;
  cursor: grab;
  overflow: hidden;
  padding: 4px 7px 10px;
  box-sizing: border-box;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  user-select: none;
  touch-action: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  transition: box-shadow 0.12s, opacity 0.12s;
  z-index: 2;
}

.event-block:active {
  cursor: grabbing;
}

.event-block:hover {
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  z-index: 5;
}

.event-label {
  overflow: hidden;
  line-height: 1.35;
  pointer-events: none;
}

.event-label .event-type {
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-label .event-time {
  opacity: 0.85;
  font-size: 10.5px;
  white-space: nowrap;
}

.event-label .event-notes-preview {
  margin-top: 3px;
  font-size: 10.5px;
  opacity: 0.8;
  font-style: italic;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-weight: 400;
}

.resize-handle {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 8px;
  background: rgba(0, 0, 0, 0.18);
  cursor: ns-resize;
  border-radius: 0 0 6px 6px;
}

.resize-handle:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* Template overlay events shown in week view — solid but visually distinct */
.template-overlay {
  opacity: 0.92;
  border-left: 4px solid rgba(255, 255, 255, 0.7);
  box-shadow: none;
  pointer-events: none; /* block is non-interactive… */
}

/* …except the ★ button inside it */
.template-overlay .event-template-btn {
  pointer-events: all;
}

/* ── Template toggle button (☆ / ★) ──────────────── */

.event-template-btn {
  position: absolute;
  top: 3px;
  right: 4px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  color: rgba(255,255,255,0.55);
  padding: 2px 3px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
  pointer-events: all;
}
.event-block:hover .event-template-btn,
.template-overlay .event-template-btn { opacity: 1; }
.event-template-btn:hover { color: #fff; background: rgba(0,0,0,0.18); }
.event-template-btn.is-template { color: #fde68a; opacity: 1; }

/* ── Note popup ─────────────────────────────────── */

#note-popup {
  position: fixed;
  width: 256px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18), 0 0 0 1px var(--border);
  z-index: 500;
  overflow: hidden;
}

#note-popup.hidden {
  display: none;
}

.np-header {
  padding: 12px 12px 8px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.np-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
}

.np-info {
  flex: 1;
  min-width: 0;
}

.np-type {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.np-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.np-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px;
  flex-shrink: 0;
  border-radius: 4px;
  transition: background 0.12s;
}

.np-close:hover {
  background: var(--bg);
  color: var(--text);
}

#np-notes {
  width: 100%;
  border: none;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 13px;
  resize: none;
  outline: none;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  height: 90px;
  line-height: 1.5;
  display: block;
}

.np-footer {
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.btn-danger-sm {
  padding: 5px 10px;
  background: transparent;
  color: #ef4444;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-danger-sm:hover {
  background: #fef2f2;
}

.btn-primary-sm {
  padding: 5px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-primary-sm:hover {
  background: #2563eb;
}

/* ── Drag ghost ─────────────────────────────────── */

#drag-ghost {
  pointer-events: none;
  position: fixed;
  z-index: 9999;
}

/* ── Modal ──────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  overflow: hidden;
}

.modal-header {
  padding: 20px 22px 0;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.modal-body {
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.modal-field input[type="text"],
.modal-field select {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.modal-field input[type="text"]:focus,
.modal-field select:focus {
  border-color: var(--accent);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-field input[type="color"] {
  width: 40px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

#color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.color-preset {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
  padding: 0;
}

.color-preset:hover {
  transform: scale(1.2);
  border-color: rgba(0,0,0,0.25);
}

.modal-footer {
  padding: 12px 22px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--border);
}

.modal-footer-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn-primary {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: #2563eb;
}

.btn-secondary {
  padding: 8px 16px;
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: #f1f5f9;
}

.btn-danger {
  padding: 8px 14px;
  background: transparent;
  color: #ef4444;
  border: 1.5px solid #fca5a5;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-danger:hover {
  background: #fef2f2;
  border-color: #ef4444;
}

.hidden {
  display: none !important;
}

/* ── Scrollbar styling ──────────────────────────── */

#cal-body::-webkit-scrollbar {
  width: 6px;
}

#cal-body::-webkit-scrollbar-track {
  background: transparent;
}

#cal-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

#cal-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ── Login screen ─────────────────────────────────── */

#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 1000;
}

#login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

#login-logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 2px;
  letter-spacing: -0.5px;
}

#auth-form-title {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  margin-bottom: 4px;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-google:hover { background: #f1f5f9; border-color: #cbd5e1; }

#auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
}
#auth-divider::before,
#auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

#login-card input[type="email"],
#login-card input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}
#login-card input:focus { border-color: var(--accent); }

#auth-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}

.btn-auth-primary {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-auth-primary:hover { background: #2563eb; }

#auth-toggle-text {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
#auth-toggle-link { color: var(--accent); cursor: pointer; text-decoration: none; }
#auth-toggle-link:hover { text-decoration: underline; }

/* ── User badge ───────────────────────────────────── */

#user-badge {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  margin-left: auto;
  user-select: none;
  transition: background 0.15s;
}
#user-badge:hover { background: var(--border); }

#user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
}

.user-initials {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

#user-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#user-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  min-width: 160px;
  z-index: 200;
  overflow: hidden;
  padding: 4px 0;
}

.user-menu-section-label {
  padding: 6px 14px 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#user-export, #user-import, #user-signout {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 14px;
  background: none;
  border: none;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}
#user-export:hover, #user-import:hover { background: rgba(0,0,0,0.04); }
#user-signout { color: #e53e3e; font-weight: 500; }
#user-signout svg { stroke: #e53e3e; }
#user-signout:hover { background: #fff5f5; }

.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ── Habits view ──────────────────────────────────── */

#habits-view {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ── Habits sidebar ───────────────────────────────── */

#habits-sidebar {
  width: 200px;
  min-width: 200px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 12px 0 12px;
  overflow-y: auto;
}

#habits-groups-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.habit-group-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background 0.12s;
  position: relative;
}
.habit-group-row:hover { background: var(--bg); }
.habit-group-row.active { background: #eff6ff; color: #1d4ed8; font-weight: 500; }

.hg-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.hg-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hg-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 10px;
  padding: 1px 6px;
}
.hg-del-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 15px; line-height: 1;
  padding: 0 2px; border-radius: 4px;
  opacity: 0; transition: opacity 0.1s;
}
.habit-group-row:hover .hg-del-btn { opacity: 1; }
.hg-del-btn:hover { color: #dc2626; background: #fee2e2; }

#add-group-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 8px 0;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
#add-group-btn:hover { background: var(--bg); color: var(--accent); }

/* ── Habits main ──────────────────────────────────── */

#habits-main {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--bg);
}

#habits-body {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 860px;
}

.habits-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.habits-empty-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.4; }
.habits-empty-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.habits-empty-sub { font-size: 13px; }

.habits-section {
  margin-bottom: 24px;
}

.habits-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.hsh-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.hsh-name { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Habit row ────────────────────────────────────── */

.habit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 10px;
  transition: background 0.12s;
}
.habit-row:hover { background: var(--surface); }

.habit-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  flex-shrink: 0;
}

.habit-edit-btn {
  background: none; border: none; cursor: pointer;
  padding: 2px; border-radius: 50%;
  flex-shrink: 0;
}
.habit-dot {
  display: block;
  width: 14px; height: 14px;
  border-radius: 50%;
  transition: transform 0.12s;
}
.habit-edit-btn:hover .habit-dot { transform: scale(1.25); }

.habit-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.habit-freq-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Period cells ─────────────────────────────────── */

.habit-cells {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
}

.habit-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.habit-circle {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--hc) 40%, transparent);
  background: transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  position: relative;
}
.habit-circle.current {
  border-color: var(--hc);
  border-width: 2.5px;
}
.habit-circle.done {
  background: var(--hc);
  border-color: var(--hc);
}
.habit-circle.done::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -55%) rotate(-45deg);
  width: 10px; height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
}
.habit-circle:hover { transform: scale(1.12); }

.habit-cell-label {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
}

/* ── Streak ───────────────────────────────────────── */

.habit-streak {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 44px;
  justify-content: flex-end;
  font-size: 13px;
  flex-shrink: 0;
}
.streak-fire { font-size: 14px; }
.streak-count { font-weight: 700; color: var(--text); }
.streak-zero { color: var(--text-muted); font-size: 13px; }

/* ── Habit modal: frequency buttons ──────────────── */

#habit-freq-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.freq-btn {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.freq-btn:hover { border-color: var(--accent); color: var(--accent); }
.freq-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ── Habit row delete button ──────────────────────── */

.habit-del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s, background 0.1s;
  flex-shrink: 0;
}
.habit-row:hover .habit-del-btn { opacity: 1; }
.habit-del-btn:hover { color: #dc2626; background: #fee2e2; }
