:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f2f4;
  --surface-3: #e6e8ec;
  --text: #172033;
  --text-2: #4a5568;
  --text-3: #6b7385;
  --border: #d9dde4;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --ok: #1e7f4f;
  --warn: #b26a00;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.12), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.24);
  --list-bg: #ebedf0;
  --radius: 10px;
  --c-green: #1f845a;
  --c-yellow: #e2b203;
  --c-orange: #e56910;
  --c-red: #c9372c;
  --c-purple: #6e5dc6;
  --c-blue: #0c66e4;
  --c-sky: #2898bd;
  --c-lime: #5b7f24;
  --c-pink: #ae4787;
  --c-slate: #626f86;
  --bg-slate: linear-gradient(135deg, #5d6b82, #3a4558);
  --bg-ocean: linear-gradient(135deg, #0b5cad, #1f8fc4);
  --bg-forest: linear-gradient(135deg, #1d5d3f, #3f8f5f);
  --bg-sunset: linear-gradient(135deg, #b4441f, #d9822b);
  --bg-plum: linear-gradient(135deg, #4b2a6b, #8a4c9c);
  --bg-sand: linear-gradient(135deg, #b9a07a, #d9c7a3);
  --bg-night: linear-gradient(135deg, #10172a, #27324d);
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #12161d;
  --surface: #1d232c;
  --surface-2: #252c37;
  --surface-3: #2f3744;
  --text: #e6e9ef;
  --text-2: #b6bdca;
  --text-3: #8f98a8;
  --border: #353e4c;
  --accent: #4c8dff;
  --accent-text: #0b1220;
  --list-bg: #161b22;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { flex-shrink: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; min-height: 34px; 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 { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(127, 127, 127, 0.15); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 28px; padding: 3px 8px; font-size: 13px; }
.btn.icon { padding: 6px; min-width: 34px; justify-content: center; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
input[type='text'], input[type='email'], input[type='number'], input[type='date'], input[type='datetime-local'], input[type='search'], select, textarea {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 9px; min-height: 34px; width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--text); margin-right: 4px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; }
.topbar .spacer { flex: 1; }
.search-wrap { position: relative; min-width: 160px; flex: 0 1 260px; }
.search-wrap svg { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search-wrap input { padding-left: 32px; }
.badge-dot { position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; display: grid; place-items: center; padding: 0 4px; }
.rel { position: relative; }

/* board header */
.boardbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap; color: #fff; }
.boardbar h1 { font-size: 18px; margin: 0; padding: 4px 8px; border-radius: 6px; cursor: text; }
.boardbar h1:hover { background: rgba(255, 255, 255, 0.18); }
.boardbar .btn { background: rgba(255, 255, 255, 0.18); border-color: transparent; color: #fff; }
.boardbar .btn:hover { background: rgba(255, 255, 255, 0.3); }
.boardbar .btn[aria-pressed='true'] { background: #fff; color: #172033; }
.views { display: flex; gap: 4px; flex-wrap: wrap; }
.presence { display: flex; margin-left: 4px; }
.presence .avatar { margin-left: -6px; border: 2px solid rgba(255, 255, 255, 0.85); }
.board-page { min-height: calc(100vh - 51px); display: flex; flex-direction: column; }
.board-page[data-bg] { background: var(--bg-slate); }
.board-page[data-bg='ocean'] { background: var(--bg-ocean); }
.board-page[data-bg='forest'] { background: var(--bg-forest); }
.board-page[data-bg='sunset'] { background: var(--bg-sunset); }
.board-page[data-bg='plum'] { background: var(--bg-plum); }
.board-page[data-bg='sand'] { background: var(--bg-sand); }
.board-page[data-bg='night'] { background: var(--bg-night); }
.filters-active { background: #fff !important; color: #172033 !important; }

/* board view */
.lists { display: flex; gap: 12px; padding: 4px 12px 16px; overflow-x: auto; flex: 1; align-items: flex-start; -webkit-overflow-scrolling: touch; }
.list {
  background: var(--list-bg); border-radius: 12px; width: 280px; min-width: 280px; max-height: calc(100vh - 140px);
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.list-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 4px 12px; }
.list-head h2 { font-size: 14px; margin: 0; flex: 1; padding: 4px; border-radius: 6px; cursor: grab; overflow-wrap: anywhere; }
.list-head .count { color: var(--text-3); font-size: 12px; }
.cards { display: flex; flex-direction: column; gap: 8px; padding: 4px 8px; min-height: 12px; overflow-y: auto; }
.list-foot { padding: 6px 8px 8px; }
.add-list { min-width: 260px; }
.add-list .btn { width: 100%; background: rgba(255, 255, 255, 0.24); color: #fff; border: 0; }

.card-tile {
  background: var(--surface); border-radius: 9px; box-shadow: var(--shadow); cursor: pointer; overflow: hidden;
  border: 1px solid transparent; touch-action: manipulation; user-select: none; -webkit-user-select: none; flex-shrink: 0;
}
.card-tile:hover { border-color: var(--accent); }
.card-tile .cover { height: 28px; }
.card-tile .body { padding: 7px 10px 8px; display: grid; gap: 6px; }
.card-tile .title { overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 4px; padding: 1px 7px; font-size: 12px; font-weight: 600; color: #fff; min-height: 20px; }
.chip.empty-name { min-width: 36px; height: 8px; min-height: 8px; padding: 0; border-radius: 4px; }
.chip.soft { background: var(--surface-2) !important; color: var(--text-2); font-weight: 500; border: 1px solid var(--border); }
.badges { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--text-3); font-size: 12px; }
.badges .b { display: inline-flex; align-items: center; gap: 3px; }
.due-over { color: #fff; background: var(--danger); border-radius: 4px; padding: 0 5px; }
.due-done { color: #fff; background: var(--ok); border-radius: 4px; padding: 0 5px; }
.due-soon { color: #172033; background: var(--c-yellow); border-radius: 4px; padding: 0 5px; }
.avatars { display: flex; gap: 2px; margin-left: auto; }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--c-slate); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { transform: rotate(2deg); }
.sortable-fallback { box-shadow: var(--shadow-lg) !important; opacity: 0.95 !important; }

.bg-green { background: var(--c-green); } .bg-yellow { background: var(--c-yellow); color: #172033; }
.bg-orange { background: var(--c-orange); } .bg-red { background: var(--c-red); }
.bg-purple { background: var(--c-purple); } .bg-blue { background: var(--c-blue); }
.bg-sky { background: var(--c-sky); } .bg-lime { background: var(--c-lime); }
.bg-pink { background: var(--c-pink); } .bg-slate { background: var(--c-slate); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 34px; height: 26px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch[aria-pressed='true'] { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface) inset; }

/* panels: table, calendar, timeline, dashboard */
.panel { margin: 0 12px 16px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.grid th { position: sticky; top: 0; background: var(--surface-2); cursor: pointer; white-space: nowrap; font-weight: 600; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--surface-2); }
.cal-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.cal-head h2 { font-size: 16px; margin: 0 8px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); }
.cal .dow { padding: 6px; font-size: 12px; color: var(--text-3); text-align: center; border-bottom: 1px solid var(--border); }
.cal .day { min-height: 104px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal .day.other { background: var(--surface-2); color: var(--text-3); }
.cal .day.today .num { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 6px; }
.cal .num { font-size: 12px; align-self: flex-start; }
.cal-item { font-size: 12px; border-radius: 4px; padding: 2px 5px; color: #fff; background: var(--c-blue); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; text-align: left; }
.tl { position: relative; min-width: 720px; }
.tl-row { display: grid; grid-template-columns: 220px 1fr; border-bottom: 1px solid var(--border); min-height: 34px; align-items: center; }
.tl-row .name { padding: 6px 10px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.tl-row.group .name { font-weight: 700; background: var(--surface-2); }
.tl-track { position: relative; height: 34px; }
.tl-bar { position: absolute; top: 7px; height: 20px; border-radius: 5px; background: var(--c-blue); color: #fff; font-size: 11px; padding: 2px 6px; overflow: hidden; white-space: nowrap; cursor: pointer; border: 0; text-align: left; }
.tl-scale { display: grid; grid-template-columns: 220px 1fr; position: sticky; top: 0; background: var(--surface-2); z-index: 1; }
.tl-days { position: relative; height: 28px; }
.tl-days span { position: absolute; top: 6px; font-size: 11px; color: var(--text-3); transform: translateX(-50%); }
.tl-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); opacity: 0.6; pointer-events: none; }
.dash { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; padding: 0 12px 16px; }
.dash .tile { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 14px; }
.dash h3 { margin: 0 0 10px; font-size: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; padding: 0 12px 12px; }
.kpi { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; }
.kpi .v { font-size: 26px; font-weight: 700; }
.kpi .l { color: var(--text-3); font-size: 12px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 32px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.bar-row .track { background: var(--surface-2); border-radius: 4px; height: 12px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--c-blue); border-radius: 4px; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; }

/* dialogs and drawers */
.overlay { position: fixed; inset: 0; background: rgba(9, 12, 18, 0.55); z-index: 50; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 32px 12px; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(860px, 100%); position: relative; }
.modal .cover-band { height: 64px; border-radius: 14px 14px 0 0; }
.modal-head { display: flex; gap: 10px; padding: 16px 16px 6px; align-items: flex-start; }
.modal-head input.title-input { font-size: 19px; font-weight: 700; border-color: transparent; background: transparent; }
.modal-head input.title-input:focus { border-color: var(--border); background: var(--surface); }
.modal-body { display: grid; grid-template-columns: 1fr 200px; gap: 16px; padding: 6px 16px 18px; }
.modal-side { display: grid; gap: 6px; align-content: start; }
.modal-side h4 { margin: 8px 0 2px; font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.modal-side .btn { justify-content: flex-start; width: 100%; }
.section { margin-bottom: 18px; }
.section > h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 15px; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.md { overflow-wrap: anywhere; }
.md p:first-child { margin-top: 0; }
.md pre { background: var(--surface-2); padding: 8px; border-radius: 6px; overflow: auto; }
.md blockquote { margin: 0; padding-left: 10px; border-left: 3px solid var(--border); color: var(--text-2); }
.placeholder { color: var(--text-3); background: var(--surface-2); border-radius: 8px; padding: 10px; cursor: pointer; }
.check-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.check-item input { width: 18px; height: 18px; }
.check-item.done span { text-decoration: line-through; color: var(--text-3); }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 4px 0 8px; }
.progress > div { height: 100%; background: var(--ok); }
.comment, .act { display: grid; grid-template-columns: 28px 1fr; gap: 8px; margin: 10px 0; }
.comment .meta, .act .meta { font-size: 12px; color: var(--text-3); }
.att { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.att a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover { position: absolute; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 10px; width: 290px; display: grid; gap: 8px; }
.popover h4 { margin: 0; font-size: 13px; text-align: center; color: var(--text-2); }
.pick-row { display: flex; align-items: center; gap: 6px; }
.pick-row .chip { flex: 1; min-height: 30px; cursor: pointer; border: 0; text-align: left; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); background: var(--surface); z-index: 55; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 16px; margin: 0; flex: 1; }
.drawer-body { padding: 12px; overflow-y: auto; display: grid; gap: 12px; align-content: start; }
.menu-list { display: grid; gap: 4px; }
.menu-list .btn { justify-content: flex-start; border: 0; }
.rule { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: grid; gap: 6px; }
.rule .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rule-step { display: grid; gap: 6px; border-left: 3px solid var(--accent); padding-left: 8px; }
.muted { color: var(--text-3); font-size: 12px; }
.toast-wrap { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; width: min(420px, calc(100% - 24px)); }
.toast { background: #172033; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); display: flex; gap: 8px; align-items: center; }
.toast.err { background: var(--danger); }
.notif { display: grid; gap: 2px; padding: 8px; border-radius: 8px; cursor: pointer; border: 0; background: transparent; text-align: left; width: 100%; }
.notif:hover { background: var(--surface-2); }
.notif.unread { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.home { padding: 20px 16px; max-width: 1100px; margin: 0 auto; }
.home h1 { font-size: 20px; }
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.board-tile { border-radius: 12px; height: 104px; padding: 12px; color: #fff; text-decoration: none; display: flex; flex-direction: column; justify-content: space-between; box-shadow: var(--shadow); border: 0; cursor: pointer; text-align: left; font-size: 15px; font-weight: 700; }
.board-tile small { font-weight: 400; opacity: 0.9; }
.board-tile.new { background: var(--surface-2); color: var(--text-2); border: 1px dashed var(--border); align-items: center; justify-content: center; }
.token-box { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 8px; border-radius: 6px; word-break: break-all; user-select: all; }
.rec { color: var(--danger); }
.empty { padding: 24px; text-align: center; color: var(--text-3); }

@media (max-width: 720px) {
  .modal-body { grid-template-columns: 1fr; }
  .modal-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal-side h4 { grid-column: 1 / -1; }
  .overlay { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; }
  .modal .cover-band { border-radius: 0; }
  .list { width: 84vw; min-width: 84vw; max-height: none; }
  .search-wrap { order: 10; flex: 1 1 100%; }
  .hide-sm { display: none; }
  .cal .day { min-height: 72px; }
  .bar-row { grid-template-columns: 90px 1fr 28px; }
}

select {
  -webkit-appearance: none; appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7385' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
/* iOS Safari zooms into inputs under 16px; keep them at 16px on touch screens. */
@media (pointer: coarse) {
  input[type='text'], input[type='email'], input[type='number'], input[type='date'], input[type='search'], select, textarea { font-size: 16px; }
}
