:root {
  --bg: #f3f5fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e3e7f0;
  --primary: #4f63e7;
  --primary-hover: #3f51c8;
  --shadow: 0 2px 10px rgba(30, 40, 90, 0.08);

  --low-bg: #e6f4ea;    --low-text: #2d6a3e;
  --medium-bg: #fff4d6; --medium-text: #8a6100;
  --high-bg: #fde8e8;   --high-text: #a03030;
  --danger: #c0392b;
}

[data-theme="dark"] {
  --bg: #12141c;
  --card: #1c1f2b;
  --text: #e8eaf2;
  --muted: #9aa1b5;
  --border: #2c3142;
  --primary: #7283f5;
  --primary-hover: #8d9bff;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);

  --low-bg: #1e3a29;    --low-text: #8fd3a4;
  --medium-bg: #3d3318; --medium-text: #efcd7a;
  --high-bg: #452424;   --high-text: #f2a0a0;
  --danger: #ef7b6d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}

.container { max-width: 1000px; margin: 0 auto; padding: 0 20px; }
h1, h2, p { margin: 0; }
.visually-hidden { position: absolute; left: -9999px; }

.header { background: var(--card); border-bottom: 1px solid var(--border); padding: 16px 0; }
.header-inner { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.logo { font-size: 1.6rem; color: var(--primary); }
.tagline { color: var(--muted); font-size: 0.95rem; }

.intro { margin: 28px 0 18px; }
.intro h2 { font-size: 1.8rem; }
.intro p { color: var(--muted); }

.section-title { font-size: 1.1rem; margin-bottom: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.form { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 12px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
label { font-size: 0.85rem; color: var(--muted); }

input, select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, button:focus-visible {
  outline: 3px solid rgba(79, 99, 231, 0.45);
  outline-offset: 1px;
}
.form-error { color: var(--danger); font-size: 0.9rem; margin-top: 10px; min-height: 1.2em; }

.btn, .filter-btn, .task-actions button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 10px 16px;
  background: var(--card);
  color: var(--text);
  transition: background 0.15s, transform 0.1s;
}
.btn:hover, .filter-btn:hover, .task-actions button:hover { background: var(--bg); transform: translateY(-1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 18px; }
.stat { text-align: center; padding: 16px; }
.stat-number { display: block; font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.completion { text-align: center; margin: 12px 0 24px; color: var(--muted); }

.filters { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-buttons { display: flex; gap: 8px; }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
#filter-subject { width: auto; min-width: 180px; }

.task-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 60px; }
.task { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 20px; }
.task-title { font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.85rem; color: var(--muted); }
.task-actions { display: flex; gap: 8px; }
.task-actions .delete-btn { color: var(--danger); }

.badge { padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.priority-low { background: var(--low-bg); color: var(--low-text); }
.priority-medium { background: var(--medium-bg); color: var(--medium-text); }
.priority-high { background: var(--high-bg); color: var(--high-text); }

.due-soon { color: var(--medium-text); font-weight: 600; }
.due-overdue { color: var(--danger); font-weight: 600; }
.task.overdue { border-left: 4px solid var(--danger); }

.task.completed { opacity: 0.6; }
.task.completed .task-title { text-decoration: line-through; }

.empty { text-align: center; color: var(--muted); padding: 30px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 16px; border-radius: 12px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow); z-index: 10; max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }
.toast button {
  font: inherit; font-weight: 600; cursor: pointer;
  background: none; border: none; color: var(--primary); padding: 4px 8px;
}

@media (max-width: 700px) {
  .form { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .filter-buttons .filter-btn { flex: 1; }
  #filter-subject { width: 100%; }
  .task { flex-direction: column; align-items: stretch; }
  .task-actions button { flex: 1; padding: 12px; }
  .btn-primary { padding: 12px; }
}
