/* Schedule: Gantt timeline + "Generate schedule" sheet. Loaded after theme.css; colours come from the theme tokens (navy / amber, light + dark). */
:root {
  --gt-ns: #64738f; --gt-ns-ink: #ffffff; --gt-ip: #e3a03a; --gt-ip-ink: #2b1a03; --gt-blk: #8a6aa8; --gt-blk-ink: #ffffff;
  --gt-done: #4a9269; --gt-done-ink: #ffffff; --gt-over: #c8442f; --gt-over-ink: #ffffff;
  --gt-weekend: color-mix(in srgb, var(--ink) 4.5%, transparent); --gt-week: color-mix(in srgb, var(--line-2) 70%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root {
    --gt-ns: #5b6e95; --gt-ns-ink: #f4f0e8; --gt-ip: #eab25a; --gt-ip-ink: #1f1405; --gt-blk: #9a80c2; --gt-blk-ink: #170f22;
    --gt-done: #3e9467; --gt-done-ink: #f2fbf5; --gt-over: #f0877a; --gt-over-ink: #2a0d08;
    --gt-weekend: color-mix(in srgb, #000 22%, transparent); --gt-week: color-mix(in srgb, var(--line-2) 75%, transparent);
  }
}

/* ---------- card + top strip ---------- */
.gantt { --gt-label: 232px; --gt-head: 54px; --gt-row: 46px; position: relative; padding: 0; overflow: visible; }
.gantt.is-phone { --gt-label: 0px; --gt-row: 56px; }
.gt-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem 1rem; flex-wrap: wrap; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line); }
.gt-span { font-size: .95rem; white-space: nowrap; }
.gt-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .8rem; color: var(--muted); font-weight: 600; }
.gt-legend span { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
.gt-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--gt-ns); }
.gt-dot.st-in-progress { background: var(--gt-ip); } .gt-dot.st-blocked { background: var(--gt-blk); } .gt-dot.st-done { background: var(--gt-done); } .gt-dot.st-overdue { background: var(--gt-over); }

/* ---------- scroller + grid ---------- */
.gt-scroll { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; border-radius: 0 0 var(--radius) var(--radius); scrollbar-width: thin; }
.gt-grid { position: relative; display: grid; grid-template-columns: var(--gt-label) var(--gt-w); width: max-content; }
.gantt.is-phone .gt-grid { grid-template-columns: var(--gt-w); }
.gantt.is-phone .gt-corner, .gantt.is-phone .gt-label { display: none; }

