/* ============================================================
   Reset & design tokens
   ============================================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fff;
  --bg2: #f5f4f1;
  --bg3: #eceae6;
  --text: #1a1a1a;
  --text2: #666;
  --text3: #aaa;
  --border: rgba(0, 0, 0, .11);
  --border2: rgba(0, 0, 0, .2);
  --red: #dc2626;
  --grn-bg: #f0fdf4;
  --grn-t: #15803d;
  --blu-bg: #eff6ff;
  --blu-t: #1d4ed8;
}

html {
  height: 100%;
}

body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ============================================================
   App shell & tabs
   ============================================================ */
.app {
  width: 100%;
  height: 100%;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
  flex-shrink: 0;
}

.tab {
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  background: none;
  font-family: inherit;
  touch-action: manipulation;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
  font-weight: 500;
}

/* ============================================================
   Toolbar & form controls
   ============================================================ */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
}

.toolbar input[type=text] {
  flex: 1;
  min-width: 130px;
}

.toolbar input[type=number] {
  width: 86px;
}

input[type=text],
input[type=number],
input[type=date],
select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
select:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .07);
}

select {
  padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn:hover {
  background: var(--bg2);
}

.btn:active {
  transform: scale(.98);
}

.btn.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn.primary:hover {
  opacity: .85;
}

.btn.xs {
  height: 26px;
  padding: 0 8px;
  font-size: 11px;
}

.btn.sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.btn.danger {
  color: var(--red);
}

.btn.danger:hover {
  background: var(--red-bg);
}

/* ============================================================
   Task cards
   ============================================================ */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 8px;
}

.card:hover {
  border-color: var(--border2);
}

.card-hdr {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.card-hdr:hover {
  background: var(--bg2);
}

.ch-arr {
  font-size: 9px;
  color: var(--text3);
  transition: transform .15s;
  width: 12px;
  flex-shrink: 0;
}

.ch-arr.open {
  transform: rotate(90deg);
}

.ch-ttl {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

.ch-ttl.done {
  text-decoration: line-through;
  color: var(--text3);
}

.card-body {
  border-top: 1px solid var(--border);
  padding: 12px;
}

/* ============================================================
   Badges
   ============================================================ */
.bdgs {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.bdg {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
}

.b-td {
  background: var(--bg2);
  color: var(--text2);
}

.b-ip {
  background: var(--blu-bg);
  color: var(--blu-t);
}

.b-dn {
  background: var(--grn-bg);
  color: var(--grn-t);
}

.b-dr {
  background: var(--bg2);
  color: var(--text2);
  border: 1px solid var(--border);
}

/* ============================================================
   Progress bar
   ============================================================ */
.prog {
  height: 3px;
  background: var(--border);
  margin: 0 12px 6px;
  border-radius: 2px;
  overflow: hidden;
}

.prog-bar {
  height: 100%;
  background: var(--text);
  border-radius: 2px;
  transition: width .3s;
}

/* ============================================================
   Sub-cards (subtasks)
   ============================================================ */
.sub-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  overflow: hidden;
}

.sub-hdr {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg2);
  cursor: pointer;
  touch-action: manipulation;
}

.sub-hdr:hover {
  background: var(--bg3);
}

.sub-arr {
  font-size: 9px;
  color: var(--text3);
  transition: transform .15s;
  flex-shrink: 0;
}

.sub-arr.open {
  transform: rotate(90deg);
}

.sub-ttl {
  flex: 1;
  font-size: 13px;
}

.sub-ttl.done {
  text-decoration: line-through;
  color: var(--text3);
}

.sub-body {
  padding: 10px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Checkbox
   ============================================================ */
.chk {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border-radius: 4px;
  border: 1.5px solid var(--border2);
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  flex-shrink: 0;
}

.chk.on {
  background: var(--text);
  border-color: var(--text);
}

.chk.on::after {
  content: '';
  width: 8px;
  height: 5px;
  border-left: 1.5px solid var(--bg);
  border-bottom: 1.5px solid var(--bg);
  transform: rotate(-45deg) translateY(-1px);
  display: block;
}

/* ============================================================
   Dependencies
   ============================================================ */
.dep-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--bg2);
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.dep-type {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 500;
  background: var(--blu-bg);
  color: var(--blu-t);
  white-space: nowrap;
}

.add-dep {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
}

.add-dep select {
  font-size: 12px;
  height: 30px;
}

/* ============================================================
   Section labels, separators & misc form rows
   ============================================================ */
.slbl {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 12px 0 6px;
  display: block;
}

.slbl:first-child {
  margin-top: 0;
}

.sep {
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 10px;
}

.row-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.row-form input[type=text] {
  flex: 1;
  min-width: 100px;
}

.row-form input[type=number] {
  width: 78px;
}

.hint {
  font-size: 11px;
  color: var(--text3);
  padding: 6px 10px;
  background: var(--bg2);
  border-radius: 6px;
  margin-bottom: 8px;
}

.empty-hint {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text3);
  font-size: 13px;
}

