/* نبض: calm, editorial, right-to-left. Tokens first, then layout. */

@font-face { font-family: 'Thmanyah Sans'; font-weight: 400; font-display: swap; src: url('/fonts/Thmanyahsans12-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Thmanyah Sans'; font-weight: 500; font-display: swap; src: url('/fonts/Thmanyahsans12-Medium.woff2') format('woff2'); }
@font-face { font-family: 'Thmanyah Sans'; font-weight: 700; font-display: swap; src: url('/fonts/Thmanyahsans12-Bold.woff2') format('woff2'); }
@font-face { font-family: 'Thmanyah Display'; font-weight: 700; font-display: swap; src: url('/fonts/Thmanyahserifdisplay12-Bold.woff2') format('woff2'); }

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.04);
  --c-int: #2a78d6;      /* interactions: always blue */
  --c-closed: #eb6834;   /* closed tasks: always orange */
  --up: #006300;
  --warn: #b5501f;
  --primary: #0b0b0b;
  --primary-ink: #fcfcfb;
  --font: 'Thmanyah Sans', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --font-num: -apple-system, 'SF Pro Text', 'Segoe UI', Roboto, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --hairline: #2c2c2a; --baseline: #383835; --ring: rgba(255, 255, 255, 0.1); --wash: rgba(255, 255, 255, 0.05);
    --c-int: #3987e5; --c-closed: #d95926; --up: #0ca30c; --warn: #ec835a;
    --primary: #f0efec; --primary-ink: #0d0d0d;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --hairline: #2c2c2a; --baseline: #383835; --ring: rgba(255, 255, 255, 0.1); --wash: rgba(255, 255, 255, 0.05);
  --c-int: #3987e5; --c-closed: #d95926; --up: #0ca30c; --warn: #ec835a;
  --primary: #f0efec; --primary-ink: #0d0d0d;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.6 var(--font);
  font-feature-settings: 'anum' 0, 'locl' 0;   /* Western digits everywhere */
  font-variant-numeric: lining-nums;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.nums { font-family: var(--font-num); font-variant-numeric: lining-nums; direction: ltr; unicode-bidi: isolate; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--c-int); outline-offset: 2px; border-radius: 6px; }
button, select, input { font: inherit; color: inherit; font-feature-settings: inherit; }

