* {
  box-sizing: border-box;
}

:root {
  --sidebar-width: 288px;
  --sidebar-collapsed-width: 84px;
  --topbar-height: 72px;
  --app-bg: #f5f7f3;
  --panel-bg: #ffffff;
  --ink: #16211b;
  --muted: #66706a;
  --line: #dfe5dc;
  --sidebar-bg: #19231e;
  --sidebar-bg-2: #21352b;
  --sidebar-text: #eef5ef;
  --sidebar-muted: #9fb2a6;
  --accent: #2e7d5b;
  --accent-strong: #236348;
  --accent-soft: #e6f2ec;
  --gold: #c9922b;
  --danger: #c44d4d;
  --shadow: 0 18px 44px rgba(28, 40, 34, 0.12);
}

html {
  min-height: 100%;
}

body.app-body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--app-bg);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  transition: grid-template-columns 180ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  color: var(--sidebar-text);
  background:
    linear-gradient(180deg, rgba(46, 125, 91, 0.24), rgba(25, 35, 30, 0) 34%),
    var(--sidebar-bg);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 1040;
  overflow: hidden;
}

.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--sidebar-text);
}

.brand-mark:hover {
  color: #ffffff;
}

.brand-icon,
.user-avatar,
.topbar-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.brand-icon {
  color: #fff9e9;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
}

.brand-copy,
.user-meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.brand-title,
.user-name {
  overflow: hidden;
  color: #ffffff;
  font-weight: 700;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-subtitle,
.user-role {
  overflow: hidden;
  color: var(--sidebar-muted);
  font-size: 0.78rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  text-transform: capitalize;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  padding: 16px 12px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.nav-section-label {
  margin: 16px 12px 8px;
  color: var(--sidebar-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-section-label:first-child {
  margin-top: 4px;
}

.sidebar-link {
  position: relative;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: #dbe7de;
  border-radius: 8px;
  transition: background-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.sidebar-link i {
  width: 22px;
  flex: 0 0 22px;
  color: #b7c7bd;
  font-size: 1rem;
  text-align: center;
}

.sidebar-link span:not(.sidebar-badge) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-link:hover,
.sidebar-link.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-link:hover i,
.sidebar-link.active i {
  color: #ffffff;
}

.sidebar-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  width: 4px;
  height: 24px;
  border-radius: 0 4px 4px 0;
  background: var(--gold);
}

.sidebar-badge {
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.14);
}

.sidebar-user {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  color: #173226;
  background: #e7f2eb;
}

.sidebar-footer-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.sidebar-icon-btn,
.topbar-icon-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: var(--sidebar-text);
  background: rgba(255, 255, 255, 0.08);
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.sidebar-icon-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.16);
}

.sidebar-icon-btn.danger:hover {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.sidebar-backdrop {
  display: none;
}

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

.topbar {
  position: sticky;
  top: 0;
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px clamp(16px, 3vw, 32px);
  background: rgba(245, 247, 243, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  z-index: 1020;
}

.topbar-icon-btn {
  flex: 0 0 42px;
  color: var(--ink);
  background: var(--panel-bg);
  border-color: var(--line);
}

.topbar-icon-btn:hover {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.topbar-title {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.topbar-kicker {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.topbar-heading {
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-profile {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 4px 4px;
  color: var(--ink);
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar-profile:hover {
  color: var(--accent-strong);
  border-color: rgba(46, 125, 91, 0.35);
}

.topbar-avatar {
  width: 34px;
  height: 34px;
  flex-basis: 34px;
  color: #fff;
  background: var(--accent);
}

.topbar-profile-text {
  max-width: 120px;
  overflow: hidden;
  font-size: 0.88rem;
  font-weight: 700;
  text-overflow: ellipsis;
  text-transform: capitalize;
  white-space: nowrap;
}

.content-area {
  width: 100%;
  min-width: 0;
  max-width: 1500px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px);
}

.content-area > :first-child {
  margin-top: 0;
}

.card,
.modal-content,
.dropdown-menu,
.alert,
.toast {
  border-radius: 8px;
}

.card {
  border-color: var(--line);
  box-shadow: 0 14px 34px rgba(31, 42, 35, 0.06);
}

.btn {
  border-radius: 8px;
}

.form-control,
.form-select {
  border-radius: 8px;
}

.table {
  margin-bottom: 0;
}

.table-responsive {
  border-radius: 8px;
}

.toast {
  position: relative;
  overflow: hidden;
}

.toast-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: rgba(255, 255, 255, 0.7);
  animation: toast-progress linear forwards;
}

@keyframes toast-progress {
  from {
    width: 100%;
  }
  to {
    width: 0%;
  }
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .nav-section-label,
.app-shell.sidebar-collapsed .sidebar-link span:not(.sidebar-badge),
.app-shell.sidebar-collapsed .sidebar-user .user-meta,
.app-shell.sidebar-collapsed .sidebar-badge {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-header,
.app-shell.sidebar-collapsed .sidebar-link,
.app-shell.sidebar-collapsed .sidebar-user {
  justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-footer-actions {
  grid-template-columns: 1fr;
  justify-items: center;
}

.app-shell.sidebar-collapsed .sidebar-footer {
  padding-inline: 12px;
}

@media (max-width: 991.98px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    display: block;
  }

  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 326px);
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow);
  }

  body.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    display: block;
    background: rgba(14, 22, 18, 0.48);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
    z-index: 1030;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .topbar {
    min-height: 64px;
    padding: 10px 14px;
  }

  .topbar-profile-text {
    display: none;
  }

  .content-area {
    padding: 16px 12px 24px;
    overflow-x: auto;
  }

  .content-area .card {
    min-width: 0;
  }
}

@media (max-width: 575.98px) {
  .topbar-heading {
    max-width: 52vw;
  }

  .content-area {
    padding-inline: 10px;
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 40px;
  }

  .table {
    font-size: 0.9rem;
  }
}

@media print {
  body.app-body {
    background: #ffffff;
  }

  .no-print,
  .app-sidebar,
  .topbar,
  .sidebar-backdrop {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .content-area {
    max-width: none;
    padding: 0;
  }
}
