/* ── Tokens ─────────────────────────────────────────────── */
:root {
  --font: 'Cairo', 'Tahoma', sans-serif;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --topbar-h: 64px;
  --nav-h: 48px;

  /* Workstream colours */
  --ws-d1: #0D7377; --ws-d2: #1A7A4A; --ws-d3: #C96A10;
  --ws-d4: #6B3FA0; --ws-d5: #0A1931; --ws-d6: #B03030;
  --ws-d7: #C9A84C; --ws-d8: #2A6496; --ws-d9: #5C7A8A; --ws-d10: #7B4EA0;

  /* Status colours */
  --status-upcoming-bg: #E2E8F0;    --status-upcoming-fg: #4A5568;
  --status-inprogress-bg: #FEF9C3;  --status-inprogress-fg: #92400E;
  --status-completed-bg: #DCFCE7;   --status-completed-fg: #166534;
  --status-blocker-bg: #FEE2E2;     --status-blocker-fg: #991B1B;
  --status-critical-bg: #FEF3C7;    --status-critical-fg: #92400E;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  font-size: 14px;
  line-height: 1.5;
}
button { cursor: pointer; font-family: var(--font); }

/* ── Top bar ─────────────────────────────────────────────── */
#topbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--topbar-h);
  background: #4C1D95; color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.topbar-brand { display: flex; align-items: center; gap: 14px; }
