/**
 * Tasks (Checklists — member view) styles (v5-mini-app-6-2)
 * Telegram Mini App — uses CSS variables provided by app.css / Telegram theme.
 *
 * Variables assumed available:
 *   --cl-bg, --cl-card, --cl-text, --cl-text-secondary, --cl-border,
 *   --cl-link, --cl-btn, --cl-btn-text, --cl-error, --cl-success,
 *   --cl-radius, --cl-shadow
 */

/* ── Screen container ─────────────────────────────────────────────────────── */

.tasks-screen {
  padding: 0 16px 80px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  height: 100%;
}

/* ── Pull-to-refresh indicator ────────────────────────────────────────────── */

.pull-refresh-indicator {
  display: flex;
  justify-content: center;
  padding: 12px 0 4px;
}

/* ── Admin actions (v5-mini-app-6-3) ─────────────────────────────────────── */

.tasks-admin-actions {
  padding: 12px 0 4px;
}

.btn-create-checklist {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--cl-btn);
  color: var(--cl-btn-text);
  border: none;
  border-radius: var(--cl-radius, 8px);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.checklist-card__track-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.checklist-card__track-link {
  font-size: 13px;
  color: var(--cl-link);
  font-weight: 500;
}

/* ── Sections ─────────────────────────────────────────────────────────────── */

.tasks-section {
  margin-bottom: 16px;
}

.tasks-section--done {
  margin-top: 24px;
  opacity: 0.75;
}

.tasks-section__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--cl-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 16px 0 8px;
}

