/* Timeboxing — calendar styles that are easier to express as plain CSS */
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }

/* ── Form fields & buttons ── */
.field {
  width: 100%; border-radius: .5rem; border: 1px solid #cbd5e1; background: #fff;
  padding: .375rem .625rem; font-size: .875rem; line-height: 1.25rem;
}
.field:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 1px #6366f1; }
.field:disabled { background: #f8fafc; color: #94a3b8; }
.field-label { display: block; font-size: .75rem; font-weight: 500; color: #475569; margin-bottom: .25rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .375rem;
  padding: .5rem .875rem; font-size: .875rem; font-weight: 500; border-radius: .5rem;
  transition: background-color .15s, color .15s;
}
.btn:focus-visible { outline: 2px solid #6366f1; outline-offset: 2px; }
.btn-sm { padding: .375rem .625rem; font-size: .75rem; }
.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-secondary { background: #fff; color: #334155; border: 1px solid #cbd5e1; }
.btn-secondary:hover { background: #f8fafc; }
.btn-ghost { color: #475569; }
.btn-ghost:hover { background: #f1f5f9; }

/* ── Countdown ── */
.tb-timer {
  flex: none; padding: 0 4px; border-radius: 4px; font-size: 11px; font-weight: 700;
  font-variant-numeric: tabular-nums; background: #fff; color: #b45309; box-shadow: 0 0 0 1px rgb(245 158 11 / .45);
}
.status-paused .tb-timer { color: #0369a1; box-shadow: 0 0 0 1px rgb(14 165 233 / .45); }
.tb-timer.is-over { background: #e11d48; color: #fff; box-shadow: none; }
#running-pill.is-over { background: #fff1f2; color: #be123c; border-color: #fecdd3; }

.calendar-scroll::-webkit-scrollbar { height: 8px; width: 8px; }
.calendar-scroll::-webkit-scrollbar-track { background: #f1f5f9; }
.calendar-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

details > summary::-webkit-details-marker { display: none; }

/* ── Toasts ── */
.toast-enter { animation: toastIn .25s ease-out forwards; }
.toast-leave { animation: toastOut .25s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(12px); } }

/* ── Priority palette ── */
.prio-critical { --p: #ef4444; --p-bg: #fef2f2; --p-fg: #7f1d1d; }
.prio-high     { --p: #f97316; --p-bg: #fff7ed; --p-fg: #7c2d12; }
.prio-medium   { --p: #f59e0b; --p-bg: #fffbeb; --p-fg: #78350f; }
.prio-low      { --p: #3b82f6; --p-bg: #eff6ff; --p-fg: #1e3a8a; }
.prio-very_low { --p: #94a3b8; --p-bg: #f8fafc; --p-fg: #334155; }
.legend-dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; background: var(--p); }

/* ── Day grid ── */
.day-grid {
  background-image:
    linear-gradient(to bottom, #eef2f7 1px, transparent 1px),
    linear-gradient(to bottom, #f6f8fb 1px, transparent 1px);
  background-size: 100% var(--hour), 100% calc(var(--hour) / 2);
  cursor: cell;
}
.day-grid.drop-target { background-color: #eef2ff80; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: #e11d48; z-index: 16; pointer-events: none; }
.now-line::before { content: ''; position: absolute; left: -4px; top: -4px; width: 10px; height: 10px; border-radius: 9999px; background: #e11d48; }

/* ── Task blocks ── */
.task-block {
  position: absolute; left: 3px; right: 3px; min-height: 22px; z-index: 10;
  display: flex; border-radius: 8px; cursor: grab;
  background: var(--p-bg); color: var(--p-fg);
  border: 1px solid color-mix(in srgb, var(--p) 35%, transparent);
  border-left: 4px solid var(--p);
  box-shadow: 0 1px 2px rgb(15 23 42 / .06);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: box-shadow .15s, opacity .15s, filter .15s;
}
.task-block:hover, .task-block:focus-visible { box-shadow: 0 4px 12px rgb(15 23 42 / .12); z-index: 12; outline: none; }
.task-block:focus-visible { box-shadow: 0 0 0 2px #6366f1; }
.task-block.is-chained { outline: 2px solid var(--chain); outline-offset: 1px; }
.task-block.dragging { cursor: grabbing; opacity: .9; z-index: 40; box-shadow: 0 10px 24px rgb(15 23 42 / .25); transition: none; }
.task-block.dragging, .task-block.following { pointer-events: none; }
.task-block.following { opacity: .75; transition: none; }
.task-block.link-target { box-shadow: 0 0 0 3px #6366f1, 0 8px 20px rgb(99 102 241 / .3); }
.task-block.offscreen { display: none; }
.task-block.status-done { opacity: .6; }
.task-block.status-done .tb-title { text-decoration: line-through; }
.task-block.status-started { box-shadow: 0 0 0 2px #fbbf24, 0 4px 12px rgb(245 158 11 / .25); }
.task-block.status-paused { background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgb(148 163 184 / .14) 6px 12px); }

.tb-body { flex: 1; min-width: 0; overflow: hidden; padding: 2px 6px; pointer-events: none; }
.tb-title { display: flex; align-items: center; gap: 4px; font-size: 12px; line-height: 16px; font-weight: 600; }
.tb-meta { display: flex; align-items: center; gap: 5px; font-size: 10.5px; line-height: 14px; opacity: .8; white-space: nowrap; }
.tb-chain-pill { padding: 0 4px; border-radius: 4px; color: #fff; background: var(--chain); font-weight: 600; font-size: 9.5px; }
.tb-live { width: 7px; height: 7px; flex: none; border-radius: 9999px; background: #f59e0b; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* Actions toolbar: visible on hover / focus, always on touch screens */
.tb-actions {
  position: absolute; top: 2px; right: 2px; display: flex; gap: 2px; z-index: 2;
  opacity: 0; transition: opacity .12s;
}
.task-block:hover .tb-actions, .task-block:focus-within .tb-actions { opacity: 1; }
.tb-btn {
  width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; background: #fff; color: #475569; cursor: pointer;
  box-shadow: 0 1px 2px rgb(15 23 42 / .15);
}
.tb-btn:hover { background: #f1f5f9; color: #0f172a; }
.tb-btn-start:hover { background: #fef3c7; color: #b45309; }
.tb-btn-done:hover { background: #d1fae5; color: #047857; }
.tb-btn-delete:hover { background: #ffe4e6; color: #be123c; }

/* Connection ports (one on each side, Obsidian canvas style) */
.tb-port {
  position: absolute; top: 50%; width: 12px; height: 12px; margin-top: -6px; z-index: 3;
  border-radius: 9999px; background: #fff; border: 2px solid var(--chain, #6366f1);
  cursor: crosshair; opacity: 0; transition: opacity .12s, transform .12s; touch-action: none;
}
.tb-port::after { content: ''; position: absolute; inset: -8px; } /* larger hit area */
.tb-port-in  { left: -8px; }
.tb-port-out { right: -8px; }
.task-block:hover .tb-port, .task-block:focus-within .tb-port { opacity: 1; }
.tb-port:hover { transform: scale(1.25); background: var(--chain, #6366f1); }

.tb-resize { position: absolute; left: 0; right: 0; bottom: -2px; height: 8px; cursor: ns-resize; touch-action: none; }
.tb-resize::after {
  content: ''; position: absolute; left: 50%; bottom: 3px; width: 18px; height: 3px; margin-left: -9px;
  border-radius: 2px; background: currentColor; opacity: 0; transition: opacity .12s;
}
.task-block:hover .tb-resize::after { opacity: .35; }

@media (hover: none) {
  .tb-actions, .tb-port { opacity: 1; }
  .tb-resize { height: 14px; }
  .tb-resize::after { opacity: .3; }
}

/* Very short blocks: compact layout */
.task-block.is-short .tb-meta { display: none; }
.task-block.is-short .tb-title { font-size: 11px; line-height: 14px; }
.task-block.is-short .tb-btn { width: 18px; height: 18px; }
.task-block.is-narrow .tb-actions { left: 2px; right: auto; top: auto; bottom: 2px; }

/* Chain hover highlight */
.chain-focus .task-block:not(.in-focus) { opacity: .35; }
.chain-focus .chain-arrow:not(.in-focus) { opacity: .2; }

/* ── Arrows ── */
.chain-arrow path.line { fill: none; stroke-width: 2; }
.chain-arrow path.hit { fill: none; stroke: transparent; stroke-width: 12; pointer-events: stroke; cursor: pointer; }
.chain-arrow:hover path.line { stroke-width: 3.5; }
.chain-arrow.stub path.line { stroke-dasharray: 4 3; }
#chain-arrows.busy path.hit { pointer-events: none; }
.link-preview { fill: none; stroke: #6366f1; stroke-width: 2; stroke-dasharray: 6 4; }

/* ── Month view chips ── */
.month-chip {
  font-size: 11px; line-height: 16px; padding: 0 4px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--p-bg); color: var(--p-fg); border-left: 3px solid var(--p);
}
.month-chip.is-chained { box-shadow: inset 0 0 0 1.5px var(--chain); }
.month-chip.status-done { opacity: .55; text-decoration: line-through; }

/* ── Hashtags ── */
.tag {
  display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
  padding: 0 5px; border-radius: 9999px; font-size: 11px; line-height: 16px; font-weight: 600; white-space: nowrap;
  background: hsl(var(--tag-h, 230) 85% 93%); color: hsl(var(--tag-h, 230) 55% 30%);
}
.tb-meta .tag { font-size: 9.5px; line-height: 13px; padding: 0 4px; }
.tag-removable button { margin-left: 1px; font-size: 13px; line-height: 1; opacity: .6; }
.tag-removable button:hover { opacity: 1; }
.tag-editor { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 34px; cursor: text; padding-top: 4px; padding-bottom: 4px; }
.tag-editor input { flex: 1; min-width: 7rem; border: 0; outline: 0; background: transparent; font-size: .875rem; padding: 0; }
.tag-editor:focus-within { border-color: #6366f1; box-shadow: 0 0 0 1px #6366f1; }

/* ── Filters ── */
.filter-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #64748b; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 9999px;
  font-size: 12px; font-weight: 500; color: #334155; background: #fff; border: 1px solid #e2e8f0;
}
.filter-chip:hover { background: #f8fafc; }
.filter-chip[aria-pressed="true"] { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.filter-chip[data-group="tags"] { background: hsl(var(--tag-h) 85% 96%); border-color: hsl(var(--tag-h) 60% 85%); color: hsl(var(--tag-h) 55% 30%); }
.filter-chip[data-group="tags"][aria-pressed="true"] { background: hsl(var(--tag-h) 55% 40%); border-color: hsl(var(--tag-h) 55% 40%); color: #fff; }
.filter-count { font-size: 10px; opacity: .65; font-variant-numeric: tabular-nums; }
.filter-badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9999px; background: #4f46e5; color: #fff;
  font-size: 11px; display: inline-flex; align-items: center; justify-content: center;
}
.active-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 4px 1px 8px; border-radius: 9999px;
  font-size: 12px; font-weight: 500; background: #eef2ff; color: #3730a3;
}
.active-chip[data-remove="tags"] { background: hsl(var(--tag-h) 85% 93%); color: hsl(var(--tag-h) 55% 30%); }
.active-chip span { font-size: 14px; line-height: 1; padding: 0 3px; opacity: .6; }
.active-chip:hover span { opacity: 1; }

/* ═══════════════ App shell & mobile UI ═══════════════ */
.nav-link { color: #475569; }
.nav-link:hover { background: #f1f5f9; }
.nav-link[aria-current="page"] { background: #eef2ff; color: #4338ca; }

/* Bottom tab bar (phones) */
.tab-link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; font-size: 11px; font-weight: 500; color: #64748b;
}
.tab-link[aria-current="page"] { color: #4f46e5; }
.tab-link[aria-current="page"] svg { stroke-width: 2.4; }
.tab-link:active { background: #f8fafc; }

/* Hamburger drawer */
.drawer-link {
  display: flex; align-items: center; gap: .75rem; padding: .7rem .75rem; border-radius: .5rem;
  font-size: .9375rem; font-weight: 500; color: #334155; text-align: left;
}
.drawer-link:hover, .drawer-link:active { background: #f1f5f9; }
.drawer-link[aria-current="page"] { background: #eef2ff; color: #4338ca; }
#drawer:not(.hidden) .drawer-panel { animation: drawerIn .2s ease-out; }
@keyframes drawerIn { from { transform: translateX(-100%); } to { transform: none; } }

/* Bottom sheets slide up on phones */
@media (max-width: 639px) {
  .modal:not(.hidden):not(#drawer) .rounded-t-2xl { animation: sheetUp .22s ease-out; }
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

/* Running task mini player (phones) */
#mini-player.is-over { background: #fff1f2; border-color: #fecdd3; }
#mini-player.is-over #mp-time { color: #be123c; }

/* Task action sheet */
.sheet-primary {
  display: flex; align-items: center; justify-content: center; gap: .5rem; height: 3rem;
  border-radius: .75rem; font-size: 1rem; font-weight: 600;
}
.sheet-primary:active { filter: brightness(.95); }
.sheet-row {
  display: flex; width: 100%; align-items: center; gap: .875rem; padding: .8rem .75rem; border-radius: .5rem;
  font-size: .9375rem; font-weight: 500; color: #334155; text-align: left;
}
.sheet-row:hover, .sheet-row:active { background: #f1f5f9; }
.sheet-row.text-rose-600 { color: #e11d48; }

/* Month view: selected day (phones) */
@media (max-width: 639px) {
  .month-cell.is-selected { background: #eef2ff; box-shadow: inset 0 0 0 2px #6366f1; }
}

/* Week view on phones: 3 days per screen with snapping (like native calendars) */
@media (max-width: 639px) {
  #cal-scroll.cal-week { scroll-snap-type: x mandatory; scroll-padding-left: 2.75rem; }
  .cal-week .day-column { flex: 0 0 calc((100vw - 2.75rem) / 3); scroll-snap-align: start; }
}

/* Filters panel → bottom sheet on phones */
@media (max-width: 639px) {
  details.filters[open] > summary::before {
    content: ""; position: fixed; inset: 0; z-index: 44; background: rgb(15 23 42 / .5); cursor: default;
  }
  details.filters .filter-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; margin: 0;
    max-height: 85dvh; border-radius: 1rem 1rem 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    animation: sheetUp .22s ease-out;
  }
  .filter-chip { padding: 6px 12px; font-size: 13px; }
}

/* Touch screens: the action sheet replaces the tiny hover buttons and ports */
@media (pointer: coarse) {
  .task-block .tb-actions, .task-block .tb-port { display: none; }
  .task-block { cursor: default; }
  .tb-resize { height: 16px; bottom: -4px; }
  .tb-resize::after { opacity: .35; }
}
.task-block { -webkit-tap-highlight-color: transparent; }

/* Compact form controls on phones so the task form fits without scrolling */
@media (max-width: 639px) {
  .field { padding: .375rem .5rem; }
  input[type="date"].field, input[type="time"].field { min-width: 0; font-size: .8125rem; }
}
.auto-grow { min-height: 2.125rem; }
/* Mouse instructions and legend are for desktop; touch users have the menu / help */
@media (pointer: coarse), (max-height: 500px) { .desktop-hint { display: none !important; } }

/* Sync indicator in the header */
.sync-dot {
  position: absolute; right: 6px; bottom: 7px; width: 9px; height: 9px; border-radius: 9999px;
  border: 2px solid #fff; background: #94a3b8;
}
.sync-btn[data-status="idle"] .sync-dot { background: #10b981; }
.sync-btn[data-status="syncing"] .sync-dot { background: #6366f1; animation: pulse 1s ease-in-out infinite; }
.sync-btn[data-status="offline"] .sync-dot { background: #94a3b8; }
.sync-btn[data-status="error"] .sync-dot { background: #e11d48; }
.sync-btn[data-status="signed-out"] { color: #94a3b8; }
.sync-btn[data-status="signed-out"] .sync-dot { display: none; }

/* ── Backlog ── */
.nav-badge:empty { display: none; }
.nav-badge {
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9999px;
  background: #4f46e5; color: #fff; font-size: 11px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
}
.tab-badge { position: absolute; top: 4px; left: calc(50% + 6px); margin: 0; }
.bl-card {
  display: flex; width: 100%; align-items: flex-start; gap: 8px; padding: 7px 9px; border-radius: 8px;
  border: 1px solid #e2e8f0; background: #fff; cursor: grab; text-align: left;
}
.bl-card:hover { border-color: #a5b4fc; background: #f8faff; }
.bl-ghost {
  position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none; max-width: 16rem;
  padding: 6px 10px; border-radius: 8px; background: #4f46e5; color: #fff; font-size: 12px; font-weight: 600;
  box-shadow: 0 10px 24px rgb(15 23 42 / .25); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.drop-preview {
  position: absolute; left: 3px; right: 3px; z-index: 30; pointer-events: none; min-height: 18px;
  border: 2px dashed #6366f1; background: rgb(99 102 241 / .12); border-radius: 8px;
  font-size: 11px; font-weight: 600; color: #4338ca; padding: 2px 6px; overflow: hidden; white-space: nowrap;
}

/* ── Time's up ── */
.tu-extend { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 3.25rem;
  border-radius: .75rem; background: #f1f5f9; font-weight: 700; color: #334155; }
.tu-extend span { font-size: 10px; font-weight: 500; color: #64748b; }
.tu-extend:active, .tu-chip:active { filter: brightness(.95); }
.tu-chip { padding: .4rem .8rem; border-radius: 9999px; border: 1px solid #e2e8f0; font-size: .875rem; font-weight: 500; }
.tu-chip[aria-pressed="true"] { background: #4f46e5; border-color: #4f46e5; color: #fff; }

/* Edit linked tasks: hashtag toggles */
.ce-tag { display: inline-flex; align-items: center; gap: .25rem; padding: .125rem .375rem .125rem .125rem; border: 1px solid #e2e8f0; border-radius: 9999px; background: #fff; color: #64748b; }
.ce-tag:hover { border-color: #cbd5e1; background: #f8fafc; }
.ce-tag.is-removing { opacity: .55; border-style: dashed; }
.ce-tag.is-removing .tag { text-decoration: line-through; }
.ce-tag.is-adding { border-color: #a7f3d0; background: #ecfdf5; padding-left: .375rem; }
