:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #111827;
  --accent-text: #ffffff;
  --link: #2563eb;
  --danger: #dc2626;
  --warn-bg: #fef2f2;
  --warn: #b91c1c;
  --now: #b45309;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.06);
  --shadow-lg: 0 20px 50px rgb(16 24 40 / 0.18);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f2630;
    --border: #2a313c;
    --text: #e6e8eb;
    --muted: #8b949e;
    --accent: #e6e8eb;
    --accent-text: #0d1117;
    --link: #60a5fa;
    --danger: #f87171;
    --warn-bg: #3a1618;
    --warn: #fca5a5;
    --now: #fbbf24;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 20px 50px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
svg { width: 16px; height: 16px; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn.google svg { width: 18px; height: 18px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn.xs { width: 22px; height: 22px; }
.icon-btn.xs svg { width: 13px; height: 13px; }
.link { border: 0; background: none; padding: 0; color: var(--link); cursor: pointer; font-size: inherit; }
.link.danger { color: var(--danger); }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-height: 34px; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible, .card:focus-visible {
  outline: 2px solid var(--link); outline-offset: 1px;
}

.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; cursor: pointer;
  color: var(--muted); font-weight: 500; font-size: 13px;
}
.seg button span { font-size: 11px; opacity: 0.7; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; justify-content: center; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 28px; text-align: center; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin: 16px 0 6px; }
.login-card .btn { margin-top: 20px; }
.login-actions { display: flex; flex-direction: column; gap: 8px; }
.login-actions .btn { margin: 0; justify-content: center; height: 40px; }
.demo-note { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 20px 0 14px; text-align: left; }
.error { color: var(--danger); }

.logo {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 16px;
}
.logo.lg { width: 52px; height: 52px; border-radius: 14px; font-size: 26px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.brand small, .me small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.nav nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500;
}
.nav nav a:hover { background: var(--surface-2); color: var(--text); }
.nav nav a.active { background: var(--surface-2); color: var(--text); }
.nav nav a em {
  margin-left: auto; font-style: normal; font-size: 11px; font-weight: 600;
  background: var(--accent); color: var(--accent-text); border-radius: 99px; padding: 1px 7px;
}
.me { display: flex; align-items: center; gap: 10px; padding: 10px 6px 0; border-top: 1px solid var(--border); }
.me > div { flex: 1; min-width: 0; }

.main { padding: 28px 32px 48px; min-width: 0; max-width: 1400px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar h1 { font-size: 24px; }
.topbar p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar select { width: auto; min-width: 180px; }

/* ---------- Overview ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; color: var(--text); box-shadow: var(--shadow);
}
.stat:hover { border-color: var(--muted); }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; font-size: 28px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.warn { background: var(--warn-bg); }
.stat.warn strong { color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.panel h2 { font-size: 15px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.more { font-size: 12px; font-weight: 500; }
.empty { color: var(--muted); margin: 8px 0; }

.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 8px; margin: 0 -8px;
  border-radius: 8px; cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-title.done, .task-title.done { text-decoration: line-through; color: var(--muted); }
.row-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 12px; }
.row-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check { width: 17px; height: 17px; min-height: 0; margin: 0; accent-color: var(--accent); cursor: pointer; flex: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.mini-progress { width: 70px; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; flex: none; }
.mini-progress span { display: block; height: 100%; background: var(--c); }

.due { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.due svg { width: 12px; height: 12px; }
.due.late { color: var(--warn); font-weight: 500; }
.due.now { color: var(--now); font-weight: 500; }
.tag { font-size: 11px; background: var(--surface-2); padding: 1px 7px; border-radius: 99px; }
.pchip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text);
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pchip::before { content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--c); flex: none; }

.avatar {
  --c: #64748b;
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: color-mix(in srgb, var(--c) 20%, var(--surface));
  color: color-mix(in srgb, var(--c) 80%, var(--text));
  font-weight: 600; font-size: 13px;
}
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.avatar.xs { width: 18px; height: 18px; font-size: 10px; }
.avatar.empty { background: var(--surface-2); color: var(--muted); }
.avatars { display: inline-flex; }
.avatars .avatar + .avatar { margin-left: -6px; box-shadow: 0 0 0 2px var(--surface); }

/* ---------- Agenda ---------- */
.agenda-day + .agenda-day { margin-top: 12px; }
.agenda-day h3 { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.chip {
  --c: var(--link);
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 6px 8px; border-radius: 7px; margin-bottom: 4px; font-size: 13px; color: var(--text);
  background: color-mix(in srgb, var(--c) 9%, var(--surface)); border: 0; border-left: 3px solid var(--c); cursor: default;
}
.chip.busy {
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, color-mix(in srgb, var(--c) 10%, var(--surface)) 6px 12px);
  color: var(--muted);
}
a.chip, button.chip { cursor: pointer; }
a.chip:hover, button.chip:hover { filter: brightness(0.97); }
.chip.task { --c: var(--now); }
.chip .t { color: var(--muted); font-size: 12px; white-space: nowrap; display: inline-flex; align-items: center; gap: 3px; }
.chip .t svg { width: 12px; height: 12px; }
.chip .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .who { display: inline-flex; gap: 2px; flex: none; }

.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 11px;
  border-radius: 99px; border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.legend-item i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.legend-item.off { color: var(--muted); }
.legend-item.off i { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }
.notice {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); margin-bottom: 14px; color: var(--muted);
}
.notice span { flex: 1; }
.notice.error { background: var(--warn-bg); color: var(--warn); }

/* ---------- Projects ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); cursor: pointer;
}
.card:hover { border-color: var(--muted); }
.card.project { border-top: 4px solid var(--c); }
.card.project h3 { font-size: 16px; margin: 10px 0 2px; }
.card-top { display: flex; justify-content: space-between; align-items: center; }
.card-foot { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.card-foot .avatars, .card-foot > .avatar { margin-left: auto; }
.icon-count { display: inline-flex; align-items: center; gap: 4px; }
.icon-count svg { width: 13px; height: 13px; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 12px; }
.progress span { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 99px; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.active { background: #dcfce7; color: #166534; }
.pill.on_hold { background: #fef3c7; color: #92400e; }
@media (prefers-color-scheme: dark) {
  .pill.active { background: #12341f; color: #86efac; }
  .pill.on_hold { background: #3a2a0c; color: #fcd34d; }
}

/* ---------- Board ---------- */
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; border: 2px dashed transparent; }
.col.over { border-color: var(--link); }
.col header { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px 10px; }
.col h2 { font-size: 13px; display: flex; gap: 8px; align-items: center; }
.count { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface); border-radius: 99px; padding: 1px 7px; }
.col-body { display: flex; flex-direction: column; gap: 8px; }
.card.task { padding: 11px 12px; border-left: 3px solid transparent; }
.card.task.prio-high { border-left-color: var(--danger); }
.card.task.prio-low { opacity: 0.85; }
.task-title { font-weight: 500; margin-bottom: 6px; }
.card.task .card-foot { margin-top: 8px; }
.prio { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.prio-high .prio { color: var(--danger); }

/* ---------- Calendar ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 260px; display: flex; flex-direction: column; }
.day.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 6px; border-bottom: 1px solid var(--border); }
.day-head span { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.day-head strong { font-size: 16px; }
.day-head .icon-btn { margin-left: auto; opacity: 0; }
.day:hover .day-head .icon-btn, .day-head .icon-btn:focus-visible { opacity: 1; }
.is-today .day-head strong { background: var(--accent); color: var(--accent-text); border-radius: 6px; padding: 0 6px; }
.day-body { padding: 6px; flex: 1; }
.day-body .chip { flex-direction: column; align-items: flex-start; gap: 1px; }
.day-body .chip .title { white-space: normal; }
.day-body .chip .who { margin-top: 2px; }

/* ---------- Drawer ---------- */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.25); z-index: 20; }
.backdrop.enter { animation: fade 0.15s; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); z-index: 21;
  background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
}
.drawer.enter { animation: slide 0.18s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 19px; margin-top: 6px; overflow-wrap: anywhere; }
.drawer-head .actions { flex-wrap: nowrap; align-self: flex-start; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; display: flex; flex-direction: column; gap: 16px; }
.drawer-body h3 { font-size: 14px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.drawer-body h3 .btn { margin-left: auto; }
.drawer-body h3 .h-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.folder-name { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files { list-style: none; margin: 0; padding: 0; }
.file {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; margin: 0 -8px;
  border-radius: 8px; color: var(--text);
}
.file:hover { background: var(--surface-2); }
.ficon {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; flex: none;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--c);
}
.fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.file .muted { white-space: nowrap; }
.meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0; }
.meta dt { font-size: 12px; color: var(--muted); }
.meta dd { margin: 2px 0 0; font-weight: 500; }
.drawer-body .progress { margin-top: -4px; }
.desc { white-space: pre-wrap; margin: 0; background: var(--surface-2); padding: 12px; border-radius: 10px; }
.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.field-grid label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.cal-ok { display: flex; align-items: center; gap: 6px; margin: 0; }
.drawer-body > .btn { align-self: flex-start; }

