:root {
  --bg: #0b0d12;
  --surface: #14161d;
  --surface-2: #1a1d26;
  --surface-3: #21252f;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e7e9ee;
  --text-muted: #9aa4b2;
  --text-faint: #6b7280;
  --accent: #5b8cff;
  --accent-strong: #7ca2ff;
  --accent-contrast: #f5f8ff;
  --danger: #f2685f;
  --radius-lg: 12px;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);

  --urgency-high: #f2685f;
  --urgency-medium: #f0b429;
  --urgency-low: #3ecf8e;
  --urgency-none: #7a8394;

  --status-todo: #7a8394;
  --status-in_progress: #5b8cff;
  --status-done: #3ecf8e;
  --status-blocked: #f2685f;

  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 20px; border: 2px solid var(--bg); }

a { color: var(--accent); }

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
}

input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.7rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-right: auto;
}
.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), #9b6bff);
  box-shadow: 0 0 12px rgba(91, 140, 255, 0.6);
}

.user-picker select {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
}
.user-picker label { display: flex; align-items: center; gap: 0.4rem; color: var(--text-muted); font-size: 0.85rem; }

.telegram-link { display: flex; align-items: center; }
.telegram-link .link-btn {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
}
.telegram-link .link-btn:hover { color: var(--text); }
.telegram-status {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.telegram-status.connected { color: var(--urgency-low); font-weight: 600; }
.telegram-status code {
  background: var(--surface-3);
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
}

.settings-link {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.settings-link:hover { color: var(--text); background: var(--surface-2); }

/* Notifications */

.notif-dropdown { position: relative; }
.notif-summary {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  list-style: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.35rem 0.45rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.notif-summary::-webkit-details-marker { display: none; }
.notif-summary:hover { color: var(--text); background: var(--surface-2); }
.notif-dropdown[open] .notif-summary { color: var(--text); background: var(--surface-2); }

.notif-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 0.3rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.notif-badge:empty { display: none; }

.notif-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 300px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
  padding: 0.4rem;
}
.notif-items { list-style: none; margin: 0; padding: 0; }
.notif-items li {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.55rem;
  border-radius: var(--radius-sm);
  border-bottom: 1px solid var(--border);
}
.notif-items li:last-child { border-bottom: none; }
.notif-items li.unread { background: rgba(91, 140, 255, 0.08); }
.notif-msg { font-size: 0.82rem; color: var(--text); line-height: 1.4; }
.notif-time { font-size: 0.7rem; color: var(--text-faint); }
.notif-empty { font-size: 0.82rem; color: var(--text-faint); padding: 0.6rem; margin: 0; }

/* Layout */

.layout {
  display: flex;
  height: calc(100vh - 53px);
}

.board-pane {
  flex: 0 0 75%;
  padding: 1.25rem;
  overflow-y: auto;
}
.chat-pane {
  flex: 0 0 25%;
  min-width: 280px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

/* New task form */

.new-task-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
}
.new-task-form input[type="text"] { flex: 1; min-width: 200px; }
.new-task-form input,
.new-task-form select {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
}
.new-task-form button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45rem 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.new-task-form button:hover { background: var(--accent-strong); }
.remind-field {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.remind-field input[type="number"] { width: 3.2rem; padding: 0.45rem 0.4rem; }

/* Filters */

.filters {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.8rem;
}
.filters label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
}
.filters input, .filters select {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.45rem;
  color-scheme: dark;
}
.filters button {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s, border-color 0.15s;
}
.filters button:hover { color: var(--text); border-color: var(--text-muted); }

/* Board */

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
  align-items: start;
}
.column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.6rem;
  min-height: 220px;
}
.column h2 {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0.3rem 0.3rem 0.7rem;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-todo);
  flex-shrink: 0;
}
.status-todo .status-dot { background: var(--status-todo); }
.status-in_progress .status-dot { background: var(--status-in_progress); }
.status-done .status-dot { background: var(--status-done); }
.status-blocked .status-dot { background: var(--status-blocked); }

.count {
  margin-left: auto;
  background: var(--surface-3);
  color: var(--text-faint);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  letter-spacing: normal;
  text-transform: none;
}

.column-tasks { min-height: 160px; }
.empty { color: var(--text-faint); font-size: 0.82rem; margin: 0.6rem 0.3rem; }

/* Task cards */

.task-card {
  position: relative;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0.7rem 0.75rem 0.7rem 1.9rem;
  margin-bottom: 0.55rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--urgency-none);
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s, background 0.15s;
}
.task-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.task-card.urgency-high { border-left-color: var(--urgency-high); }
.task-card.urgency-medium { border-left-color: var(--urgency-medium); }
.task-card.urgency-low { border-left-color: var(--urgency-low); }
.task-card.urgency-none { border-left-color: var(--urgency-none); }
.task-card.selected { background: rgba(91, 140, 255, 0.1); border-color: var(--accent); }

.task-select-wrap {
  position: absolute;
  top: 0.7rem;
  left: 0.65rem;
  cursor: pointer;
}
.task-select { cursor: pointer; }

.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.75rem 0.75rem 0;
  padding: 0.45rem 0.7rem;
  background: rgba(91, 140, 255, 0.12);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}
.selection-bar button {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
}

.sortable-ghost { opacity: 0.35; }
.sortable-chosen { box-shadow: var(--shadow); }
.sortable-drag { cursor: grabbing; }

