:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --border: #e2e8f0;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  gap: 12px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-mark { font-size: 26px; }

.brand h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface);
  padding: 10px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.range-label {
  font-size: 16px;
  margin: 0 8px;
  font-weight: 600;
  flex: 1;
  min-width: 120px;
}

.view-switch {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 999px;
  padding: 4px;
}

.btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn:hover { background: var(--primary-soft); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: #4338ca; }

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
}
.btn-danger:hover { background: #fecaca; }

.btn-install {
  background: var(--primary-soft);
  color: var(--primary);
}

.icon-btn {
  font-size: 20px;
  line-height: 1;
  padding: 4px 12px;
}

.view-btn.active {
  background: var(--primary);
  color: #fff;
}

.view-root { flex: 1; }

/* Calendar grid (month) */
.calendar {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.calendar .weekdays,
.calendar .week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.calendar .weekday {
  padding: 10px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.calendar .day {
  min-height: 96px;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  padding: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.calendar .day:nth-child(7n + 1) { border-left: none; }

.calendar .day:hover { background: var(--primary-soft); }

.calendar .day.other { background: #f8fafc; color: var(--muted); }

.calendar .day.today .day-num {
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.day-num {
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.day-items {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.day-chip {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.day-chip.task { background: #ecfdf5; color: #059669; }
.day-chip.done { text-decoration: line-through; opacity: 0.6; }

/* Week view */
.week-grid {
  display: grid;
  grid-template-columns: 48px repeat(7, 1fr);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.week-header-corner { background: var(--surface); }
.week-header {
  padding: 10px 4px;
  text-align: center;
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.week-header .dow { font-size: 12px; color: var(--muted); font-weight: 600; }
.week-header .dnum {
  font-size: 16px;
  font-weight: 700;
  width: 30px;
  height: 30px;
  margin: 2px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.week-header.today .dnum { background: var(--primary); color: #fff; }

.week-hours {
  display: flex;
  flex-direction: column;
}
.week-hours .hour-label {
  height: 56px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  padding-right: 8px;
  position: relative;
  top: -8px;
}
.week-day-col {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  position: relative;
}
.week-day-col .slot {
  height: 56px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.week-day-col .slot:hover { background: var(--primary-soft); }
.week-event {
  position: absolute;
  left: 3px;
  right: 3px;
  background: var(--primary-soft);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  font-size: 11px;
  padding: 3px 6px;
  overflow: hidden;
  cursor: pointer;
  z-index: 2;
}
.week-event.task { background: #ecfdf5; color: #059669; border-left-color: #059669; }
.week-event.done { text-decoration: line-through; opacity: 0.6; }

/* Day view */
.day-view {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.day-heading {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.day-heading h2 { margin: 0; font-size: 20px; }
.day-heading .sub { color: var(--muted); font-size: 13px; }

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.panel h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
}
.entry:hover { background: var(--primary-soft); }
.entry.done { opacity: 0.6; }
.entry .time {
  font-size: 12px;
  color: var(--muted);
  min-width: 60px;
  padding-top: 2px;
}
.entry .body { flex: 1; }
.entry .title { font-weight: 600; font-size: 14px; }
.entry .title.done { text-decoration: line-through; }
.entry .notes { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: pre-wrap; }
.entry .type-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-left: 6px;
}
.entry .type-badge.task { background: #ecfdf5; color: #059669; }

.checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: transparent;
  font-size: 13px;
}
.checkbox.checked { background: var(--primary); border-color: var(--primary); color: #fff; }

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

.add-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  border: none;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
  cursor: pointer;
  z-index: 10;
}
.add-fab:hover { background: #4338ca; }

/* Dialog */
.event-dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}
.event-dialog::backdrop { background: rgba(15, 23, 42, 0.4); }
.event-dialog form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.event-dialog h3 { margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field span { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.field-row { display: flex; gap: 12px; }

.dialog-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.spacer { flex: 1; }

@media (max-width: 640px) {
  .app { padding: 10px; }
  .calendar .day { min-height: 60px; padding: 3px; }
  .day-chip { display: none; }
  .field-row { flex-direction: column; }
  .range-label { font-size: 14px; }
}