.topbar-logos {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.topbar-logos-divider { width: 1px; height: 38px; background: rgba(255,255,255,.3); }
.topbar-logo-brand   { height: 44px; width: auto; display: block; object-fit: contain; }
.topbar-divider { width: 1px; height: 36px; background: rgba(255,255,255,.25); flex-shrink: 0; }
.brand-title { font-size: 16px; font-weight: 700; color: #fff; }
.brand-subtitle { font-size: 11px; color: #C4B5FD; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }

.countdown-badge {
  background: #5B21B6; color: #fff;
  padding: 4px 12px; border-radius: 20px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.countdown-badge.urgent { background: #c53030; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  padding: 6px 14px; border-radius: var(--radius);
  border: 1.5px solid transparent; font-size: 13px; font-weight: 600;
  transition: opacity .15s; white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: #C9A84C; color: #3B0764; }
.btn-ghost    { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary{ background: var(--border); color: var(--text); }
#topbar .btn-ghost { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.btn-danger   { background: #FEE2E2; color: #991B1B; }
.btn-success  { background: #DCFCE7; color: #166534; }

.admin-indicator { color: #C9A84C; font-size: 13px; font-weight: 700; }
.hidden { display: none !important; }

/* ── Nav tabs ────────────────────────────────────────────── */
#main-nav {
  display: flex; background: #3B0764;
  padding: 0 24px; height: var(--nav-h);
}
.tab-btn {
  background: none; border: none; color: #C4B5FD;
  padding: 0 20px; height: var(--nav-h); font-size: 14px;
  border-bottom: 3px solid transparent; transition: all .15s;
}
.tab-btn:hover { color: #fff; }
.tab-btn.active { color: #C9A84C; border-bottom-color: #C9A84C; font-weight: 700; }

/* ── Filter bar ──────────────────────────────────────────── */
.filter-bar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 24px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.filter-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.filter-chip {
  padding: 3px 10px; border-radius: 20px;
  border: 1.5px solid var(--border);
  background: #fff; font-size: 11px; cursor: pointer;
  transition: all .15s; font-family: var(--font);
  white-space: nowrap;
}
.filter-chip:hover { border-color: #a0aec0; }
.filter-chip.active { font-weight: 700; }
.filter-search {
  padding: 5px 10px; border-radius: var(--radius);
  border: 1.5px solid var(--border); font-size: 13px;
  font-family: var(--font); direction: rtl; min-width: 180px;
}
.filter-search:focus { outline: none; border-color: #7C3AED; }

/* ── Views ───────────────────────────────────────────────── */
#app-main { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  margin-bottom: 16px;
}
.card-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 16px; }

/* ── KPI Strip ───────────────────────────────────────────── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 12px; text-align: center;
  border-top: 4px solid var(--border);
}
.kpi-value { font-size: 32px; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi-total    { border-top-color: #7C3AED; }
.kpi-done     { border-top-color: #166534; }
.kpi-inprog   { border-top-color: #92400E; }
.kpi-blocker  { border-top-color: #991B1B; }
.kpi-critical { border-top-color: #C96A10; }

/* ── Stream health grid ──────────────────────────────────── */
.stream-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.stream-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
  border-right: 4px solid #ccc;
}
.stream-card-name { font-size: 12px; font-weight: 700; margin-bottom: 3px; }
.stream-card-lead { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.progress-bar-track {
  background: var(--border); border-radius: 4px; height: 6px; overflow: hidden;
}
.progress-bar-fill { height: 6px; border-radius: 4px; transition: width .4s; }
.stream-card-stats {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-muted); margin-top: 5px;
}

/* ── Status pills ────────────────────────────────────────── */
.status-pill {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.status-upcoming   { background: var(--status-upcoming-bg);   color: var(--status-upcoming-fg); }
.status-inprogress { background: var(--status-inprogress-bg); color: var(--status-inprogress-fg); }
.status-completed  { background: var(--status-completed-bg);  color: var(--status-completed-fg); }
.status-blocker    { background: var(--status-blocker-bg);    color: var(--status-blocker-fg); }
.status-critical   { background: var(--status-critical-bg);   color: var(--status-critical-fg); }

/* ── Owner chip ──────────────────────────────────────────── */
.owner-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #EDE9FE; color: #6D28D9;
  padding: 2px 8px; border-radius: 12px; font-size: 11px;
  cursor: pointer; border: none;
}
.owner-chip:hover { background: #DDD6FE; }

/* ── Dep chip ────────────────────────────────────────────── */
.dep-chip {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: #EDF2F7; color: #4A5568; font-size: 10px;
  cursor: pointer; border: 1px solid var(--border);
}
.dep-chip:hover { background: #E2E8F0; }
.dep-chip.highlighted { background: #FEF9C3; border-color: #D69E2E; }

/* ── Milestone table ─────────────────────────────────────── */
.milestone-table { width: 100%; border-collapse: collapse; }
.milestone-table th {
  background: #F7FAFC; padding: 10px 12px; text-align: right;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid var(--border); cursor: pointer; white-space: nowrap;
  user-select: none;
}
.milestone-table th:hover { color: var(--text); }
.milestone-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.milestone-table tr:hover td { background: #F7FAFC; }
.row-critical td:first-child { border-right: 3px solid #E53E3E; }
.stream-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 700; color: #fff; white-space: nowrap;
}
.milestone-name-btn {
  background: none; border: none; font-family: var(--font);
  font-size: 14px; font-weight: 600; color: var(--text);
  cursor: pointer; text-align: right; padding: 0;
}
.milestone-name-btn:hover { color: #7C3AED; text-decoration: underline; }
/* ── Task hierarchy ──────────────────────────────────────── */
.row-parent td { background: inherit; }
.row-parent:not(:first-child) td { border-top: 2px solid var(--border); }

.row-subtask td {
  background: #F5F3FF !important;
  padding-top: 5px; padding-bottom: 5px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px dashed #DDD6FE;
}
.row-subtask td:first-child {
  border-inline-start: 3px solid #7C3AED;
}
.row-subtask .name-cell {
  padding-inline-start: 32px;
}
.row-subtask .milestone-name-btn {
  color: #5B21B6;
  font-size: 12px;
}
.row-subtask .stream-badge {
  font-size: 10px;
  padding: 1px 5px;
  opacity: 0.8;
}
.row-subtask:hover td { background: #EDE9FE !important; }

.subtask-toggle {
  background: none; border: none; font-size: 11px;
  color: var(--text-muted); cursor: pointer; padding: 0 4px 0 0;
  vertical-align: middle; font-family: var(--font);
}
.subtask-toggle:hover { color: var(--text); }

.cp-badge {
  display: inline-block; background: #FEE2E2; color: #991B1B;
  font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px;
  margin-inline-start: 4px; vertical-align: middle;
}

/* ── Gantt ───────────────────────────────────────────────── */
/* Toolbar */
.gantt-toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 0 12px; font-size: 12px; direction: rtl;
}
.gantt-tb-group { display: flex; align-items: center; gap: 4px; }
.gantt-tb-sep   { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.gantt-tb-legend { display: flex; align-items: center; gap: 12px; margin-inline-start: auto; color: var(--text-muted); font-size: 11px; }
.gantt-tb-legend span { display: flex; align-items: center; gap: 4px; }
.gantt-swatch { display: inline-block; width: 10px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.gantt-ctrl { font-size: 12px; padding: 3px 10px; }

/* Layout wrapper: label col on RIGHT, timeline on LEFT */
.gantt-wrapper {
  display: flex;
  direction: ltr;                /* override RTL body so row-reverse works as expected */
  flex-direction: row-reverse;   /* first child → right, second → left */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
  overflow: hidden;
  max-height: 75vh;
}

/* RIGHT: task label column */
.gantt-label-col {
  width: 260px; min-width: 260px;
  flex-shrink: 0;
  display: flex; flex-direction: column;
  border-inline-start: 1px solid var(--border);   /* divider on left edge of column */
  background: #f7fafc;
  z-index: 2;
}
.gantt-lh {
  height: 44px; min-height: 44px;
  display: flex; align-items: center; padding: 0 12px;
  background: #f7fafc;
  border-bottom: 2px solid var(--border);
  font-size: 12px; font-weight: 700; color: #4A5568;
  flex-shrink: 0;
}
.gantt-label-body {
  overflow: hidden;   /* vertical scroll synced with timeline */
  flex: 1;
}
.gantt-lr {
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px 0 6px;
  cursor: pointer;
  transition: background .1s;
  box-sizing: border-box;
  overflow: hidden;
}
.gantt-lr:hover { background: #EDF2F7 !important; }
.gantt-lr-name {
  flex: 1; min-width: 0;
  word-break: break-word;
  white-space: normal;
  line-height: 1.3;
}
.gantt-lr-indent { color: #A0AEC0; font-size: 11px; flex-shrink: 0; }

/* LEFT: scrollable timeline */
.gantt-timeline {
  flex: 1; min-width: 0;
  overflow: auto;
}
.gantt-timeline svg { display: block; }

/* Legacy container kept for any old references */
.gantt-container { overflow-x: auto; }

/* ── Risk register ───────────────────────────────────────── */
.risk-table { width: 100%; border-collapse: collapse; }
.risk-table th {
  background: #F7FAFC; padding: 10px 12px; text-align: right;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}
.risk-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.risk-row-open td:first-child { border-right: 3px solid #E53E3E; }
.sev-high   { color: #991B1B; font-weight: 700; }
.sev-medium { color: #92400E; font-weight: 600; }
.sev-low    { color: var(--text-muted); }

/* ── Comments ────────────────────────────────────────────── */
.comment-thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.comment-item {
  background: #F7FAFC; border-radius: var(--radius);
  padding: 10px 12px; border: 1px solid var(--border);
}
.comment-meta {
  font-size: 11px; color: var(--text-muted); margin-bottom: 4px;
  display: flex; justify-content: space-between;
}
.comment-text { font-size: 13px; }
.comment-form { display: flex; flex-direction: column; gap: 6px; }
.comment-form .form-control { margin: 0; }

/* ── Audit log ───────────────────────────────────────────── */
.audit-table { width: 100%; border-collapse: collapse; }
.audit-table th {
  background: #F7FAFC; padding: 8px 12px; text-align: right;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}
.audit-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px;
}
.audit-old { color: #991B1B; text-decoration: line-through; }
.audit-new { color: #166534; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 200;
}
.modal {
  position: fixed; z-index: 210;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.25); padding: 24px;
  min-width: 340px; max-width: 94vw; max-height: 88vh; overflow-y: auto;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  direction: rtl;
}
.modal-wide { min-width: min(700px, 94vw); }
.modal-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-title { font-size: 16px; font-weight: 700; line-height: 1.3; flex: 1; }
.modal-close {
  background: none; border: none; font-size: 22px;
  color: var(--text-muted); cursor: pointer; line-height: 1;
  flex-shrink: 0; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-footer {
  margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end;
  padding-top: 12px; border-top: 1px solid var(--border); flex-wrap: wrap;
}

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 4px;
}
.form-control {
  width: 100%; padding: 8px 10px; border-radius: var(--radius);
  border: 1.5px solid var(--border); font-family: var(--font);
  font-size: 13px; direction: rtl; background: #fff; color: var(--text);
}
.form-control:focus { outline: none; border-color: #7C3AED; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Open risks panel ────────────────────────────────────── */
.risks-panel .risk-item {
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid #FEB2B2; background: #FFF5F5; margin-bottom: 8px;
}
.risk-item-title { font-size: 13px; font-weight: 700; color: #991B1B; }
.risk-item-meta  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Overview grid ───────────────────────────────────────── */
.overview-bottom {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px; align-items: start;
}
@media (max-width: 900px) {
  .overview-bottom { grid-template-columns: 1fr; }
}

/* ── Section heading ─────────────────────────────────────── */
.section-heading {
  font-size: 14px; font-weight: 700; margin-bottom: 10px;
  color: var(--text);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  #app-main { padding: 12px; }
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  .stream-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .milestone-table th:nth-child(n+6),
  .milestone-table td:nth-child(n+6) { display: none; }
}
@media (max-width: 480px) {
  .topbar-actions .btn-ghost { display: none; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .stream-grid { grid-template-columns: 1fr; }
}

/* ── Print ───────────────────────────────────────────────── */
@media print {
  #topbar, #main-nav, .filter-bar,
  .modal-overlay, .modal { display: none !important; }
  .view { display: block !important; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: #fff; }
}

/* ── Footer ──────────────────────────────────────────────── */
#app-footer {
  background: #4C1D95; color: rgba(255,255,255,.7);
  padding: 16px 24px; margin-top: 32px;
}
.footer-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  justify-content: space-between;
}
.footer-logo-link { display: flex; align-items: center; }
.footer-logo { height: 28px; width: auto; filter: brightness(0) invert(1); opacity: .85; }
.footer-copy { font-size: 12px; color: rgba(255,255,255,.65); }
.footer-copy a { color: #C9A84C; text-decoration: none; }
.footer-copy a:hover { text-decoration: underline; }

/* ── Kanban ──────────────────────────────────────────────── */
.kanban-board {
  display: flex; gap: 12px; align-items: flex-start;
  overflow-x: auto; padding-bottom: 12px; min-height: 60vh;
}
.kanban-col {
  flex: 0 0 220px; min-width: 220px;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.kanban-col-header {
  padding: 10px 14px; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.kanban-col-count {
  background: rgba(0,0,0,.12); border-radius: 20px;
  padding: 1px 7px; font-size: 11px; font-weight: 700;
}
.kanban-cards {
  padding: 8px; min-height: 80px;
  display: flex; flex-direction: column; gap: 8px;
  transition: background .15s;
}
.kanban-cards.kanban-drop-active { background: #EBF8FF; }
.kanban-card {
  background: var(--surface); border-radius: 6px;
  border: 1px solid var(--border); padding: 10px 10px 8px;
  cursor: default; user-select: none;
  transition: box-shadow .15s, opacity .15s;
}
.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.kanban-card.kanban-card-cp { border-top: 2px solid #C9A84C; }
.kanban-card.kanban-dragging { opacity: .45; box-shadow: none; }
.kanban-card-top {
  display: flex; align-items: center; gap: 5px;
  margin-bottom: 6px; flex-wrap: wrap;
}
.kanban-card-name {
  font-size: 12px; font-weight: 600; line-height: 1.4;
  margin-bottom: 6px; cursor: pointer; color: var(--text);
}
.kanban-card-name:hover { color: #7C3AED; text-decoration: underline; }
.kanban-card-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.kanban-drop-hint {
  font-size: 11px; color: var(--text-muted); text-align: center;
  padding: 6px 0; opacity: .6;
}
.cp-badge {
  background: #C9A84C; color: #fff;
  padding: 1px 5px; border-radius: 3px; font-size: 9px; font-weight: 700;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 3px; }
