/* ============================================================
   app.css  —  EnterpriseApp Global Stylesheet
   Mobile-first · Bootstrap 5 extension · PWA-ready
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --sidebar-width:    260px;
  --topbar-height:     56px;
  --brand-primary:   #3b5bdb;
  --brand-dark:      #1a1f36;
  --sidebar-bg:      #1a1f36;
  --sidebar-text:    rgba(255,255,255,.72);
  --sidebar-hover:   rgba(255,255,255,.07);
  --sidebar-active:  rgba(59,91,219,.22);
  --sidebar-border:  rgba(255,255,255,.08);
  --topbar-bg:       #ffffff;
  --content-bg:      #f4f5f9;
  --card-radius:     12px;
  --ease:            cubic-bezier(.4,0,.2,1);
  --transition:      all .22s var(--ease);
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--content-bg);
  color: #2d3748;
  margin: 0;
  /* safe-area for iPhone notch / home indicator */
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── App wrapper ────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ════════════════════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1050;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .28s var(--ease), box-shadow .28s var(--ease);
  /* Smooth scrollbar on sidebar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}

/* ── Sidebar header ───────────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.brand-logo {
  display: flex; align-items: center; gap: 10px;
}
.brand-logo .bi-hexagon-fill {
  font-size: 1.55rem; color: var(--brand-primary);
}
.brand-name {
  font-size: 1.1rem; font-weight: 700;
  color: #fff; letter-spacing: .01em;
}

.sidebar-close {
  color: var(--sidebar-text); border: none;
  background: transparent; padding: 6px 8px;
  border-radius: 8px; line-height: 1;
  display: none; /* shown only on mobile via JS */
}
.sidebar-close:hover { background: var(--sidebar-hover); color: #fff; }

/* ── Sidebar user block ───────────────────────────────────── */
.sidebar-user {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.user-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--brand-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .82rem; color: #fff;
  flex-shrink: 0; text-transform: uppercase;
}
.user-info { overflow: hidden; min-width: 0; }
.user-name {
  font-size: .84rem; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role { font-size: .68rem; margin-top: 3px; }

/* ── Sidebar nav ──────────────────────────────────────────── */
.sidebar-nav {
  list-style: none; padding: 10px 0; margin: 0; flex: 1;
}
.nav-label {
  font-size: .62rem; font-weight: 700; letter-spacing: .1em;
  color: rgba(255,255,255,.28);
  padding: 14px 20px 5px; text-transform: uppercase;
}
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: var(--sidebar-text);
  text-decoration: none; font-size: .865rem;
  transition: var(--transition); border-left: 3px solid transparent;
}
.sidebar-nav .nav-link .bi {
  font-size: 1.05rem; width: 20px;
  text-align: center; flex-shrink: 0;
}
.sidebar-nav .nav-link:hover {
  background: var(--sidebar-hover); color: #fff;
}
.sidebar-nav .nav-link.active {
  background: var(--sidebar-active);
  color: #fff; font-weight: 600;
  border-left-color: var(--brand-primary);
}

/* ── Sidebar footer ───────────────────────────────────────── */
.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  /* Account for iPhone home indicator */
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
.sidebar-logout {
  display: flex; align-items: center; gap: 8px;
  color: rgba(255,255,255,.55); border: 1px solid rgba(255,255,255,.12);
  background: transparent; width: 100%; padding: 8px 14px;
  border-radius: 8px; font-size: .84rem; transition: var(--transition);
  cursor: pointer;
}
.sidebar-logout:hover { color: #fff; background: rgba(255,255,255,.08); }

/* ── Overlay (mobile) ─────────────────────────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.55); z-index: 1040;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ════════════════════════════════════════════════════════════
   MAIN AREA
════════════════════════════════════════════════════════════ */
.main-area {
  margin-left: var(--sidebar-width);
  flex: 1; display: flex; flex-direction: column;
  min-height: 100vh; min-width: 0;
  transition: margin-left .28s var(--ease);
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid #e8ecf0;
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky; top: 0; z-index: 100;
  gap: 10px;
  /* Safe area top for iOS status bar */
  padding-top: env(safe-area-inset-top);
  height: calc(var(--topbar-height) + env(safe-area-inset-top));
}
.topbar-left, .topbar-right {
  display: flex; align-items: center; gap: 6px;
}
.topbar-toggle {
  background: transparent; border: none;
  color: #555; padding: 6px 8px; border-radius: 8px;
  line-height: 1; display: none; /* shown on mobile */
}
.topbar-toggle:hover { background: #f0f2f5; }
.breadcrumb { font-size: .82rem; }
.breadcrumb-item a { text-decoration: none; color: var(--brand-primary); }
.breadcrumb-item.active { color: #6c757d; }

/* ── Content area ─────────────────────────────────────────── */
.content-area {
  flex: 1; padding: 24px 20px;
}

/* ── Page header ──────────────────────────────────────────── */
.page-header {
  border-bottom: 1px solid #e8ecf0; padding-bottom: 12px;
}
.page-title {
  font-size: 1.15rem; font-weight: 700; margin-bottom: 2px;
}

/* ── Cards ────────────────────────────────────────────────── */
.card { border: 1px solid #e8ecf0; border-radius: var(--card-radius); }
.card-header { border-radius: var(--card-radius) var(--card-radius) 0 0 !important; }

/* ── Stat cards ───────────────────────────────────────────── */
.stat-card {
  background: #fff; border-radius: var(--card-radius);
  padding: 18px; display: flex; align-items: center; gap: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  transition: var(--transition); border: 1px solid #e8ecf0;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
}
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; flex-shrink: 0;
}
.stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .76rem; color: #6c757d; margin-top: 3px; }

/* ── Alert toasts ─────────────────────────────────────────── */
.alert-toast { border-radius: 10px; font-size: .875rem; }

/* ── Table helpers ────────────────────────────────────────── */
.table > :not(caption) > * > * { padding: .7rem .75rem; }
.table th { font-size: .78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: #6c757d; }

/* ── Pagination ───────────────────────────────────────────── */
.page-link { min-width: 34px; text-align: center; border-radius: 6px !important; }

/* ════════════════════════════════════════════════════════════
   LOGIN PAGE
════════════════════════════════════════════════════════════ */
.login-body { margin: 0; background: var(--content-bg); }

.login-page {
  display: flex; min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport — avoids iOS address bar jump */
}

/* Brand panel — left, desktop only */
.login-brand {
  flex: 1; background: var(--sidebar-bg);
  background-image: radial-gradient(ellipse at top left, #2d3fc7 0%, #1a1f36 60%);
  display: none; /* hidden on mobile, shown on lg */
  align-items: center; justify-content: center;
  padding: 60px 50px; position: relative; overflow: hidden;
}
.login-brand::before {
  content: ''; position: absolute;
  width: 400px; height: 400px; border-radius: 50%;
  background: rgba(255,255,255,.03); top: -100px; right: -100px;
}

.brand-content { position: relative; z-index: 1; max-width: 400px; }
.brand-icon    { font-size: 3.5rem; color: var(--brand-primary); margin-bottom: 24px; }
.brand-title   { font-size: 2.4rem; font-weight: 800; color: #fff;
  margin-bottom: 14px; line-height: 1.1; }
.brand-title span { color: var(--brand-primary); }
.brand-tagline { font-size: 1rem; color: rgba(255,255,255,.6);
  margin-bottom: 32px; line-height: 1.6; }
.brand-features { list-style: none; padding: 0; margin: 0; }
.brand-features li {
  color: rgba(255,255,255,.7); font-size: .88rem;
  padding: 8px 0; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-features li .bi { color: var(--brand-primary); font-size: 1rem; }

/* Form panel */
.login-form-panel {
  width: 100%; display: flex;
  align-items: center; justify-content: center;
  padding: 40px 24px;
  /* Safe area on iPhone */
  padding-top: max(40px, env(safe-area-inset-top));
  padding-bottom: max(40px, env(safe-area-inset-bottom));
  background: #fff;
}
.login-form-wrap { width: 100%; max-width: 380px; }
.login-title { font-size: 1.65rem; font-weight: 800; color: var(--brand-dark); margin-bottom: 4px; }
.login-subtitle { color: #6c757d; font-size: .88rem; margin-bottom: 26px; }
.login-btn { height: 50px; font-weight: 600; border-radius: 10px; }

/* Input groups */
.input-group-text { border-color: #dee2e6; }
.form-control:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(59,91,219,.12);
}

/* Password strength bar */
.password-strength {
  height: 4px; border-radius: 2px; background: #e9ecef; overflow: hidden;
}
.password-strength::after {
  content: ''; display: block; height: 100%;
  border-radius: 2px; transition: var(--transition);
}
.strength-0::after { width: 0; }
.strength-1::after { width: 25%; background: #dc3545; }
.strength-2::after { width: 50%; background: #fd7e14; }
.strength-3::after { width: 75%; background: #ffc107; }
.strength-4::after { width: 100%; background: #198754; }

/* ════════════════════════════════════════════════════════════
   PWA INSTALL BANNER
════════════════════════════════════════════════════════════ */
#pwaInstallBanner {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff; border-top: 1px solid #e2e8f0;
  box-shadow: 0 -4px 24px rgba(0,0,0,.12);
  padding: 14px 20px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 2000; display: none; /* shown by JS */
  animation: slideUp .3s var(--ease);
}
#pwaInstallBanner.show { display: block; }

.pwa-banner-inner {
  display: flex; align-items: center;
  gap: 14px; max-width: 600px; margin: 0 auto;
}
.pwa-banner-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--brand-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.pwa-banner-text { flex: 1; min-width: 0; }
.pwa-banner-text strong { display: block; font-size: .9rem; }
.pwa-banner-text span   { font-size: .78rem; color: #6c757d; }
.pwa-banner-actions     { display: flex; gap: 8px; flex-shrink: 0; }

/* Apple iOS hint toast */
#iosHintToast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1a1f36; color: #fff;
  padding: 12px 20px; border-radius: 14px;
  font-size: .84rem; text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,.3);
  z-index: 2000; display: none;
  max-width: calc(100vw - 32px);
  animation: fadeIn .3s var(--ease);
}
#iosHintToast.show { display: block; }
#iosHintToast .bi  { font-size: 1.1rem; vertical-align: middle; }

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
════════════════════════════════════════════════════════════ */

/* ── Large (≥992px) — desktop sidebar visible ─────────────── */
@media (min-width: 992px) {
  .login-brand    { display: flex; }
  .topbar-toggle  { display: none !important; }
  .sidebar-close  { display: none !important; }
}

/* ── Below large — sidebar as drawer ─────────────────────── */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  .sidebar-close  { display: inline-flex !important; }
  .topbar-toggle  { display: inline-flex !important; }
  .main-area      { margin-left: 0 !important; }

  /* Tighter content on tablet */
  .content-area   { padding: 20px 16px; }
  .stat-card      { padding: 14px; }
  .stat-value     { font-size: 1.2rem; }

  /* Tables — allow horizontal scroll */
  .table-responsive { -webkit-overflow-scrolling: touch; }
}

/* ── Small (≤767px) — phones ──────────────────────────────── */
@media (max-width: 767.98px) {
  .content-area   { padding: 16px 12px; }
  .page-title     { font-size: 1rem; }

  /* Stack page header on mobile */
  .page-header.d-flex { flex-direction: column; align-items: flex-start !important; gap: 10px; }
  .page-header .btn   { width: 100%; }

  /* Full-width action buttons */
  .form-actions-mobile { flex-direction: column !important; }
  .form-actions-mobile .btn { width: 100%; }

  /* Stat cards — 2 per row */
  .stat-card      { padding: 12px; gap: 10px; }
  .stat-icon      { width: 40px; height: 40px; font-size: 1.1rem; }
  .stat-value     { font-size: 1.1rem; }
  .stat-label     { font-size: .72rem; }

  /* Hide less-important table columns on phone */
  .d-mobile-none  { display: none !important; }

  /* Card radius tighter */
  --card-radius:  8px;

  /* Login form full height */
  .login-form-panel { padding: 28px 18px; min-height: 100dvh; }
  .login-title      { font-size: 1.5rem; }
}

/* ── Extra small (≤575px) ─────────────────────────────────── */
@media (max-width: 575.98px) {
  .topbar { padding: 0 12px; }

  /* Table action buttons — icon only */
  .btn-group .btn-text { display: none; }

  /* Pagination compact */
  .pagination { flex-wrap: wrap; gap: 2px !important; }
}

/* ── Landscape phone ──────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .login-page { align-items: flex-start; }
  .login-form-panel { padding: 20px 24px; }
  .login-form-wrap  { padding-top: 10px; }
}
