:root {
  --bg: #f6f6f3;
  --panel: #ffffff;
  --panel-2: #efeee9;
  --text: #1d1f24;
  --muted: #6b6e76;
  --line: #e2e1db;
  --accent: #e8743b;
  --accent-ink: #ffffff;
  --danger: #c8372d;
  --today: rgba(232, 116, 59, 0.07);
  --shadow: 0 10px 40px rgba(20, 20, 30, 0.18);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --panel: #1d2027;
    --panel-2: #252932;
    --text: #e7e8ec;
    --muted: #9196a1;
    --line: #2e333d;
    --accent: #f08a54;
    --accent-ink: #1a1208;
    --danger: #ef6a5e;
    --today: rgba(240, 138, 84, 0.08);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 0; }
.spacer { flex: 1; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.icon-btn {
  border: 0; background: transparent; border-radius: 8px; width: 32px; height: 32px;
  font-size: 20px; line-height: 1; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--panel-2); }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: none; }
.pill { border: 0; border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.pill.warn { background: #f4b740; color: #2b1d00; font-weight: 600; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 5px; background: var(--accent);
  box-shadow: inset 0 5px 0 rgba(0,0,0,.18);
}

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px; display: grid; gap: 12px; box-shadow: var(--shadow);
}
.login-card .brand { font-size: 20px; }
.login-card p { margin: 0; }

label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
input:not([type=checkbox]):not([type=color]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  padding: 7px 9px; font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=color] { width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 2px; }

/* layout */
.app {
  height: 100%; display: grid;
  grid-template-columns: 250px 1fr; grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "side main";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar .brand { margin-right: 18px; }
.nav { display: flex; gap: 2px; }
.title { font-size: 18px; font-weight: 600; margin: 0 0 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 11px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--panel-2); font-weight: 600; }

.sidebar {
  grid-area: side; overflow-y: auto; padding: 14px 12px; border-right: 1px solid var(--line);
  background: var(--panel); display: flex; flex-direction: column; gap: 18px;
}
.sidebar h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 6px 6px; }
.sidebar p { margin: 0 6px 8px; }
.cal-list, .label-list { list-style: none; margin: 0; padding: 0; }
.cal-list li, .label-list li {
  display: flex; align-items: center; gap: 9px; padding: 5px 6px; border-radius: 7px; cursor: pointer; user-select: none;
}
.cal-list li:hover, .label-list li:hover { background: var(--panel-2); }
.box {
  width: 16px; height: 16px; border-radius: 4px; border: 2px solid var(--c); flex: none;
  display: grid; place-items: center; color: #fff; font-size: 11px; line-height: 1;
}
li.on .box { background: var(--c); }
li.on .box::after { content: "✓"; color: var(--ink, #fff); font-weight: 700; }
.cal-list .name, .label-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.cal-list .tag { font-size: 10px; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.label-list .count { font-size: 11px; color: var(--muted); }
.label-list .unnamed .name { color: var(--muted); font-style: italic; }
.g-state { padding: 2px 6px; display: grid; gap: 8px; }
.g-state .btn { justify-self: start; }
.side-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding: 6px; }

.main { grid-area: main; min-height: 0; padding: 8px 12px 12px; }
#calendar { height: 100%; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }

/* FullCalendar theming */
.fc {
  --fc-border-color: var(--line);
  --fc-page-bg-color: var(--bg);
  --fc-neutral-bg-color: var(--panel-2);
  --fc-today-bg-color: var(--today);
  --fc-now-indicator-color: var(--accent);
  --fc-list-event-hover-bg-color: var(--panel-2);
  --fc-highlight-color: rgba(232, 116, 59, .15);
  --fc-event-border-color: transparent;
  --fc-small-font-size: 12px;
}
.fc .fc-col-header-cell-cushion, .fc .fc-daygrid-day-number { color: var(--muted); text-decoration: none; font-weight: 500; }
.fc .fc-day-today .fc-daygrid-day-number {
  background: var(--accent); color: var(--accent-ink); border-radius: 99px; min-width: 24px; text-align: center; margin: 3px;
}
.fc .fc-timegrid-slot-label, .fc .fc-timegrid-axis { color: var(--muted); font-size: 11px; }
.fc .fc-timegrid-slot { height: 2.4em; }
.fc .fc-timegrid-slot-minor { border-top-style: none; }
.fc-event { border-radius: 6px; padding: 1px 2px; cursor: pointer; }
.fc-timegrid-event { box-shadow: 0 0 0 1px var(--bg); }
.fc .fc-event-title { font-weight: 600; }
.fc-daygrid-dot-event .fc-event-title { font-weight: 500; }
.fc .fc-list { border-radius: var(--radius); overflow: hidden; }
.fc .fc-list-day-cushion { background: var(--panel-2); }
.fc .fc-list-event-title a, .fc .fc-list-day-text, .fc .fc-list-day-side-text { color: var(--text); text-decoration: none; }
.fc .fc-scrollgrid { border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.fc .fc-popover { background: var(--panel); box-shadow: var(--shadow); border-radius: var(--radius); }
.fc .fc-more-link { color: var(--muted); }
.ev-ro { opacity: .92; }

/* dialogs */
dialog.editor {
  width: min(460px, calc(100% - 24px)); border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--text); padding: 20px; box-shadow: var(--shadow);
}
dialog.small-dialog { width: min(340px, calc(100% - 24px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { display: grid; gap: 12px; position: relative; }
dialog h3 { margin: 0; font-size: 16px; }
.close { position: absolute; top: -10px; right: -10px; font-size: 16px; }
.ev-title { font-size: 20px !important; font-weight: 600; border: 0 !important; border-bottom: 2px solid var(--line) !important; border-radius: 0 !important; background: transparent !important; padding: 4px 36px 6px 0 !important; }
.ev-title:focus { outline: 0 !important; border-bottom-color: var(--accent) !important; }
.row { display: flex; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.row.when label:first-child { flex: 1.2; }
.row.when .time { flex: 1; }
.seg.scope { align-self: start; }
.seg.scope button { padding: 6px 14px; }
.note { margin: 0; padding: 8px 10px; background: var(--panel-2); border-radius: 8px; font-size: 13px; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch-name { color: var(--text); font-weight: 600; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--panel); outline: 1px solid var(--line); cursor: pointer; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

/* narrow screens: sidebar becomes a drawer */
.only-narrow { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .only-narrow { display: inline-block; }
  .only-wide { display: none; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(290px, 85vw); z-index: 30;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .topbar { flex-wrap: wrap; gap: 6px; padding: 8px 12px; }
  .topbar .brand { margin-right: 0; }
  .title { font-size: 16px; order: 10; flex-basis: 100%; margin: 2px 0 0; }
  .seg { order: 11; flex-basis: 100%; }
  .seg button { flex: 1; padding: 6px 4px; font-size: 13px; }
  .seg [data-view=timeGridWeek] { display: none; }
  .main { padding: 6px 4px 8px; }
}