.tasks-section__title--done {
  color: var(--cl-success, #10b981);
}

/* ── Checklist list ───────────────────────────────────────────────────────── */

.tasks-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Checklist card ───────────────────────────────────────────────────────── */

.checklist-card {
  background: var(--cl-card);
  border-radius: var(--cl-radius, 12px);
  overflow: hidden;
  box-shadow: var(--cl-shadow, 0 1px 4px rgba(0,0,0,0.08));
  transition: box-shadow 0.15s;
}

.checklist-card--overdue {
  border-left: 3px solid var(--cl-error, #ef4444);
}

.checklist-card--done {
  background: var(--cl-card);
}

.checklist-card__header {
  padding: 12px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.checklist-card__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.checklist-card__title {
  font-size: 15px;
  font-weight: 500;
  color: var(--cl-text);
  flex: 1;
  min-width: 0;
  /* M4 fix: truncate long titles with ellipsis */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: calc(100% - 80px); /* leave room for progress count and chevron */
}

.checklist-card__title--done {
  text-decoration: line-through;
  color: var(--cl-text-secondary);
}

.checklist-card__chevron {
  flex-shrink: 0;
  color: var(--cl-text-secondary);
  transition: transform 0.2s ease;
}

.checklist-card__chevron--open {
  transform: rotate(180deg);
}

.checklist-card__due {
  font-size: 12px;
  color: var(--cl-text-secondary);
  margin-top: 4px;
}

.checklist-card__due--overdue {
  color: var(--cl-error, #ef4444);
  font-weight: 500;
}

.checklist-card__progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.checklist-card__count {
  font-size: 11px;
  color: var(--cl-text-secondary);
  white-space: nowrap;
}

/* ── Progress bar ─────────────────────────────────────────────────────────── */

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--cl-border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar--sm {
  height: 3px;
  flex: none;
  width: 60px;
}

.progress-bar__fill {
  height: 100%;
  border-radius: 2px;
  background: var(--cl-link);
  transition: width 0.3s ease, background 0.3s ease;
}

/* ── Expanded item list ───────────────────────────────────────────────────── */

/*
 * M1 fix: Standardise expand/collapse animation on max-height transition.
 * Alpine x-show on .checklist-items uses display:block/none by default; we
 * override with max-height so the card slides open from 0 → 500px (large enough
 * for any checklist) and collapses back. overflow:hidden is required to clip
 * content during the transition and also prevents items from bleeding outside
 * the card during animation.
 */
.checklist-items {
  border-top: 1px solid var(--cl-border);
  padding: 4px 0 8px;
  /* M1 fix: animate expand/collapse with max-height */
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.checklist-items--expanded {
  max-height: 500px; /* large enough for any checklist content */
}

.checklist-items__empty {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--cl-text-secondary);
  margin: 0;
}

/* ── Checklist item row ───────────────────────────────────────────────────── */

.checklist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.checklist-item:active {
  background: var(--cl-bg);
}

.checklist-item--checked .checklist-item__label {
  text-decoration: line-through;
  color: var(--cl-text-secondary);
}

/* M3 fix: red flash when item PATCH fails */
@keyframes item-error-flash {
  0%   { background: transparent; }
  20%  { background: rgba(var(--cl-negative-rgb, 255, 59, 48), 0.15); }
  80%  { background: rgba(var(--cl-negative-rgb, 255, 59, 48), 0.15); }
  100% { background: transparent; }
}

.checklist-item--error {
  animation: item-error-flash 3s ease-in-out forwards;
}

.checklist-item--error .checklist-item__label {
  color: var(--cl-error, #ef4444);
}

.checklist-item__label {
  font-size: 15px;
  color: var(--cl-text);
  flex: 1;
  transition: color 0.2s, text-decoration 0.2s;
}

/* ── Custom checkbox ──────────────────────────────────────────────────────── */

.checkbox-wrap {
  flex-shrink: 0;
}

.checkbox {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--cl-border);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}

.checkbox--checked {
  background: var(--cl-link);
  border-color: var(--cl-link);
}

/* ── Spring animation (AC4, T5a) ──────────────────────────────────────────── */

@keyframes spring-check {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.3); }
  70%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

.checkbox--spring {
  animation: spring-check 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55) both;
}

/* ── Checkmark SVG (draw-on effect via stroke-dasharray) ──────────────────── */

.checkbox__mark {
  width: 12px;
  height: 10px;
  display: block;
}

.checkbox__draw {
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
  animation: draw-check 0.25s ease-out 0.05s forwards;
}

@keyframes draw-check {
  to { stroke-dashoffset: 0; }
}

/* ── Tab badge ────────────────────────────────────────────────────────────── */

/*
 * .tab-badge is positioned over the Tasks tab icon in index.html.
 * The component writes to $store.app.tasksBadgeCount; index.html binds it.
 * Example markup in index.html:
 *
 *   <div style="position:relative;display:inline-block;">
 *     <svg>…checklist icon…</svg>
 *     <span class="tab-badge"
 *           x-show="$store.app.tasksBadgeCount > 0"
 *           x-text="$store.app.tasksBadgeCount">
 *     </span>
 *   </div>
 */

.tab-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--cl-error, #ef4444);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  padding: 0 4px;
  pointer-events: none;
}

/* ── Skeleton loading ─────────────────────────────────────────────────────── */

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

.skeleton-line,
.skeleton-progress {
  background: linear-gradient(90deg,
    var(--cl-border) 25%,
    var(--cl-card)   50%,
    var(--cl-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}

.checklist-card--skeleton {
  background: var(--cl-card);
  border-radius: var(--cl-radius, 12px);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton-line--title {
  height: 14px;
  width: 65%;
}

.skeleton-progress {
  height: 4px;
  width: 100%;
  border-radius: 2px;
}

.skeleton-line--sm {
  height: 11px;
  width: 40%;
}

/* ── State messages ───────────────────────────────────────────────────────── */

.tasks-error,
.tasks-empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--cl-text-secondary);
}

.tasks-empty__icon { font-size: 40px; margin-bottom: 12px; }
.tasks-empty__text { font-size: 14px; margin: 0; }

.tasks-error p   { font-size: 14px; margin: 0 0 12px; color: var(--cl-error, #ef4444); }

.btn-retry {
  padding: 8px 16px;
  background: var(--cl-btn);
  color: var(--cl-btn-text);
  border: none;
  border-radius: var(--cl-radius, 8px);
  font-size: 14px;
  cursor: pointer;
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--cl-border);
  border-top-color: var(--cl-link);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