.thread { border-top: 1px solid var(--border); padding-top: 16px; }
.comments { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 12px; }
.comment { display: flex; gap: 10px; }
.bubble { flex: 1; min-width: 0; }
.comment-meta { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.comment-meta span { color: var(--muted); font-size: 12px; }
.comment-meta .link { margin-left: auto; font-size: 12px; opacity: 0; }
.comment:hover .comment-meta .link, .comment-meta .link:focus-visible { opacity: 1; }
.comment p { margin: 3px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
mark { background: color-mix(in srgb, var(--link) 18%, transparent); color: var(--link); border-radius: 4px; padding: 0 2px; font-weight: 500; }
.composer { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }

/* ---------- Modal ---------- */
.modal {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgb(0 0 0 / 0.35); }
.modal header, .modal footer { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; }
.modal header h2 { font-size: 17px; }
.modal footer { justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 4px 20px 20px; }
.field span { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.field.wide { grid-column: 1 / -1; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--accent); color: var(--accent-text); padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-weight: 500; transition: opacity 0.3s; max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.hide { opacity: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .week { gap: 6px; }
  .day-head { padding: 8px 6px 6px; }
  .day-body { padding: 4px; }
  .day-body .chip { padding: 5px 6px; font-size: 12px; }
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .board { grid-template-columns: 1fr; }
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .day-head .icon-btn { opacity: 1; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 10;
    flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
  }
  .brand { display: none; }
  .nav nav { flex-direction: row; justify-content: space-around; }
  .nav nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 10px; position: relative; }
  .nav nav a em { position: absolute; top: 0; right: 4px; margin: 0; }
  .me { border: 0; padding: 0; }
  .me > div, .me > .avatar { display: none; }
  .main { padding: 20px 16px 96px; }
  .topbar h1 { font-size: 20px; }
  .fields, .field-grid, .meta { grid-template-columns: 1fr; }
  .toolbar select { width: 100%; }
}
