/* ============================================================
   CI4 Web Template - Main Stylesheet
   Modern, Professional, Compact, Mobile & Tablet Friendly
   ============================================================ */

/* --- CSS Variables / Theme Colors --- */
:root {
  --sidebar-width: 250px;
  --sidebar-collapsed-width: 0px;
  --navbar-height: 56px;
  --sidebar-bg: #1a1f2e;
  --sidebar-text: rgba(255,255,255,.75);
  --sidebar-active: #ffffff;
  --sidebar-hover-bg: rgba(255,255,255,.07);
  --sidebar-active-bg: rgba(255,255,255,.13);
  --sidebar-border: rgba(255,255,255,.06);
  --body-bg: #f0f2f5;
  --card-bg: #ffffff;
  --navbar-bg: #ffffff;
  --navbar-border: #e9ecef;
  --footer-bg: #ffffff;
  --footer-border: #e9ecef;
  --text-color: #212529;
  --muted-color: #6c757d;
  --border-color: #dee2e6;

  /* Theme colors */
  --theme-blue:   #0d6efd;
  --theme-green:  #198754;
  --theme-purple: #6f42c1;
  --theme-orange: #fd7e14;
  --theme-red:    #dc3545;
  --theme-teal:   #20c997;
  --theme-indigo: #6610f2;
  --theme-pink:   #d63384;

  --primary-color: var(--theme-blue);
}

/* --- Dark Mode Variables --- */
[data-bs-theme="dark"] {
  --body-bg: #0f1117;
  --card-bg: #1a1f2e;
  --navbar-bg: #141821;
  --navbar-border: rgba(255,255,255,.08);
  --footer-bg: #141821;
  --footer-border: rgba(255,255,255,.08);
  --text-color: #e2e8f0;
  --muted-color: #94a3b8;
  --border-color: rgba(255,255,255,.08);
  --sidebar-bg: #0f1117;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 0.875rem;
  background-color: var(--body-bg);
  color: var(--text-color);
  margin: 0;
  transition: background-color .2s, color .2s;
}

/* --- Layout Structure --- */
.app-body {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.app-sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background-color: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  transition: transform .3s ease, width .3s ease;
  overflow: hidden;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: .5rem 0 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

/* Sidebar Brand */
.sidebar-brand {
  border-bottom: 1px solid var(--sidebar-border);
  min-height: var(--navbar-height);
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 8px;
}

.sidebar-logo-placeholder {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.7);
  flex-shrink: 0;
}

.sidebar-brand-text { color: var(--sidebar-active); line-height: 1.3; overflow: hidden; }

/* Sidebar Nav */
.sidebar-nav { padding: 0; margin: 0; list-style: none; }

.sidebar-nav .nav-item { width: 100%; }

.sidebar-header-text {
  display: block;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.55);
  padding: .25rem 1rem .2rem;
}

.sidebar-header {
  margin-top: 1rem;
  padding-top: .5rem;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: .5rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: background .15s, color .15s;
  border-radius: 0;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link:hover {
  background-color: var(--sidebar-hover-bg);
  color: var(--sidebar-active);
}

.sidebar-link.active {
  background-color: var(--sidebar-active-bg);
  color: var(--sidebar-active);
  border-left: 3px solid var(--primary-color);
}

.sidebar-link.has-children .toggle-icon {
  transition: transform .2s;
  font-size: .7rem;
  flex-shrink: 0;
}

.sidebar-link.has-children[aria-expanded="true"] .toggle-icon {
  transform: rotate(180deg);
}

/* Sub-menus */
.sub-menu {
  padding-left: 0 !important;
  margin: 0;
  list-style: none;
}

.sub-menu .sidebar-link {
  padding: .38rem .75rem .38rem 2.25rem;
  font-size: .82rem;
  opacity: .9;
}

.sub-menu .sub-menu .sidebar-link {
  padding-left: 3rem;
  font-size: .79rem;
  opacity: .85;
}

/* --- Main Content --- */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left .3s ease;
}

