:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #eef7f4;
  --text: #111827;
  --muted: #64748b;
  --line: #d8e2e7;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #d97706;
  --danger: #b42318;
  --sidebar: #111c26;
  --sidebar-soft: #1d2a36;
  --shadow: 0 16px 42px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.08), transparent 30%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

[data-theme="dark"] {
  --bg: #111827;
  --surface: #1f2937;
  --surface-soft: #263445;
  --text: #f8fafc;
  --muted: #a8b3c5;
  --line: #354458;
  --primary: #2dd4bf;
  --primary-dark: #14b8a6;
  --accent: #f59e0b;
  --danger: #f87171;
  --sidebar: #0b1220;
  --sidebar-soft: #182235;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.18);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(240px, 260px) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.16), transparent 240px),
    var(--sidebar);
  color: #f8fafc;
  padding: 24px 22px;
  min-width: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: block;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  overflow: visible;
  letter-spacing: 0;
  padding: 4px 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a,
.nav button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  color: #d9e6f2;
  background: transparent;
  cursor: pointer;
  padding: 11px 12px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav a::before,
.nav button::before {
  width: 22px;
  min-width: 22px;
  text-align: center;
  font-size: 16px;
  line-height: 1;
  opacity: 0.92;
}

.nav a[href*="dashboard"]::before { content: "📊"; }
.nav a[href*="notes"]::before { content: "📝"; }
.nav a[href*="categories"]::before { content: "📁"; }
.nav a[href*="community"]::before { content: "🌐"; }
.nav a[href*="favorites"]::before { content: "⭐"; }
.nav a[href*="flashcards"]::before { content: "🧠"; }
.nav a[href*="error-logs"]::before { content: "🐞"; }
.nav a[href*="study-logs"]::before { content: "📅"; }
.nav a[href*="notifications"]::before { content: "🔔"; }
.nav a[href*="profile"]::before { content: "👤"; }
.nav a[href*="admin"]::before { content: "🛡️"; }
.nav button[data-theme-toggle]::before { content: "🌙"; }
.nav button[data-logout]::before { content: "🚪"; }

.nav a:hover,
.nav button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  transform: translateX(2px);
}

.nav .active {
  background: rgba(45, 212, 191, 0.15);
  color: #ffffff;
  box-shadow: inset 3px 0 0 #2dd4bf;
}

.main {
  width: 100%;
  max-width: 1680px;
  padding: 34px 40px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  min-height: 44px;
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-heading h1 {
  margin: 0;
  font-size: 36px;
  line-height: 1.12;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
}

.btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: var(--shadow-soft);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease, border-color 0.14s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: #f8fafc;
  color: #243447;
}

[data-theme="dark"] .btn.ghost {
  background: #263445;
  color: var(--text);
}

.btn.danger {
  color: var(--danger);
  border-color: #ffd1cc;
  background: #fff7f6;
}

[data-theme="dark"] .btn.danger {
  background: #3b1f24;
  border-color: #7f3038;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.profile-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
  align-items: start;
}

.profile-summary {
  margin-bottom: 18px;
}

.panel,
.stat,
.form-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel,
.form-panel {
  padding: 22px;
}

.main > .form-panel {
  max-width: 980px;
}

.form-list-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.form-list-layout > .form-panel {
  position: sticky;
  top: 24px;
}

.list-panel {
  min-width: 0;
}

.list-panel .toolbar {
  margin-bottom: 18px;
}

