html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

/* =========================================================
   Design system tokens
   ========================================================= */
:root {
  --app-primary: #2563eb;
  --app-primary-dark: #1d4ed8;
  --app-primary-soft: #eff6ff;
  --app-secondary: #475569;
  --app-success: #16a34a;
  --app-success-soft: #f0fdf4;
  --app-warning: #d97706;
  --app-warning-soft: #fffbeb;
  --app-danger: #dc2626;
  --app-danger-soft: #fef2f2;
  --app-info: #0891b2;
  --app-info-soft: #ecfeff;

  --app-sidebar-bg: #0f172a;
  --app-sidebar-bg-active: #1e293b;
  --app-sidebar-text: #cbd5e1;
  --app-sidebar-text-active: #ffffff;

  --app-bg: #f4f6fa;
  --app-surface: #ffffff;
  --app-border: #e2e8f0;
  --app-text: #0f172a;
  --app-text-muted: #64748b;

  --app-radius-sm: 0.5rem;
  --app-radius: 0.75rem;
  --app-radius-lg: 1rem;

  --app-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --app-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  --app-shadow-hover: 0 6px 20px rgba(15, 23, 42, 0.12);

  --app-space-1: 0.25rem;
  --app-space-2: 0.5rem;
  --app-space-3: 0.75rem;
  --app-space-4: 1rem;
  --app-space-5: 1.5rem;
  --app-space-6: 2rem;
}

/* =========================================================
   Base
   ========================================================= */
body {
  background-color: var(--app-bg);
  color: var(--app-text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  color: var(--app-text);
  letter-spacing: -0.01em;
}

.text-muted {
  color: var(--app-text-muted) !important;
}

/* =========================================================
   Layout shell (sidebar + main content)
   ========================================================= */
.wrapper {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--app-sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 1040;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  color: var(--app-sidebar-text-active);
  font-size: 1.0625rem;
  font-weight: 700;
  padding: 1.125rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 0.5rem;
}

.sidebar .nav {
  flex-direction: column;
  flex: 1;
  padding: 0 0.5rem;
}

.sidebar .nav-section-label {
  color: rgba(203, 213, 225, 0.55);
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.9rem 0.75rem 0.35rem;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--app-sidebar-text);
  padding: 0.55rem 0.75rem;
  border-radius: var(--app-radius-sm);
  margin: 1px 0;
  white-space: nowrap;
  font-size: 0.9rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar .nav-link i,
.sidebar .nav-link .nav-emoji {
  width: 1.1rem;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.9;
}

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

.sidebar .nav-link.active {
  background: var(--app-primary);
  color: #fff;
  font-weight: 600;
}

.sidebar hr {
  border-color: rgba(255, 255, 255, 0.08);
  margin: 0.5rem 0.75rem;
}

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

.sidebar-backdrop {
  display: none;
}

.topbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-border);
  padding: 0.65rem 1rem;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.sidebar-toggle-btn {
  border: 1px solid var(--app-border);
  background: var(--app-surface);
  border-radius: var(--app-radius-sm);
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.main-content {
  flex: 1;
  padding: var(--app-space-5);
  overflow-x: hidden;
  min-width: 0;
}

@media (max-width: 991.98px) {
  .topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: var(--app-shadow-hover);
  }

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

  .wrapper.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1035;
  }

  .main-content {
    padding: var(--app-space-4);
  }
}

/* =========================================================
   Cards
   ========================================================= */
.card {
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow-sm);
}

.card-header {
  border-bottom: 1px solid var(--app-border);
  font-weight: 600;
  border-top-left-radius: var(--app-radius) !important;
  border-top-right-radius: var(--app-radius) !important;
}

/* Dashboard stat tiles */
.stat-tile {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1.1rem 1.25rem;
}

.stat-tile-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--app-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.stat-tile-label {
  color: var(--app-text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.stat-tile-value {
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-tile.tone-danger .stat-tile-icon { background: var(--app-danger-soft); color: var(--app-danger); }
.stat-tile.tone-success .stat-tile-icon { background: var(--app-success-soft); color: var(--app-success); }
.stat-tile.tone-primary .stat-tile-icon { background: var(--app-primary-soft); color: var(--app-primary); }
.stat-tile.tone-warning .stat-tile-icon { background: var(--app-warning-soft); color: var(--app-warning); }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  border-radius: var(--app-radius-sm);
  font-weight: 500;
}

.btn-primary {
  background-color: var(--app-primary);
  border-color: var(--app-primary);
}

.btn-primary:hover, .btn-primary:focus {
  background-color: var(--app-primary-dark);
  border-color: var(--app-primary-dark);
}

.btn-outline-primary {
  color: var(--app-primary);
  border-color: var(--app-primary);
}

.btn-outline-primary:hover {
  background-color: var(--app-primary);
  border-color: var(--app-primary);
}

/* Comfortable touch targets on mobile */
@media (max-width: 575.98px) {
  .btn {
    min-height: 44px;
  }
}

/* =========================================================
   Tables
   ========================================================= */
.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--app-text-muted);
  font-weight: 700;
  border-bottom-width: 1px;
}

.table > :not(caption) > * > * {
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

/* Scrollable wide tables keep a visible edge + sticky first column */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--app-radius);
  -webkit-overflow-scrolling: touch;
}

.table-scroll .sticky-col {
  position: sticky;
  left: 0;
  background: inherit;
  z-index: 2;
}

/* Card-based layout for simple tables on small screens */
@media (max-width: 767.98px) {
  .table-cards-mobile thead {
    display: none;
  }

  .table-cards-mobile, .table-cards-mobile tbody, .table-cards-mobile tr, .table-cards-mobile td {
    display: block;
    width: 100%;
  }

  .table-cards-mobile tr {
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    box-shadow: var(--app-shadow-sm);
  }

  .table-cards-mobile td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    text-align: right !important;
    border: none;
    padding: 0.4rem 0;
  }

  .table-cards-mobile td[data-label]::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--app-text-muted);
    text-align: left;
    flex-shrink: 0;
  }

  .table-cards-mobile td:empty {
    display: none;
  }
}

/* =========================================================
   Badges & status
   ========================================================= */
.badge {
  font-weight: 600;
  border-radius: 999px;
  padding: 0.4em 0.75em;
}

/* =========================================================
   Forms
   ========================================================= */
.form-control, .form-select {
  border-radius: var(--app-radius-sm);
  border-color: var(--app-border);
}

.form-label {
  font-weight: 500;
  font-size: 0.875rem;
}

/* =========================================================
   Empty state
   ========================================================= */
.empty-state {
  text-align: center;
  padding: var(--app-space-6) var(--app-space-4);
  color: var(--app-text-muted);
}

.empty-state i {
  font-size: 2.25rem;
  opacity: 0.5;
  margin-bottom: 0.75rem;
  display: block;
}