/* ------------------------------------------------------------ header -- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px clamp(16px, 4vw, 40px) 14px; border-bottom: 1px solid var(--hairline);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex-wrap: wrap; }
.brand h1 { margin: 0; font: 700 28px/1.2 'Thmanyah Display', var(--font); letter-spacing: 0; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.quiet { color: var(--muted); font-size: 13px; }
.quiet-link { color: var(--ink-2); font-size: 13px; text-underline-offset: 3px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 8px; border: 0; cursor: pointer;
  background: var(--surface); box-shadow: 0 0 0 1px var(--ring); font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--wash); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); box-shadow: none; }
.btn.primary:hover { opacity: 0.88; }
.btn.icon { width: 36px; padding: 0; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: var(--warn); }
.select, .input {
  min-height: 36px; padding: 0 10px; border-radius: 8px; border: 0; background: var(--surface);
  box-shadow: 0 0 0 1px var(--ring); max-width: 100%;
}
.input { width: 100%; padding: 0 12px; }

.progress { height: 2px; background: var(--hairline); }
.progress-bar { height: 100%; width: 0; background: var(--c-int); transition: width 0.4s ease; }
.banner {
  margin: 12px clamp(16px, 4vw, 40px) 0; padding: 10px 14px; border-radius: 10px;
  background: var(--surface); box-shadow: 0 0 0 1px var(--ring); color: var(--ink-2);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

/* -------------------------------------------------------------- main -- */
main { padding: 20px clamp(16px, 4vw, 40px) 64px; max-width: 1280px; margin: 0 auto; }
main.loading { opacity: 0.55; transition: opacity 0.15s; }
.filters { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.weeknav { display: flex; align-items: center; gap: 8px; }
.week-label { font-size: 17px; font-weight: 700; min-width: 11.5em; text-align: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 32px; padding: 0 12px; border-radius: 999px; border: 0; cursor: pointer;
  background: transparent; box-shadow: 0 0 0 1px var(--ring); color: var(--ink-2); font-size: 14px;
}
.chip[aria-pressed='true'] { background: var(--ink); color: var(--page); box-shadow: none; }
.note { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 18px 0 22px; }
.tile { background: var(--surface); border-radius: 10px; box-shadow: 0 0 0 1px var(--ring); padding: 14px 16px; min-width: 0; }
.tile-label { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.int { background: var(--c-int); }
.dot.closed { background: var(--c-closed); }
.tile-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-top: 6px; }
.tile-value { font: 600 34px/1.05 var(--font-num); letter-spacing: -0.01em; }
.tile-value small { font: 400 15px/1 var(--font); color: var(--muted); margin-inline-start: 4px; }
.tile-sub { margin-top: 6px; font-size: 13px; color: var(--muted); min-height: 1.6em; }
.delta { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.delta.up { color: var(--up); }

/* ------------------------------------------------------------- table -- */
.table-card { background: var(--surface); border-radius: 10px; box-shadow: 0 0 0 1px var(--ring); overflow-x: auto; }
table.people { width: 100%; border-collapse: collapse; }
.people th, .people td { padding: 10px 12px; text-align: start; vertical-align: middle; border-bottom: 1px solid var(--hairline); }
.people thead th { font-size: 12.5px; font-weight: 500; color: var(--ink-2); white-space: nowrap; background: var(--surface); }
.people thead th .legend { display: inline-flex; gap: 8px; margin-inline-start: 6px; color: var(--muted); font-weight: 400; }
.people thead th .legend span { display: inline-flex; align-items: center; gap: 4px; }
.sortbtn { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font: inherit; color: inherit; border-radius: 6px; }
.sortbtn:focus-visible { outline: 2px solid var(--c-int); outline-offset: 2px; }
.sortbtn .arrow { color: var(--muted); font-size: 10px; }
tr.role-head th { background: var(--page); font-size: 13px; font-weight: 700; color: var(--ink-2); padding-top: 9px; padding-bottom: 9px; }
tr.role-head .count { color: var(--muted); font-weight: 400; margin: 0 6px; }
tr.person { cursor: pointer; }
tr.person:hover td, tr.person:hover th, tr.person:focus-visible td, tr.person:focus-visible th { background: var(--wash); }
tr.person:focus-visible { outline: 2px solid var(--c-int); outline-offset: -2px; }
tr.person.idle .who-name, tr.person.idle .metric-num { color: var(--muted); }
.people tbody tr:last-child td, .people tbody tr:last-child th { border-bottom: 0; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 400; }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; background: var(--hairline); color: var(--ink-2); display: grid; place-items: center; font-size: 13px; font-weight: 700; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.who-text { min-width: 0; }
.who-name { font-weight: 500; overflow-wrap: anywhere; }
.who-title { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 26ch; }
/* number + bar on one line, the week-over-week change beneath: nothing can
   spill into the next column however long the change text is */
.metric { display: grid; grid-template-columns: 2.2em minmax(40px, 96px); align-items: center; column-gap: 8px; row-gap: 3px; white-space: nowrap; }
.metric .delta { grid-column: 1 / -1; min-height: 0; }
.metric .delta:empty { display: none; }
.metric-num { font: 600 18px/1 var(--font-num); font-variant-numeric: tabular-nums lining-nums; }
.track { height: 6px; border-radius: 3px; background: transparent; position: relative; }
.track i { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 0 3px 3px 0; min-width: 0; }
[dir='rtl'] .track i { border-radius: 3px 0 0 3px; }
.track.int i { background: var(--c-int); }
.track.closed i { background: var(--c-closed); }
.plain { font: 500 15px/1 var(--font-num); font-variant-numeric: tabular-nums lining-nums; color: var(--ink-2); }
.plain.warn { color: var(--warn); font-weight: 700; }
.off { color: var(--baseline); }
.sparks { display: flex; align-items: center; gap: 8px; }
.spark { display: block; overflow: visible; }
.spark .line { fill: none; stroke: var(--c-int); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .enddot { fill: var(--c-int); stroke: var(--surface); stroke-width: 2; }
.spark .col { fill: var(--c-closed); opacity: 0.4; }
.spark .col.now { opacity: 1; }
.spark .base { stroke: var(--hairline); stroke-width: 1; }
.when { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.when.never { color: var(--muted); }

/* -------------------------------------------------------------- empty -- */
.empty { max-width: 560px; margin: 12vh auto 0; padding: 28px; text-align: center; }
.empty h2 { margin: 0 0 8px; font-size: 22px; }
.empty p { margin: 0 0 18px; color: var(--ink-2); }
.empty code, .code { display: inline-block; direction: ltr; padding: 8px 12px; border-radius: 8px; background: var(--surface); box-shadow: 0 0 0 1px var(--ring); font: 13px/1.5 ui-monospace, 'SF Mono', Menlo, monospace; user-select: all; }
.empty .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* ------------------------------------------------------------- drawer -- */
dialog { color: var(--ink); border: 0; padding: 0; background: var(--page); }
dialog::backdrop { background: rgba(0, 0, 0, 0.32); }
.drawer {
  position: fixed; inset-block: 0; inset-inline: auto 0; margin: 0; height: 100dvh; max-height: none;
  width: min(560px, 100vw); max-width: 100vw; box-shadow: 0 0 0 1px var(--ring); overflow-y: auto;
}
.drawer-head { position: sticky; top: 0; z-index: 1; background: var(--page); display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--hairline); }
.drawer-head .avatar { width: 44px; height: 44px; font-size: 15px; }
.drawer-head h2 { margin: 0; font-size: 18px; line-height: 1.3; }
.drawer-head .sub { color: var(--muted); font-size: 13px; }
.drawer-head .grow { flex: 1; min-width: 0; }
.drawer-body { padding: 18px 20px 40px; display: grid; gap: 22px; }
.heroes { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.hero { background: var(--surface); border-radius: 10px; box-shadow: 0 0 0 1px var(--ring); padding: 12px 14px; }
.hero b { display: block; font: 600 28px/1.1 var(--font-num); margin-top: 4px; }
.hero .tile-label { font-size: 12.5px; }
.section h3 { margin: 0 0 10px; font-size: 14px; font-weight: 700; }
.section h3 small { color: var(--muted); font-weight: 400; margin-inline-start: 6px; }
.bars { display: grid; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 9em 1fr 2.4em; align-items: center; gap: 10px; font-size: 13.5px; }
.bar-row .track { height: 8px; background: var(--wash); border-radius: 4px; overflow: hidden; }
.bar-row .v { text-align: end; font: 600 13.5px/1 var(--font-num); }
.bar-row.is-off { color: var(--muted); }
.bar-row.is-off .track i { background: var(--baseline); }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font: 11px var(--font-num); fill: var(--muted); }
.chart .axis { stroke: var(--baseline); stroke-width: 1; }
.chart .grid { stroke: var(--hairline); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--c-int); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--c-int); stroke: var(--page); stroke-width: 2; }
.chart .col { fill: var(--c-closed); }
.chart .val { fill: var(--ink); font-weight: 600; }
.chart-title { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); margin: 0 0 4px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--hairline); display: grid; gap: 2px; }
.list li:last-child { border-bottom: 0; }
.list .t { font-weight: 500; overflow-wrap: anywhere; }
.list .t a { text-decoration: none; }
.list .t a:hover { text-decoration: underline; text-underline-offset: 3px; }
.list .m { color: var(--muted); font-size: 12.5px; }
.list .x { color: var(--ink-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.group-title { margin: 12px 0 2px; font-size: 12.5px; color: var(--ink-2); font-weight: 700; }
.group-title:first-child { margin-top: 0; }
.none { color: var(--muted); font-size: 13.5px; margin: 0; }

/* ------------------------------------------------------------ settings -- */
.dialog { width: min(920px, calc(100vw - 24px)); max-height: min(86dvh, 860px); border-radius: 14px; box-shadow: 0 0 0 1px var(--ring), 0 24px 60px rgba(0, 0, 0, 0.18); overflow: hidden; }
.dialog[open] { display: flex; flex-direction: column; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.tabs { display: flex; gap: 4px; padding: 12px 20px 0; border-bottom: 1px solid var(--hairline); }
.tab { all: unset; cursor: pointer; padding: 8px 12px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tab[aria-selected='true'] { color: var(--ink); border-bottom-color: var(--ink); }
.tab:focus-visible { outline: 2px solid var(--c-int); outline-offset: -2px; }
.dialog-body { padding: 16px 20px; overflow: auto; flex: 1; }
.dialog-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--hairline); flex-wrap: wrap; }
.dialog-foot .msg { color: var(--warn); font-size: 13px; }
.lead { margin: 0 0 12px; color: var(--ink-2); font-size: 13.5px; }
.rows { display: grid; }
.prow { display: grid; grid-template-columns: auto 1fr minmax(120px, 170px); align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--hairline); }
.prow:last-child { border-bottom: 0; }
.prow .who-title { max-width: 44ch; }
.prow input[type='checkbox'], .matrix input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--ink); }
.tag { font-size: 11.5px; color: var(--muted); box-shadow: 0 0 0 1px var(--ring); border-radius: 6px; padding: 1px 6px; margin-inline-start: 6px; }
.matrix-wrap { overflow-x: auto; }
table.matrix { border-collapse: collapse; width: 100%; min-width: 640px; }
.matrix th, .matrix td { padding: 8px 10px; border-bottom: 1px solid var(--hairline); text-align: center; vertical-align: middle; }
.matrix th:first-child, .matrix td:first-child { text-align: start; position: sticky; inset-inline-start: 0; background: var(--page); min-width: 190px; }
.matrix thead th { vertical-align: bottom; font-weight: 500; }
.matrix .role-name { width: 104px; min-height: 32px; text-align: center; padding: 0 6px; }
.matrix .rm { all: unset; cursor: pointer; display: block; margin: 4px auto 0; font-size: 12px; color: var(--muted); border-radius: 4px; }
.matrix .rm:hover { color: var(--warn); }
.matrix .rm:focus-visible { outline: 2px solid var(--c-int); }
.matrix tr.sec td { background: var(--page); font-size: 12.5px; font-weight: 700; color: var(--ink-2); text-align: start; padding-top: 14px; }
.matrix .mname { font-weight: 500; }
.matrix .mhint { color: var(--muted); font-size: 12px; display: block; }
.proj { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--hairline); }
.addproj { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 14px; }

