:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --accent-fg: #ffffff;
  --green: #35c281;
  --amber: #f0ad4e;
  --red: #ef5f5f;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Light theme: applied when the OS prefers light (and no explicit choice),
   or when the user picks light via the toggle. */
:root[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #d7dce5;
  --text: #1a1e26;
  --muted: #5c6472;
  --accent: #3b6fe0;
  --accent-fg: #ffffff;
  --green: #1f9d63;
  --amber: #c07d10;
  --red: #d64545;
  --shadow: 0 6px 24px rgba(20, 30, 60, 0.12);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --border: #d7dce5;
    --text: #1a1e26;
    --muted: #5c6472;
    --accent: #3b6fe0;
    --accent-fg: #ffffff;
    --green: #1f9d63;
    --amber: #c07d10;
    --red: #d64545;
    --shadow: 0 6px 24px rgba(20, 30, 60, 0.12);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); }
button { font-family: inherit; cursor: pointer; }

/* ---------- Buttons & inputs ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { background: #262b36; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { background: transparent; }
.btn-danger:hover { border-color: var(--red); color: var(--red); }
.btn-sm { padding: 0.3rem 0.55rem; font-size: 0.8rem; }

input, textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 60px; }
label { font-size: 0.78rem; color: var(--muted); display: block; margin-bottom: 0.25rem; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.login-card p.sub { margin: 0 0 1.5rem; color: var(--muted); font-size: 0.9rem; }
.field { margin-bottom: 1rem; }
.form-error {
  color: var(--red);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-top: 0.25rem;
}

/* ---------- App layout ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar .user { color: var(--muted); font-size: 0.85rem; margin-right: 0.5rem; }
.container { max-width: 900px; margin: 0 auto; padding: 1.5rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.card h2 { margin: 0 0 1rem; font-size: 1rem; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
.grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr; } }

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.toolbar .search { flex: 1; min-width: 160px; }
.toolbar select { width: auto; }

/* ---------- Todo items ---------- */
.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 1.5rem 0 0.6rem;
}
.todo {
  display: flex;
  gap: 0.85rem;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
}
.todo.done { opacity: 0.62; }
.todo.done .todo-title { text-decoration: line-through; }
.check {
  appearance: none;
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin-top: 2px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  position: relative;
}
.check:checked { background: var(--green); border-color: var(--green); }
.check:checked::after {
  content: "✓";
  color: #06231a;
  font-size: 13px;
  font-weight: 700;
  position: absolute;
  top: -1px; left: 3px;
}
.todo-main { flex: 1; min-width: 0; }
.todo-title { font-weight: 600; word-break: break-word; }
.todo-desc { color: var(--muted); font-size: 0.88rem; margin-top: 0.25rem; white-space: pre-wrap; }
.meta { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.tag {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag.project { color: var(--accent); border-color: rgba(91, 140, 255, 0.4); }
.tag.status { font-weight: 600; }
.tag.status.open { color: var(--muted); }
.tag.status.started { color: var(--amber); border-color: rgba(240, 173, 78, 0.5); }
.tag.status.done { color: var(--green); border-color: rgba(53, 194, 129, 0.5); }
.tag.assignee::before { content: "👤 "; }
.tag.due::before { content: "📅 "; }
.tag.overdue { color: var(--red); border-color: rgba(239, 95, 95, 0.5); }
.todo-actions { display: flex; flex-direction: column; gap: 0.35rem; }

.empty { color: var(--muted); text-align: center; padding: 2rem; }
.hidden { display: none !important; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 620px;
  margin: auto;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal-head h2 { margin: 0; }
.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.3rem;
}
.modal-close:hover { color: var(--text); }

/* ---------- Attachments ---------- */
.attachments { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; align-items: flex-start; }
.att-wrap { position: relative; display: inline-flex; }
.att-thumb {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}
.att-chip {
  font-size: 0.78rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}
.att-chip:hover { border-color: var(--accent); }
.att-del {
  position: absolute;
  top: -7px; right: -7px;
  width: 18px; height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  padding: 0;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}
.att-wrap:hover .att-del { opacity: 1; }

/* ---------- Notes ---------- */
.notes {
  margin-top: 0.7rem;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.note {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}
.note-body { font-size: 0.88rem; white-space: pre-wrap; word-break: break-word; }
.note-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}
.note-del {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.2rem;
}
.note-del:hover { color: var(--red); }
.note-add { display: flex; gap: 0.4rem; margin-top: 0.1rem; }
.note-add .note-input { flex: 1; }