/* ============================================================
   Inline rename
   ============================================================ */
.rename-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s;
  line-height: 1;
  flex-shrink: 0;
  touch-action: manipulation;
}

.card-hdr:hover .rename-btn,
.sub-hdr:hover .rename-btn {
  opacity: 1;
}

.rename-btn:hover {
  background: var(--bg3);
  color: var(--text);
}

.rename-input {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-bottom: 2px solid var(--text);
  outline: none;
  background: transparent;
  padding: 0;
  font-family: inherit;
  color: var(--text);
  min-width: 60px;
}

.rename-overlay {
  position: absolute;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 4px 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
  display: flex;
  gap: 6px;
  align-items: center;
  z-index: 100;
}

.rename-overlay input {
  border: none;
  border-bottom: 2px solid var(--text);
  outline: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text);
  min-width: 120px;
  padding: 2px 0;
}

/* ============================================================
   Project bar & floating action buttons
   ============================================================ */
.proj-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.proj-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  position: fixed;
  right: 1rem;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #000;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  z-index: 1000;
  transition: transform .15s;
  touch-action: manipulation;
}

.icon-btn:hover {
  transform: scale(1.05);
}

.sort-btn {
  top: 5.5rem;
}

.sort-btn,
.proj-btn {
  width: 40px;
  height: 40px;
}

.proj-btn {
  top: 1rem;
}

.sort-icon {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 18px;
  height: 14px;
}

.sort-icon span {
  display: block;
  width: 100%;
  height: 2px;
  background: #fff;
  border-radius: 1px;
}

.proj-icon {
  font-size: 18px;
  line-height: 1;
}

.proj-unsaved {
  font-size: 11px;
  color: var(--text3);
  margin-left: 4px;
}

.proj-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 320px;
  overflow-y: auto;
  margin: 12px 0;
}

.proj-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background .1s;
}

.proj-item:hover {
  background: var(--bg2);
}

.proj-item-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

.proj-item-date {
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
}

.proj-user {
  font-size: 12px;
  color: var(--text3);
  white-space: nowrap;
}

.signout-btn {
  top: 10rem;
  font-size: 16px;
}

/* ============================================================
   Auth gate (Supabase Auth login/signup)
   ============================================================ */
