:root {
  --latar: #f3f5fb;
  --kartu: #ffffff;
  --teks: #182034;
  --lembut: #6c7791;
  --garis: #e4e9f3;
  --aksen: #4f6ef7;
  --aksen-gelap: #3a55d8;
  --bahaya: #e2485c;
  --radius: 13px;
  --bayang: 0 14px 34px rgba(24, 32, 52, 0.09);
  --cek-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 13l4 4L19 7'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --latar: #0f1420;
    --kartu: #181f2e;
    --teks: #eef2fb;
    --lembut: #98a4bd;
    --garis: #29324a;
    --aksen: #7f95ff;
    --aksen-gelap: #6479f2;
    --bahaya: #ff6b7d;
    --bayang: 0 14px 34px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: radial-gradient(1100px 520px at 50% -8%, rgba(79, 110, 247, 0.16), transparent 62%), var(--latar);
  color: var(--teks);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: min(620px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.5rem 0 3rem;
}

.head { margin-bottom: 1.4rem; }

.head h1 {
  margin: 0;
  font-size: clamp(1.55rem, 1.2rem + 1.5vw, 2rem);
  letter-spacing: -0.02em;
}

.count {
  margin: 0.2rem 0 0;
  color: var(--lembut);
  font-size: 0.9rem;
}

/* form tambah */
.add { display: flex; gap: 0.5rem; margin-bottom: 0.9rem; }

.add input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  color: var(--teks);
  background: var(--kartu);
  border: 1px solid var(--garis);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.add input::placeholder { color: var(--lembut); }

.add input:focus {
  border-color: var(--aksen);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.18);
}

.add button {
  flex: 0 0 auto;
  padding: 0.8rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--aksen);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.add button:hover { background: var(--aksen-gelap); }
.add button:active { transform: translateY(1px); }

/* kotak cari judul */
.search { margin-bottom: 0.9rem; }

.search input[type="search"] {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  color: var(--teks);
  background: var(--kartu);
  border: 1px solid var(--garis);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search input[type="search"]::placeholder { color: var(--lembut); }

.search input[type="search"]:focus {
  border-color: var(--aksen);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.18);
}

/* filter */
.filters {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  padding: 0.25rem;
  background: rgba(127, 145, 180, 0.14);
  border-radius: 11px;
  width: fit-content;
}

.filters a {
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--lembut);
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.filters a:hover { color: var(--teks); }

.filters a.active {
  color: var(--teks);
  background: var(--kartu);
  box-shadow: 0 1px 4px rgba(24, 32, 52, 0.14);
}

/* daftar */
.list {
  list-style: none;
  margin: 0;
  padding: 0.3rem;
  background: var(--kartu);
  border: 1px solid var(--garis);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--bayang);
  min-height: 62px;
}

.todo {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.68rem 0.6rem;
  border-bottom: 1px solid var(--garis);
  transition: background 0.15s ease;
}

.todo:last-child { border-bottom: none; }
.todo:hover { background: rgba(79, 110, 247, 0.06); }

.check { flex: 0 0 auto; display: flex; }

.check input {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 2px solid #aab2c6;
  border-radius: 7px;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px 14px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.check input:hover { border-color: var(--aksen); }

.check input:checked {
  background-color: var(--aksen);
  border-color: var(--aksen);
  background-image: var(--cek-svg);
}

/* input judul (bisa diedit langsung) */
.edit { flex: 1 1 auto; min-width: 0; margin: 0; display: flex; }

.title-input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  padding: 0.3rem 0.45rem;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  outline: none;
  text-overflow: ellipsis;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.title-input:hover { border-color: var(--garis); }

.title-input:focus {
  border-color: var(--aksen);
  background: var(--kartu);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.18);
}

.is-done .title-input {
  color: var(--lembut);
  text-decoration: line-through;
}

.del {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--lembut);
  background: transparent;
  border: none;
  border-radius: 9px;
  cursor: pointer;
  opacity: 0.55;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.todo:hover .del { opacity: 1; }

.del:hover {
  color: var(--bahaya);
  background: rgba(226, 72, 92, 0.12);
}

.empty {
  padding: 1.6rem 1rem;
  text-align: center;
  color: var(--lembut);
  font-size: 0.95rem;
}

.add button:focus-visible,
.check input:focus-visible,
.title-input:focus-visible,
.del:focus-visible,
.filters a:focus-visible,
.search input:focus-visible {
  outline: 2px solid var(--aksen);
  outline-offset: 2px;
}

/* animasi swap htmx */
.htmx-swapping { opacity: 0; }
.htmx-added { opacity: 0; }

@media (max-width: 480px) {
  .app { padding-top: 1.75rem; }
  .add { flex-wrap: wrap; }
  .add button { width: 100%; }
  .del { opacity: 1; }
  .filters { width: 100%; justify-content: space-between; }
  .filters a { flex: 1; text-align: center; }
}

@media (max-width: 400px) {
  .todo { gap: 0.5rem; padding: 0.6rem 0.45rem; }
  .check input { width: 20px; height: 20px; }
  .del { width: 30px; }
}

/* kontras fokus input judul di dark mode (usulan Nadia) */
@media (prefers-color-scheme: dark) {
  .title-input:hover { border-color: #3a4666; }
  .title-input:focus {
    border-color: var(--aksen);
    background: rgba(127, 149, 255, 0.12);
    box-shadow: 0 0 0 3px rgba(127, 149, 255, 0.35);
  }
  .is-done .title-input { color: #a9b4cc; }
}
