:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --surface-3: #262b36;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b909c;
  --accent: #6366f1;
  --accent-hover: #7679f2;
  --radius: 14px;
  --radius-sm: 10px;

  /* priority colors */
  --p-low: #3b82f6;
  --p-medium: #10b981;
  --p-high: #f59e0b;
  --p-urgent: #ef4444;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--p-urgent); font-size: 13px; margin-top: 8px; }
.view { min-height: 100vh; }
.app-view { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: transparent; border-color: var(--p-urgent); color: var(--p-urgent); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 8px; }
.icon-btn { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; padding: 6px; line-height: 1; }

/* ---------- LOGIN ---------- */
.login-view { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px 24px;
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 60px; height: 60px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff; font-weight: 800; font-size: 20px; letter-spacing: 1px; margin-bottom: 12px;
}
.brand h1 { margin: 6px 0 2px; font-size: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, textarea, select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 12px; font-size: 15px; font-family: inherit; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

/* ---------- TOPBAR ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: rgba(15,17,21,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-weight: 700; font-size: 16px; }

/* avatars */
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-3); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--text);
  background-size: cover; background-position: center; overflow: hidden; flex: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }
.avatar-xs { width: 24px; height: 24px; font-size: 10px; }

/* ---------- DRAWER ---------- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); z-index: 0; }
.drawer-panel {
  position: absolute; top: 0; left: 0; bottom: 0; width: 82%; max-width: 320px; z-index: 1;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: calc(18px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  display: flex; flex-direction: column;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.drawer-header { display: flex; gap: 12px; align-items: center; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.drawer-name { font-weight: 700; }
.drawer-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 14px; flex: 1; overflow-y: auto; }
.drawer-item {
  text-align: left; background: none; border: none; color: var(--text);
  padding: 12px 10px; border-radius: var(--radius-sm); font-size: 15px; cursor: pointer;
}
.drawer-item:hover, .drawer-item.active { background: var(--surface-2); }
.drawer-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 12px 10px 4px; }
.drawer-footer { margin-top: 14px; text-align: center; }

/* ---------- BOARD ---------- */
.board {
  display: flex; gap: 12px; padding: 14px;
  overflow-x: auto; overflow-y: hidden;
  flex: 1; min-height: 0;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.column {
  flex: 0 0 84%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; scroll-snap-align: start;
  max-height: 100%;
}
.column-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.column-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.column-count { background: var(--surface-3); color: var(--muted); font-size: 11px; padding: 2px 8px; border-radius: 20px; }
.column-body { padding: 10px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 40px; }
.column-body.drag-over { background: var(--surface-2); outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: 10px; }
.column-add { padding: 10px; }
.column-actions { display: flex; align-items: center; gap: 2px; }
.col-add-btn { font-size: 22px; color: var(--muted); }
.col-add-btn:hover { color: var(--accent); }
.ghost-card {
  background: none; border: 1px dashed var(--border); color: var(--muted);
  border-radius: var(--radius-sm); padding: 16px; cursor: pointer;
  font-size: 22px; line-height: 1; text-align: center; width: 100%;
  transition: border-color .15s, color .15s;
}
.ghost-card:hover { border-color: var(--accent); color: var(--accent); }
.add-column-btn {
  flex: 0 0 60px; align-self: flex-start; margin-top: 0;
  background: var(--surface); border: 1px dashed var(--border); color: var(--muted);
  border-radius: var(--radius); cursor: pointer; font-size: 22px; height: 52px; width: 60px;
}

/* ---------- CARD ---------- */
.card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; cursor: pointer;
  transition: border-color .15s, transform .05s;
}
.card:active { transform: scale(.99); }
.card.p-low { border-left-color: var(--p-low); }
.card.p-medium { border-left-color: var(--p-medium); }
.card.p-high { border-left-color: var(--p-high); }
.card.p-urgent { border-left-color: var(--p-urgent); }
.card.dragging { opacity: .5; }
.card.done .card-title { text-decoration: line-through; color: var(--muted); }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-title { font-size: 14px; font-weight: 600; line-height: 1.35; word-break: break-word; }
.card-meta { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 20px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.pill-priority.p-low { background: rgba(59,130,246,.15); color: var(--p-low); }
.pill-priority.p-medium { background: rgba(16,185,129,.15); color: var(--p-medium); }
.pill-priority.p-high { background: rgba(245,158,11,.15); color: var(--p-high); }
.pill-priority.p-urgent { background: rgba(239,68,68,.15); color: var(--p-urgent); }
.pill-deadline { background: var(--surface-3); color: var(--muted); }
.pill-deadline.overdue { background: rgba(239,68,68,.15); color: var(--p-urgent); }
.pill-count { background: var(--surface-3); color: var(--muted); }
.card-badges { display: flex; align-items: center; gap: 6px; }
.mirror-badge { font-size: 10px; color: var(--accent); background: rgba(99,102,241,.12); padding: 2px 6px; border-radius: 6px; }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; border: 1px solid var(--border);
  max-height: 92vh; overflow-y: auto;
  padding: 18px 18px calc(24px + var(--safe-bottom));
  animation: modalUp .22s ease;
}
@keyframes modalUp { from { transform: translateY(30px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 18px; }
}
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.modal-title { font-size: 18px; font-weight: 700; line-height: 1.3; flex: 1; }
.modal-section { margin-top: 18px; }
.modal-section h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.form-row { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn { flex: 1; }

/* subtasks */
.subtask { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.subtask:last-child { border-bottom: none; }
.subtask input[type=checkbox] { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.subtask-text { flex: 1; font-size: 14px; }
.subtask.done .subtask-text { text-decoration: line-through; color: var(--muted); }
.subtask-time { font-size: 11px; color: var(--muted); }
.add-inline { display: flex; gap: 8px; margin-top: 8px; }
.add-inline input { flex: 1; }

/* comments */
.comment { padding: 10px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: none; }
.comment-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.comment-author { font-size: 13px; font-weight: 600; }
.comment-date { font-size: 11px; color: var(--muted); }
.comment-body { font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }

/* users list */
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-bottom: 1px solid var(--border); }
.user-row .grow { flex: 1; }
.role-badge { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: var(--surface-3); color: var(--muted); }
.role-badge.admin { background: rgba(239,68,68,.15); color: var(--p-urgent); }
.role-badge.manager { background: rgba(245,158,11,.15); color: var(--p-high); }

/* delegate row */
.assignee-line { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* toast */
#toast {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface-3); color: var(--text); padding: 12px 18px; border-radius: 12px;
  border: 1px solid var(--border); z-index: 100; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* install hint */
.install-hint {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-bottom)); z-index: 50;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 10px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.install-hint span { flex: 1; }

.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 8px; }
.code-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; white-space: pre-wrap; }

/* ---------- VIEW TABS ---------- */
.tabs {
  display: flex; gap: 4px; padding: 8px 12px 0; overflow-x: auto; flex: none;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.tab {
  background: none; border: none; color: var(--muted); font-size: 13px; font-weight: 600;
  padding: 8px 12px; border-radius: 8px 8px 0 0; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- LABEL FILTER BAR ---------- */
.label-bar { display: flex; gap: 6px; padding: 10px 12px 2px; overflow-x: auto; flex-wrap: nowrap; flex: none; }
.label-chip {
  border: 1px solid var(--border); background: transparent; border-radius: 20px;
  padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; flex: none;
}
.label-chip.active { color: #fff; }
.label-chip.clear { color: var(--muted); border-color: var(--border); }
.label-chip.add { color: var(--accent); border-style: dashed; }

/* label chips on cards */
.card-labels { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag-chip { font-size: 11px; padding: 2px 8px; border-radius: 12px; font-weight: 600; border: 1px solid transparent; }
.tag-chip-sm { font-size: 10px; padding: 1px 7px; }

/* label editor */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: var(--text); }
.label-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.label-row .grow { flex: 1; }

/* label picker in task editor */
.label-picker { display: flex; flex-wrap: wrap; gap: 6px; }

/* recurrence weekday buttons */
.weekday-row { display: flex; gap: 6px; flex-wrap: wrap; }
.weekday-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 8px 6px; font-size: 12px; font-weight: 600; cursor: pointer; min-width: 42px;
}
.weekday-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- FLAT LIST (delegated / history / search) ---------- */
.board.list-view { display: block; overflow-y: auto; padding: 12px; }
.flat-list { display: flex; flex-direction: column; gap: 8px; max-width: 720px; margin: 0 auto; }
.flat-row {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; cursor: pointer;
}
.flat-row:active { transform: scale(.995); }
.flat-row.is-archived { opacity: .8; }
.flat-main { min-width: 0; flex: 1; }
.flat-title { font-weight: 600; font-size: 14px; word-break: break-word; }
.flat-meta { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.flat-right { display: flex; align-items: center; gap: 8px; flex: none; }
.status-pill { font-size: 11px; padding: 3px 9px; border-radius: 20px; background: rgba(245,158,11,.15); color: var(--p-high); font-weight: 600; }
.status-pill.done { background: rgba(16,185,129,.15); color: var(--p-medium); }
.flat-search-wrap { max-width: 720px; margin: 0 auto 12px; }
.flat-search { width: 100%; }

/* ---------- SEARCH RESULTS ---------- */
.search-results { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- ATTACHMENTS ---------- */
.attach-list { display: flex; flex-direction: column; gap: 6px; }
.attach-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.attach-row:last-child { border-bottom: none; }
.attach-link { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; text-decoration: none; color: var(--text); }
.attach-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.attach-size { flex: none; }
.attach-icon { flex: none; }
