/* ============================================================
   COMPONENTS — app shell, cards, dashboard widgets
   All values come from design-tokens.css variables.
   ============================================================ */

body {
  font-family: var(--font-body);
  background: var(--surface-app);
  color: var(--text-primary);
  margin: 0;
}

/* ── App shell: mobile-first ───────────────────────────────────────────────
   Mobile (<992px): sidebar is a Bootstrap offcanvas (hamburger in topbar);
   positioning/size come from .offcanvas-lg — do NOT override them here.
   Desktop (≥992px): static sticky sidebar docked at the inline start (right
   in RTL). Desktop-only shell styles live inside the media query. */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  background: var(--surface-sidebar);
  --bs-offcanvas-width: 280px;   /* mobile drawer width */
}

@media (min-width: 992px) {
  .app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    border-inline-end: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
  }
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-inline-end: var(--sp-4);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  text-decoration: none;
}
.sidebar-brand .brand-mark {
  width: 32px; height: 32px;
  border-radius: var(--r-lg);
  background: var(--brand-600);
  color: var(--text-inverse);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}

.sidebar-nav { padding: var(--sp-4) var(--sp-3); flex: 1; }
.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-1);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-weight: 500;
  text-decoration: none;
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar-nav .nav-link:hover { background: var(--surface-hover); color: var(--text-brand); }
.sidebar-nav .nav-link.active { background: var(--surface-active); color: var(--text-brand); }

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-topbar {
  height: var(--topbar-height);
  background: var(--surface-header);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
}
.app-topbar .page-title { font-size: 1rem; font-weight: 600; margin: 0; flex: 1; }
.app-topbar .topbar-user { color: var(--text-secondary); font-size: .9rem; }
.app-topbar .sidebar-toggle {
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 1.2rem;
  line-height: 1;
  padding: var(--sp-1) var(--sp-2);
}

/* Mobile-first content padding; roomier on desktop */
.app-content { padding: var(--sp-4); flex: 1; }
@media (min-width: 992px) {
  .app-topbar { padding: 0 var(--sp-6); }
  .app-content { padding: var(--sp-6); }
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.panel-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xs);
}
.panel-card .panel-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-card .panel-body { padding: var(--sp-5); }

/* ── Dashboard stat tiles ──────────────────────────────────────────────── */
.stat-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xs);
  padding: var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  height: 100%;
}
.stat-card .stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}
.stat-card .stat-icon.i-brand   { background: var(--brand-50);   color: var(--brand-600);   }
.stat-card .stat-icon.i-success { background: var(--success-bg); color: var(--success-dot); }
.stat-card .stat-icon.i-warning { background: var(--warning-bg); color: var(--warning-dot); }
.stat-card .stat-icon.i-purple  { background: var(--purple-bg);  color: var(--purple-dot);  }
/* Neutral variant — for a tile the user has no access to (see .stat-card-locked) */
.stat-card .stat-icon.i-muted   { background: var(--surface-app); color: var(--text-disabled); }
.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-card .stat-label { color: var(--text-tertiary); font-size: .85rem; }

/* A stat tile that is itself a link (whole card is the tap target — mobile) */
a.stat-card-link {
  text-decoration: none;
  color: inherit;
  transition: box-shadow .15s ease, border-color .15s ease;
}
a.stat-card-link:hover,
a.stat-card-link:focus-visible {
  box-shadow: var(--shadow-md);
  border-color: var(--border-default);
}

/* A tile the user lacks the capability for: present but visibly inert, so the
   dashboard layout stays stable across users instead of losing a tile. */
.stat-card-locked { background: var(--surface-app); box-shadow: none; }
.stat-card-locked .stat-value { color: var(--text-disabled); }

/* ── Empty states (icon + message, per admin standard) ─────────────────── */
.empty-state {
  text-align: center;
  padding: var(--sp-10) var(--sp-6);
  color: var(--text-tertiary);
}
.empty-state .empty-icon { font-size: 2rem; display: block; margin-bottom: var(--sp-3); color: var(--text-disabled); }
.empty-state .empty-title { font-weight: 600; color: var(--text-secondary); margin-bottom: var(--sp-1); }
.empty-state .empty-hint { font-size: .85rem; }

