:root {
  --navy: #1B2451;
  --navy-2: #232e63;
  --gold: #B08D43;
  --gold-bright: #cda755;
  --ink: #11162f;
  --paper: #f6f7fb;
  --card: #ffffff;
  --muted: #8a90a6;
  --line: #e6e8f0;
  --high: #d2553f;
  --low: #6b9bd1;
  --ok: #4caf72;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--navy);
  color: #fff;
  padding: calc(var(--safe-top) + 14px) 18px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(17, 22, 47, 0.18);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--gold); color: var(--navy);
  display: grid; place-items: center;
  font-weight: 800; font-size: 18px;
}
.app-header h1 { font-size: 20px; margin: 0; letter-spacing: .3px; color: #fff; }

.sync { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #c9cee6; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: background .3s; }
.sync-dot.ok { background: var(--ok); }
.sync-dot.syncing { background: var(--gold-bright); animation: pulse 1s infinite; }
.sync-dot.err { background: var(--high); }
.sync-dot.offline { background: #777; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* Quick add */
.quick-add {
  background: var(--navy);
  padding: 0 14px calc(14px) 14px;
}
.quick-add input#addInput {
  width: 100%;
  border: none; border-radius: 12px;
  padding: 14px 16px; font-size: 17px;
  background: #fff; color: var(--ink);
  outline: none;
}
.quick-add-meta { display: flex; gap: 8px; margin-top: 8px; }
.quick-add-meta input, .quick-add-meta select {
  border: none; border-radius: 10px; padding: 9px 10px;
  background: var(--navy-2); color: #fff; font-size: 13px; flex: 1;
  outline: none;
}
.quick-add-meta input[type="date"] { color-scheme: dark; }
.add-btn {
  flex: 0 0 auto;
  background: var(--gold); color: var(--navy);
  border: none; border-radius: 10px; padding: 9px 20px;
  font-weight: 700; font-size: 14px;
}
.add-btn:active { background: var(--gold-bright); }

/* Header right + reminders bell */
.header-right { display: flex; align-items: center; gap: 12px; }
.bell {
  background: var(--navy-2); border: none; border-radius: 9px;
  width: 34px; height: 34px; font-size: 16px; line-height: 1;
  display: grid; place-items: center; cursor: pointer; filter: grayscale(1) opacity(.7);
}
.bell.on { filter: none; background: var(--gold); }

/* Quick date chips */
.date-chips { display: flex; gap: 7px; margin-top: 8px; align-items: center; }
.dchip {
  border: none; border-radius: 9px; padding: 9px 12px; font-size: 13px; font-weight: 600;
  background: var(--navy-2); color: #fff; white-space: nowrap;
}
.dchip.active { background: var(--gold); color: var(--navy); }
.date-chips input[type="date"] {
  border: none; border-radius: 9px; padding: 8px 10px; font-size: 13px; flex: 1; min-width: 0;
  background: var(--navy-2); color: #fff; color-scheme: dark; outline: none;
}
/* edit-modal chips sit on a light card */
#editChips .dchip { background: #eef0f7; color: var(--navy); }
#editChips .dchip.active { background: var(--gold); color: var(--navy); }
#addRepeat, #addAssignee { color-scheme: dark; }
.quick-add-meta { flex-wrap: wrap; }
.quick-add-meta select { min-width: 0; }
.date-chips { flex-wrap: wrap; }
.chips-label { font-size: 12px; color: #c9cee6; align-self: center; margin-right: 2px; }
.dchip.pick { background: var(--gold); color: var(--navy); position: relative; overflow: hidden; display: inline-flex; align-items: center; cursor: pointer; }
#editChips .dchip.pick { background: var(--gold); color: var(--navy); }

/* native date input overlaying the 📅 Date button — tapping the button taps the
   input, so iOS opens the native picker reliably (no showPicker needed) */
.overlay-date {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: none; padding: 0; margin: 0; background: transparent;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}

/* selected-date pill */
.date-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--gold); color: var(--navy); font-weight: 700;
  border-radius: 9px; padding: 8px 11px; font-size: 13px;
}
.date-pill .x { cursor: pointer; opacity: .8; font-weight: 700; }
#editDatePill { background: #fff2d6; color: #8a6d1e; }

/* edit-modal field group */
.ed-field { display: flex; flex-direction: column; gap: 7px; }
.ed-label { font-size: 13px; color: var(--muted); }
.ed-select { font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 11px; background: #fff; color: var(--ink); }

/* repeat + assignee badges on a task */
.tag.rep { background: #ece6f7; color: #5b4a8a; font-weight: 600; }
.tag.who { background: #e2eef0; color: #2c6e74; font-weight: 600; }

/* Swipe-to-act */
.task { position: relative; touch-action: pan-y; }
.task-swipe { transition: transform .18s ease; will-change: transform; position: relative; z-index: 1;
  display: flex; align-items: flex-start; gap: 12px; background: var(--card); padding: 14px; }
.task-swipe.dragging { transition: none; }
.swipe-bg {
  position: absolute; inset: 0; border-radius: 14px; display: flex; align-items: center;
  padding: 0 22px; font-weight: 700; color: #fff; font-size: 15px;
}
.swipe-bg .done-side { margin-right: auto; }
.swipe-bg .del-side { margin-left: auto; }
.swipe-bg.complete { background: var(--ok); justify-content: flex-start; }
.swipe-bg.delete { background: var(--high); justify-content: flex-end; }

/* Filters */
.filters {
  display: flex; gap: 8px;
  padding: 12px 14px 6px;
  overflow-x: auto;
}
.chip {
  border: 1px solid var(--line); background: var(--card);
  color: var(--muted);
  border-radius: 999px; padding: 7px 16px; font-size: 14px;
  white-space: nowrap;
}
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* List */
.list { padding: 6px 14px calc(120px + var(--safe-bot)); }
.group-head {
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin: 16px 4px 8px;
}
.task {
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(17,22,47,.04);
  overflow: hidden;            /* clip the sliding content + colored bg */
}
.task.high { border-left: 4px solid var(--high); }
.task.low { border-left: 4px solid var(--low); }
.check {
  flex: 0 0 auto;
  width: 24px; height: 24px; margin-top: 1px;
  border-radius: 50%; border: 2px solid var(--gold);
  display: grid; place-items: center;
  color: transparent; font-size: 14px; font-weight: 800;
  transition: all .15s;
}
.task.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 16px; line-height: 1.35; word-wrap: break-word; }
.task.done .task-title { color: var(--muted); text-decoration: line-through; }
.task-notes { font-size: 13px; color: var(--muted); margin-top: 3px; white-space: pre-wrap; }
.task-meta { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 2px 9px; border-radius: 6px; background: #eef0f7; color: var(--muted); }
.tag.due-over { background: #fbe4e0; color: var(--high); font-weight: 600; }
.tag.due-today { background: #fff2d6; color: #8a6d1e; font-weight: 600; }
.tag.pri-high { background: #fbe4e0; color: var(--high); }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* Floating sync button */
.refresh {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-bot));
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--gold); color: var(--navy);
  border: none; font-size: 24px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(176,141,67,.5);
  z-index: 20;
}
.refresh.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Edit modal */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(17,22,47,.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  width: 100%; max-width: 520px;
  background: #fff; border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bot));
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 -8px 30px rgba(0,0,0,.25);
}
.modal-card textarea, .modal-card input, .modal-card select {
  font: inherit; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; outline: none; width: 100%; background: #fff; color: var(--ink);
}
#editTitle { font-size: 17px; font-weight: 600; resize: none; }
.modal-row { display: flex; gap: 12px; }
.modal-row label { flex: 1; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.spacer { flex: 1; }
.modal-actions button { border: none; border-radius: 10px; padding: 11px 18px; font-weight: 600; font-size: 15px; }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-ghost { background: #eef0f7; color: var(--ink); }
.btn-danger { background: #fbe4e0; color: var(--high); }

/* JobTread section in edit modal */
.jt-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.jt-head {
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--navy); font-weight: 700;
}
.jt-picker { position: relative; }
.jt-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 5;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  margin-top: 4px; max-height: 220px; overflow-y: auto;
  box-shadow: 0 8px 22px rgba(17,22,47,.16);
}
.jt-result {
  padding: 11px 12px; font-size: 14px; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.jt-result:last-child { border-bottom: none; }
.jt-result:active, .jt-result.hl { background: #f1f3fb; }
.jt-result.muted { color: var(--muted); cursor: default; }
.jt-selected {
  display: flex; align-items: center; gap: 10px;
  background: #f1f3fb; border-radius: 10px; padding: 10px 12px;
}
.jt-job { flex: 1; font-size: 14px; font-weight: 600; color: var(--navy); }
.jt-clear {
  border: none; background: transparent; color: var(--muted);
  font-size: 16px; padding: 2px 6px;
}
.jt-actions { display: flex; align-items: center; gap: 12px; }
.btn-jt {
  border: none; border-radius: 10px; padding: 11px 16px;
  background: var(--navy); color: #fff; font-weight: 600; font-size: 14px;
}
.btn-jt:disabled { opacity: .55; }
.jt-status { font-size: 13px; color: var(--muted); }
.jt-status.ok { color: var(--ok); }
.jt-status.err { color: var(--high); }

/* JobTread badge on task cards */
.tag.jt { background: #e7ebfb; color: var(--navy); font-weight: 600; }
.tag.jt-posted { background: #e2f3e8; color: #2f7d4f; font-weight: 600; }

@media (min-width: 620px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 18px; }
}
