:root {
  --app-bg: #f5f7fb;
  --app-ink: #0f172a;
  --app-muted: #64748b;
  --app-border: #e2e8f0;
  --app-surface: #ffffff;
  --app-surface-muted: #f8fafc;
  --app-primary: #2563eb;
  --app-radius: 18px;
  --app-shadow: 0 14px 30px rgba(15, 23, 42, 0.08);
  --app-shadow-soft: 0 8px 20px rgba(15, 23, 42, 0.06);
}

body.app-body {
  min-height: 100vh;
  color: var(--app-ink);
  background-color: var(--app-bg);
  background-image:
    radial-gradient(circle at 18% 12%, rgba(37, 99, 235, 0.12), transparent 42%),
    radial-gradient(circle at 84% 0%, rgba(14, 165, 233, 0.12), transparent 38%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0));
  font-family: "Noto Sans SC", "Manrope", sans-serif;
}

main.app-main {
  padding: 2.5rem 0 3rem;
  flex: 1;
}

.app-shell {
  position: relative;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: 240px;
  height: 100vh;
  padding: 1rem;
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-right: 1px solid var(--app-border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
}

.app-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.5px;
  text-decoration: none;
  color: var(--app-ink);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-brand-text {
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: 0.08rem;
}

.sidebar-toggle {
  border-radius: 0.6rem;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-link {
  font-weight: 500;
  color: #475569;
}

.nav-link.active,
.nav-link:hover {
  color: var(--app-primary);
}

.sidebar-icon {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 0.5rem;
  background: #e2e8f0;
  color: #334155;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.nav-link.active .sidebar-icon {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.sidebar-text {
  white-space: nowrap;
}

.sidebar-caret {
  margin-left: auto;
  font-size: 0.75rem;
  opacity: 0.8;
  transition: transform 0.2s ease;
}

.sidebar-group-toggle[aria-expanded="true"] .sidebar-caret {
  transform: rotate(180deg);
}

.app-sidebar .nav {
  gap: 0.35rem;
}

.app-sidebar .nav-pills .nav-link {
  border-radius: 0.75rem;
  padding: 0.55rem 0.85rem;
  color: #334155;
}

.app-sidebar .nav-pills .nav-link:hover {
  background: var(--app-surface-muted);
  color: var(--app-primary);
}

.app-sidebar .nav-pills .nav-link.active,
.app-sidebar .nav-pills .nav-link.active:hover {
  background: var(--app-primary);
  color: #ffffff;
}

.sidebar-subnav {
  padding-left: 2.4rem;
  margin-top: 0.3rem;
  gap: 0.2rem;
}

.sidebar-subnav .nav-link {
  font-size: 0.92rem;
  padding: 0.35rem 0.85rem;
}

.app-sidebar .dropdown-toggle {
  width: 100%;
  justify-content: space-between;
  gap: 0.5rem;
}

.app-sidebar .dropdown-toggle::after {
  margin-left: auto;
}

.app-sidebar .dropdown-menu {
  width: 100%;
}

.sidebar-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e2e8f0;
  color: #1e293b;
  font-weight: 600;
  font-size: 0.85rem;
  object-fit: cover;
}

.surface {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
}

.card {
  border-radius: var(--app-radius);
  border-color: var(--app-border);
}

.card.shadow-sm {
  box-shadow: var(--app-shadow-soft);
}

.card .card {
  background: var(--app-surface-muted);
  box-shadow: none;
}

.surface-muted {
  background: var(--app-surface-muted);
}

.surface-footer {
  border-top: 1px solid var(--app-border);
}

.page-hero {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 2rem;
  animation: float-in 0.55s ease both;
}

.page-hero::after {
  content: "";
  position: absolute;
  top: -40%;
  right: -10%;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.2), transparent 60%);
  opacity: 0.7;
  pointer-events: none;
}

.page-hero > * {
  position: relative;
  z-index: 1;
}

.page-hero-text {
  min-width: 220px;
}

.page-hero-meta {
  flex-basis: 100%;
  color: var(--app-muted);
}

.page-hero-simple {
  flex-direction: column;
  align-items: flex-start;
}

.page-title {
  font-size: clamp(1.6rem, 2vw + 1rem, 2.4rem);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.page-subtitle {
  margin-bottom: 0;
  color: var(--app-muted);
  max-width: 42rem;
}

.section-title {
  font-weight: 600;
  color: #1e293b;
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--app-border);
  border-radius: 14px;
  background: var(--app-surface);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  animation: float-in 0.45s ease both;
  animation-delay: calc(var(--i, 0) * 60ms);
}

.tile:hover {
  transform: translateY(-2px);
  border-color: rgba(37, 99, 235, 0.25);
  box-shadow: var(--app-shadow-soft);
}

.tile-title {
  font-weight: 600;
  color: #0f172a;
}

.form-control,
.form-select {
  border-radius: 12px;
  border-color: var(--app-border);
}

.btn-primary {
  box-shadow: 0 10px 18px rgba(37, 99, 235, 0.25);
}

.table thead th {
  font-weight: 600;
  color: #475569;
}

.tag-panel {
  max-height: 360px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.tag-name {
  font-weight: 600;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-count {
  font-size: 0.8rem;
  color: var(--app-muted);
}

.tag-list .tag-item {
  border: 1px solid var(--app-border);
  border-radius: 12px;
  margin-bottom: 0.5rem;
}

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

.tag-list .tag-item:hover {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: var(--app-shadow-soft);
}

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

footer.app-footer {
  background: rgba(255, 255, 255, 0.9);
  border-top: 1px solid var(--app-border);
}

.app-layout.sidebar-collapsed .app-sidebar {
  width: 76px;
  padding: 0.75rem 0.6rem;
}

.app-layout.sidebar-collapsed .sidebar-brand-text,
.app-layout.sidebar-collapsed .sidebar-text,
.app-layout.sidebar-collapsed .sidebar-user-name {
  display: none;
}

.app-layout.sidebar-collapsed .nav-link {
  justify-content: center;
}

.app-layout.sidebar-collapsed .sidebar-subnav,
.app-layout.sidebar-collapsed .sidebar-caret {
  display: none;
}

.app-layout.sidebar-collapsed .sidebar-toggle {
  width: 100%;
}

.app-layout.sidebar-collapsed .dropdown-toggle {
  justify-content: center;
}

.app-layout.sidebar-collapsed .dropdown-toggle::after {
  display: none;
}

.app-layout.sidebar-collapsed .sidebar-cta {
  padding: 0.45rem;
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 767px) {
  .app-layout {
    flex-direction: column;
  }

  .app-sidebar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--app-border);
  }

  .app-sidebar .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .app-sidebar .nav-link {
    width: auto;
    padding: 0.5rem 0.75rem;
  }

  .app-layout.sidebar-collapsed .app-sidebar {
    width: 100%;
  }

  .app-layout.sidebar-collapsed .sidebar-brand-text,
  .app-layout.sidebar-collapsed .sidebar-text,
  .app-layout.sidebar-collapsed .sidebar-user-name {
    display: inline;
  }

  .app-layout.sidebar-collapsed .nav-link {
    justify-content: flex-start;
  }

  .app-layout.sidebar-collapsed .sidebar-subnav,
  .app-layout.sidebar-collapsed .sidebar-caret {
    display: block;
  }

  .app-layout.sidebar-collapsed .dropdown-toggle::after {
    display: inline-block;
  }

  .page-hero {
    padding: 1.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .page-hero {
    animation: none;
    transition: none;
  }
}