/* ── Loading spinner row ───────────────────────────────────────────────── */
.loading-row {
  display: flex; align-items: center; justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-8);
  color: var(--text-tertiary);
}

/* ── Notifications (fixed top-center alert, auto-dismiss) ──────────────── */
.notify {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  min-width: min(320px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
}

/* ── Clickable cell values ─────────────────────────────────────────────── */
.cell-link { color: var(--text-brand); text-decoration: none; cursor: pointer; }
.cell-link:hover { text-decoration: underline; }

/* ── Status badges (project status — colors per tools standard) ────────── */
.badge-status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--r-full);
  font-size: .78rem;
  font-weight: 600;
}
.badge-status.s-draft     { background: #e9ecef; color: #495057; }
.badge-status.s-active    { background: #d1f0e0; color: #1a7a47; }
.badge-status.s-pending   { background: #e7e9fd; color: #4338ca; }
.badge-status.s-on_hold   { background: #fff3cd; color: #856404; }
.badge-status.s-completed { background: #cfe2ff; color: #084298; }
.badge-status.s-cancelled { background: #f8d7da; color: #842029; }

/* ── Project cards (mobile-first list) ─────────────────────────────────── */
.project-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xs);
  padding: var(--sp-4) var(--sp-5);
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.project-card .project-title { font-weight: 600; font-size: 1rem; color: var(--text-primary); }
.project-card .project-meta { color: var(--text-tertiary); font-size: .85rem; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.project-card .project-dates { color: var(--text-tertiary); font-size: .8rem; margin-top: auto; }

/* Whole card is the tap target (mobile-first) — plain link wrapper, no
   per-field links inside the card. */
a.project-card-link { display: block; height: 100%; text-decoration: none; }
a.project-card-link .project-card {
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
a.project-card-link:hover .project-card,
a.project-card-link:focus-visible .project-card {
  border-color: var(--brand-600);
  box-shadow: var(--shadow-sm);
}

/* ── Project detail page ───────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-secondary);
  font-size: .9rem;
  text-decoration: none;
  min-height: 44px;             /* touch target */
}
.back-link:hover { color: var(--text-brand); }

.detail-header .detail-title { font-size: 1.2rem; font-weight: 700; }
.detail-header .detail-dates { color: var(--text-tertiary); font-size: .85rem; }
/* Reuse the card meta vocabulary outside .project-card */
.project-meta { color: var(--text-tertiary); font-size: .85rem; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* Label/value list for general + technical sections */
.info-list dt { font-size: .8rem; font-weight: 600; color: var(--text-tertiary); margin-bottom: var(--sp-1); }
.info-list dd {
  margin: 0 0 var(--sp-4);
  color: var(--text-primary);
  white-space: pre-wrap;        /* long API text keeps its line breaks */
  overflow-wrap: break-word;
}
.info-list dd:last-child { margin-bottom: 0; }

/* Team member rows */
.team-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  min-height: 44px;             /* touch target */
}
.team-row + .team-row { border-top: 1px solid var(--border-subtle); }
.team-row .team-icon { font-size: 1.3rem; color: var(--text-disabled); }
.team-row .team-name { font-weight: 500; }
.team-row .team-role { color: var(--text-tertiary); font-size: .85rem; margin-inline-start: auto; }

/* ── Detail tabs (v6) — sticky bar, lazy-loaded panes ──────────────────── */
.detail-tabs {
  position: sticky;
  top: 0;
  z-index: 5;                    /* above panel content, below the offcanvas */
  display: flex;
  overflow-x: auto;              /* 4 tabs fit at 390px, but never overflow the page */
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xs);
}
.detail-tabs .tab-btn {
  flex: 1;
  min-height: 44px;              /* touch target */
  min-width: max-content;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: .9rem;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.detail-tabs .tab-btn.active {
  color: var(--text-brand);
  border-bottom-color: var(--brand-600);
  font-weight: 600;
}

/* Task status badge — project statuses cover pending/completed already */
.badge-status.s-in_progress { background: #e7f1fd; color: #0b5ed7; }

/* Slim progress bar (tasks + plan) */
.progress-slim {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--border-subtle);
  overflow: hidden;
}
.progress-slim .progress-slim-fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--brand-600);
  transition: width var(--t-fast);
}

/* Task rows — <details>: summary is the 44px tap target, body is the editor */
.task-row { border-top: 1px solid var(--border-subtle); }
.task-row:first-child { border-top: none; }
.task-row summary {
  list-style: none;
  cursor: pointer;
  padding: var(--sp-3) 0;
  min-height: 44px;              /* touch target */
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.task-row summary::-webkit-details-marker { display: none; }
.task-row .task-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.task-row .task-title { font-weight: 500; }
.task-row .task-meta { color: var(--text-tertiary); font-size: .8rem; }
.task-row .task-edit { padding: 0 0 var(--sp-4); }
.task-row .task-desc {
  color: var(--text-secondary);
  font-size: .9rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  margin-bottom: var(--sp-3);
}
.task-row .task-controls {
  display: flex;
  flex-direction: column;        /* mobile-first: controls stack */
  gap: var(--sp-3);
}
.task-row .task-controls .btn { min-height: 44px; }
@media (min-width: 992px) {
  .task-row .task-controls {
    flex-direction: row;
    align-items: flex-end;
  }
  .task-row .task-controls > div { flex: 1; }
}

/* Inline task-create form sits between header and list */
.task-create { border-bottom: 1px solid var(--border-subtle); }
.task-create .btn { min-height: 44px; }

/* File rows */
.file-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  min-height: 44px;              /* touch target */
}
.file-row + .file-row { border-top: 1px solid var(--border-subtle); }
.file-row .file-icon { font-size: 1.4rem; color: var(--text-disabled); }
.file-row .file-info { flex: 1; min-width: 0; }
.file-row .file-name {
  font-weight: 500;
  color: var(--text-brand);
  text-decoration: none;
  overflow-wrap: break-word;
  display: block;
  unicode-bidi: plaintext;      /* LTR filenames keep their real char order in RTL */
}
.file-row a.file-name:hover { text-decoration: underline; }
.file-row .file-meta { color: var(--text-tertiary); font-size: .8rem; }
.file-row .file-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;               /* touch target */
  min-height: 44px;
  color: var(--text-secondary);
}

/* Filter chips (files section filter) */
.filter-chips { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.filter-chips .chip {
  min-height: 44px;              /* touch target */
  padding: var(--sp-1) var(--sp-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-full);
  background: var(--surface-card);
  color: var(--text-secondary);
  font-size: .85rem;
}
.filter-chips .chip.active {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
  font-weight: 600;
}

/* Updates feed */
.update-compose { border-bottom: 1px solid var(--border-subtle); }
.update-compose-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;               /* mobile-first: wraps when tight */
}
.update-compose-actions .form-select { flex: 1; min-width: 0; min-height: 44px; }
.update-compose-actions .btn { min-height: 44px; }

.update-row { padding: var(--sp-3) 0; }
.update-row + .update-row { border-top: 1px solid var(--border-subtle); }
.update-row .update-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-1);
}
.update-row .update-author { font-weight: 600; font-size: .9rem; }
.update-row .update-time {
  color: var(--text-tertiary);
  font-size: .8rem;
  margin-inline-start: auto;
}
.update-row .visibility-tag {
  padding: 1px 8px;
  border-radius: var(--r-full);
  font-size: .72rem;
  font-weight: 600;
  background: #fff3cd;           /* internal — amber, matches s-on_hold family */
  color: #856404;
}
.update-row .update-body {
  color: var(--text-primary);
  font-size: .92rem;
  white-space: pre-wrap;         /* multi-line updates keep their line breaks */
  overflow-wrap: break-word;
}

/* Plan tab */
.plan-pct { font-size: 1.6rem; font-weight: 700; margin-bottom: var(--sp-2); }
.plan-caption { color: var(--text-tertiary); font-size: .85rem; margin-top: var(--sp-2); }
.phase-name { font-weight: 600; font-size: 1.05rem; margin-bottom: var(--sp-1); }

/* ══ Workflow tasks (משימות) ═══════════════════════════════════════════════
   The Trac-style Task: created→assigned→solved/cancelled→closed, returned to
   its issuer. Distinct from the plan-task rows above. Mobile-first: cards on
   the inbox, a stacked action sheet on the detail page. */

/* Workflow status badges — reuse the .badge-status shape, own palette.
   Green = the ball is in the issuer's court (done, awaiting their check). */
.badge-status.s-created   { background: #e9ecef; color: #495057; }
.badge-status.s-assigned  { background: #e7f1fd; color: #0b5ed7; }
.badge-status.s-solved    { background: #d1f0e0; color: #1a7a47; }
.badge-status.s-closed    { background: #cfe2ff; color: #084298; }
/* s-cancelled is already defined with the project statuses */

/* Scope tabs on the inbox — horizontally scrollable, never wrap on mobile */
.scope-tabs {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-3);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scope-tabs::-webkit-scrollbar { display: none; }
.scope-tabs .chip {
  flex: 0 0 auto;
  min-height: 44px;              /* touch target */
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-4);
  border-radius: var(--r-full);
  border: 1px solid var(--border-subtle);
  background: var(--surface-card);
  color: var(--text-secondary);
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
}
.scope-tabs .chip.active {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
  font-weight: 600;
}

/* Task cards in the inbox — the whole card is the tap target */
.task-card-link { text-decoration: none; color: inherit; display: block; }
.task-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xs);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.task-card-link:hover .task-card { border-color: var(--brand-600); }
.task-card .tc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
}
.task-card .tc-title {
  font-weight: 600;
  overflow-wrap: break-word;
  min-width: 0;                  /* let long Hebrew titles wrap, not overflow */
}
.task-card .tc-meta {
  color: var(--text-tertiary);
  font-size: .82rem;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-3);
}
/* "Waiting for you" marker — the reason this task is in your inbox */
.task-card .tc-flag {
  font-size: .78rem;
  font-weight: 600;
  color: var(--warning-text);
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--r-full);
  padding: 1px 8px;
  align-self: flex-start;
}