.auth-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-box {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-title {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 8px;
}

.auth-msg {
  font-size: 12px;
  color: var(--text2);
  text-align: center;
}

.auth-msg.auth-error {
  color: var(--red);
}

.auth-switch {
  align-self: center;
  border: none;
  background: none;
  color: var(--text2);
  text-decoration: underline;
}

/* ============================================================
   Timeline (Gantt)
   ============================================================ */
.tl-wrap {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
  user-select: none;
  touch-action: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.tl-labels {
  flex: 0 0 180px;
  padding-top: 44px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}

.tl-content {
  flex: 1;
  overflow: auto;
}

.tl-label-row {
  height: 24px;
  margin-bottom: 9.6px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-label-row.tl-label-sub {
  color: var(--text2);
  font-size: 12px;
}

/* Timeline x-axis scale slider bar (bottom of the timeline) */
.tl-scale-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg2);
}

.tl-scale-ico {
  font-size: 13px;
  color: var(--text2);
  user-select: none;
}

.tl-scale-slider {
  flex: 1;
  cursor: ew-resize;
  accent-color: var(--accent, #2563eb);
}

.tl-scale-val {
  flex: 0 0 auto;
  min-width: 56px;
  text-align: right;
  font-size: 11px;
  color: var(--text3);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Editor panel
   ============================================================ */
.ep {
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 14px;
  margin-top: 12px;
}

.ep-ttl {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ef {
  margin-bottom: 10px;
}

.ef label {
  display: block;
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}

.ef input,
.ef select {
  width: 100%;
}

.ep-acts {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

/* ============================================================
   Modal
   ============================================================ */
.modal-ov {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .22);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 14px;
  padding: 20px;
  min-width: 260px;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .1);
}

.modal h3 {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 14px;
}

.mf {
  margin-bottom: 10px;
}

.mf label {
  display: block;
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}

.mf input,
.mf select {
  width: 100%;
}

.m-acts {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ============================================================
   Calendar (week) view
   ============================================================ */
.cal-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg2);
  flex-shrink: 0;
}

.cal-range {
  font-size: 12px;
  color: var(--text2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cal-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  cursor: pointer;
}

.cal-check input {
  width: auto;
  height: auto;
  margin: 0;
  cursor: pointer;
}

.cal-wrap {
  display: flex;
  flex: 1;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.cal-grid {
  display: flex;
  flex: 1;
  min-height: 0;
}

.cal-gutter {
  flex: 0 0 46px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg2);
}

.cal-gutter-body {
  flex: 1;
  position: relative;
}

/* Vertical inset matches each day frame's inner area (frame border + inner pad),
   so the hour ticks line up with the task fields inside the frames. */
.cal-gutter-inner {
  position: absolute;
  left: 0;
  right: 0;
  top: 8px;
  bottom: 8px;
}

.cal-tick {
  position: absolute;
  right: 6px;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--text3);
  font-variant-numeric: tabular-nums;
}

.cal-day {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cal-col-hdr {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cal-col-hdr.cal-weekend {
  color: var(--text3);
  background: var(--bg3);
}

.cal-col-hdr.cal-today {
  color: var(--blu-t);
  background: var(--blu-bg);
  font-weight: 600;
}

/* Each day is framed like a timeline parent: a gray rounded outline with a light
   fill. Horizontal margin keeps neighbouring frames from touching; the task fields
   live in .cal-day-inner, inset by the same gap the timeline leaves around its bars. */
.cal-day-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  margin: 0 4px;
  border: 2px solid #cbd5e1;
  border-radius: 16px;
  background: rgba(249, 250, 251, 0.5);
}

.cal-day-inner {
  position: absolute;
  inset: 6px;
}

.cal-events {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
}

.cal-strip {
  position: absolute;
  border: 2px solid #1a1a1a;
  border-radius: 12px;
  cursor: pointer;
  box-sizing: border-box;
  min-height: 4px;
  overflow: hidden;
}

/* Owner avatar — its centre must land on the corner-radius arc centre, at (12,12)
   from the border-box corner. left/top are measured from the padding box (inside the
   2px border), so offset = 12 - 2 (border) - 8 (half of the 16px icon) = 2px. */
.cal-own {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}

.cal-own-photo {
  background: #fff;
  border: 1px solid #e5e7eb;
}

.cal-own-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.cal-own-init {
  background: #1d4ed8;
  color: #fff;
  font-size: 8px;
  font-weight: 600;
}

.cal-own-none {
  background: #9ca3af;
}

.cal-strip:hover {
  filter: brightness(0.95);
}

.cal-strip-sel {
  border-width: 4px;
  z-index: 3;
}

.cal-ev {
  position: absolute;
  border: 2px solid #1a1a1a;
  border-radius: 12px;
  padding: 2px 7px;
  overflow: hidden;
  cursor: pointer;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 14px;
}

/* Resize affordance: grabbing the top/bottom edge of a task's true start/end
   thickens that border inward (box-sizing:border-box keeps the box the same
   size) to signal it's draggable to change the task's length. */
.cal-ev.cal-edge-top {
  border-top-width: 6px;
}
.cal-ev.cal-edge-bottom {
  border-bottom-width: 6px;
}

.cal-ev:hover {
  filter: brightness(0.97);
}

.cal-ev-sel {
  border-width: 4px;
  z-index: 2;
}

/* critical path: red dashed outline touching the black border, as in the timeline
   (outline-offset 0 => the red's inner edge meets the black border's outer edge) */
.cal-crit {
  outline: 2px dashed #e11d2b;
  outline-offset: 0;
}

.cal-ev-ttl {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 15px;   /* clear the owner avatar sitting at the top-left corner */
}

.cal-ev-dur {
  font-size: 10px;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}
