/*
 * TIMEPLAN-DS-1 — «متابعة الجدول الزمني» on the HOMEi design system (.ts-*).
 *
 * The approved merged A+B design (Kamal 6-10-2026): «ادمج a و b وادمج البنود
 * بحيث يظهر اكتر عدد في الصفحه» — every بند of the three sections in ONE dense
 * grid sorted by due date, the budget's fields as one read-only line under
 * the title, a slim KPI strip, one toolbar line, and a mini timeline per row.
 * The grid fills the window and scrolls inside its card with its header pinned.
 *
 * Scope: body.homei-schedule (EditTimePlan). Every colour is a --ho-* token,
 * so dark mode follows tokens.css. Text never below 12px.
 */

.homei-schedule {
  --ts-ink: var(--ho-brand-ink);
  --ts-muted: var(--ho-brand-ink-muted);
  --ts-line: var(--ho-brand-line);
  --ts-soft: var(--ho-brand-soft);
  --ts-card: var(--ho-brand-card);
  --ts-accent: var(--ho-brand-accent);
  --ts-license: var(--ho-info-ink);
  --ts-construction: var(--ho-warning-ink);
  --ts-finishing: var(--ho-success-ink);
}

/* ── Page header: title, the read-only meta line, open budget + save ── */
.homei-schedule .fi-header { align-items: center; gap: 12px; margin-bottom: 0; }
.homei-schedule .fi-header-heading { font-size: 22px; font-weight: 800; color: var(--ts-ink); line-height: 1.3; }
.homei-schedule .fi-header-subheading { color: var(--ts-muted); font-size: 13px; margin-top: 2px; }
.homei-schedule .fi-header .fi-btn { min-height: 36px; border-radius: 10px; font-weight: 700; }
.homei-schedule .fi-header [data-ts-save] { background: var(--ts-accent); color: var(--ho-brand-on-accent); }
.homei-schedule .fi-page-header-main-ctn { row-gap: 10px; padding-top: 12px; padding-bottom: 12px; }
.homei-schedule :is(.fi-page-content, .fi-page-main) { row-gap: 10px; }
.homei-schedule .fi-sc-form, .homei-schedule .fi-page-content > .fi-sc, .homei-schedule .fi-sc-form .fi-sc.fi-sc-has-gap { gap: 10px; }

.ts-unsaved {
  display: none; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 11px;
  font-size: var(--ho-text-xs); font-weight: 700; white-space: nowrap;
  background: var(--ho-warning-soft); color: var(--ho-warning-ink); border: 1px solid var(--ho-warning-line);
}
.ts-unsaved.is-on { display: inline-flex; }