/* Detail page: the workflow panel is the primary affordance on mobile */
.task-detail-head { display: flex; flex-direction: column; gap: var(--sp-3); }
.task-detail-head .td-title {
  font-size: 1.15rem;
  font-weight: 700;
  overflow-wrap: break-word;
}
.task-detail-head .td-badges {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.task-desc-block {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  color: var(--text-secondary);
}

/* Action buttons stack full-width on mobile, sit inline on desktop */
.task-actions { display: flex; flex-direction: column; gap: var(--sp-2); }
.task-actions .btn { min-height: 44px; }
@media (min-width: 992px) {
  .task-actions { flex-direction: row; flex-wrap: wrap; }
  .task-actions .btn { flex: 0 1 auto; }
}
/* Hint under an action that hands the task back to whoever opened it */
.action-hint {
  color: var(--text-tertiary);
  font-size: .82rem;
  margin-top: var(--sp-1);
}

/* History timeline — newest first */
.tl-row {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-top: 1px solid var(--border-subtle);
}
.tl-row:first-child { border-top: none; }
.tl-dot {
  flex: 0 0 auto;
  width: 10px; height: 10px;
  border-radius: var(--r-full);
  background: var(--brand-600);
  margin-top: 6px;
}
.tl-body { min-width: 0; flex: 1; }
.tl-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
  font-size: .85rem;
  margin-bottom: var(--sp-1);
}
.tl-actor { font-weight: 600; }
.tl-time { color: var(--text-tertiary); margin-inline-start: auto; }
.tl-note {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: .9rem;
  color: var(--text-primary);
}
.tl-transition { color: var(--text-tertiary); font-size: .8rem; }
