:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e2e6ef;
  --text: #1f2530;
  --muted: #6b7280;
  --accent: #3b62f6;
  --accent-hover: #2c4fd6;
  --danger: #e0483e;
  --sidebar-bg: #171b26;
  --sidebar-text: #c6cbd8;
  --sidebar-active: #2a3040;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { min-height: 100vh; display: flex; }

/* ---- Auth screen ---- */
.auth-wrap {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1f2530 0%, #3b62f6 120%);
}
.auth-card {
  background: var(--panel);
  border-radius: 16px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-card h1 {
  font-size: 22px;
  margin: 0 0 6px;
}
.auth-card p.sub {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #374151;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: var(--accent-hover); }
.btn.full { width: 100%; }
.btn.secondary { background: #eef1fb; color: var(--accent); }
.btn.secondary:hover { background: #dfe4fa; }
.btn.danger { background: var(--danger); }
.error-msg {
  background: #fdecea;
  color: #a3231b;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.switch-mode {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}
.switch-mode a { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 600; }

/* ---- Layout ---- */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.sidebar .brand {
  color: white;
  font-weight: 700;
  font-size: 16px;
  padding: 0 10px 20px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar nav a:hover { background: #232838; color: white; }
.sidebar nav a.active { background: var(--sidebar-active); color: white; font-weight: 600; }
.sidebar nav a .dot {
  width: 6px; height: 6px; border-radius: 50%; background: #4a5164; flex-shrink: 0;
}
.sidebar nav a.active .dot { background: var(--accent); }
.sidebar .user-box {
  border-top: 1px solid #2a3040;
  padding-top: 14px;
  margin-top: 14px;
  font-size: 13px;
}
.sidebar .user-box .uname { color: white; font-weight: 600; margin-bottom: 8px; }
.sidebar .user-box button {
  width: 100%;
  background: transparent;
  border: 1px solid #333b4e;
  color: var(--sidebar-text);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.sidebar .user-box button:hover { background: #232838; color: white; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar h1 { font-size: 18px; margin: 0; }

.board-wrap {
  flex: 1;
  overflow-x: auto;
  padding: 24px 28px;
}
.board {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  min-height: 60vh;
}
.column {
  background: #eceff5;
  border-radius: var(--radius);
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 160px);
}
.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  gap: 8px;
}
.column-header .title-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.column-header .color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.column-header h3 {
  font-size: 14px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.column-header .count {
  background: #dde1ea;
  color: #4b5563;
  font-size: 12px;
  padding: 1px 7px;
  border-radius: 10px;
}
.column-header .col-actions { display: flex; gap: 4px; }
.column-header .col-actions button {
  background: none; border: none; cursor: pointer; color: #8890a0; font-size: 13px; padding: 2px 4px;
  border-radius: 4px;
}
.column-header .col-actions button:hover { background: #dde1ea; color: #1f2530; }

.task-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 40px;
}
.task-card {
  background: white;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  cursor: grab;
  border: 1px solid transparent;
}
.task-card:hover { border-color: var(--accent); }
.task-card.dragging { opacity: 0.4; }
.task-card .task-title { font-size: 13.5px; font-weight: 600; margin-bottom: 4px; word-break: break-word; }
.task-card .task-desc {
  font-size: 12.5px; color: var(--muted); word-break: break-word;
  white-space: pre-wrap;
  max-height: 60px;
  overflow: hidden;
}
.task-list.drag-over { background: #e2e7f5; border-radius: 8px; }

.add-task-btn, .add-col-btn {
  background: none;
  border: none;
  text-align: left;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
  width: 100%;
}
.add-task-btn:hover { color: var(--accent); }
.add-col-column {
  width: 260px;
  flex-shrink: 0;
}
.add-col-column button {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 1.5px dashed #c9cfdc;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.add-col-column button:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,18,26,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--panel);
  border-radius: 14px;
  padding: 24px;
  width: 420px;
  max-width: 90vw;
}
.modal h2 { margin: 0 0 16px; font-size: 17px; }
.modal textarea {
  width: 100%; min-height: 90px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); font-size: 14px; font-family: inherit; resize: vertical;
}
.desc-editable {
  width: 100%;
  min-height: 100px;
  max-height: 320px;
  overflow-y: auto;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}
.desc-editable:focus { border-color: var(--accent); }
.desc-editable:empty::before {
  content: attr(data-placeholder);
  color: #9aa1b0;
}
.desc-editable img, .task-desc img {
  max-width: 100%;
  border-radius: 6px;
  display: block;
  margin: 6px 0;
}
.img-upload-placeholder {
  color: var(--muted);
  font-style: italic;
  font-size: 12.5px;
}
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---- Users table ---- */
.users-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.users-table th, .users-table td {
  text-align: left;
  padding: 10px 14px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}
.users-table th { color: var(--muted); font-weight: 600; background: #f8f9fc; }
.users-table tbody tr:last-child td { border-bottom: none; }
.users-actions { display: flex; gap: 8px; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.color-row { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.color-swatch {
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer; border: 2px solid transparent;
}
.color-swatch.selected { border-color: #1f2530; }

@media (max-width: 720px) {
  .sidebar { width: 72px; padding: 16px 8px; }
  .sidebar .brand { display: none; }
  .sidebar nav a span.label { display: none; }
  .sidebar .user-box .uname { display: none; }
}