/* ── KPI strip: one slim line ────────────────────────────────── */
.ts-kpis { display: flex; background: var(--ts-card); border: 1px solid var(--ts-line); border-radius: 12px; overflow: hidden; }
.ts-kpi { flex: 1 1 0; min-width: 0; display: flex; align-items: baseline; gap: 8px; padding: 7px 14px; border-inline-start: 1px solid var(--ts-line); white-space: nowrap; }
.ts-kpi:first-child { border-inline-start: 0; flex-grow: 1.5; }
.ts-kpi--ok .ts-kpi-v { unicode-bidi: isolate; direction: ltr; }
.ts-kpi-l { font-size: var(--ho-text-xs); font-weight: 600; color: var(--ts-muted); }
.ts-kpi-v { font-size: 18px; font-weight: 800; color: var(--ts-ink); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.ts-kpi-c { font-size: var(--ho-text-xs); color: var(--ts-muted); overflow: hidden; text-overflow: ellipsis; }
.ts-kpi--ok .ts-kpi-v { color: var(--ho-success-ink); }
.ts-kpi--danger .ts-kpi-v { color: var(--ho-danger-ink); }
.ts-kpi--accent .ts-kpi-v { color: var(--ho-brand-accent-ink); }
.ts-kpi--text .ts-kpi-v { font-size: 14px; }
.ts-kpi-bar { flex: none; align-self: center; inline-size: 64px; block-size: 6px; border-radius: 6px; background: var(--ts-soft); overflow: hidden; }
.ts-kpi-bar i { display: block; block-size: 100%; background: var(--ho-success-ink); border-radius: 6px; }

/* ── The card: 3px blue rule, toolbar, grid, foot ────────────── */
.homei-schedule .ts-card { border: 1px solid var(--ts-line); border-top: 3px solid var(--ho-info-ink); border-radius: 14px; box-shadow: none; overflow: hidden; }
.homei-schedule .ts-card .fi-section-content-ctn, .homei-schedule .ts-card .fi-section-content { padding: 0; }
.homei-schedule .ts-card .fi-section-content.fi-sc-has-gap, .homei-schedule .ts-card .fi-sc-has-gap { gap: 0; }
.homei-schedule .ts-card .fi-fo-field, .homei-schedule .ts-card .fi-in-entry { row-gap: 0; }

.ts-toolbar { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-bottom: 1px solid var(--ts-line); flex-wrap: nowrap; min-width: 0; }
.ts-chips { min-width: 0; flex-wrap: nowrap; overflow: hidden; }
.ts-pills, .ts-chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.ts-pill {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--ts-line); border-radius: 999px; padding: 4px 11px;
  background: var(--ts-card); color: var(--ts-ink); font-weight: 700; font-size: 13px; white-space: nowrap; cursor: pointer;
}
.ts-pill b { font-weight: 800; font-size: var(--ho-text-xs); }
.ts-pill-c { font-size: var(--ho-text-xs); font-weight: 600; color: var(--ts-muted); font-variant-numeric: tabular-nums; }
.ts-pill.is-on { background: var(--ts-ink); border-color: var(--ts-ink); color: var(--ts-card); }
.ts-pill.is-on .ts-pill-c { color: inherit; opacity: .8; }
.ts-chip {
  border: 1px solid var(--ts-line); background: var(--ts-soft); color: var(--ts-muted); border-radius: 999px; padding: 3px 10px;
  font-size: var(--ho-text-xs); font-weight: 700; white-space: nowrap; cursor: pointer;
}
.ts-chip b { font-weight: 800; }
.ts-chip--danger { color: var(--ho-danger-ink); }
.ts-chip.is-on { background: var(--ho-info-soft); border-color: var(--ho-info-line); color: var(--ho-info-ink); }
.ts-sep { inline-size: 1px; block-size: 22px; background: var(--ts-line); margin-inline: 4px; }
.ts-search { margin-inline-start: auto; }
.ts-search input {
  inline-size: 180px; block-size: 30px; border: 1px solid var(--ts-line); border-radius: 9px; padding-inline: 10px;
  background: var(--ts-card); color: var(--ts-ink); font-size: 13px;
}
.ts-search input:focus { outline: 2px solid var(--ts-accent); outline-offset: -1px; }
.ts-link { font-size: var(--ho-text-xs); font-weight: 700; color: var(--ho-info-ink); white-space: nowrap; padding: 4px 6px; border-radius: 6px; }
.ts-link:hover { background: var(--ho-info-soft); }

.ts-dot { display: inline-block; flex: none; inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--ts-muted); }
.ts-dot--license { background: var(--ts-license); }
.ts-dot--construction { background: var(--ts-construction); }
.ts-dot--finishing { background: var(--ts-finishing); }

/* ── The grid: one row per بند, 34px, header pinned ──────────── */
.homei-schedule .ts-grid {
  display: block; overflow: auto; max-width: 100%; padding: 0; isolation: isolate; border: 0; border-radius: 0; box-shadow: none;
  max-height: calc(100vh - var(--ts-grid-top, 300px)); min-height: 240px; scrollbar-gutter: stable;
}
.homei-schedule .ts-grid > table { display: table; inline-size: 100%; min-width: 0; table-layout: fixed; border-collapse: separate; border-spacing: 0; }
.homei-schedule .ts-grid > table > thead > tr > th {
  position: sticky; top: 0; z-index: 3; background: var(--ts-soft); color: var(--ts-muted);
  font-size: var(--ho-text-xs); font-weight: 700; padding: 6px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-bottom: 1px solid var(--ts-line); text-align: start;
}
.homei-schedule .ts-grid > table > thead > tr > th:first-of-type { padding-inline-start: 14px; }
/*
 * Column widths (TIMEPLAN-TL-1, 7-10): every column has a fixed width except
 * the timeline, which takes what is left — so it grows with the screen
 * instead of the بند column swallowing the space (432px at 1512).
 * بند · due · confirmed · status · area · note · TIMELINE · media · actions.
 */
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(1) { inline-size: 190px; }
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(2) { inline-size: 176px; }
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(3) { inline-size: 122px; }
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(4) { inline-size: 116px; }
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(5) { inline-size: 80px; }
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(6) { inline-size: 110px; }
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(7) { overflow: visible; }
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(8) { inline-size: 60px; }
.homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(9) { inline-size: 64px; }

