:root {
  --bg: #f6f5f9; --surface: #ffffff; --surface-2: #f1eff6; --border: #e2dfea;
  --text: #1d1b26; --muted: #6b6779; --accent: #6d3fd9; --accent-ink: #ffffff; --accent-soft: #efe8ff;
  --star: #7c3aed; --green: #1f9d55; --yellow: #d69e0b; --red: #d64545; --red-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(20, 16, 40, .06), 0 2px 8px rgba(20, 16, 40, .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14121b; --surface: #1d1a27; --surface-2: #262232; --border: #352f45;
    --text: #ece9f5; --muted: #a29db3; --accent: #9b7bff; --accent-ink: #14121b; --accent-soft: #2c2445;
    --star: #b394ff; --green: #3ccf7f; --yellow: #f2c14e; --red: #f07070; --red-soft: #3a1f25;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.btn { text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 4px; border-radius: 6px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.logo { font-weight: 800; font-size: 20px; letter-spacing: -.5px; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: 6px; }
.logo span { color: var(--star); }
.topbar .spacer { flex: 1; }
.bell { position: relative; }
.badge { position: absolute; top: -4px; right: -6px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 6px; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 80px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px 18px; }

/* Auth */
.auth { max-width: 380px; margin: 8vh auto; }
.auth h1 { font-size: 34px; text-align: center; margin-bottom: 4px; }
.auth .tag { text-align: center; color: var(--muted); margin-bottom: 20px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin-bottom: 16px; }
.tabs button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* Events list */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; flex: 1; }
.event-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.event-card { text-decoration: none; color: inherit; display: block; transition: transform .1s; }
.event-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.event-card h3 { font-size: 17px; margin-bottom: 2px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; background: var(--star); }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.red { background: var(--red-soft); color: var(--red); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* Event view */
.event-head { padding: 18px 20px; margin-bottom: 14px; }
.event-head h1 { font-size: 26px; }
.event-head .when { font-size: 16px; color: var(--accent); font-weight: 600; margin-top: 2px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.type-section { margin-bottom: 22px; }
.type-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 8px 2px; }
.type-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.type-head p { margin: 0; font-size: 13px; color: var(--muted); }

.project { margin-bottom: 10px; overflow: hidden; }
.item-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.project > .item-row { padding: 12px 14px; }
.item-row .title { flex: 1; min-width: 0; cursor: pointer; }
.item-row .title strong, .item-row .title span.t { overflow-wrap: anywhere; }
.item-row .title:hover strong, .item-row .title:hover .t { text-decoration: underline; text-decoration-color: var(--border); }
.item-row .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.tasks { border-top: 1px solid var(--border); background: var(--surface-2); }
.tasks .item-row { border-bottom: 1px solid var(--border); padding-left: 44px; }
.tasks .item-row:last-child { border-bottom: 0; }
.done .t, .done strong { color: var(--muted); text-decoration: line-through; }
.chev { transition: transform .15s; display: inline-block; color: var(--muted); }
.chev.open { transform: rotate(90deg); }

.star { font-size: 20px; line-height: 1; border: 0; background: none; cursor: pointer; color: var(--border); padding: 0 2px; }
.star.on { color: var(--star); }
.star:hover { color: var(--star); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.green { background: var(--green); } .dot.yellow { background: var(--yellow); } .dot.red { background: var(--red); }
.dot.none { border: 1.5px dashed var(--border); }
.flag { color: var(--red); font-weight: 600; font-size: 12px; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; flex: none;
}
.avatar.none { background: var(--red-soft); color: var(--red); }
.count { font-size: 12px; color: var(--muted); }
.add-task { padding: 8px 14px 10px 44px; }
.add-task form { display: flex; gap: 8px; flex-wrap: wrap; }
.add-task input { flex: 1; min-width: 160px; }
.add-task select, .add-task input[type=datetime-local] { width: auto; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10, 8, 20, .35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); z-index: 21;
  overflow-y: auto; box-shadow: -4px 0 24px rgba(0, 0, 0, .15); padding: 18px 20px 60px;
}
.drawer h2 { font-size: 20px; }
.drawer section { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 16px; }
.drawer section > h3 { font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.status-pick button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 10px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.status-pick button.on { border-color: var(--text); font-weight: 600; }
.thread { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.thread .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.thread .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.reply { margin: 8px 0 0 14px; padding-left: 10px; border-left: 2px solid var(--accent); }
.qmark { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 13px; align-items: center; justify-content: center; }
.missed-box { background: var(--red-soft); border-radius: 10px; padding: 12px; margin-top: 14px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 8px; }
.checks label { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; margin: 0; cursor: pointer; }
.checks input { width: auto; }

/* Modal */
.modal-wrap { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; background: rgba(10, 8, 20, .4); overflow-y: auto; }
.modal { width: min(560px, 100%); padding: 20px; }
.modal h2 { font-size: 20px; margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
pre.report { white-space: pre-wrap; background: var(--surface-2); padding: 14px; border-radius: 10px; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; overflow-wrap: anywhere; }

/* Notifications */
.notif { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif:last-child { border-bottom: 0; }
.notif.unread { background: var(--accent-soft); }
.notif .ico { font-size: 18px; width: 24px; text-align: center; flex: none; }
.notif .msg { flex: 1; min-width: 0; }

.summary textarea { min-height: 90px; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; transition: transform .2s; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--red); color: #fff; }

@media (max-width: 640px) {
  main { padding: 16px 16px 80px; }
  .topbar { padding: 10px 16px; gap: 6px; }
  .hide-sm { display: none; }
  .tasks .item-row, .add-task { padding-left: 16px; }
  .item-row { flex-wrap: wrap; }
  .item-row .meta { width: 100%; justify-content: flex-start; padding-left: 30px; }
}
@media print {
  .topbar, .toolbar, .add-task, .star { display: none !important; }
  body { background: #fff; }
}
#toast:empty { display: none; }
