/* ── Reset & variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #ffffff;
  --surface:      #f7f7f5;
  --border:       #e4e4e0;
  --text:         #1a1a1a;
  --muted:        #888;
  --accent:       #2d7dd2;
  --overdue:      #d93025;
  --upcoming:     #b36200;
  --done-start:   #e4e4e0;
  --done-end:     #22c55e;
  --radius:       10px;
  --shadow:       0 1px 3px rgba(0,0,0,.08);
  font-size: 16px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

/* ── Login ─────────────────────────────────────────────────────── */
.login-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem 1rem;
  gap: 1rem;
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 16px;
}

.login-wrap h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.login-wrap form {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  width: 100%;
  max-width: 340px;
}

.login-wrap label {
  font-size: .875rem;
  color: var(--muted);
}

.login-wrap input[type="email"] {
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}

.login-wrap input[type="email"]:focus {
  border-color: var(--accent);
}

.login-wrap button {
  padding: .7rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  transition: opacity .15s;
}

.login-wrap button:disabled { opacity: .5; }

#login-msg {
  font-size: .875rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.25em;
}

/* ── Layout ────────────────────────────────────────────────────── */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1rem;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

#search {
  width: 100%;
  padding: .55rem 2rem .55rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  font-size: 1rem;
  outline: none;
  background: var(--surface);
  transition: border-color .15s;
}

#search:focus { border-color: var(--accent); background: var(--bg); }

/* Hide browser-native clear button */
#search::-webkit-search-cancel-button { display: none; }

#search-clear {
  position: absolute;
  right: .55rem;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: .2rem .3rem;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
}

#search-clear:hover { color: var(--text); background: var(--border); }

/* Show only when the field has content */
#search:not(:placeholder-shown) + #search-clear { display: flex; }

.btn-add {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1), background .15s;
}

.btn-add.open { transform: rotate(45deg); }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: .5rem 0 6rem;
}

/* ── Section headings ──────────────────────────────────────────── */
.section-heading {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: .9rem 1rem .35rem;
}

.section-heading.overdue { color: var(--overdue); }
.section-heading.upcoming { color: var(--upcoming); }

/* ── Task card ─────────────────────────────────────────────────── */
.task-card {
  border-bottom: 1px solid var(--border);
}

.task-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .7rem 1rem;
  min-height: 56px;
}

/* Done button */
.btn-done {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--done-start);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: border-color .2s;
}

.btn-done svg {
  width: 16px;
  height: 16px;
  stroke: var(--done-start);
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke .2s;
}

.btn-done:hover { border-color: var(--done-end); }
.btn-done:hover svg { stroke: var(--done-end); }

@keyframes done-pop {
  0%   { background: transparent;    border-color: var(--done-end); }
  40%  { background: var(--done-end); border-color: var(--done-end); }
  100% { background: transparent;    border-color: var(--done-start); }
}

@keyframes task-exit {
  0%   { opacity: 1; transform: translateX(0);     max-height: 200px; margin-bottom: 0; }
  55%  { opacity: 0; transform: translateX(100vw); max-height: 200px; margin-bottom: 0; }
  100% { opacity: 0; transform: translateX(100vw); max-height: 0;     margin-bottom: 0; border-bottom: none; }
}

.task-card.completing {
  animation: task-exit 1.2s ease forwards;
  overflow: hidden;
}

.btn-done.animating {
  animation: done-pop .5s ease forwards;
}