.homei-schedule .ts-grid > table > tbody > tr > td:not(.fi-hidden) {
  display: table-cell; min-width: 0; padding: 1px 6px; block-size: 34px; vertical-align: middle;
  border-bottom: 1px solid var(--ts-line); overflow: hidden;
}
.homei-schedule .ts-grid :is(td, th):first-of-type { position: static; min-width: 0 !important; max-width: none; box-shadow: none; background: transparent; }
.homei-schedule .ts-grid > table > thead > tr > th:first-of-type { position: sticky; background: var(--ts-soft); }
.homei-schedule .ts-grid > table > tbody > tr > td:first-of-type { padding-inline-start: 12px; }
.homei-schedule .ts-grid > table > tbody > tr:hover > td { background: color-mix(in srgb, var(--ts-soft) 45%, transparent); }
.homei-schedule .ts-grid > table > tbody > tr[hidden] { display: none; }
.homei-schedule .ts-grid > table > tbody > tr.ts-changed > td { background: var(--ho-brand-accent-soft); }
.homei-schedule .ts-grid > table > tbody > tr.ts-changed > td:first-of-type { box-shadow: inset -3px 0 0 var(--ts-accent); }
[dir="ltr"] .homei-schedule .ts-grid > table > tbody > tr.ts-changed > td:first-of-type { box-shadow: inset 3px 0 0 var(--ts-accent); }
.homei-schedule .ts-grid .ts-empty-row td { text-align: center; color: var(--ts-muted); padding: 24px; font-size: 13px; }

.homei-schedule .ts-grid .fi-fo-field-label-col { display: none; }
.homei-schedule .ts-grid .fi-fo-field { row-gap: 0; }
.homei-schedule .ts-grid .fi-input-wrp { min-height: 0; border-radius: 7px; box-shadow: 0 0 0 1px var(--ts-line); position: relative; }
.homei-schedule .ts-grid .fi-input-wrp:focus-within { box-shadow: 0 0 0 2px var(--ts-accent); }
.homei-schedule .ts-grid .fi-input { padding: 2px 6px; font-size: 13px; line-height: 20px; font-variant-numeric: tabular-nums; font-weight: 600; }
.homei-schedule .ts-grid input[type="date"] { padding-inline: 6px; font-size: 13px; }
.homei-schedule .ts-grid .fi-input-wrp-suffix:has(.fi-dictation-btn), .homei-schedule .ts-grid .fi-input-wrp-suffix:empty { display: none; }
.homei-schedule .ts-grid .fi-fo-field-wrp-error-message { font-size: var(--ho-text-xs); }
/* An empty confirmed date reads «—», never Safari's grey «today». */
.homei-schedule .ts-grid .fi-input-wrp.ts-empty input[type="date"] { color: transparent; }
.homei-schedule .ts-grid .fi-input-wrp.ts-empty input[type="date"]::-webkit-datetime-edit { color: transparent; }
.homei-schedule .ts-grid .fi-input-wrp.ts-empty::after {
  content: "—"; position: absolute; inset-block: 0; inset-inline-start: 10px; display: flex; align-items: center;
  color: var(--ts-muted); font-weight: 600; pointer-events: none;
}

/* Status: a pill in its tone (pending · started · done). */
.homei-schedule .ts-grid .fi-input-wrp[data-ts-tone] { border-radius: 999px; box-shadow: none; }
.homei-schedule .ts-grid .fi-input-wrp[data-ts-tone] select { font-size: var(--ho-text-xs); font-weight: 700; padding-block: 2px; line-height: 20px; background-color: transparent; color: inherit; }
.homei-schedule .ts-grid .fi-input-wrp[data-ts-tone="wait"] { background: var(--ts-soft); color: var(--ts-muted); box-shadow: 0 0 0 1px var(--ts-line); }
.homei-schedule .ts-grid .fi-input-wrp[data-ts-tone="go"] { background: var(--ho-info-soft); color: var(--ho-info-ink); }
.homei-schedule .ts-grid .fi-input-wrp[data-ts-tone="done"] { background: var(--ho-success-soft); color: var(--ho-success-ink); }
.homei-schedule .ts-grid .fi-input-wrp[data-ts-tone]:focus-within { box-shadow: 0 0 0 2px var(--ts-accent); }