.task-title { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.task-desc { font-size: 0.8rem; color: var(--text-muted); margin: 0.3rem 0; line-height: 1.4; }

.task-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0.3rem;
  flex-wrap: wrap;
}
.task-meta .owner { display: flex; align-items: center; gap: 0.3rem; }
.task-meta .owner.unassigned { color: var(--text-faint); }
.avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}
.task-meta .due { background: var(--surface-3); padding: 0.1rem 0.45rem; border-radius: 999px; }

.urgency-badge {
  text-transform: capitalize;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
}
.urgency-badge.urgency-high { background: rgba(242, 104, 95, 0.16); color: var(--urgency-high); }
.urgency-badge.urgency-medium { background: rgba(240, 180, 41, 0.16); color: var(--urgency-medium); }
.urgency-badge.urgency-low { background: rgba(62, 207, 142, 0.16); color: var(--urgency-low); }
.urgency-badge.urgency-none { background: rgba(122, 131, 148, 0.16); color: var(--urgency-none); }
.remind-badge {
  background: rgba(91, 140, 255, 0.14);
  color: var(--accent);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
}
.remind-badge.sent { background: rgba(122, 131, 148, 0.16); color: var(--text-muted); }

.blocked-by {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--status-blocked);
}

.subtasks {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  padding-top: 0.4rem;
}
.subtasks li { display: flex; align-items: center; gap: 0.4rem; padding: 0.15rem 0; color: var(--text); }
.subtasks li.done { text-decoration: line-through; color: var(--text-faint); }
.subtask-title { flex: 1; }
.subtask-owner-form { margin-left: auto; }
.subtask-owner-form select {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0.1rem 0;
  max-width: 5.5rem;
}
.subtask-owner-form select:hover { color: var(--text); }
.subtask-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0;
  color: var(--text-muted);
  line-height: 1;
}

.add-subtask-form { margin: 0.35rem 0 0; }
.add-subtask-form input {
  width: 100%;
  padding: 0.3rem 0.1rem;
  background: none;
  border: none;
  border-bottom: 1px dashed var(--border-strong);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.add-subtask-form input:focus {
  outline: none;
  border-bottom-color: var(--accent);
  color: var(--text);
}

.task-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  gap: 0.5rem;
}
.task-actions select {
  font-size: 0.72rem;
  padding: 0.25rem 0.4rem;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color-scheme: dark;
}

.icon-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0.3rem;
  display: inline-flex;
  color: var(--text-faint);
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--danger); background: rgba(242, 104, 95, 0.12); }
.icon-btn.archive-btn:hover { color: var(--accent); background: rgba(91, 140, 255, 0.12); }

/* Chat */

.chat-panel { display: flex; flex-direction: column; height: 100%; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.msg {
  max-width: 88%;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-size: 0.87rem;
  line-height: 1.4;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-contrast);
  border-bottom-right-radius: 3px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.chat-task-list {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0.5rem 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-task-list li { padding: 0; }
.ctl-top { display: flex; align-items: center; gap: 0.4rem; }
.ctl-title { font-weight: 600; font-size: 0.85rem; }
.ctl-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0 1.1rem;
}
.ctl-meta span:not(.urgency-badge) {
  background: var(--surface-3);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}

.overview-btn {
  margin: 0.75rem 0.75rem 0;
  padding: 0.5rem 0.7rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.overview-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}
.chat-form input {
  flex: 1;
  padding: 0.55rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
.chat-form button {
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-form button:hover { background: var(--accent-strong); }

/* Settings */

.settings-page { padding: 1.75rem; max-width: 480px; }
.settings-page h2 { margin-top: 0; }
.settings-page h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 1.75rem 0 0.4rem;
}
.settings-page h3:first-of-type { margin-top: 1rem; }
.settings-page form { display: flex; gap: 0.5rem; margin: 0.9rem 0; }
.settings-page input {
  flex: 1;
  padding: 0.55rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
.settings-page button {
  padding: 0.55rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
}
.settings-page button[type="submit"] {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
  font-weight: 600;
}
.hint { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; }
.flash {
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin: 0 0 0.9rem;
}
.flash-success { background: rgba(62, 207, 142, 0.12); color: var(--urgency-low); }
.flash-error { background: rgba(242, 104, 95, 0.14); color: var(--urgency-high); }
.delete-btn { color: var(--danger); border-color: rgba(242, 104, 95, 0.3); }

.team-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.team-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.team-list li:last-child { border-bottom: none; }
.settings-page .team-list form { margin: 0; }
.settings-page .icon-btn {
  background: none;
  border: 1px solid transparent;
  padding: 0.3rem;
}

/* Archive */

.archive-page { padding: 1.75rem; max-width: 900px; }
.archive-page h2 { margin-top: 0; }
.archive-page .hint { margin-bottom: 1.25rem; }

.archive-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.archive-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border-strong);
}
.archive-table td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.archive-table .empty { color: var(--text-faint); text-align: center; padding: 1.5rem; }
.archive-row-actions { display: flex; gap: 0.4rem; white-space: nowrap; }
.archive-row-actions form { margin: 0; }
.archive-row-actions button {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
}
.archive-row-actions button.delete-btn { background: none; }
.add-teammate-form { margin-top: 0.6rem !important; }

/* Auth (setup / login / admin login) */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}
.auth-card .brand { margin-bottom: 1.25rem; font-size: 1.1rem; }
.auth-card h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.auth-form { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1rem; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.auth-form input {
  padding: 0.6rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}
.auth-form button {
  margin-top: 0.3rem;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.auth-form button:hover { background: var(--accent-strong); }

.logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
}