.list-panel .notes-grid {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.form-panel h2,
.panel h2 {
  margin: 0 0 14px;
  font-size: 20px;
  line-height: 1.25;
}

.stat {
  min-height: 132px;
  padding: 20px;
  display: grid;
  align-content: space-between;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  width: 54px;
  height: 54px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  position: absolute;
  right: 16px;
  top: 16px;
}

.stat span {
  color: var(--muted);
  font-size: 14px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
  line-height: 1;
  color: var(--primary-dark);
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.list-row:hover {
  background: var(--surface-soft);
  border-color: rgba(15, 118, 110, 0.26);
  transform: translateY(-1px);
}

.list-row:last-child {
  margin-bottom: 0;
}

.list-row h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.list-row p {
  margin: 0;
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  border-radius: 999px;
  background: var(--tag-color, var(--surface-soft));
  color: var(--primary-dark);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
  border: 1px solid rgba(15, 118, 110, 0.12);
}

.badge.category,
.badge.public {
  background: #dcfce7;
  color: #166534;
  border-color: #bbf7d0;
}

.badge.private {
  background: #e0f2fe;
  color: #075985;
  border-color: #bae6fd;
}

.badge.easy,
.badge.learning,
.badge.active {
  background: #ecfdf5;
  color: #047857;
  border-color: #bbf7d0;
}

.badge.medium,
.badge.remembered {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

.badge.hard,
.badge.archived {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

.badge.pending,
.badge.system,
.badge.user {
  background: #f1f5f9;
  color: #334155;
  border-color: #cbd5e1;
}

.badge.admin {
  background: #eef2ff;
  color: #3730a3;
  border-color: #c7d2fe;
}

.badge.locked {
  background: #fff1f2;
  color: #be123c;
  border-color: #fecdd3;
}

[data-theme="dark"] .badge.category,
[data-theme="dark"] .badge.public,
[data-theme="dark"] .badge.private,
[data-theme="dark"] .badge.easy,
[data-theme="dark"] .badge.medium,
[data-theme="dark"] .badge.hard,
[data-theme="dark"] .badge.learning,
[data-theme="dark"] .badge.remembered,
[data-theme="dark"] .badge.active,
[data-theme="dark"] .badge.archived,
[data-theme="dark"] .badge.pending,
[data-theme="dark"] .badge.system,
[data-theme="dark"] .badge.user,
[data-theme="dark"] .badge.admin,
[data-theme="dark"] .badge.locked {
  background: rgba(45, 212, 191, 0.1);
  color: #ccfbf1;
  border-color: rgba(45, 212, 191, 0.24);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.card-image,
.detail-image,
.avatar-preview {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: cover;
}

.card-image {
  aspect-ratio: 16 / 9;
  margin-bottom: 12px;
}

.detail-image {
  max-height: 420px;
  margin: 12px 0;
}

.avatar-preview {
  width: 120px;
  height: 120px;
  border-radius: 999px;
}

.unread {
  background: var(--surface-soft);
  border-radius: 8px;
  padding-left: 12px;
  padding-right: 12px;
}

.empty-state {
  color: var(--muted);
  padding: 28px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  max-width: 520px;
  display: grid;
  justify-items: start;
  gap: 8px;
  line-height: 1.6;
}

.empty-state::before {
  content: "📝";
  width: 46px;
  height: 46px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-soft);
  color: var(--primary);
  font-size: 22px;
  margin-bottom: 2px;
}

.empty-state:has(.empty-icon)::before {
  content: none;
  display: none;
}

.empty-state .empty-icon {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-soft);
  color: var(--primary);
  font-size: 23px;
}

.empty-state h3,
.empty-state p {
  margin: 0;
}

.empty-state h3 {
  color: var(--text);
  font-size: 18px;
}

.notes-grid > .empty-state,
.list-panel .empty-state,
[data-categories-list] > .empty-state {
  grid-column: 1 / -1;
  max-width: none;
  min-height: 170px;
  align-content: center;
}

.form-grid {
  display: grid;
  gap: 16px;
  max-width: 960px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  font-weight: 800;
  font-size: 14px;
}

.field input,
.field textarea,
.field select,
.search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.search-input:focus,
.toolbar input:focus,
.toolbar select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

.search-input {
  max-width: 320px;
}

.field textarea {
  min-height: 140px;
  resize: vertical;
}

textarea[name*="code" i],
textarea[name="exampleCode"],
textarea[name="errorCode"],
textarea[name="fixedCode"],
pre,
code {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.form-message {
  min-height: 22px;
  font-weight: 700;
  padding: 2px 0;
}

.form-message.error {
  color: var(--danger);
  background: rgba(180, 35, 24, 0.08);
  border-radius: 8px;
  padding: 8px 10px;
}

.form-message.success {
  color: var(--primary);
  background: rgba(15, 118, 110, 0.08);
  border-radius: 8px;
  padding: 8px 10px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tabs .btn {
  box-shadow: none;
}

.comments-panel {
  margin-top: 18px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    min-width: 0;
    padding: 16px;
    gap: 14px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav a,
  .nav button {
    min-height: 42px;
    padding: 9px 10px;
    text-align: left;
  }

  .main {
    padding: 22px 18px 36px;
  }

  .grid.three {
    grid-template-columns: 1fr;
  }

  .grid.four,
  .profile-layout,
  .form-list-layout {
    grid-template-columns: 1fr;
  }

  .form-list-layout > .form-panel {
    position: static;
  }

  .page-heading,
  .topbar,
  .list-row {
    align-items: stretch;
    flex-direction: column;
  }

  .row-actions,
  .toolbar {
    width: 100%;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .search-input {
    max-width: none;
  }
}

@media (max-width: 600px) {
  .main {
    padding: 18px 14px 32px;
  }

  .topbar,
  .page-heading,
  .list-row {
    gap: 12px;
  }

  .toolbar,
  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .notes-grid,
  .list-panel .notes-grid {
    grid-template-columns: 1fr;
  }

  .field input,
  .field textarea,
  .field select,
  .search-input,
  .toolbar input,
  .toolbar select {
    min-width: 0;
  }
}

@media (max-width: 420px) {
  .main {
    padding: 14px;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  body {
    overflow-x: hidden;
  }

  .page-heading h1 {
    font-size: 28px;
  }

  .stat strong {
    font-size: 28px;
  }

  .btn,
  .nav button {
    width: 100%;
  }

  .panel,
  .form-panel,
  .note-card,
  .empty-state {
    padding: 16px;
  }
}
