/* ===== VARIABLES CSS ===== */
:root {
  --brand-primary: #2E7D32;
  --brand-accent: #F57C00;
  --brand-dark: #0F172A;
  --brand-muted: #64748B;
  --brand-bg: #F6F7FB;
  --brand-white: #FFFFFF;
  --ring: 0 0 0 .25rem rgba(46,125,50,.25);
  --shadow-soft: 0 10px 30px rgba(15,23,42,.08);
  --shadow-strong: 0 16px 40px rgba(15,23,42,.12);
  --sidebar-w: 260px;
  --header-height: 80px;
}

/* ===== RESET & BASE STYLES ===== */
html, body {
  background: var(--brand-bg);
}

a {
  text-decoration: none;
}

.btn:focus,
.form-control:focus,
.nav-link:focus {
  box-shadow: var(--ring);
  outline: none;
}

/* ===== LAYOUT STRUCTURE ===== */
.topbar-accent {
  height: 3px;
  background: linear-gradient(90deg, var(--brand-accent), var(--brand-primary));
}

.app-wrapper {
  padding-top: var(--header-height) !important;
  padding-left: var(--sidebar-w);
}

/* ===== HEADER & NAVIGATION ===== */
.navbar-branding {
  backdrop-filter: blur(10px);
  background: rgba(255,255,255,.82);
  box-shadow: var(--shadow-soft);
  border-bottom: 1px solid rgba(15,23,42,.06);
  min-height: var(--header-height);
}

.navbar {
  --bs-navbar-padding-y: .5rem;
}

.navbar-brand {
  padding: 0.5rem 0;
}

.navbar-brand img {
  height: 48px !important;
}

.navbar-nav .nav-link {
  padding: 0.5rem 0.75rem;
}

.navbar-branding .container-fluid {
  padding-left: 2rem;
  padding-right: 2rem;
}

.app-name {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--brand-primary);
  letter-spacing: -0.01em;
}

/* ===== SEARCH COMPONENT ===== */
.header-search {
  position: relative;
  margin-left: 2rem !important;
  margin-right: 2rem !important;
  flex-grow: 1;
  max-width: 400px;
}

.header-search .form-control {
  border-radius: 999px;
  padding-left: 3rem;
  background: #fff;
  border: 1px solid rgba(15,23,42,.1);
  font-size: 0.9rem;
}

.header-search .form-control:focus {
  box-shadow: var(--ring);
  border-color: var(--brand-primary);
}

.header-search .bi-search {
  position: absolute;
  left: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: .6;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  padding-top: var(--header-height) !important;
  background: #fff;
  border-right: 1px solid rgba(15,23,42,.06);
  box-shadow: var(--shadow-soft);
  z-index: 1030;
}

.sidebar .brand-pane {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: var(--header-height) !important;
  display: flex;
  align-items: center;
  padding: 0 .75rem;
  background: #fff;
  border-right: 1px solid rgba(15,23,42,.06);
}

.sidebar .brand-pane img {
  height: 40px !important;
}

.sidebar-app-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand-primary);
  margin-left: 0.75rem;
  display: none;
}

.sidebar .menu {
  padding: .75rem;
}

.sidebar .menu .menu-title {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--brand-muted);
  margin: .75rem 1rem;
}

.sidebar .nav-link {
  color: #0f172a;
  opacity: .9;
  font-weight: 500;
  border-radius: 12px;
  padding: .6rem .75rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}

.sidebar .nav-link:hover {
  background: rgba(15,23,42,.04);
  opacity: 1;
}

.sidebar .nav-link.active {
  color: #0f172a;
  background: linear-gradient(90deg, rgba(46,125,50,.12), rgba(245,124,0,.12));
  border-left: 3px solid var(--brand-primary);
}

.sidebar .nav-link .bi {
  font-size: 1rem;
  opacity: .9;
}

/* ===== PAGE CONTENT ===== */
.page-header {
  background: #fff;
  border-bottom: 1px solid rgba(15,23,42,.06);
}

.page-title {
  margin: 0;
  font-weight: 700;
}

.breadcrumb a {
  color: var(--brand-primary);
}

/* ===== CARDS & COMPONENTS ===== */
.card {
  border: 1px solid rgba(15,23,42,.06);
  box-shadow: var(--shadow-soft);
  border-radius: 16px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-strong) !important;
}

.card-title {
  color: var(--brand-dark);
  font-weight: 600;
}

.card-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

/* ===== KPI & DATA VISUALIZATION ===== */
.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.kpi-trend {
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.kpi-trend.up {
  color: #16a34a;
}

.kpi-trend.down {
  color: #ef4444;
}

/* ===== TABLES ===== */
.table th {
  font-weight: 600;
  border-top: none;
  padding: 1rem 0.75rem;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brand-muted);
}

.table td {
  padding: 1rem 0.75rem;
  vertical-align: middle;
}

/* ===== BADGES & AVATARS ===== */
.badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.35em 0.65em;
}

.badge.rounded-pill {
  font-size: 0.7rem;
  padding: 0.35em 0.65em;
}

.avatar-placeholder {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #E2E8F0;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  color: #475569;
}

.user-name {
  font-weight: 600;
  color: var(--brand-dark);
}

.list-group-flush .list-group-item {
  border-color: rgba(15, 23, 42, 0.08);
}

/* ===== DARK THEME ===== */
.theme-dark {
  background: #0B1220;
  color: #E5E7EB;
}

.theme-dark .navbar-branding {
  background: rgba(13,18,31,.85);
  border-color: rgba(255,255,255,.06);
}

.theme-dark .sidebar,
.theme-dark .page-header {
  background: #0F172A;
  border-color: rgba(255,255,255,.08);
}

.theme-dark .nav-link {
  color: #E5E7EB;
}

.theme-dark .sidebar .nav-link:hover {
  background: rgba(255,255,255,.06);
}

.theme-dark .sidebar .nav-link.active {
  background: linear-gradient(90deg, rgba(46,125,50,.25), rgba(245,124,0,.25));
  color: #fff;
}

.theme-dark .card {
  background: #0F172A;
  border-color: rgba(255,255,255,.08);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (min-width: 992px) {
  .sidebar-app-name {
    display: block;
  }
  
  .navbar-branding .container-fluid {
    padding-left: 3rem;
    padding-right: 3rem;
  }
}

@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .sidebar.show {
    transform: translateX(0);
  }
  
  .app-wrapper {
    padding-left: 0;
  }
  
  .navbar-brand img {
    height: 40px !important;
  }
  
  .navbar-branding {
    min-height: 64px;
  }
  
  .navbar-branding .container-fluid {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  .header-search {
    margin-left: 1rem !important;
    margin-right: 1rem !important;
    max-width: 100%;
  }
  
  .app-name {
    font-size: 1.2rem;
  }
}

@media (max-width: 768px) {
  .kpi-value {
    font-size: 1.5rem;
  }
  
  .card-icon {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
  
  .card-body canvas {
    max-height: 250px !important;
  }
  
  .display-4 {
    font-size: 2rem;
  }
}