:root {
  --bg: #f5f6f8;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --check: #64748b;
  --band: #d6e4fb;
  --band-edge: #7aa5ea;
  --good: #15803d;
  --bad: #dc2626;
  --bad-bg: #fdf1f1;
  --change: #d97706;
  --label-w: 220px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
.page { max-width: 1400px; margin: 0 auto; padding: 22px 24px 40px; }
h1 { font-size: 1.35rem; margin: 0; }
.title-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.title-kicker { display: block; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); }
.tag { font-size: 0.75rem; font-weight: 700; color: #92400e; background: #fef3c7; border-radius: 99px; padding: 2px 10px; }
button.small { padding: 4px 10px; font-size: 0.85rem; }
.lead { margin: 0; color: var(--muted); }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 7px; border: 1px solid transparent; padding: 7px 14px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #1d4ed8; }
button.secondary { background: #fff; border-color: #d1d5db; }
button.secondary:hover:not(:disabled) { background: #f3f4f6; }
select, input[type=number] { border: 1px solid #d1d5db; border-radius: 7px; padding: 6px 8px; background: #fff; }
input[type=number] { width: 56px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.head-right { display: flex; gap: 12px; align-items: center; }
.status { font-size: 0.85rem; color: var(--muted); }
.status.ok { color: var(--good); }
.status.bad { color: var(--bad); }

.example-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: -4px 0 16px; }
.example-bar .spacer { flex: 1; }
.example-bar label { font-weight: 700; font-size: 0.92rem; }
.example-bar select { min-width: 260px; }
button.add-record { display: block; width: 100%; margin-top: 8px; background: #fff; border: 1px dashed #cbd5e1; color: var(--accent); font-weight: 600; padding: 9px; border-radius: 10px; }
button.add-record:hover:not(:disabled) { background: #f8fafc; border-color: var(--accent); }
.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.wins { display: inline-flex; gap: 16px; flex-wrap: wrap; }
.schedule { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #d1d5db; border-radius: 9px; padding: 4px 6px 4px 12px; }
.schedule-label { font-weight: 600; font-size: 0.92rem; }
.schedule input[type=number] { width: 60px; }
.schedule input[type=date] { border: 1px solid #d1d5db; border-radius: 7px; padding: 5px 8px; }
.hint { margin: -4px 0 10px; font-size: 0.88rem; color: var(--muted); }
.toolbar .win { font-size: 0.9rem; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.toolbar.disabled .win { opacity: 0.6; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px 16px; }
.summary { margin: 0 0 10px; font-weight: 600; }
.summary.good { color: var(--good); }
.summary.bad { color: var(--bad); }
.summary.warn { color: #b45309; }

/* ---------- Timeline ---------- */
.tl { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; user-select: none; -webkit-user-select: none; }
.tl.dragging, .tl.dragging * { cursor: grabbing !important; }
.tl-row { display: grid; grid-template-columns: var(--label-w) 1fr; border-top: 1px solid var(--line); position: relative; }
.tl-row.tl-head { border-top: none; height: 34px; }
.tl-row.tl-checks { height: 72px; }
.tl-row.record { height: 64px; }
.tl-row.record.missed { background: var(--bad-bg); }
.tl-row.record.active { background: #f5f9ff; }
.tl-row.empty { height: 56px; color: var(--muted); }
.tl-row.empty .tl-track { display: flex; align-items: center; padding-left: 14px; }
.tl-label { padding: 8px 10px 8px 16px; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0; background: inherit; position: relative; z-index: 2; }
.tl-label strong { font-size: 0.95rem; }
.tl-label .sub { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-label .sub.good { color: var(--good); }
.tl-label .sub.bad { color: var(--bad); font-weight: 600; }
.label-line { display: flex; align-items: center; gap: 4px; }
.label-input { border: 1px solid transparent; border-radius: 5px; padding: 1px 4px; margin-left: -5px; font-weight: 700; width: 100%; min-width: 0; background: transparent; }
.label-input:hover:not(:disabled), .label-input:focus { border-color: #d1d5db; background: #fff; }
.label-input:disabled { color: inherit; }
.record.missed .label-input { color: var(--bad); }
.row-remove { visibility: hidden; background: none; border: none; color: var(--muted); font-size: 1.15rem; padding: 0 4px; line-height: 1; }
.tl-row:hover .row-remove, .row-remove:focus-visible { visibility: visible; }
.row-remove:hover { color: var(--bad); }

.tl-track { position: relative; min-width: 0; }
.tl-lines { position: absolute; left: var(--label-w); right: 0; top: 0; bottom: 0; pointer-events: none; z-index: 1; }
.vline { position: absolute; top: 0; bottom: 0; width: 0; }
.vline.month { border-left: 1px solid var(--line); }
.vline.check { top: 34px; border-left: 1.5px dashed rgba(100, 116, 139, 0.35); }
.vline.check.active { border-left: 2px solid var(--accent); }
.month-label { position: absolute; top: 9px; padding-left: 6px; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* Checks (grabbers) */
.checks-track { cursor: default; }
.grabber { position: absolute; top: 12px; transform: translateX(-50%); width: 22px; height: 46px; display: flex; flex-direction: column; align-items: center; cursor: grab; z-index: 3; touch-action: none; }
.grabber:focus-visible { outline: none; }
.grab-handle { width: 12px; height: 28px; border-radius: 6px; background: var(--check); display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 3px; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .08s, background .08s; }
.grab-handle span { width: 6px; height: 1.5px; background: rgba(255,255,255,.8); border-radius: 1px; }
.grabber:hover .grab-handle, .grabber:focus-visible .grab-handle { background: #475569; transform: scale(1.12); }
.grabber.active .grab-handle, .grabber:focus-visible .grab-handle { background: var(--accent); }
.grab-date { font-size: 0.68rem; color: var(--muted); white-space: nowrap; margin-top: 3px; opacity: 0; transition: opacity .1s; pointer-events: none; }
.grabber:hover .grab-date, .grabber:focus-visible .grab-date, .grabber.active .grab-date { opacity: 1; }
.grab-remove { position: absolute; top: -10px; left: 15px; width: 18px; height: 18px; border-radius: 50%; padding: 0; border: none; background: #fff; color: var(--muted); box-shadow: 0 0 0 1px #d1d5db; font-size: 0.8rem; line-height: 18px; display: none; }
.grabber:hover .grab-remove, .grabber:focus-within .grab-remove { display: block; }
.tl.dragging .grab-remove { display: none !important; }
.grab-remove:hover { background: var(--bad); color: #fff; box-shadow: none; }

/* Record marks */
.band { position: absolute; top: 50%; height: 18px; margin-top: -9px; background: var(--band); border: 1px solid var(--band-edge); border-radius: 4px; cursor: grab; touch-action: none; }
.band:hover { filter: brightness(0.96); }
.band.missed-band { background: repeating-linear-gradient(135deg, #fde2e2 0 6px, #fff5f5 6px 12px); border: 1.5px dashed var(--bad); }
.warnings { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.warnings li { display: flex; gap: 10px; align-items: flex-start; background: var(--bad-bg); border: 1px solid #fecaca; border-left: 4px solid var(--bad); border-radius: 8px; padding: 8px 12px; font-size: 0.9rem; }
.warnings strong { color: var(--bad); }
.warnings li.ok { background: #f0fdf4; border-color: #bbf7d0; border-left-color: var(--good); }
.warnings li.ok strong, .warnings li.ok .warn-icon { color: var(--good); }
.warnings li.near { background: #fffbeb; border-color: #fde68a; border-left-color: #d97706; }
.warnings li.near strong, .warnings li.near .warn-icon { color: #b45309; }
.tl-label .sub.warn { color: #b45309; font-weight: 600; }
.warn-icon { color: var(--bad); font-size: 1.05rem; line-height: 1.3; }
.pickup { position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: var(--good); border: 2px solid #fff; z-index: 2; pointer-events: none; }
.notice-line { position: absolute; top: 50%; height: 2.5px; margin-top: -1.25px; background: var(--good); pointer-events: none; }
.notice-label { position: absolute; top: 50%; margin-top: 11px; transform: translateX(-50%); font-size: 0.75rem; font-weight: 700; color: var(--good); white-space: nowrap; pointer-events: none; }
.paid { position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; background: #1f2937; transform: rotate(45deg); z-index: 2; cursor: grab; touch-action: none; }
.missed-mark { position: absolute; top: 50%; transform: translate(12px, -50%); color: var(--bad); font-weight: 700; font-size: 0.85rem; white-space: nowrap; pointer-events: none; display: flex; align-items: center; gap: 4px; }
.missed-mark .x { font-size: 1.15rem; }
.change { position: absolute; top: 50%; margin: -25px 0 0 -6px; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid var(--change); z-index: 2; cursor: grab; touch-action: none; }
.change::before { content: ''; position: absolute; left: -10px; top: -6px; width: 20px; height: 20px; } /* bigger grab area */
.change.after { border-bottom-color: #d1d5db; }
.change-label { position: absolute; top: 50%; margin-top: -29px; padding-left: 9px; font-size: 0.72rem; font-weight: 700; color: var(--change); white-space: nowrap; z-index: 2; cursor: grab; touch-action: none; }
.change-label.below { margin-top: 12px; }
.change.below { margin-top: 14px; }
.change-label.after { color: #9ca3af; font-weight: 600; }
.tl-row.record.selected { box-shadow: inset 3px 0 0 var(--accent); }
.row-edit { background: none; border: 1px solid #d1d5db; border-radius: 6px; font-size: 0.75rem; padding: 1px 8px; color: var(--accent); flex: none; }
.row-edit:hover { background: #eff6ff; }
.tl-row.selected .row-edit { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Details panel */
.details { margin-top: 14px; }
.details-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.details-head h2 { margin: 0; font-size: 1.05rem; }
.details-result { margin: 4px 0 12px; font-weight: 600; }
.details-result.good { color: var(--good); }
.details-result.bad { color: var(--bad); }
.details-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field-label { font-size: 0.85rem; font-weight: 700; }
.details input[type=date] { border: 1px solid #d1d5db; border-radius: 7px; padding: 5px 8px; width: max-content; }
.change-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.change-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 6px 10px; font-size: 0.9rem; }
.change-note { font-size: 0.8rem; color: var(--muted); }
.icon-btn { background: none; border: none; font-size: 1.15rem; line-height: 1; padding: 0 6px; color: var(--muted); }
.icon-btn:hover { color: var(--bad); }
.muted { color: var(--muted); font-size: 0.875rem; margin: 0 0 6px; }
.small { font-size: 0.8rem; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; font-size: 0.82rem; color: var(--muted); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend i { display: inline-block; font-style: normal; }
.lg-grab { width: 8px; height: 16px; border-radius: 4px; background: var(--check); }
.lg-band { width: 20px; height: 10px; border-radius: 2px; background: var(--band); border: 1px solid var(--band-edge); }
.band.risk-band { background: #fef3c7; border: 1.5px dashed #d97706; }
.lg-band-risk { background: #fef3c7; border: 1.5px dashed #d97706; }
.lg-band-missed { background: repeating-linear-gradient(135deg, #fde2e2 0 4px, #fff5f5 4px 8px); border: 1.5px dashed var(--bad); }
.lg-pick { width: 11px; height: 11px; border-radius: 50%; background: var(--good); }
.lg-paid { width: 9px; height: 9px; background: #1f2937; transform: rotate(45deg); margin: 0 2px; }
.lg-miss { color: var(--bad); font-weight: 700; }
.lg-change { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid var(--change); }

.help { font-size: 0.85rem; color: var(--muted); margin: 10px 2px 0; }

.drag-tip { position: fixed; transform: translate(-50%, -150%); background: #111827; color: #fff; font-size: 0.8rem; padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; z-index: 20; }

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; max-width: 560px; font-size: 0.9rem; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.ok { background: #14532d; }
.toast.bad { background: #7f1d1d; }

@media (max-width: 700px) { :root { --label-w: 150px; } }