/* Read-only cells. */
.ts-item { display: flex; align-items: center; gap: 7px; min-width: 0; font-weight: 700; color: var(--ts-ink); font-size: 13px; }
.ts-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ts-due { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; color: var(--ts-ink); font-size: 13px; font-variant-numeric: tabular-nums; }
.ts-due--late { color: var(--ho-danger-ink); }
.ts-due-x { font-size: var(--ho-text-xs); font-weight: 700; margin-inline-start: 6px; }
.ts-due-x--soon { color: var(--ho-warning-ink); }
.ts-note { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ts-muted); font-size: var(--ho-text-xs); }
.ts-muted { color: var(--ts-muted); }

/* Mini timeline: years, today, due ◯, confirmed ◆, the delay between. */
.ts-th-timeline { position: relative; }
.ts-axis { position: absolute; inset-inline: 6px; inset-block: 0; }
.ts-axis i { position: absolute; inset-block-start: 6px; transform: translateX(50%); font-style: normal; font-size: var(--ho-text-xs); font-weight: 700; color: var(--ts-muted); }
[dir="ltr"] .ts-axis i { transform: translateX(-50%); }
.ts-gt { position: relative; display: block; block-size: 26px; }
.ts-gt i { position: absolute; display: block; }
.ts-gt-ax { inset-block: 0; inline-size: 1px; background: var(--ts-line); }
.ts-gt-today { inset-block: 0; inline-size: 2px; background: var(--ts-accent); }
.ts-gt-gap { inset-block-start: 50%; block-size: 4px; transform: translateY(-50%); background: var(--ho-danger-soft); box-shadow: 0 0 0 1px var(--ho-danger-line); border-radius: 2px; }
.ts-gt-due {
  inset-block-start: 50%; inline-size: 10px; block-size: 10px; border-radius: 50%; transform: translate(50%, -50%);
  border: 2px solid var(--ts-ink); background: var(--ts-card); z-index: 1;
}
.ts-gt-due.is-late { border-color: var(--ho-danger-ink); background: var(--ho-danger-soft); }
.ts-gt-done { inset-block-start: 50%; inline-size: 10px; block-size: 10px; border-radius: 2px; transform: translate(50%, -50%) rotate(45deg); background: var(--ho-success-ink); z-index: 2; }
[dir="ltr"] :is(.ts-gt-due, .ts-gt-done) { transform: translate(-50%, -50%); }
[dir="ltr"] .ts-gt-done { transform: translate(-50%, -50%) rotate(45deg); }

/* Media: two thumbnails at row size; no-file warnings shrink to their icon. */
.homei-schedule .ts-grid td:nth-of-type(8) > * > div, .homei-schedule .ts-grid td:nth-of-type(8) div[style*="display:flex"] { gap: 3px !important; flex-wrap: nowrap; }
.homei-schedule .ts-grid td:nth-of-type(8) a:nth-of-type(n + 3) { display: none !important; }
.homei-schedule .ts-grid td:nth-of-type(8) :is(img, a) { block-size: 24px !important; inline-size: 24px !important; border-radius: 6px !important; }
.homei-schedule .ts-grid td:nth-of-type(8) .fi-badge { font-size: 0; padding: 2px; gap: 0; }
.homei-schedule .ts-grid .fi-fo-table-repeater-actions { gap: 0; flex-wrap: nowrap; }
.homei-schedule .ts-grid .fi-fo-table-repeater-actions .fi-icon-btn { inline-size: 26px; block-size: 26px; }
.homei-schedule .ts-grid .fi-fo-table-repeater-actions .fi-icon-btn .fi-icon { inline-size: 18px; block-size: 18px; }

.ts-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 6px 12px;
  background: var(--ts-soft); border-top: 1px solid var(--ts-line); font-size: var(--ho-text-xs); color: var(--ts-muted); font-weight: 600;
}
.ts-foot .ts-late { color: var(--ho-danger-ink); }
.ts-legend { display: flex; gap: 12px; align-items: center; }
.ts-legend span { display: inline-flex; gap: 5px; align-items: center; }
.ts-legend i { display: inline-block; }
.ts-lg-due { inline-size: 9px; block-size: 9px; border-radius: 50%; border: 2px solid var(--ts-ink); }
.ts-lg-done { inline-size: 8px; block-size: 8px; background: var(--ho-success-ink); transform: rotate(45deg); border-radius: 2px; }
.ts-lg-today { inline-size: 2px; block-size: 11px; background: var(--ts-accent); }
.ts-lg-gap { inline-size: 14px; block-size: 4px; background: var(--ho-danger-soft); box-shadow: 0 0 0 1px var(--ho-danger-line); border-radius: 2px; }