/* --- Navbar --- */
.app-navbar {
  height: var(--navbar-height);
  background-color: var(--navbar-bg);
  border-bottom: 1px solid var(--navbar-border);
  gap: .5rem;
  z-index: 1030;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.sidebar-toggle {
  color: var(--text-color);
  font-size: 1.2rem;
}

.navbar-avatar {
  width: 34px;
  height: 34px;
  object-fit: cover;
}

.navbar-avatar-placeholder {
  width: 34px;
  height: 34px;
  background: var(--primary-color);
  color: white;
  font-size: .85rem;
}

/* --- Page Content --- */
.app-content { flex: 1; min-width: 0; }

/* --- Footer --- */
.app-footer {
  background-color: var(--footer-bg);
  border-top: 1px solid var(--footer-border);
  min-height: 44px;
  font-size: .8rem;
}

/* --- Cards --- */
.card {
  background-color: var(--card-bg);
  border-color: var(--border-color) !important;
  border-radius: .75rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.card-header, .card-footer {
  background-color: transparent;
}

/* --- Stat Cards --- */
.stat-card {
  border-radius: .75rem;
  transition: transform .15s, box-shadow .15s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.1) !important;
}

.stat-icon { flex-shrink: 0; }

/* --- Activity dot --- */
.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-color);
  flex-shrink: 0;
  margin-top: 4px;
}

/* --- Color Swatches --- */
.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}

.color-swatch:hover { transform: scale(1.2); }
.color-swatch.active { border-color: white; box-shadow: 0 0 0 2px var(--primary-color); transform: scale(1.15); }

.color-swatch-lg {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.color-swatch-lg:hover { transform: scale(1.1); }
.color-swatch-lg.active { border: 3px solid var(--card-bg); box-shadow: 0 0 0 2px var(--primary-color); }

/* --- Breadcrumb --- */
.breadcrumb { font-size: .8rem; }
.breadcrumb-item a { text-decoration: none; color: var(--muted-color); }
.breadcrumb-item a:hover { color: var(--primary-color); }

/* --- Badges --- */
.badge { font-weight: 500; }

/* --- Tables --- */
.table { font-size: .85rem; --bs-table-bg: var(--card-bg); }
.table-light { --bs-table-bg: rgba(0,0,0,.03); }
[data-bs-theme="dark"] .table-light { --bs-table-bg: rgba(255,255,255,.04); }
.table-hover > tbody > tr:hover > * { background-color: rgba(0,0,0,.03); }
[data-bs-theme="dark"] .table-hover > tbody > tr:hover > * { background-color: rgba(255,255,255,.04); }

/* --- Buttons --- */
.btn { font-size: .85rem; }
.btn-sm { font-size: .8rem; }

/* --- Sidebar Overlay (Mobile) --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1039;
}

.sidebar-overlay.show { display: block; }

/* --- Collapsed sidebar state --- */
.app-body.sidebar-collapsed .app-sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }
.app-body.sidebar-collapsed .app-main { margin-left: 0; }

/* --- Pager --- */
.pagination { font-size: .85rem; }
.page-link { padding: .35rem .65rem; }

/* --- Alert --- */
.alert { font-size: .875rem; border-radius: .5rem; }

/* --- Form --- */
.form-control, .form-select {
  font-size: .875rem;
  border-radius: .5rem;
}

.form-label { font-size: .85rem; margin-bottom: .3rem; }

/* --- Dropdown --- */
.dropdown-menu {
  font-size: .85rem;
  border-radius: .75rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}

/* --- Progress --- */
.progress { border-radius: 4px; }

/* --- Scrollbar (global) --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); }

/* ============================================================
   RESPONSIVE - Mobile / Tablet
   ============================================================ */

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
    box-shadow: none;
  }

  .app-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
  }

  .app-main { margin-left: 0 !important; }

  /* Remove collapsed class effect on mobile */
  .app-body.sidebar-collapsed .app-sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }
}

@media (max-width: 767.98px) {
  .app-content { padding: .75rem !important; }
  .card-body { padding: 1rem; }
}

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; }

.auth-card {
  width: 100%;
  max-width: 440px;
  border-radius: 1rem !important;
  backdrop-filter: blur(10px);
}

.auth-logo { max-height: 70px; max-width: 200px; object-fit: contain; }

.auth-logo-placeholder {
  width: 70px;
  height: 70px;
  border-radius: 1rem;
  background: linear-gradient(135deg, var(--theme-blue), var(--theme-purple));
  color: white;
}

/* ============================================================
   UTILITY
   ============================================================ */
.min-w-0 { min-width: 0; }
.fw-black { font-weight: 900; }

.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
