:root {
  --hour: 48px;
  --line: #e5e7eb;
  --muted: #6b7280;
  --accent: #2563eb;
  --today: #eff6ff;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: #111827;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #fff;
}

button, input, select {
  font: inherit;
}

button {
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

button:hover { background: #f3f4f6; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1d4ed8; }
button.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
button.danger:hover { background: #b91c1c; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar h1 {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.nav { display: flex; gap: 4px; }

.views { display: flex; }
.views button { border-radius: 0; margin-left: -1px; }
.views button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.views button:last-child { border-radius: 0 6px 6px 0; }
.views button.active { background: #dbeafe; border-color: var(--accent); color: var(--accent); position: relative; }

.period { flex: 1; overflow-x: hidden; overflow-y: auto; }

.month {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(110px, 1fr);
  grid-template-rows: auto;
  min-height: 100%;
}

.month-head {
  padding: 8px 4px;
  text-align: center;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  min-height: 0;
}

.month-cell {
  padding: 4px 6px;
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
  cursor: cell;
}

.month-cell.other { background: #f9fafb; }
.month-cell.other .day-num { color: #9ca3af; }
.month-cell.today { background: var(--today); }
.month-cell.today .day-num { background: var(--accent); color: #fff; }

.day-num {
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 12px;
  background: none;
  font-size: 12px;
}

.chip {
  display: block;
  width: 100%;
  margin-bottom: 2px;
  padding: 1px 6px;
  overflow: hidden;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
  line-height: 1.5;
  border: 0;
  border-left: 3px solid var(--color);
  border-radius: 4px;
  background: color-mix(in srgb, var(--color) 22%, white);
}

.chip:hover { background: color-mix(in srgb, var(--color) 36%, white); }

.chip.cont-before {
  width: calc(100% + 6px);
  margin-left: -6px;
  border-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.chip.cont-after {
  width: calc(100% + 6px);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.chip.cont-before.cont-after { width: calc(100% + 12px); }

.more {
  padding: 0 4px;
  border: 0;
  background: none;
  font-size: 11px;
  color: var(--muted);
}

.year {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  padding: 20px;
}

.mini-title {
  margin-bottom: 6px;
  padding: 0;
  border: 0;
  background: none;
  font-weight: 600;
  text-transform: capitalize;
}

.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mini-head { text-align: center; font-size: 10px; color: var(--muted); }

.mini-day {
  position: relative;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 12px;
}

.mini-day:hover { background: #f3f4f6; }
.mini-day.today { background: var(--accent); color: #fff; }

.mini-day i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  display: flex;
  justify-content: center;
  gap: 2px;
}

.mini-day i b { width: 5px; height: 5px; border-radius: 50%; }

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

.grid {
  display: grid;
  grid-template-columns: 56px repeat(7, minmax(0, 1fr));
}

.head {
  border-bottom: 1px solid var(--line);
  padding-right: var(--scrollbar, 0px);
}

.day-name {
  padding: 8px 4px;
  text-align: center;
  color: var(--muted);
  border-left: 1px solid var(--line);
}

.day-name b { color: #111827; font-size: 18px; margin-left: 4px; }
.day-name.today { background: var(--today); }
.day-name.today b { color: var(--accent); }

.scroll { flex: 1; overflow-y: scroll; }

.times > div {
  height: var(--hour);
  padding-right: 8px;
  text-align: right;
  font-size: 11px;
  color: var(--muted);
  transform: translateY(-7px);
}

.day-col {
  position: relative;
  height: calc(var(--hour) * 24);
  border-left: 1px solid var(--line);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) - 1px), var(--line) calc(var(--hour) - 1px), var(--line) var(--hour));
  cursor: cell;
}

.day-col.today { background-color: var(--today); }

.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #ef4444;
  pointer-events: none;
  z-index: 3;
}

.event {
  position: absolute;
  padding: 2px 6px;
  overflow: hidden;
  text-align: left;
  border: 0;
  border-left: 4px solid var(--color);
  border-radius: 6px;
  background: color-mix(in srgb, var(--color) 20%, white);
  color: #111827;
  cursor: pointer;
  z-index: 2;
}

.event:hover { background: color-mix(in srgb, var(--color) 32%, white); }

.event .title { font-size: 13px; font-weight: 600; line-height: 1.25; }
.event .time { font-size: 11px; color: #374151; line-height: 1.25; }

.event.cont-before {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: 2px dashed var(--color);
}

.event.cont-after {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: 2px dashed var(--color);
}

.event.cont-before::before,
.event.cont-after::after {
  position: absolute;
  right: 4px;
  font-size: 10px;
  color: var(--color);
  filter: brightness(0.7);
}

.event.cont-before::before { content: '▲'; top: 1px; }
.event.cont-after::after { content: '▼'; bottom: 1px; }

dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 20px;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

dialog::backdrop { background: rgba(17, 24, 39, 0.4); }

dialog h2 { margin: 0 0 12px; font-size: 18px; }

form label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

form input:not([type='color']), form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  color: #111827;
}

.colors {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.colors > span { margin-right: 4px; }

.swatch, #custom-color {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
}

.swatch { background: var(--swatch); }
.swatch:hover { background: var(--swatch); }
#custom-color { background: none; }
#custom-color::-webkit-color-swatch-wrapper { padding: 0; }
#custom-color::-webkit-color-swatch { border: 0; border-radius: 50%; }
#custom-color:not(.active)::-webkit-color-swatch { background: conic-gradient(#ef4444, #eab308, #22c55e, #06b6d4, #3b82f6, #a855f7, #ef4444); }

.swatch.active, #custom-color.active { border-color: #111827; box-shadow: 0 0 0 2px #fff inset; }

.row { display: flex; gap: 12px; }
.row > label { flex: 1; }

.template-row { display: flex; align-items: flex-end; gap: 8px; }
.template-row label { flex: 1; }
.template-row button { margin-bottom: 12px; white-space: nowrap; }

.push-left { margin-right: auto; }

.template-name { display: flex; gap: 8px; margin-bottom: 12px; }
form .template-name input { flex: 1; margin-top: 0; }
.template-name button { white-space: nowrap; }

#confirm-text { margin: 0 0 12px; }

.presets { display: flex; gap: 8px; margin: -4px 0 8px; }
.presets button { padding: 3px 10px; font-size: 12px; }

.hint { margin: 0 0 12px; font-size: 12px; color: var(--muted); }
.error { margin: 0 0 12px; color: #dc2626; font-size: 13px; }

.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

#details-time { font-size: 15px; margin: 0 0 4px; }
#details-repeat { margin: 0 0 12px; color: var(--muted); }
