:root {
  --accent: #663399;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #666666;
  --line: #e2e2e2;
  --chip: #f1eaf9;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--accent);
  color: #ffffff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

#sign-out,
#menu-button {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  font-size: 1.1rem;
}

#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(20rem, 90vw);
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
}

#login-form h2 {
  margin: 0;
  color: var(--accent);
}

#login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#login-form input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  background: var(--bg);
}

#login-error {
  color: #b00020;
  margin: 0;
  font-size: 0.85rem;
}

#topbar {
  position: sticky; /* the site header + view buttons stay fixed ... */
  top: 0;
  z-index: 6;
  background: var(--bg); /* ... while the task list scrolls behind them */
}

.views {
  display: flex;
  flex-wrap: wrap; /* buttons wrap instead of causing a horizontal scrollbar */
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
}

.view-link {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 6px; /* narrow tabs, not pills: everything fits on one line */
  padding: 0.25rem 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.view-link.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

main {
  flex: 1;
  padding: 0.75rem 1rem 5rem;
  max-width: 48rem;
  width: 100%;
  margin: 0 auto;
}

#quick-add {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

#quick-add input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}

button.primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.priority-block {
  margin: 0.75rem 0 0.25rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.priority-block::before {
  content: '';
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 2px;
  margin-right: 0.35rem;
  background: currentColor;
}

.priority-block.p1 {
  color: #d32f2f;
}

.priority-block.p2 {
  color: #ef6c00;
}

.priority-block.p3 {
  color: #a67c00; /* darker gold for readable text; the square keeps the defined yellow */
}

.priority-block.p3::before {
  background: #fdd835;
}

#task-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.task-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--line);
  border-radius: 0; /* straight corners */
}

.row-pills {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* mobile: line 1 = handle + title + complete control; pills and tags get their own lines */
.drag-handle {
  order: 1;
}

.task-title {
  order: 2;
}

.complete-btn,
.completed-indicator {
  order: 3;
  margin-left: auto;
}

.row-pills {
  order: 4;
  flex-basis: 100%;
  padding-left: 1.55rem;
}

.row-tags {
  order: 5;
  flex-basis: 100%;
  padding-left: 1.55rem;
}

@media (min-width: 40rem) {
  /* desktop: one row - handle, title, pills, complete control fully right */
  .drag-handle,
  .task-title,
  .complete-btn,
  .completed-indicator,
  .row-pills {
    order: 0;
    margin-left: 0;
  }
  .row-pills {
    flex-basis: auto;
    padding-left: 0;
  }
  .row-tags {
    padding-left: 0;
  }
}

.row-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  width: 100%;
}

.row-tags .mini-tag {
  font-size: 0.7rem;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  color: var(--muted);
}

.task-row.dragging {
  opacity: 0.4;
}

/* the full task card that follows the pointer while dragging */
.task-row.dragging-clone {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 25;
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0.95;
  pointer-events: none;
}

/* drop target highlight: straight line, no rounded corners */
.task-row.drop-before {
  box-shadow: inset 0 2px 0 var(--accent);
}

.task-row.drop-after {
  box-shadow: inset 0 -2px 0 var(--accent);
}

.drag-handle {
  cursor: grab;
  touch-action: none;
  color: var(--muted);
  padding: 0.5rem 0.15rem;
  min-width: 1.25rem; /* slim: leave room for the title */
  min-height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.complete-btn {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  cursor: pointer;
  font-weight: 700;
}

/* while the 5s confirmation countdown runs, the button shows the complete (green) state */
.complete-btn.confirming {
  background: #2e7d32;
  border-color: #2e7d32;
  color: #ffffff;
}

.completed-indicator {
  color: #2e7d32;
  font-weight: 800;
  font-size: 1.1rem;
  width: 2rem;
  text-align: center;
}

.task-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-row.complete .task-title {
  text-decoration: line-through;
  color: var(--muted);
}

.chip {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip.status-pending {
  background: #ef6c00; /* orange */
  border-color: #ef6c00;
  color: #ffffff;
}

.chip.status-working {
  background: #1565c0; /* blue */
  border-color: #1565c0;
  color: #ffffff;
}

.chip.status-paused {
  background: #9e9e9e;
  border-color: #9e9e9e;
  color: #ffffff;
}

.chip.status-complete {
  background: #2e7d32; /* green */
  border-color: #2e7d32;
  color: #ffffff;
}

.chip.p1 {
  background: #d32f2f;
  border-color: #d32f2f;
  color: #ffffff;
}

.chip.p2 {
  background: #ef6c00;
  border-color: #ef6c00;
  color: #ffffff;
}

.chip.p3 {
  background: #fdd835;
  border-color: #fdd835;
  color: #1a1a1a;
}

.chip.due-overdue {
  background: #d32f2f;
  border-color: #d32f2f;
  color: #ffffff;
  font-weight: 700;
}

.chip.due-none {
  background: var(--chip);
  color: var(--muted);
}

.tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag-pills .tag-pill {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.tag-pills .tag-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

#bulk-bar {
  margin-bottom: 0.75rem;
  text-align: center; /* center the Reschedule overdue button */
}

#bulk-reschedule {
  background: #e64a19; /* bright orange-red */
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-weight: 700;
  cursor: pointer;
}

#search-bar input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

.tag-item {
  display: inline-block;
  margin: 0.15rem 0.25rem 0.15rem 0;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--line);
  cursor: pointer;
}

#editor-backdrop,
#password-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg); /* mobile: opaque, the dialog is the only page on screen */
  display: flex;
  align-items: stretch; /* mobile: the dialog fills the whole screen */
  justify-content: center;
  z-index: 10;
}

