:root {
  --row-h: 34px;
  --cols: 5;
  --accent: #7c3aed;
  --bg: #ffffff;
  --fg: #1c1c1e;
  --muted: #9a9a9f;
  --line: #ededf0;
  --line-strong: #e2e2e6;
  --field-focus: #f5f3ff;
  --topbar-bg: rgba(255, 255, 255, 0.85);
  --border: #eaeaee;

  --c-red-bg: #ffd7d7;
  --c-red-fg: #7a1f1f;
  --c-yellow-bg: #fbe6a0;
  --c-yellow-fg: #6b5310;
  --c-green-bg: #cdeccf;
  --c-green-fg: #1f5a2a;

  --sw-red: #ef5350;
  --sw-yellow: #f6c744;
  --sw-green: #4caf6a;
}

:root[data-theme="dark"] {
  --accent: #a78bfa;
  --bg: #161618;
  --fg: #e9e9ec;
  --muted: #77777e;
  --line: #262629;
  --line-strong: #303035;
  --field-focus: #201d2e;
  --topbar-bg: rgba(22, 22, 24, 0.85);
  --border: #262629;

  --c-red-bg: #5a2626;
  --c-red-fg: #ffc9c9;
  --c-yellow-bg: #574718;
  --c-yellow-fg: #ffe6a3;
  --c-green-bg: #234d2b;
  --c-green-fg: #bdedc2;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  font-size: 15px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(env(safe-area-inset-top), 10px) 16px 10px;
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}
.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
}
.controls { display: flex; align-items: center; gap: 6px; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  margin-right: 2px;
}
.segmented button {
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 6px 11px;
  cursor: pointer;
  line-height: 1;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--accent); color: #fff; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: none; background: none; color: var(--fg);
  border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: var(--line); }
.icon-btn.active { color: var(--accent); background: var(--field-focus); }
.ic-sun { display: none; }
:root[data-theme="dark"] .ic-moon { display: none; }
:root[data-theme="dark"] .ic-sun { display: block; }

/* ---------- Board ---------- */
.board {
  flex: 1;
  display: flex;
  gap: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.day {
  flex: 0 0 calc(100% / var(--cols));
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 20px;
  scroll-snap-align: start;
}

.day-head {
  padding: 18px 0 10px;
  flex: 0 0 auto;
}
.day-date {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}
.day-name {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.day.is-today .day-name { color: var(--accent); }

.day-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 40vh;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--row-h) - 1px),
    var(--line) calc(var(--row-h) - 1px),
    var(--line) var(--row-h)
  );
  background-position: 0 0;
}
.day-list::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- Task row ---------- */
.task {
  display: flex;
  align-items: center;
  min-height: var(--row-h);
  gap: 4px;
  padding: 0 2px;
  border-radius: 6px;
}

/* Bolinha de relevância — estilo Macintosh */
.dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
  display: inline-block;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.45), 0 0 0 0.5px rgba(0,0,0,0.12);
}
.dot-red { background: radial-gradient(circle at 35% 28%, #ff9d92, #e5433a 82%); }
.dot-yellow { background: radial-gradient(circle at 35% 28%, #ffc880, #ef7d10 82%); }
.dot-green { background: radial-gradient(circle at 35% 28%, #a7ea9c, #35a63f 82%); }
.dot-none { background: var(--muted); opacity: 0.28; box-shadow: none; }

.dot-btn {
  flex: 0 0 auto;
  width: 20px; height: 100%;
  min-height: var(--row-h);
  display: grid; place-items: center;
  border: none; background: none;
  cursor: pointer; padding: 0;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  opacity: 0;
  flex: 0 0 auto;
  width: 16px;
  text-align: center;
  touch-action: none;
  transition: opacity .15s;
  font-size: 14px;
  line-height: 1;
}
.task:hover .drag-handle { opacity: .5; }

.checkbox {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1.8px solid var(--muted);
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: border-color .12s, background .12s;
}
.checkbox svg { width: 11px; height: 11px; opacity: 0; }
.task.done .checkbox { background: var(--accent); border-color: var(--accent); }
.task.done .checkbox svg { opacity: 1; stroke: #fff; }

.task-text {
  flex: 1;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  padding: 6px 2px;
  min-width: 0;
  outline: none;
}
.task-text::placeholder { color: var(--muted); }
.task.done .task-text { text-decoration: line-through; color: var(--muted); }

.overdue-badge {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  color: #fff;
  background: var(--sw-red);
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
}
.task.done .overdue-badge { display: none; }


/* ---------- Add line ---------- */
.add-line {
  display: flex;
  align-items: center;
  min-height: var(--row-h);
  padding: 0 4px 0 6px;
}
.add-input {
  flex: 1;
  border: none; background: none;
  color: inherit; font: inherit;
  padding: 6px 2px;
  outline: none;
}
.add-input::placeholder { color: var(--muted); opacity: .8; }

/* ---------- Sortable ---------- */
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { background: var(--field-focus); }
.sortable-drag { opacity: 0.95 !important; }

/* ---------- Popover ---------- */
.popover[hidden] { display: none; }
.popover {
  position: fixed;
  z-index: 50;
  min-width: 176px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(0,0,0,.22);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.rel {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: none;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.rel:hover { background: var(--line); }
.rel .dot { width: 12px; height: 12px; }
.pop-sep { height: 1px; background: var(--border); margin: 4px 8px; }
.pop-delete {
  display: block;
  width: 100%;
  border: none;
  background: none;
  color: var(--sw-red);
  font: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.pop-delete:hover { background: var(--line); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  :root { --row-h: 40px; }
  .day { flex: 0 0 100%; }
  .day-head { padding: 22px 0 12px; }
  .day-name { font-size: 26px; }
  .drag-handle { opacity: .4; width: 22px; font-size: 16px; }
  .task-text, .add-input { padding: 9px 2px; }
  .segmented button { padding: 6px 9px; }
  .brand { font-size: 18px; }
}
