:root {
  --font: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --bg: #f0ebe3;
  --surface: #fffcf7;
  --surface-2: #f7f3ec;
  --ink: #1c1917;
  --ink-soft: #44403c;
  --muted: #57534e;
  --line: #e4ddd3;
  --line-strong: #d6cfc3;

  --accent: #0f5c56;
  --accent-hover: #0a4540;
  --accent-soft: #d8efeb;
  --accent-ring: rgba(15, 92, 86, 0.22);

  --ok: #166534;
  --ok-bg: #e8f5e9;
  --warn: #9a3412;
  --warn-bg: #ffedd5;
  --danger: #991b1b;
  --danger-bg: #fee2e2;
  --info: #1e3a5f;
  --info-bg: #e8eef5;

  --sidebar-w: 15.5rem;
  --radius: 0.5rem;
  --radius-sm: 0.35rem;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.05), 0 1px 3px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 4px 16px rgba(28, 25, 23, 0.07);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 100% -10%, rgba(15, 92, 86, 0.06), transparent),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(154, 52, 18, 0.04), transparent);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: 1.25;
}

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

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  overflow-y: auto;
  overflow-x: hidden;
  background: #1a2421;
  color: #e7e5e4;
  border-right: 1px solid #0f1614;
  display: flex;
  flex-direction: column;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar .brand {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1.15rem 1.1rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: #fafaf9;
  text-decoration: none;
}

.sidebar .brand:hover {
  color: #fff;
}

.brand-mark {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.45rem;
  background: var(--accent);
  color: #ecfdf8;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.brand-text {
  line-height: 1.2;
  min-width: 0;
}
.brand-text strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-text small {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: #a8a29e;
  font-weight: 400;
}

.nav-section {
  padding: 0.85rem 0.85rem 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #78716c;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.1rem 0.55rem;
  padding: 0.6rem 0.7rem;
  min-height: 2.75rem;
  border-radius: var(--radius-sm);
  color: #d6d3d1;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.sidebar .nav-link i {
  width: 1.15rem;
  font-size: 1rem;
  opacity: 0.85;
  text-align: center;
}

.sidebar .nav-link:hover {
  background: #2a3834;
  color: #fafaf9;
}

.sidebar .nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar .nav-link.active i {
  opacity: 1;
}

.sidebar .nav-link.nav-logout {
  margin-top: auto;
  color: #d6d3d1;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0;
  margin-left: 0;
  margin-right: 0;
  padding: 0.85rem 1.25rem;
}

.sidebar .nav-link.nav-logout:hover {
  background: rgba(185, 28, 28, 0.2);
  color: #fee2e2;
}

.sidebar-nav {
  flex: 1;
  padding: 0.35rem 0 0.75rem;
}

.menu-toggle {
  display: none;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Desktop: collapse / expand the left sidebar rail */
.sidebar-collapse-toggle {
  width: 2.25rem;
  height: 2.25rem;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease;
}

.sidebar-collapse-toggle:hover,
.sidebar-collapse-toggle:focus-visible {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
  outline: 0;
}

.sidebar-collapse-toggle i {
  font-size: 1.2rem;
  line-height: 1;
}

.sidebar-backdrop {
  display: none;
}

.topbar-start {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.main-wrap {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  width: 100%;
  padding: 0.85rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--ink);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.topbar-clock {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: -0.02em;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.28rem 0.65rem 0.28rem 0.35rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.user-chip .avatar {
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 600;
}

.user-chip .role {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.content {
  flex: 1;
  width: 100%;
  max-width: none;
  padding: 1.35rem 1.5rem 2rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.content > .page-toolbar,
.content > .page-back {
  margin-bottom: 0;
}

.content > .dash-bottom,
.content > .kpi-grid,
.content > .dash-charts {
  margin-bottom: 0;
}

.content-narrow {
  max-width: 42rem;
}

.app-footer {
  width: 100%;
  padding: 0.85rem 1.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: center;
}

@media (min-width: 768px) {
  body.sidebar-collapsed {
    --sidebar-w: 4.25rem;
  }
  body.sidebar-collapsed .sidebar .brand-text,
  body.sidebar-collapsed .sidebar .nav-section span,
  body.sidebar-collapsed .sidebar .nav-link span {
    display: none;
  }
  body.sidebar-collapsed .sidebar .brand {
    padding: 1.15rem 0.5rem 1rem;
    justify-content: center;
    position: relative;
  }
  body.sidebar-collapsed .sidebar .brand-mark {
    width: 2rem;
    height: 2rem;
  }
  body.sidebar-collapsed .sidebar .nav-section {
    text-align: center;
    padding: 0.85rem 0 0.35rem;
  }
  body.sidebar-collapsed .sidebar .nav-section::after {
    content: "···";
    display: block;
    color: rgba(255, 255, 255, 0.2);
    font-size: 1.25rem;
    line-height: 0.5;
  }
  body.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding: 0.65rem 0;
  }
  body.sidebar-collapsed .sidebar .nav-link i {
    width: auto;
    font-size: 1.25rem;
  }
}