#editor,
#password-form {
  background: var(--bg);
  width: 100%;
  height: 100%;
  border-radius: 0; /* mobile: no rounded corners */
  padding: 0.5rem 1rem 1rem; /* less space above the heading */
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}

#editor h2,
#password-form h2 {
  margin: 0;
}

#editor > *:not(.editor-actions),
#password-form > *:not(.editor-actions) {
  margin-bottom: 0.6rem;
}

@media (min-width: 40rem) {
  #editor-backdrop,
  #password-backdrop {
    align-items: center; /* desktop: centered dialog over a dimmed backdrop */
    background: rgba(0, 0, 0, 0.4);
  }
  #editor,
  #password-form {
    height: auto;
    max-width: 32rem;
    max-height: 90vh;
    border-radius: 16px;
  }
  /* desktop only: wider repeat value input, narrower unit select */
  #editor fieldset input[type='number'] {
    width: 7rem;
  }
  #editor fieldset select#edit-repeat-unit {
    width: 5.5rem;
    flex: 0 0 auto;
  }
}

#editor label,
#password-form label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#editor input,
#editor textarea,
#editor select,
#password-form input {
  width: 100%;
  min-width: 0; /* let controls shrink instead of overflowing on narrow screens */
  max-width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  background: var(--bg);
}

#editor fieldset {
  min-width: 0; /* override the UA fieldset min-content quirk that forces horizontal overflow */
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: nowrap; /* keep interval, unit, and anchor on one line */
}

#editor fieldset select {
  flex: 0 1 auto;
  min-width: 0;
  font-size: 0.8rem;
  padding: 0.35rem 0.4rem;
}

#editor fieldset legend {
  font-size: 0.85rem;
  color: var(--muted);
}

.editor-row {
  display: flex;
  gap: 0.5rem;
}

.editor-row label {
  flex: 1;
  min-width: 0;
}

.editor-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  /* in-flow after the form fields, not fixed to the bottom of the screen */
  background: #ffffff;
  border-top: 1px solid var(--line);
  /* same space above and below the buttons */
  padding: calc(0.5rem + env(safe-area-inset-bottom, 0px)) 0;
}

.editor-actions button {
  border: 1px solid transparent;
  color: #ffffff;
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}

/* filled: Cancel gray, Save green */
.editor-actions button:not(.primary):not(.danger) {
  background: #9e9e9e;
  border-color: #9e9e9e;
}

.editor-actions button.primary {
  background: #2e7d32;
  border-color: #2e7d32;
  color: #ffffff;
}

.due-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem; /* tighter spacing between the fast due date pills */
}

.due-shortcuts button {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
}

#editor fieldset input[type='number'] {
  width: 4.5rem;
}

.editor-actions .danger {
  background: #d32f2f;
  border-color: #d32f2f;
  color: #ffffff;
  margin-right: auto;
}

#popup {
  position: fixed;
  z-index: 20;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  min-width: 9rem;
}

#popup button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  background: none;
  text-align: left;
  padding: 0.7rem 1rem;
  min-height: 2.75rem; /* easy to touch */
  font-size: 1rem;
  border-radius: 6px;
  cursor: pointer;
}

#popup button .dot {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex: 0 0 auto;
}

#popup button.current {
  background: var(--chip);
  font-weight: 700;
}

#popup button:hover {
  background: var(--chip);
}