.toast { position: fixed; inset-block-end: 24px; inset-inline-start: 50%; transform: translateX(50%); background: var(--ink); color: var(--page); padding: 9px 16px; border-radius: 999px; font-size: 14px; z-index: 50; }
[dir='rtl'] .toast { transform: translateX(50%); }

/* -------------------------------------------------------------- login -- */
.login { max-width: 360px; margin: 14vh auto 0; padding: 0 20px; text-align: center; }
.login h1 { margin: 0; font: 700 44px/1.2 'Thmanyah Display', var(--font); }
.login-form { display: grid; gap: 8px; margin-top: 28px; text-align: start; }
.login-form label { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.login-form .btn { margin-top: 14px; min-height: 42px; }
.login-error { color: var(--warn); font-size: 13.5px; min-height: 1.6em; margin: 4px 0 0; }
.field { display: grid; gap: 6px; margin-bottom: 12px; max-width: 360px; }
.field label { font-size: 13px; color: var(--ink-2); }
.connect-code { font: 600 26px/1.4 ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: 0.06em; direction: ltr; display: inline-block; padding: 6px 14px; border-radius: 10px; background: var(--surface); box-shadow: 0 0 0 1px var(--ring); user-select: all; }

/* ---------------------------------------------------------- responsive -- */
@media (max-width: 1100px) { .col-trend { display: none; } }
@media (max-width: 860px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .col-last, .col-extra { display: none; }
  .metric { grid-template-columns: 2.2em minmax(36px, 1fr); }
  .people th, .people td { padding: 10px 10px; }
  .who-title { max-width: 18ch; }
}
@media (max-width: 560px) {
  .week-label { min-width: 0; font-size: 15px; }
  .tile-value { font-size: 28px; }
  .metric { grid-template-columns: auto; }
  .metric .track { display: none; }
  .who-title { display: none; }
  .avatar { width: 28px; height: 28px; font-size: 11px; }
  .actions .quiet { width: 100%; }
  .prow { grid-template-columns: auto 1fr; }
  .prow select { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media print {
  :root { color-scheme: light; --page: #fff; --surface: #fff; --ink: #000; --ink-2: #333; --muted: #666; --hairline: #ccc; --ring: #bbb; }
  .actions, .progress, .banner, #prev, #next, #this-week, .chips, .sortbtn .arrow, dialog, .toast, #project-link { display: none !important; }
  .select { box-shadow: none; padding: 0; appearance: none; font-weight: 700; }
  main { padding: 0; max-width: none; }
  .top { border: 0; padding: 0 0 8px; }
  tr.person { break-inside: avoid; }
  .col-trend, .col-last, .col-extra { display: table-cell !important; }
}
