:root {
  --app-primary: #7c9cff;
  --app-surface: #ffffff;
  --app-muted: #64748b;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(255, 214, 231, 0.55), transparent 30%),
    radial-gradient(circle at top right, rgba(197, 233, 255, 0.55), transparent 28%),
    linear-gradient(180deg, #f8fbff 0%, #f6f7ff 100%);
  color: #1e293b;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
}

.app-header {
  background: linear-gradient(135deg, #ffb8d1 0%, #cfe6ff 50%, #d8f3dc 100%);
  color: #24324a;
}

.card,
.modal-content {
  border-radius: 1rem;
}

.card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 0.75rem 1.75rem rgba(15, 23, 42, 0.12) !important;
}

.note-content {
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.nav-pills .nav-link {
  color: #475569;
  border-radius: 0.75rem;
  font-weight: 600;
}

.nav-pills .nav-link.tab-hoa-hoc {
  background-color: #d8f3dc;
  color: #245c35;
}

.nav-pills .nav-link.tab-sinh-hoc {
  background-color: #dbeafe;
  color: #24507a;
}

.nav-pills .nav-link.tab-tieng-trung {
  background-color: #fce1e4;
  color: #7a3040;
}

.nav-pills .nav-link.tab-tieng-anh {
  background-color: #fff1cc;
  color: #7a5a00;
}

.nav-pills .nav-link.active {
  box-shadow: inset 0 0 0 2px rgba(30, 41, 59, 0.2), 0 0.25rem 0.75rem rgba(15, 23, 42, 0.12);
}

.subtopic-tabs {
  overflow-x: auto;
  flex-wrap: nowrap;
  padding-bottom: 0.25rem;
}

.subtopic-link {
  flex: 0 0 auto;
  background: var(--subtopic-bg, #ffffff);
  border: 1px solid var(--subtopic-border, #dbe3ee);
  color: var(--subtopic-text, #526174);
  white-space: nowrap;
}

.subtopic-link.active {
  background: var(--subtopic-active-bg, #e9d5ff) !important;
  border-color: var(--subtopic-active-border, #c084fc);
  color: var(--subtopic-active-text, #581c87) !important;
  box-shadow: 0 0.35rem 0.75rem rgba(15, 23, 42, 0.08);
}

.note-card {
  overflow: hidden;
  border-top: 4px solid var(--note-accent, #dbeafe);
}

.tree-root {
  position: relative;
}

.tree-node {
  position: relative;
  padding-left: 1.25rem;
}

.tree-node::before {
  content: "";
  position: absolute;
  top: 1.4rem;
  left: 0.45rem;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, hsla(var(--topic-hue, 220), 60%, 72%, 0.8), transparent);
}

.tree-node.depth-0 {
  padding-left: 0;
}

.tree-node.depth-0::before {
  display: none;
}

.node-card {
  position: relative;
  background: rgba(255, 255, 255, 0.88);
  border-left: 5px solid hsla(var(--topic-hue, 220), 60%, 76%, 0.95);
}

.tree-node.depth-0 > .node-card {
  border-left-width: 0;
  border-top: 4px solid hsla(var(--topic-hue, 220), 60%, 76%, 0.95);
}

.tree-node.depth-0 > .node-card > .card-body {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,255,255,0.9));
}

.node-badge {
  background: hsl(var(--topic-hue, 220), 78%, 92%);
  color: hsl(var(--topic-hue, 220), 36%, 26%);
}

.node-actions {
  min-width: 0;
}

.tree-children {
  position: relative;
  margin-top: 1rem;
  padding-left: 1rem;
  display: grid;
  gap: 1rem;
}

.tree-children::before {
  content: "";
  position: absolute;
  left: 0.45rem;
  top: 0;
  bottom: 0.15rem;
  width: 2px;
  background: linear-gradient(180deg, hsla(var(--topic-hue, 220), 60%, 72%, 0.7), transparent);
}

.tree-children > .tree-node {
  padding-left: 1rem;
}

.tree-children > .tree-node::before {
  left: 0.05rem;
}

.tree-children > .tree-node > .node-card::before {
  content: "";
  position: absolute;
  left: -0.9rem;
  top: 1.4rem;
  width: 0.7rem;
  height: 2px;
  background: hsla(var(--topic-hue, 220), 60%, 72%, 0.8);
}

.note-badge {
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

mark.search-highlight {
  padding: 0.05em 0.15em;
  border-radius: 0.2rem;
  background: #fef08a;
}

.attachment-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.5rem;
}

.attachment-thumb {
  display: block;
  border-radius: 0.8rem;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: #fff;
  aspect-ratio: 1 / 1;
}

.attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attachment-videos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.attachment-video {
  margin: 0;
}

.attachment-video video {
  width: 100%;
  border-radius: 0.85rem;
  background: #000;
  aspect-ratio: 16 / 9;
}

.btn {
  border-radius: 0.65rem;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  color: #24324a;
  font-weight: 600;
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-shell {
  width: min(100%, 460px);
}

.login-card {
  padding: 2rem;
  border-radius: 1.5rem;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
}

.login-badge {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 1.25rem;
  display: grid;
  place-items: center;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #ffdbeb, #dbeafe);
  color: #4c1d95;
  font-size: 1.3rem;
}

.login-title {
  font-size: 1.7rem;
  line-height: 1.2;
  margin-bottom: 0.5rem;
}

.login-subtitle {
  margin-bottom: 0.25rem;
  color: #7c3aed;
  font-weight: 700;
}

.login-note {
  color: #64748b;
  margin-bottom: 1.25rem;
}

.login-tip {
  margin-top: 1rem;
  font-size: 0.92rem;
  color: #64748b;
}

@media (max-width: 575.98px) {
  body {
    font-size: 1.0625rem;
  }

  .app-header .container,
  main.container {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .nav-pills {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.25rem !important;
  }

  .nav-pills .nav-item {
    width: auto !important;
    min-width: 0;
  }

  .nav-pills .nav-link {
    width: 100%;
    padding: 0.65rem 0.2rem;
    overflow: hidden;
    font-size: 0.8rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .input-group .form-control {
    min-width: 0;
  }

  .input-group .btn {
    flex: 0 0 auto;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    font-size: 0.9rem;
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 2.8rem;
  }

  .card-body {
    padding: 1.25rem;
  }

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

  .tree-node {
    padding-left: 0.9rem;
  }

  .tree-children {
    padding-left: 0.6rem;
  }

  .attachment-videos {
    grid-template-columns: 1fr;
  }

  .modal-dialog {
    margin: 0.75rem;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .account-chip {
    width: 100%;
    justify-content: center;
  }

  .login-card {
    padding: 1.35rem;
  }
}