/*
 * Narrower cards (laptops, the sidebar open): the read-only note folds away
 * first so the timeline keeps room; the timeline goes only when it would be
 * narrower than ~150px — never a sideways scroll, never the بند.
 * Measured on the card itself, so the sidebar's width counts.
 */
.homei-schedule .ts-card { container-type: inline-size; }
@container (max-width: 1100px) {
  .homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(6),
  .homei-schedule .ts-grid > table > tbody > tr > td:nth-of-type(6) { display: none !important; }
}
@container (max-width: 960px) {
  .homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(7),
  .homei-schedule .ts-grid > table > tbody > tr > td:nth-of-type(7) { display: none !important; }
  .homei-schedule .ts-grid > table > thead > tr > th:nth-of-type(1) { inline-size: auto; }
  .ts-legend { display: none; }
  .ts-chips { flex-wrap: wrap; }
}
@media (max-width: 1279px) {
  .ts-kpi-c { display: none; }
}

/* Phones: one card per بند, each value under its column's name; save stays reachable. */
@media (max-width: 767px) {
  .ts-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ts-kpi { flex-direction: column; gap: 0; border-inline-start: 0; border-top: 1px solid var(--ts-line); }
  .ts-kpi:nth-child(-n + 2) { border-top: 0; }
  .ts-kpi:nth-child(even) { border-inline-start: 1px solid var(--ts-line); }
  .ts-kpi-bar { display: none; }
  .ts-toolbar { gap: 6px; flex-wrap: wrap; }
  .ts-pills { flex-wrap: nowrap; overflow-x: auto; max-inline-size: 100%; }
  .ts-chips { flex-wrap: wrap; overflow: visible; }
  .ts-sep { display: none; }
  .ts-search { margin-inline-start: 0; inline-size: 100%; }
  .ts-search input { inline-size: 100%; }
  .homei-schedule .ts-grid { max-height: none; overflow: visible; padding: 8px; }
  .homei-schedule .ts-grid > table, .homei-schedule .ts-grid > table > tbody { display: block; }
  .homei-schedule .ts-grid > table > thead { display: none; }
  .homei-schedule .ts-grid > table > tbody > tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; padding: 10px 12px; margin-bottom: 8px;
    background: var(--ts-card); border: 1px solid var(--ts-line); border-radius: 12px;
  }
  .homei-schedule .ts-grid > table > tbody > tr[hidden] { display: none; }
  .homei-schedule .ts-grid > table > tbody > tr > td:not(.fi-hidden) { display: block; block-size: auto; padding: 0; border: 0; overflow: visible; }
  .homei-schedule .ts-grid > table > tbody > tr > td[data-ts-label]::before { content: attr(data-ts-label); display: block; font-size: var(--ho-text-xs); color: var(--ts-muted); font-weight: 600; margin-bottom: 2px; }
  .homei-schedule .ts-grid > table > tbody > tr > td:first-of-type { grid-column: 1 / -1; padding: 0; }
  .homei-schedule .ts-grid > table > tbody > tr > td:first-of-type::before { display: none; }
  .homei-schedule .ts-grid > table > tbody > tr > td:nth-of-type(6) { grid-column: 1 / -1; }
  .homei-schedule .ts-grid > table > tbody > tr > td:nth-of-type(7) { display: none !important; }
  .homei-schedule .ts-grid > table > tbody > tr > td:last-of-type::before { display: none; }
  /* An empty note or an item without photos says nothing on a card. */
  .homei-schedule .ts-grid > table > tbody > tr > td:nth-of-type(6):not(:has(.ts-note)),
  .homei-schedule .ts-grid > table > tbody > tr > td:nth-of-type(8):not(:has(a, img, .fi-badge)) { display: none !important; }
  .homei-schedule .ts-grid > table > tbody > tr:has([data-ts-flag="late"]) { border-inline-start: 3px solid var(--ho-danger-ink); }
  .ts-due { white-space: normal; }
  .ts-foot { display: none; }
  .homei-schedule .fi-header { flex-wrap: wrap; }
  .homei-schedule .fi-header-actions-ctn { position: sticky; bottom: 0; }
}