.gt-corner {
  position: sticky; left: 0; z-index: 4; height: var(--gt-head); display: flex; align-items: flex-end; padding: 0 14px 8px;
  background: var(--surface); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: .72rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.gt-head { position: relative; height: var(--gt-head); border-bottom: 1px solid var(--line); background: var(--surface); }
.gt-months, .gt-weeks { position: relative; }
.gt-months { height: 26px; }
.gt-weeks { height: 28px; }
.gt-month { position: absolute; top: 0; height: 26px; border-left: 1px solid var(--gt-week); overflow: hidden; }
.gt-month:first-child { border-left: 0; }
.gt-month > span { position: sticky; left: calc(var(--gt-label) + 8px); display: inline-block; padding: 6px 8px 0; font-size: .78rem; font-weight: 750; color: var(--ink); white-space: nowrap; letter-spacing: .01em; }
.gt-week { position: absolute; top: 0; height: 28px; line-height: 28px; padding-left: 7px; border-left: 1px solid var(--gt-week); font-size: .76rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; font-variant-numeric: tabular-nums; }
.gt-today-pill {
  position: absolute; top: 5px; transform: translateX(-50%); z-index: 3; padding: 1px 8px; border-radius: 99px; white-space: nowrap;
  background: var(--accent); color: var(--accent-ink); font-size: .68rem; font-weight: 800; letter-spacing: .03em; box-shadow: 0 0 0 3px var(--surface);
}

/* task name column (iPad / Mac) */
.gt-label {
  position: sticky; left: 0; z-index: 3; height: var(--gt-row); min-width: 0; margin: 0; padding: 0 14px; border: 0; border-radius: 0;
  border-right: 1px solid var(--line); border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
}
.gt-label:hover { background: var(--surface-2); }
.gt-label strong { font-size: .88rem; font-weight: 650; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gt-label small { font-size: .74rem; color: var(--muted); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* lanes: Monday lines + shaded weekends, drawn with one background so they never drift */
.gt-lane {
  position: relative; height: var(--gt-row); border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background-image: linear-gradient(90deg, var(--gt-week) 0 1px, transparent 1px),
    linear-gradient(90deg, transparent 0 calc(var(--gt-px) * 5), var(--gt-weekend) calc(var(--gt-px) * 5) calc(var(--gt-px) * 7));
  background-size: calc(var(--gt-px) * 7) 100%;
}
.gt-grid > .gt-lane:last-of-type, .gt-grid > .gt-label:nth-last-child(3) { border-bottom: 0; }

/* bars */
.gantt .bar {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; height: 28px; min-width: 10px; margin: 0; padding: 0 10px;
  display: flex; align-items: center; border: 0; border-radius: 8px; cursor: pointer; overflow: hidden; white-space: nowrap;
  font: 650 .78rem/1 var(--font); letter-spacing: .005em; text-align: left;
  background: var(--gt-ns); color: var(--gt-ns-ink); box-shadow: 0 1px 2px rgba(0,0,0,.14), inset 0 1px 0 rgba(255,255,255,.12);
  transition: filter var(--dur), box-shadow var(--dur);
}
.gantt .bar span { overflow: hidden; text-overflow: ellipsis; }
.gantt .bar:hover { filter: brightness(1.07); box-shadow: 0 3px 10px rgba(0,0,0,.18); }
.gantt .bar:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.gantt .bar.st-in-progress { background: var(--gt-ip); color: var(--gt-ip-ink); }
.gantt .bar.st-blocked { background: var(--gt-blk); color: var(--gt-blk-ink); }
.gantt .bar.st-done { background: var(--gt-done); color: var(--gt-done-ink); }
.gantt .bar.overdue { background: var(--gt-over); color: var(--gt-over-ink); }
.gt-side { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; font-size: .78rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; pointer-events: none; }

/* iPhone: no name column (spacer = bar start) */
.gantt.is-phone .gt-lane { white-space: nowrap; }
.gantt.is-phone .gt-sp { display: inline-block; height: 1px; vertical-align: top; }
/* iPhone: no name column - the name sits above its bar and slides along so it stays readable while scrolling */
.gantt.is-phone .gt-pname {
  position: sticky; left: 8px; right: 8px; z-index: 2; display: inline-block; max-width: 300px; margin-top: 7px; vertical-align: top;
  font-size: .8rem; font-weight: 650; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25;
}
.gantt.is-phone .bar { top: auto; bottom: 8px; transform: none; height: 20px; border-radius: 6px; padding: 0 6px; }

.gantt .today-line { position: absolute; top: var(--gt-head); bottom: 0; width: 2px; z-index: 1; background: var(--accent); opacity: .85; pointer-events: none; border-radius: 2px; }

/* tap a bar: small card with dates */
.gt-pop {
  position: absolute; z-index: 12; width: min(300px, calc(100% - 16px)); padding: .65rem .8rem .7rem; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow-2); font-size: .9rem;
}
.gt-pop p { margin: .15rem 0; }
.gt-pop-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.gt-pop-head b { line-height: 1.3; padding-top: .2rem; }
.gt-pop-x { flex: none; display: grid; place-items: center; width: 32px; height: 32px; margin: -2px -6px 0 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.gt-pop-x:hover { background: var(--surface-3); }
.gt-pop-foot { display: flex; align-items: center; gap: .45rem; margin-top: .45rem; font-weight: 650; font-size: .85rem; }
.gt-pop-foot .btn { margin-left: auto; }

.sched-actions { flex-wrap: wrap; }
@media (max-width: 719.98px) {
  .schedule-tab .page-head { gap: .6rem; }
  .sched-actions { flex: 1 1 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .5rem; }
  .sched-actions .segmented { display: grid; grid-template-columns: 1fr 1fr; }
  .sched-actions .seg { padding-left: .5rem; padding-right: .5rem; }
  .sched-actions #regenerate-schedule { min-width: var(--tap); padding: 0; }
  .sched-actions #regenerate-schedule .lbl { display: none; }
  .gantt.is-phone .gt-top { padding: .7rem .9rem; }
  .gantt.is-phone .gt-legend { gap: .25rem .75rem; font-size: .74rem; }
}

/* ---------- Generate schedule sheet ---------- */
.modal.gen-modal { width: min(720px, 100%); }
.gen-form .gen-intro { margin: 0 0 .8rem; }
.gen-top { display: flex; gap: .4rem 1.2rem; align-items: flex-end; flex-wrap: wrap; }
.gen-top .field { margin: 0; } .gen-top .field.check { padding-bottom: .75rem; }
.gen-top input[type=date] { width: auto; }
.gen-off-row { display: flex; gap: .5rem; align-items: center; }
.gen-off-row input { width: auto; max-width: 12rem; }
.gen-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; } .gen-chips:empty { display: none; }
.gen-chip { display: inline-flex; align-items: center; gap: .15rem; padding: .1rem .2rem .1rem .7rem; border-radius: 99px; background: var(--surface-3); font-size: .85rem; font-weight: 600; }
.gen-chip button { display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.gen-steps { margin: .9rem 0 0; border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; background: var(--surface); }
.gen-step { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 200px); gap: .6rem; align-items: center; padding: .45rem .8rem; border-top: 1px solid var(--line); }
.gen-step:first-child { border-top: 0; }
.gen-step:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.gen-name { display: flex; align-items: center; gap: .7rem; min-width: 0; cursor: pointer; margin: 0; }
.gen-name input { flex: none; }
.gen-name span { display: grid; min-width: 0; }
.gen-name b { font-size: .92rem; font-weight: 650; line-height: 1.25; }
.gen-name small { font-size: .74rem; color: var(--muted); }
.gen-days { display: inline-flex; align-items: center; gap: .3rem; margin: 0; }
.gen-days input { width: 3.6rem; min-height: 40px; padding: .25rem .3rem; text-align: center; font-variant-numeric: tabular-nums; }
.gen-days span { font-size: .78rem; color: var(--muted); }
.gen-step select { min-height: 40px; padding: .25rem 2rem .25rem .6rem; font-size: .88rem; }
.gen-step.off .gen-name span, .gen-step.off .gen-days, .gen-step.off select { opacity: .4; }
.gen-summary { margin: .7rem 0 0; padding: .6rem .85rem; border-radius: 12px; background: var(--accent-soft); color: var(--ink); font-size: .92rem; }
.gen-summary:empty { display: none; }
@media (max-width: 559.98px) {
  .gen-step { grid-template-columns: minmax(0, 1fr) auto; row-gap: .35rem; padding: .55rem .7rem; }
  .gen-step select { grid-column: 1 / -1; margin-left: 2rem; width: calc(100% - 2rem); }
  .gen-step.off select { display: none; }
}
.form.gen-form { display: block; }
.gen-form > * + * { margin-top: .9rem; }
.gen-form .gen-top .field { flex: none; }
.gen-form .gen-top .field.check { align-self: flex-end; padding: 0; height: 48px; display: flex; align-items: center; }
.gen-form .gen-top .field.check label { display: flex; align-items: center; margin: 0; }
.gen-form .gen-off { margin-top: .9rem; }
