* {
  box-sizing: border-box;
}

:root {
  --bg: #0a0f1a;
  --surface: #111827;
  --surface-hover: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --accent: #60a5fa;
  --accent-dark: #3b82f6;
  --success: #22c55e;
  --success-dark: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --star: #fbbf24;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 24px 16px;
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 860px;
  margin: 0 auto;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--accent);
}

.auth-block {
  display: flex;
  gap: 0.75rem;
}

.btn {
  padding: 0.6rem 1.3rem;
  border: none;
  border-radius: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

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

.btn-login:hover {
  background: var(--surface-hover);
}

.btn-register {
  background: linear-gradient(135deg, var(--accent), #93c5fd);
  color: white;
}

.btn-add {
  background: linear-gradient(135deg, var(--success), #4ade80);
  color: white;
  font-weight: 600;
}

.btn-add:hover {
  background: linear-gradient(135deg, var(--success-dark), var(--success));
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
  background: var(--surface);
  padding: 1rem 1.2rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
}

.search {
  flex: 1 1 300px;
}

input[type="search"],
input[type="text"],
input[type="datetime-local"] {
  width: 100%;
  padding: 0.8rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  transition: all 0.2s;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(96,165,250,0.18);
}

input::placeholder {
  color: #64748b;
}

.sort-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sort-buttons button {
  padding: 0.65rem 1.2rem;
  background: var(--surface-hover);
  color: var(--text-secondary);
  border: none;
  border-radius: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
}

.sort-buttons button:hover {
  background: #334155;
  color: var(--text);
}

.sort-buttons button.active {
  background: linear-gradient(135deg, var(--accent), #93c5fd);
  color: white;
  box-shadow: 0 4px 14px rgba(59,130,246,0.35);
}

.add-task {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 2.2rem;
  flex-wrap: wrap;
}

.add-task input[type="text"] {
  flex: 1 1 340px;
}

.add-task input[type="datetime-local"] {
  flex: 0 0 220px;
  color-scheme: dark;
}

.section-title {
  background: rgba(30,41,59,0.45);
  padding: 0.6rem 1.2rem;
  border-radius: 0.875rem;
  border-left: 4px solid var(--accent);
  margin: 2.2rem 0 1.1rem;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.1rem 1.3rem;
  display: flex;
  align-items: flex-start;
  gap: 1.1rem;
  transition: all 0.22s ease;
  animation: fadeInUp 0.4s ease-out;
}

.task:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(0,0,0,0.32);
  border-color: #475569;
  background: linear-gradient(to right, #111827, #172033);
}

.task input[type="checkbox"] {
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: 4px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.task input[type="checkbox"]:checked {
  background: var(--success);
  border-color: var(--success);
}

.task input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  inset: 0;
  color: white;
  font-size: 16px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.task-content {
  flex: 1;
  cursor: pointer;
}

.task-text {
  font-size: 1.1rem;
  font-weight: 500;
  display: block;
  margin-bottom: 0.4rem;
}

.task.done .task-text {
  text-decoration: line-through;
  color: var(--text-secondary);
  opacity: 0.78;
}

.due-badge {
  font-size: 0.78rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
  margin-right: 0.5rem;
}

.due-badge.overdue { background: #7f1d1d; color: #fecaca; }
.due-badge.today   { background: #78350f; color: #fde68a; }
.due-badge.soon    { background: #1e40af; color: #bfdbfe; }
.due-badge.future  { background: #1e293b; color: #cbd5e1; }

.due-date {
  font-size: 0.86rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.notes-preview {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-top: 0.35rem;
  opacity: 0.93;
}

.notes-preview:empty { display: none; }

.star, .delete {
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.22s;
  padding: 0.35rem;
  border-radius: 50%;
  line-height: 1;
  user-select: none;
}

.star {
  color: #475569;
}

.star.favorite {
  color: var(--star);
  animation: star-pop 0.45s ease;
}

.star:hover {
  background: rgba(251,191,36,0.14);
  transform: scale(1.18);
}

.delete {
  color: #64748b;
}

.delete:hover {
  color: var(--danger);
  background: rgba(239,68,68,0.14);
  transform: scale(1.18);
}

.empty-message {
  text-align: center;
  color: #64748b;
  padding: 3.5rem 1rem;
  font-style: italic;
  font-size: 1.1rem;
}

.status-message {
  margin-top: 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.4);
  color: #93c5fd;
  font-weight: 500;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes star-pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.65); }
  100% { transform: scale(1); }
}

/* ===== СТРАНИЦА ЗАМЕТОК (улучшенная) ===== */
.note-page {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem 1rem 3rem;
}

.note-wrapper {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 1.5rem;
  border-radius: 1.25rem;
  background: #0f172a;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.45);
  border: 1px solid #1e293b;
  animation: slideUpFade 0.5s ease-out;
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.note-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.note-header .note-label {
  margin: 0;
  font-size: 0.75rem;
  color: #6b7a8f;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.note-header h1 {
  margin: 0.2rem 0 0;
  font-size: 2rem;
  background: linear-gradient(135deg, #fff, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Круглая кнопка "Назад" */
.btn-circle {
  width: 2.8rem;
  height: 2.8rem;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.btn-circle:hover {
  background: var(--surface-hover);
  transform: scale(1.1);
}

.note-editor {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.editor-panel {
  flex: 1 1 320px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.sidebar {
  flex: 0 0 280px;
}

.editor-panel label,
.sidebar label {
  font-weight: 600;
  color: var(--text-secondary);
}

/* Текстовое поле */
.editor-panel textarea {
  min-height: 320px;
  padding: 1.1rem;
  border-radius: 0.9rem;
  background: #0b111e;
  border: 1px solid #2d3a4f;
  color: var(--text);
  resize: vertical;
  font-family: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  transition: border 0.2s, box-shadow 0.2s;
}

.editor-panel textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
  outline: none;
}

/* Поле даты с иконкой */
.input-with-icon {
  display: flex;
  align-items: center;
  background: #0b111e;
  border: 1px solid #334155;
  border-radius: 0.875rem;
  transition: border 0.2s, box-shadow 0.2s;
}

.input-with-icon:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.input-with-icon .icon {
  padding: 0 0.5rem 0 1rem;
  font-size: 1.2rem;
  opacity: 0.7;
}

.input-with-icon input {
  width: 100%;
  padding: 0.8rem 1rem 0.8rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
}

.input-with-icon input:focus {
  outline: none;
  box-shadow: none;
}

/* Кастомные чекбоксы */
.checkbox-styled {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
  transition: color 0.2s;
}

.checkbox-styled:hover {
  color: var(--text);
}

.checkbox-styled input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkbox-styled .checkmark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid #4b5563;
  border-radius: 0.5rem;
  background: #1f2937;
  transition: all 0.2s;
  font-size: 1rem;
  color: white;
}

.checkbox-styled input[type="checkbox"]:checked + .checkmark {
  background: var(--success);
  border-color: var(--success);
}

.checkbox-styled input[type="checkbox"]:checked + .checkmark::after {
  content: "✓";
}

/* Специальный стиль для избранного (звезда) */
.checkbox-styled.favorite .checkmark::before {
  content: "☆";
  font-size: 1.2rem;
  line-height: 1;
}

.checkbox-styled.favorite input[type="checkbox"]:checked + .checkmark::before {
  content: "★";
  color: var(--star);
}

.checkbox-styled.favorite .checkmark {
  border-radius: 50%; /* звёздочка лучше смотрится в круге */
}

.checkbox-styled.favorite input[type="checkbox"]:checked + .checkmark {
  background: transparent;
  border-color: var(--star);
}

.note-meta {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.5rem 0;
}

/* Предпросмотр Markdown */
.preview-panel {
  min-height: 320px;
  padding: 1.2rem;
  border-radius: 0.9rem;
  border: 1px solid #2d3a4f;
  background: #0b111e;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #d1d9e8;
}

.preview-panel h1,
.preview-panel h2,
.preview-panel h3 {
  color: var(--accent);
  margin-top: 0.5em;
  margin-bottom: 0.3em;
  font-weight: 600;
}

.preview-panel h1 { font-size: 1.8rem; border-bottom: 1px solid #334155; padding-bottom: 0.3rem; }
.preview-panel h2 { font-size: 1.5rem; }
.preview-panel h3 { font-size: 1.3rem; }

.preview-panel p { margin: 0.8rem 0; }

.preview-panel ul, 
.preview-panel ol {
  padding-left: 1.8rem;
}

.preview-panel li { margin: 0.3rem 0; }

.preview-panel code {
  background: #1e293b;
  padding: 0.2rem 0.4rem;
  border-radius: 0.4rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9em;
  color: #f472b6;
}

.preview-panel pre {
  background: #1a2332;
  padding: 1rem;
  border-radius: 0.8rem;
  overflow-x: auto;
  border: 1px solid #334155;
}

.preview-panel pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.preview-panel blockquote {
  border-left: 4px solid var(--accent);
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  background: #1e293b;
  border-radius: 0.5rem;
  color: #b4c0d0;
}

.preview-panel a {
  color: #93c5fd;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.preview-panel a:hover {
  color: var(--accent);
}

.note-actions {
  margin-top: 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
}

/* Кнопка сохранения с иконкой */
.btn-save {
  background: linear-gradient(135deg, var(--success), #4ade80);
  color: white;
  font-weight: 600;
  padding: 0.8rem 2rem;
  border-radius: 2rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.3);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-save:hover {
  background: linear-gradient(135deg, var(--success-dark), var(--success));
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(34, 197, 94, 0.4);
}

.btn-save .btn-icon {
  font-size: 1.2rem;
}

.note-status-message {
  padding: 0.5rem 1rem;
  border-radius: 2rem;
  background: #1e293b;
  border: 1px solid #334155;
  transition: all 0.3s;
  font-size: 0.95rem;
}

.note-status-error {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
  color: #fca5a5;
}

@media (max-width: 640px) {
  .add-task {
    flex-direction: column;
  }
  .add-task input[type="datetime-local"] {
    width: 100%;
  }
  .note-editor {
    flex-direction: column;
  }
  .note-header {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-circle {
    align-self: flex-start;
  }
}