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

:root {
  --bg:          #f5f5f5;
  --surface:     #ffffff;
  --border:      #e0e0e0;
  --text:        #1a1a1a;
  --text-muted:  #6b7280;
  --primary:     #2563eb;
  --primary-h:   #1d4ed8;
  --danger:      #dc2626;
  --danger-h:    #b91c1c;
  --done-bg:     #f0fdf4;
  --overdue-bg:  #fef2f2;
  --overdue-bd:  #fecaca;
  --high:        #dc2626;
  --medium:      #d97706;
  --low:         #16a34a;
  --radius:      6px;
  --shadow:      0 1px 3px rgba(0,0,0,.08);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── layout ────────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.site-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}
.site-title:hover { text-decoration: none; }

nav { display: flex; align-items: center; gap: 1rem; }
nav a { color: var(--text-muted); font-size: .9rem; }
nav a.active { color: var(--primary); font-weight: 600; }
nav a.logout { color: var(--text-muted); }
nav a:hover { text-decoration: none; color: var(--primary); }

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── cards / sections ──────────────────────────────────────────────────────── */
.add-section,
.list-section,
.edit-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: .75rem;
}
.count { color: var(--text-muted); font-weight: 400; }

/* ── flash messages ────────────────────────────────────────────────────────── */
.flash {
  padding: .6rem 1rem;
  border-radius: var(--radius);
  font-size: .9rem;
  margin-bottom: .5rem;
}
.flash-error   { background: #fef2f2; border: 1px solid var(--overdue-bd); color: var(--danger); }
.flash-success { background: var(--done-bg); border: 1px solid #bbf7d0; color: #166534; }

/* ── forms ─────────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: .45rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}

label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: .25rem;
}
.required { color: var(--danger); }

textarea { resize: vertical; }

.form-row { margin-bottom: .6rem; }
.form-row-multi {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: flex-end;
  margin-bottom: 0;
}
.input-title { font-size: 1rem; }

.field-group { flex: 1; min-width: 130px; }
.field-group-submit { flex: 0; min-width: unset; }

/* ── add form ──────────────────────────────────────────────────────────────── */
.add-form h2 { margin-bottom: .75rem; }

/* ── buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  padding: .4rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
  font-family: inherit;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
  text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg); text-decoration: none; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); }

.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }

.btn-sm { padding: .25rem .6rem; font-size: .8rem; }

.btn-block { width: 100%; justify-content: center; padding: .55rem; font-size: 1rem; }

/* check button */
.btn-check {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: transparent;
  transition: border-color .15s, background .15s, color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-check:hover { border-color: var(--primary); color: var(--primary); }
.btn-check-done {
  border-color: #22c55e;
  background: #22c55e;
  color: #fff;
}
.btn-check-done:hover { background: #16a34a; border-color: #16a34a; }

.toggle-form { display: flex; }

/* ── filter bar ────────────────────────────────────────────────────────────── */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .75rem;
}
.list-header h2 { margin-bottom: 0; }

.filter-form {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  align-items: center;
}
.filter-form select { width: auto; font-size: .8rem; padding: .3rem .55rem; }

/* ── todo list ─────────────────────────────────────────────────────────────── */
.todo-list { list-style: none; }

.todo-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}
.todo-item:last-child { border-bottom: none; }

.todo-item.overdue {
  background: var(--overdue-bg);
  margin: 0 -1.5rem;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  border-left: 3px solid var(--danger);
}

.todo-main {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  flex: 1;
  min-width: 0;
}

.todo-body { flex: 1; min-width: 0; }

.todo-title { font-size: .95rem; word-break: break-word; }
.todo-title-done {
  text-decoration: line-through;
  color: var(--text-muted);
}

.todo-notes {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .2rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.todo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .35rem;
}

.todo-actions {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-shrink: 0;
}
.todo-actions form { display: flex; }

/* ── badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .1rem .45rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 500;
  border: 1px solid transparent;
}
.badge-high    { background: #fef2f2; color: var(--high);   border-color: #fecaca; }
.badge-medium  { background: #fffbeb; color: var(--medium); border-color: #fde68a; }
.badge-low     { background: #f0fdf4; color: var(--low);    border-color: #bbf7d0; }
.badge-project { background: #eff6ff; color: var(--primary); border-color: #bfdbfe; }
.badge-tag     { background: #f5f3ff; color: #7c3aed; border-color: #ddd6fe; }
.badge-date    { background: #f9fafb; color: var(--text-muted); border-color: var(--border); }
.badge-overdue { background: #fef2f2; color: var(--danger); border-color: var(--overdue-bd); }

.field-hint { font-weight: 400; font-size: .75rem; color: var(--text-muted); }

/* ── completed list ────────────────────────────────────────────────────────── */
.todo-item-done { opacity: .75; }
.todo-item-done:hover { opacity: 1; }

/* ── login ─────────────────────────────────────────────────────────────────── */
.login-wrap {
  max-width: 360px;
  margin: 3rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}
.login-wrap h1 { font-size: 1.4rem; margin-bottom: 1.25rem; }
.login-wrap label { margin-top: .75rem; }
.login-wrap input { margin-bottom: .25rem; }
.login-wrap .btn-block { margin-top: 1rem; }

/* ── edit form ─────────────────────────────────────────────────────────────── */
.edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.edit-header h2 { margin-bottom: 0; }

.edit-form label { margin-top: .75rem; }
.edit-form input,
.edit-form textarea,
.edit-form select { margin-bottom: .1rem; }

.edit-actions {
  display: flex;
  gap: .6rem;
  margin-top: 1.25rem;
}

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

/* ── responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .add-section,
  .list-section,
  .edit-section { padding: 1rem; }

  .todo-item.overdue {
    margin: 0 -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .header-inner { padding: 0 .75rem; }
  .container { padding: 1rem .75rem 2rem; }

  .todo-actions { flex-direction: column; gap: .25rem; }

  .edit-actions { flex-direction: column; }
  .edit-actions .btn { justify-content: center; }
}