.btn-done.animating svg { stroke: #fff; }

/* Time label */
.task-time {
  font-size: .8rem;
  font-weight: 600;
  min-width: 3ch;
  text-align: right;
  color: var(--muted);
  flex-shrink: 0;
}

.task-time.overdue { color: var(--overdue); }
.task-time.upcoming { color: var(--upcoming); }

/* Name & frequency */
.task-info {
  flex: 1;
  min-width: 0;
}

.task-name {
  font-size: .975rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-freq {
  font-size: .75rem;
  color: var(--muted);
  margin-top: 1px;
}

/* More button */
.btn-more {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: .3rem;
  color: var(--muted);
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
}

.btn-more:hover { color: var(--text); background: var(--surface); }

.btn-more svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  transition: transform .2s;
}

.btn-more.open svg { transform: rotate(180deg); }

/* ── More panel ────────────────────────────────────────────────── */
.task-more {
  overflow: hidden;
  max-height: 0;
  transition: max-height .28s ease;
  background: var(--surface);
}

.task-more.open {
  max-height: 1200px;
}

.task-more-inner {
  padding: .75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* Edit fields inside more panel */
.edit-row {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.edit-row label {
  font-size: .75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.edit-row input[type="text"],
.edit-row input[type="number"],
.edit-row select {
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}

.edit-row input:focus,
.edit-row select:focus { border-color: var(--accent); }

.freq-edit-row {
  display: flex;
  align-items: center;
  gap: .4rem;
}

.freq-edit-row span { font-size: .9rem; color: var(--muted); }

.freq-edit-row input[type="number"] { width: 64px; }

.more-meta {
  font-size: .8rem;
  color: var(--muted);
}

.more-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.btn-save, .btn-delete {
  padding: .45rem .9rem;
  border-radius: 8px;
  border: none;
  font-size: .875rem;
  cursor: pointer;
  transition: opacity .15s;
}

.btn-save { background: var(--accent); color: #fff; }
.btn-delete { background: var(--overdue); color: #fff; }
.btn-save:active, .btn-delete:active { opacity: .75; }

/* Logbook */
.logbook-heading {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.logbook-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-top: .3rem;
}

.logbook-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .85rem;
  gap: .5rem;
}

.logbook-entry time { color: var(--muted); }

.btn-del-entry {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: .85rem;
  padding: .1rem .3rem;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s, background .15s;
}

.btn-del-entry:hover { color: var(--overdue); background: #ffeae8; }

.logbook-empty {
  font-size: .85rem;
  color: var(--muted);
  font-style: italic;
}

/* ── Inline add form ───────────────────────────────────────────── */
#add-form-wrap {
  max-width: 640px;
  margin: 0 auto;
  overflow: hidden;
  max-height: 0;
  transition: max-height .4s cubic-bezier(.4,0,.2,1);
  border-bottom: 1px solid transparent;
}

#add-form-wrap.open {
  max-height: 120px;
  border-bottom-color: var(--border);
}

#add-form {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .75rem 1rem;
}

#add-name {
  padding: .55rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  outline: none;
  width: 100%;
  transition: border-color .15s;
}

#add-name:focus { border-color: var(--accent); }

.add-freq-row {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.add-freq-row span { color: var(--muted); font-size: .9rem; white-space: nowrap; }

.add-freq-row input[type="number"] {
  width: 60px;
  padding: .45rem .6rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}

.add-freq-row input[type="number"]:focus { border-color: var(--accent); }

.add-freq-row select {
  padding: .45rem .5rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
  flex: 1;
}

.add-freq-row select:focus { border-color: var(--accent); }

.add-freq-row button[type="submit"] {
  padding: .45rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
}

/* ── Snackbar ──────────────────────────────────────────────────── */
#snackbar {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(calc(100% + 2rem));
  background: #1a1a1a;
  color: #fff;
  border-radius: 99px;
  padding: .6rem 1.1rem .6rem .6rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .875rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  transition: transform .25s ease;
  z-index: 1000;
  max-width: calc(100vw - 2rem);
}

#snackbar-msg {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

#snackbar.visible {
  transform: translateX(-50%) translateY(0);
}

#snackbar-undo {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,.4);
  color: #fff;
  border-radius: 99px;
  padding: .3rem .85rem;
  font-size: .85rem;
  cursor: pointer;
  transition: background .15s;
}

#snackbar-undo:hover { background: rgba(255,255,255,.15); }

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 4rem 1rem;
  font-size: .95rem;
}

/* ── Focus visible ─────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) { outline: none; }
