:root {
  --sidebar-width: 264px;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --sidebar-bg-start: #1e1b4b;
  --sidebar-bg-end: #312e81;
  --bg-body: #f4f5fa;
  --card-radius: 14px;
  --card-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --card-shadow-hover: 0 4px 8px rgba(16, 24, 40, .08), 0 2px 4px rgba(16, 24, 40, .06);

  --bs-primary: var(--primary);
  --bs-primary-rgb: 79, 70, 229;
  --bs-link-color: var(--primary);
  --bs-link-hover-color: var(--primary-dark);
  --bs-border-radius: .625rem;
  --bs-border-radius-sm: .5rem;
  --bs-border-radius-lg: .875rem;
  --bs-body-bg: var(--bg-body);
  --bs-body-color: #1f2430;
}

* { box-sizing: border-box; }

body {
  background-color: var(--bg-body);
  color: var(--bs-body-color);
}

/* ---------- Layout shell ---------- */

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg-start), var(--sidebar-bg-end));
  color: #e0e2f5;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1040;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.35rem 1.4rem;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  letter-spacing: .01em;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-brand .brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255, 255, 255, .14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem .75rem;
}

.sidebar-section-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(224, 226, 245, .45);
  padding: .85rem .75rem .35rem;
  font-weight: 600;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  color: rgba(224, 226, 245, .82);
  padding: .58rem .75rem;
  border-radius: .55rem;
  font-size: .92rem;
  font-weight: 500;
  margin-bottom: .15rem;
  transition: background-color .15s ease, color .15s ease;
}

.sidebar-nav .nav-link i {
  font-size: 1.05rem;
  width: 1.2rem;
  text-align: center;
  opacity: .9;
}

.sidebar-nav .nav-link:hover {
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: rgba(255, 255, 255, .16);
  color: #fff;
  box-shadow: inset 3px 0 0 #fff;
}

.sidebar-footer {
  padding: .9rem .9rem 1.1rem;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .5rem;
  border-radius: .6rem;
  color: #fff;
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: .85rem;
  font-weight: 600;
  line-height: 1.2;
}

.sidebar-user-role {
  font-size: .72rem;
  color: rgba(224, 226, 245, .6);
}

.sidebar-footer-links {
  margin-top: .6rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}

.sidebar-footer-links a {
  color: rgba(224, 226, 245, .75);
  font-size: .82rem;
  padding: .4rem .5rem;
  border-radius: .5rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
}

.sidebar-footer-links a:hover {
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #ecedf3;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: #1f2430;
}

.sidebar-toggle {
  border: none;
  background: #f1f2f8;
  width: 38px;
  height: 38px;
  border-radius: .55rem;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #1f2430;
}

.content {
  padding: 1.75rem;
  flex: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 30, .45);
  z-index: 1030;
}

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
  .sidebar-toggle {
    display: inline-flex;
  }
  .sidebar-overlay.show {
    display: block;
  }
}

/* ---------- Cards / tables ---------- */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.5rem;
}

.page-header h3 {
  font-weight: 700;
  margin-bottom: .15rem;
}

.page-subtitle {
  color: #6b7280;
  font-size: .9rem;
}

.surface, .table-responsive-card {
  background: #fff;
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  border: 1px solid #eef0f5;
}

.table {
  --bs-table-hover-bg: var(--primary-light);
  margin-bottom: 0;
}

.table thead th {
  text-transform: uppercase;
  font-size: .7rem;
  letter-spacing: .05em;
  color: #7a7f92;
  font-weight: 700;
  border-bottom-width: 1px;
  background: #fafafe;
  white-space: nowrap;
}

.table td, .table th {
  padding: .75rem .85rem;
  vertical-align: middle;
}

.table td.col-index, .table th.col-index {
  color: #9aa0b4;
  font-variant-numeric: tabular-nums;
  width: 1%;
  white-space: nowrap;
}

.card, .table-responsive-card, .surface {
  border-radius: var(--card-radius);
}

.form-control, .form-select {
  border-radius: .55rem;
  border-color: #dfe1ea;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15);
}

.btn {
  border-radius: .55rem;
  font-weight: 500;
}

.btn-primary {
  --bs-btn-bg: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: var(--primary-dark);
  --bs-btn-hover-border-color: var(--primary-dark);
  --bs-btn-active-bg: var(--primary-dark);
  --bs-btn-active-border-color: var(--primary-dark);
  --bs-btn-focus-shadow-rgb: 79, 70, 229;
}

.btn-outline-primary {
  --bs-btn-color: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: var(--primary);
  --bs-btn-hover-border-color: var(--primary);
}

.badge {
  font-weight: 600;
  padding: .4em .65em;
  border-radius: 999px;
  font-size: .72rem;
}

.badge-vencido {
  background-color: #fee2e2;
  color: #b42318;
}

.badge-alerta {
  background-color: #fef3c7;
  color: #92620a;
}

.badge-ok {
  background-color: #d1fae5;
  color: #05704a;
}

.alert {
  border-radius: .7rem;
  border: none;
}

.alert-warning-soft {
  background: #fff8e6;
  border: 1px solid #fbe4a8;
  color: #7a5b06;
  border-radius: .7rem;
  padding: .85rem 1rem;
}

/* ---------- Dashboard ---------- */

.dashboard-counter {
  border-radius: var(--card-radius);
  padding: 1.5rem;
  color: #fff;
  box-shadow: var(--card-shadow);
}

.dashboard-counter.bg-danger {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
}

.dashboard-counter.bg-warning {
  background: linear-gradient(135deg, #fbbf24, #d97706);
}

.dashboard-counter .numero {
  font-size: 2.5rem;
  font-weight: 700;
}

.stat-mini {
  background: #fff;
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  border: 1px solid #eef0f5;
  padding: 1rem;
  text-align: center;
}

.stat-mini .fs-3 {
  color: var(--primary);
}

/* ---------- Login ---------- */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--sidebar-bg-start), var(--sidebar-bg-end));
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  border-radius: 1rem;
}

.login-brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin: 0 auto .75rem;
}
