/* ============================
   TASK VIEW SHELL
============================ */
.tasks-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.tasks-main,
.tasks-topbar-left {
  min-width: 0;
}
.tasks-main { flex: 1; }
.tasks-sidebar {
  width: 210px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
}

/* ============================
   TASKS TOPBAR
============================ */
.tasks-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.tasks-topbar-left { flex-shrink: 0; }
.tasks-topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
  flex-shrink: 0;
}
.tasks-topbar-actions .btn {
  min-width: 0;
}
.tasks-stat-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tasks-stat-chip {
  display: flex; flex-direction: column; align-items: center;
  padding: 7px 14px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap; min-width: 56px;
}
.tasks-stat-chip:hover { border-color: var(--border-h); }
.tasks-stat-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 20px; font-weight: 500; line-height: 1;
  color: var(--text-primary);
}
.tasks-stat-lbl {
  font-size: 9px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-muted); margin-top: 3px;
}
.tasks-stat-chip.s-progress .tasks-stat-val { color: #60a5fa; }
.tasks-stat-chip.s-overdue .tasks-stat-val { color: var(--red); }
.tasks-stat-chip.s-done   .tasks-stat-val { color: var(--brand); }
.tasks-stat-chip.active           { border-color: var(--brand); background: var(--brand-dim); }
.tasks-stat-chip.s-progress.active{ border-color: #60a5fa; background: rgba(96,165,250,0.10); }
.tasks-stat-chip.s-overdue.active { border-color: var(--red); background: var(--red-dim); }
.tasks-stat-chip.s-done.active    { border-color: var(--brand); background: var(--brand-dim); }

/* ============================
   ASAP SECTION
============================ */
#asap-section {
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  overflow: hidden;
}
.asap-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: color-mix(in srgb, #f59e0b 8%, var(--surface-1));
  border-bottom: 1px solid var(--border);
}
.asap-header-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.asap-header-count {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}
.asap-list {
  padding: 4px 0;
}
.asap-task-row { border-left: 3px solid #f59e0b; }
.asap-col-header { background: var(--surface-2); }
.asap-move-btn {
  font-size: 13px;
  line-height: 1;
  color: #f59e0b;
  opacity: 0.82;
}
.asap-move-btn:hover {
  background: color-mix(in srgb, #f59e0b 12%, var(--surface-3));
  color: #fbbf24;
  opacity: 1;
}

/* ===================================================
   TASK CARDS GRID
=================================================== */
.tasks-sort-bar { display:flex; align-items:center; justify-content:space-between; padding:8px 0 10px; gap:8px; flex-wrap:wrap; }
.tasks-sort-pills { display:flex; align-items:center; gap:5px; flex-wrap:wrap; }
.sort-pill { background:var(--surface-1); border:1px solid var(--border); border-radius:20px; padding:3px 10px; font-size:11px; font-weight:600; color:var(--text-muted); cursor:pointer; white-space:nowrap; transition:all 0.13s; font-family:'DM Sans',sans-serif; }
.sort-pill:hover { border-color:var(--border-h); color:var(--text-sec); }
.sort-pill.th-sorted { border-color:var(--brand); color:var(--brand); background:var(--brand-dim); }
.tasks-sort-bar-right { display:flex; align-items:center; gap:8px; }

.tasks-card-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:10px; }
.task-card { background:var(--surface-1); border:1px solid var(--border); border-radius:var(--r-lg); overflow:hidden; transition:border-color 0.13s, box-shadow 0.13s; display:flex; flex-direction:column; }
.task-card:hover { border-color:var(--border-h); box-shadow:0 2px 12px rgba(0,0,0,0.12); }
.task-card.row-done { opacity:0.5; }
.task-card.row-overdue { border-color:rgba(239,68,68,0.3); background:rgba(239,68,68,0.018); }
.task-card.row-selected { border-color:var(--brand) !important; background:var(--brand-glow); }
.task-card:hover .task-drag-handle { opacity:0.5; }
.task-card.task-dragging { opacity:0.35; }
.task-card.task-drag-over { border-top:2px solid var(--brand); }

.task-card-head { display:flex; align-items:center; gap:8px; padding:9px 12px; border-bottom:1px solid var(--border); min-height:42px; }
.task-card-head-left { display:flex; align-items:center; gap:5px; flex-shrink:0; }
.task-card-head-badges { display:flex; align-items:center; gap:5px; flex:1; flex-wrap:wrap; min-width:0; }
.task-card-head-actions { display:flex; align-items:center; gap:3px; flex-shrink:0; opacity:0; transition:opacity 0.13s; }
.task-card:hover .task-card-head-actions { opacity:1; }

.task-card-body { padding:12px 14px 8px; flex:1; text-align:left; background:none; border:none; cursor:pointer; width:100%; display:block; }
.task-card-body:hover .task-card-name { color:var(--brand); }
.task-card-name { font-size:13.5px; font-weight:600; color:var(--text-primary); line-height:1.4; margin-bottom:4px; }
.task-card-name.struck { text-decoration:line-through; color:var(--text-muted); }
.task-card-notes { font-size:11.5px; color:var(--text-muted); overflow:hidden; text-overflow:ellipsis; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; margin-bottom:6px; }
.task-card-progress { height:3px; background:var(--surface-3); border-radius:2px; margin-top:6px; overflow:hidden; }
.task-card-progress-fill { height:100%; background:var(--brand); border-radius:2px; transition:width 0.3s; }

.task-card-footer { display:flex; align-items:center; gap:10px; padding:8px 14px; border-top:1px solid var(--border); flex-wrap:wrap; background:var(--surface-2); }
.task-card-footer-item { display:flex; align-items:center; gap:4px; font-size:11px; color:var(--text-muted); white-space:nowrap; }
.task-card-footer-item.overdue { color:var(--red); font-weight:600; }
.task-card-client { font-size:11px; color:var(--text-sec); font-weight:500; margin-left:auto; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:120px; }

/* ===================================================
   TASK LIST VIEW
=================================================== */
.tasks-list { display:flex; flex-direction:column; width:100%; border:1px solid var(--border); border-radius:var(--r-lg); overflow-x:auto; overflow-y:visible; background:var(--surface-1); }

.task-row {
  display:flex; align-items:center; gap:6px;
  width:100%; box-sizing:border-box;
  padding:0 10px 0 6px; min-height:44px; border-bottom:1px solid var(--border);
  transition:background 0.1s;
}
.task-row:last-child { border-bottom:none; }
.task-row:hover { background:var(--surface-2); }
.task-row.row-done { opacity:0.6; }

.completed-section-divider {
  display:flex; align-items:center; gap:6px;
  width:100%; box-sizing:border-box;
  padding:0 10px 0 6px; min-height:34px; font-size:11px; font-weight:600;
  text-transform:uppercase; letter-spacing:0.06em; color:var(--text-muted);
  border-top:1px solid var(--border); border-bottom:1px solid var(--border);
  background:var(--surface-2); user-select:none;
}
.csd-drag { width:20px; flex-shrink:0; }
.csd-cb { width:38px; flex-shrink:0; display:flex; align-items:center; justify-content:flex-start; }
.csd-label { flex:1; cursor:pointer; padding:0 4px; }
.csd-label:hover { color:var(--text-primary); }
.completed-toggle-chevron { font-size:9px; cursor:pointer; transition:transform 0.15s; }
.completed-toggle-chevron:hover { color:var(--text-primary); }

.task-row.row-overdue { background:rgba(var(--red-rgb,220,38,38),0.04); }
.task-row.row-selected { background:var(--brand-glow) !important; }
.task-row.task-drag-over { border-top:2px solid var(--brand); }
.task-row.task-dragging {
  opacity:1; position:relative; z-index:100;
  transform:scale(1.015) rotate(0.4deg) translateY(-3px);
  box-shadow:0 14px 36px rgba(0,0,0,0.38), 0 4px 12px rgba(0,0,0,0.22);
  background:var(--surface-2) !important;
  border-color:var(--brand) !important;
  transition:none;
}

.task-row-drag { color:var(--text-muted); cursor:grab; flex-shrink:0; padding:4px 2px; opacity:0.4; width:20px; }
.task-row-drag:hover { opacity:1; }
.task-row-checks { display:flex; gap:3px; align-items:center; justify-content:center; flex-shrink:0; width:68px; }
.task-pin-btn {
  width:22px;
  height:22px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border:none;
  border-radius:6px;
  background:none;
  color:var(--text-muted);
  cursor:pointer;
  flex-shrink:0;
  transition:background 0.13s ease, color 0.13s ease, opacity 0.13s ease, transform 0.13s ease;
  opacity:0.82;
}
.task-pin-btn:hover {
  background:var(--surface-3);
  color:var(--text-primary);
  opacity:1;
}
.task-pin-btn.active {
  background:var(--brand-dim);
  color:var(--brand);
  opacity:1;
}
.task-pin-btn.active:hover {
  background:rgba(187,193,59,0.2);
}
.task-pin-btn:active {
  transform:translateY(1px);
}
.task-pin-btn-compact {
  width:20px;
  height:20px;
}

.task-row-name-wrap {
  position:relative;
  flex:1 1 var(--col-name-w,260px);
  min-width:0;
  display:flex;
  align-items:center;
}
.task-row-mobile-main,
.task-row-mobile-body,
.task-row-mobile-footer {
  display: contents;
}
.task-row-mobile-collapse {
  display: none;
}
.task-row-name {
  flex:1 1 auto; min-width:0; text-align:left;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  background:none; border:none; padding:4px 30px 4px 6px; cursor:pointer;
  font-family:'DM Sans',sans-serif; font-size:13.5px; font-weight:500;
  color:var(--text-primary);
  transition:color 0.1s;
}
.task-recurring-indicator {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:18px;
  height:18px;
  border-radius:50%;
  background:rgba(255,255,255,0.03);
  color:var(--text-muted);
  border:1px solid var(--border);
  font-size:11px;
  line-height:1;
  vertical-align:middle;
  flex-shrink:0;
}
.task-recurring-button {
  padding:0;
  appearance:none;
  cursor:pointer;
}
.task-recurring-button:hover {
  background:rgba(139,92,246,0.2);
  color:#c4b5fd;
  border-color:rgba(139,92,246,0.34);
}
.task-recurring-indicator.active {
  background:rgba(139,92,246,0.14);
  color:#a78bfa;
  border-color:rgba(139,92,246,0.28);
}

.task-row-name:hover { color:var(--brand); }
.task-row-name.struck { text-decoration:line-through; color:var(--text-muted); }
.task-row-name-edit {
  position:absolute;
  right:4px;
  top:50%;
  transform:translateY(-50%);
  width:22px;
  height:22px;
  display:flex;
  align-items:center;
  justify-content:center;
  border:none;
  background:none;
  color:var(--text-muted);
  border-radius:6px;
  cursor:pointer;
  opacity:0;
  pointer-events:none;
  transition:opacity 0.14s ease, color 0.14s ease, background 0.14s ease;
}
.task-row-name-wrap:hover .task-row-name-edit,
.task-row-name-wrap:focus-within .task-row-name-edit {
  opacity:1;
  pointer-events:auto;
}
.task-row-name-edit:hover {
  color:var(--brand);
  background:var(--brand-dim);
}

.task-row-status,
.task-row-priority,
.task-row-date,
.task-row-due,
.task-row-assigned,
.task-row-client {
  flex-shrink:0;
  overflow:hidden;
}
.task-row-status,
.task-row-priority,
.task-row-date,
.task-row-due {
  display:flex;
  align-items:center;
  justify-content:center;
}
.task-row-date,
.task-row-due,
.task-row-assigned,
.task-row-client {
  white-space:nowrap;
  text-overflow:ellipsis;
}
.task-row-status,
.task-row-priority {
  gap:4px;
  text-align:center;
  padding:0 4px;
}
.task-row-date,
.task-row-due {
  text-align:center;
  padding:0 4px;
  font-size:11.5px;
  color:var(--text-muted);
}
.task-row-status   { width:var(--col-status-w,132px); }
.task-row-priority { width:var(--col-priority-w,112px); }
.task-row-date { width:var(--col-date-w,104px); }
.task-row-due { width:var(--col-due-w,96px); }
.task-row-due.overdue { color:var(--red); font-weight:600; }
.task-row-assigned { width:var(--col-assigned-w,100px); font-size:11.5px; color:var(--text-muted); padding:0 4px; }
.task-row-client { width:var(--col-client-w,220px); min-width:0; font-size:11.5px; color:var(--text-sec); font-weight:500; text-align:left; display:block; padding:0 8px; }
.task-row-actions { display:flex; justify-content:flex-end; gap:3px; flex-shrink:0; width:88px; padding-right:2px; }

.task-col-header {
  display:flex; align-items:center; gap:6px;
  width:100%; box-sizing:border-box;
  padding:0 10px 0 6px; min-height:36px;
  background:var(--surface-2); border-bottom:2px solid var(--border);
  font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:0.5px;
  color:var(--text-muted); position:sticky; top:0; z-index:5; user-select:none;
}
.task-col-h-drag    { width:20px; flex-shrink:0; }
.task-col-h-checks  { width:68px; flex-shrink:0; display:grid; grid-template-columns:repeat(3, 15px); justify-content:center; align-items:center; column-gap:3px; }
.task-col-check-indicator {
  font-size:12px;
  line-height:1;
  color:var(--text-muted);
  font-weight:800;
  text-align:center;
}
.task-col-pin-indicator {
  font-size:11px;
  line-height:1;
  opacity:0.7;
  text-align:center;
}
.asap-col-header .task-col-h-checks { display:flex; justify-content:center; align-items:center; }

.task-col-h-cell {
  position:relative; flex-shrink:0; display:flex; align-items:center; gap:0;
  padding:0 14px 0 6px; overflow:hidden; cursor:pointer; white-space:nowrap;
  transition:color 0.12s;
}
.task-col-h-cell:hover  { color:var(--text-primary); }
.task-col-h-cell.th-sorted { color:var(--brand); }
.task-col-h-name   { position:relative; flex:1 1 var(--col-name-w,260px); min-width:0; padding:0 14px 0 6px; cursor:pointer; transition:color 0.12s; display:flex; align-items:center; gap:0; overflow:hidden; white-space:nowrap; }
.task-col-h-name:hover { color:var(--text-primary); }
.task-col-h-name.th-sorted { color:var(--brand); }
.task-col-h-cell[data-col="status"],
.task-col-h-cell[data-col="priority"],
.task-col-h-cell[data-col="date"],
.task-col-h-cell[data-col="due"] {
  justify-content:center;
}
.task-col-h-cell[data-col="status"]   { width:var(--col-status-w,132px); justify-content:center; }
.task-col-h-cell[data-col="priority"] { width:var(--col-priority-w,112px); }
.task-col-h-cell[data-col="date"]     { width:var(--col-date-w,104px); }
.task-col-h-cell[data-col="due"]      { width:var(--col-due-w,96px); }
.task-col-h-cell[data-col="client"]   { width:var(--col-client-w,220px); justify-content:flex-start; text-align:left; }
.task-col-h-actions { width:64px; flex-shrink:0; }
.col-sort-wrap { display:inline-flex; align-items:center; margin-left:4px; flex-shrink:0; }
.col-sort-arr { font-size:9px; opacity:0.4; flex-shrink:0; text-align:left; }
.col-sort-arr.active { opacity:1; }
.col-h-lbl { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:0; }
.col-resize-h {
  position:absolute; right:0; top:4px; bottom:4px; width:6px;
  cursor:col-resize; border-radius:3px;
  border-right:2px solid var(--border);
  transition:border-color 0.15s, background 0.15s;
}
.col-resize-h:hover, .col-resize-h.col-resize-active {
  border-color:var(--brand);
  background:rgba(187,193,59,0.15);
}

.qedit-empty { color:var(--text-muted); opacity:0.35; font-size:10.5px; font-style:italic; pointer-events:none; }
.task-row-due:hover .qedit-empty, .task-row-assigned:hover .qedit-empty { opacity:0.7; }

/* ============================
   RESPONSIVE TASKS
============================ */
@media (max-width: 768px) {
  .tasks-layout { flex-direction: column; }
  .tasks-sidebar { width: 100%; }
  thead th:nth-child(1),
  thead th:nth-child(5),
  thead th:nth-child(8),
  thead th:nth-child(9),
  tbody td:nth-child(1),
  tbody td:nth-child(5),
  tbody td:nth-child(8),
  tbody td:nth-child(9) { display:none; }
  .row-actions { opacity: 1; }
  .filter-bar { gap: 6px; }
  .filter-tabs { flex-wrap: wrap; }
  .task-detail-title { font-size: 26px; }
}

@media (max-width: 680px) {
  .tasks-card-grid { grid-template-columns:1fr; }
  .tasks-list { overflow-x:hidden; }
  .task-col-header,
  .task-row,
  .completed-section-divider {
    gap:4px;
    padding-right:8px;
  }
  .task-row-drag,
  .task-col-h-drag,
  .csd-drag {
    display:none;
  }
  .task-row-checks,
  .task-col-h-checks,
  .csd-cb {
    width:52px;
  }
  .task-col-h-cell[data-col="priority"],
  .task-row-priority,
  .task-col-h-cell[data-col="due"],
  .task-row-due {
    display:none;
  }
  .task-row-name-wrap,
  .task-row-name,
  .task-col-h-name {
    flex:1 1 auto;
    min-width:0;
  }
  .task-row-actions,
  .task-col-h-actions {
    width:72px;
  }
  .task-row-name-edit {
    opacity:1;
    pointer-events:auto;
  }
}

@media (max-width: 900px) {
  .task-col-h-cell[data-col="client"],
  .task-row-client,
  .task-col-h-cell[data-col="date"],
  .task-row-date {
    display:none;
  }
}

@media (max-width: 700px) {
  .tasks-topbar-left,
  .tasks-topbar-actions {
    width: 100%;
    margin-left: 0;
  }
  .tasks-topbar-actions {
    flex-wrap: wrap;
  }
  .tasks-topbar-actions .btn {
    flex: 1 1 calc(50% - 4px);
    justify-content: center;
  }
  .tasks-list {
    overflow: visible;
    border: none;
    background: transparent;
  }
  .task-col-header,
  .completed-section-divider {
    display: none;
  }
  .task-row {
    display: block;
    padding: 10px 12px;
    margin-bottom: 8px;
    min-height: 0;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface-1);
  }
  .task-row:last-child {
    border-bottom: 1px solid var(--border);
  }
  .task-row-drag {
    display: none;
  }
  .task-row-mobile-main,
  .task-row-mobile-footer {
    display: flex;
    align-items: flex-start;
    gap: 10px;
  }
  .task-row-mobile-main {
    width: 100%;
  }
  .task-row-mobile-body {
    display: none;
    margin-top: 10px;
  }
  .task-row-mobile-body.mobile-expanded {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .task-row-checks {
    width: auto;
    justify-content: flex-start;
    align-self: flex-start;
  }
  .task-row-name-wrap {
    flex: 1 1 auto;
    align-items: flex-start;
  }
  .task-row-name {
    white-space: normal;
    line-height: 1.35;
    padding: 2px 0;
  }
  .task-row-name-edit {
    opacity: 1;
    pointer-events: auto;
    position: static;
    transform: none;
    margin-left: 8px;
    flex-shrink: 0;
  }
  .task-row-mobile-footer {
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }
  .task-row-mobile-collapse {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
  }
  .task-row-mobile-collapse:hover {
    color: var(--text-primary);
    border-color: var(--border-h);
  }
  .task-row-actions {
    width: auto;
    padding-right: 0;
    justify-content: flex-end;
    margin-left: auto;
  }
  .task-row-status,
  .task-row-priority,
  .task-row-date,
  .task-row-due,
  .task-row-client {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: auto;
    min-height: 30px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    white-space: normal;
    line-height: 1.25;
  }
  .task-row-status::before,
  .task-row-priority::before,
  .task-row-date::before,
  .task-row-due::before,
  .task-row-client::before {
    margin-right: 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
  }
  .task-row-status::before { content: "Status"; }
  .task-row-priority::before { content: "Priority"; }
  .task-row-date::before { content: "Added"; }
  .task-row-due::before { content: "Due"; }
  .task-row-client::before { content: "Client"; }
  .task-row-status {
    justify-content: flex-start;
  }
  .task-row-priority,
  .task-row-date,
  .task-row-due,
  .task-row-client {
    display: flex;
  }
  .task-row-status .badge,
  .task-row-priority .badge {
    max-width: 100%;
  }
  .task-row-actions .act-edit {
    display: none;
  }
}

@media (max-width: 520px) {
  .tasks-topbar-actions .btn {
    flex-basis: 100%;
  }
}
