/* ==========================================================================
   NgareDigital ISP Billing — Application stylesheet
   Mobile-first, app-like design system on top of Bootstrap 5.3
   ========================================================================== */

:root {
  /* Brand palette */
  --brand: #0d9488;           /* teal-600 */
  --brand-strong: #0f766e;    /* teal-700 */
  --brand-ink: #0f172a;       /* slate-900 (navy/charcoal) */
  --brand-ink-2: #1e293b;     /* slate-800 */
  --brand-soft: #ccfbf1;      /* teal-100 */
  --brand-soft-2: #f0fdfa;    /* teal-50 */

  --success: #059669;
  --success-soft: #d1fae5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --info: #0284c7;
  --info-soft: #e0f2fe;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;

  --radius: 0.875rem;
  --radius-sm: 0.625rem;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.14);

  --topbar-h: 60px;
  --topbar-h-mobile: 56px;
  --sidebar-w: 268px;
  --bottomnav-h: 64px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--brand-strong); }
a:hover { color: var(--brand); }

/* Safe-area aware app body */
.app-body {
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  height: var(--topbar-h);
  background: var(--brand-ink);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}
.topbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  max-width: 1600px;
  margin: 0 auto;
}
.topbar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 0.625rem;
  background: transparent;
  color: rgba(255,255,255,0.85);
  font-size: 1.4rem;
}
.topbar-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }
.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.topbar-brand i { color: #5eead4; font-size: 1.3rem; }
.topbar-brand span { white-space: nowrap; }
.topbar-nav { display: none; }
.topbar-link {
  color: rgba(255,255,255,0.78);
  text-decoration: none;
  padding: 0.4rem 0.65rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  white-space: nowrap;
}
.topbar-link:hover { color: #fff; background: rgba(255,255,255,0.1); }
.topbar-link.active { color: #5eead4; }
.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem;
  border: 0;
  border-radius: 0.625rem;
  background: transparent;
  color: #fff;
}
.topbar-user:hover { background: rgba(255,255,255,0.08); }
.topbar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(94,234,212,0.18);
  color: #5eead4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  flex-shrink: 0;
}
.topbar-user-name { font-size: 0.9rem; font-weight: 500; }

/* ---------- Public mobile nav (hamburger menu) ---------- */
.public-mobile-menu {
  background: var(--brand-ink-2);
  border-top: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow);
}
.public-mobile-menu nav {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
}
.public-mobile-menu a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 0.8rem 0.75rem;
  font-size: 1rem;
  border-radius: 0.5rem;
  min-height: 44px;
}
.public-mobile-menu a:hover,
.public-mobile-menu a:focus { background: rgba(255,255,255,0.08); color: #fff; }
.public-mobile-menu a.active { color: #5eead4; }
.public-mobile-menu a.public-mobile-cta {
  margin-top: 0.5rem;
  background: var(--brand);
  color: #fff;
  justify-content: center;
  font-weight: 600;
}
.public-mobile-menu a.public-mobile-cta:hover { background: var(--brand-strong); color: #fff; }

/* ---------- Sidebar (off-canvas on mobile, static on desktop) ---------- */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  max-width: 84vw;
  z-index: 1045;
  background: var(--brand-ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  box-shadow: none;
  overscroll-behavior: contain;
}
.sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-head .title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-close {
  border: 0;
  background: transparent;
  color: rgba(255,255,255,0.7);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.25rem;
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
  -webkit-overflow-scrolling: touch;
}
.sidebar-nav .nav-item-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1.1rem;
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
  min-height: 44px;
}
.sidebar-nav .nav-item-link i { width: 22px; text-align: center; font-size: 1.1rem; flex-shrink: 0; }
.sidebar-nav .nav-item-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav .nav-item-link.active {
  color: #fff;
  background: rgba(13,148,136,0.22);
  border-left-color: #2dd4bf;
}
.sidebar-foot {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.78rem;
  color: rgba(255,255,255,0.4);
}

/* ---------------------------------------------------------------------------
   Platform Admin — visually distinct from the business dashboard.
   The admin panel uses an indigo accent (business uses teal).
   --------------------------------------------------------------------------- */
.admin-badge {
  display: inline-flex;
  align-items: center;
  margin: 0.6rem 1rem 0.25rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #c7d2fe;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.4);
}
.sidebar-nav .nav-section {
  padding: 0.85rem 1.1rem 0.3rem;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.7);
}
.app-body.admin-context .sidebar { background: #10142a; }
.app-body.admin-context .sidebar-nav .nav-item-link.active {
  background: rgba(99, 102, 241, 0.24);
  border-left-color: #818cf8;
}
.app-body.admin-context .topbar,
.app-body.admin-context .app-main { background: #f5f6fb; }
.admin-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
  margin: 1.6rem 0 0.75rem;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 1040;
  background: rgba(15,23,42,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  backdrop-filter: blur(1px);
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

/* ---------- Main content ---------- */
.app-main {
  min-height: 100vh;
  padding-top: 0; /* topbar is sticky */
}
.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1rem calc(var(--bottomnav-h) + 1.5rem + env(safe-area-inset-bottom));
}
.app-main--public .app-container {
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}

/* ---------- Bottom navigation (mobile) ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1030;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  box-shadow: 0 -4px 20px rgba(15,23,42,0.06);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.68rem;
  min-height: 52px;
  position: relative;
}
.bottom-nav a i { font-size: 1.35rem; line-height: 1; }
.bottom-nav a.active { color: var(--brand-strong); font-weight: 600; }
.bottom-nav a.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 2px;
  background: var(--brand);
  border-radius: 0 0 2px 2px;
}

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}
.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  padding: 0.875rem 1.1rem;
}
.card-header:first-child { border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0; }
.card-body { padding: 1.1rem; }

/* KPI / stat cards */
.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
  height: 100%;
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card .stat-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}
.stat-card .stat-foot { margin-top: 0.5rem; font-size: 0.8rem; }
.stat-icon.primary { background: var(--brand-soft); color: var(--brand-strong); }
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Tables ---------- */
.table { margin-bottom: 0; }
.table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table td { vertical-align: middle; font-size: 0.9rem; border-color: var(--border); }
.table > :not(caption) > * > * { padding: 0.7rem 0.9rem; }
.table-responsive { border-radius: 0 0 var(--radius) var(--radius); }
.table-hover > tbody > tr:hover > * { background: var(--brand-soft-2); }

/* ---------- Badges & status ---------- */
.badge { font-weight: 500; letter-spacing: 0.01em; }
.badge-soft-success { background: var(--success-soft); color: #047857; }
.badge-soft-danger { background: var(--danger-soft); color: #b91c1c; }
.badge-soft-warning { background: var(--warning-soft); color: #b45309; }
.badge-soft-info { background: var(--info-soft); color: #0369a1; }
.badge-soft-muted { background: #eef2f7; color: #475569; }

/* ---------- Forms ---------- */
.form-label { font-weight: 500; font-size: 0.875rem; color: var(--text); margin-bottom: 0.35rem; }
.form-control, .form-select {
  border-color: var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 0.18rem rgba(13,148,136,0.15);
}
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.required::after { content: " *"; color: var(--danger); }

/* ---------- Buttons ---------- */
.btn { border-radius: var(--radius-sm); font-weight: 500; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover, .btn-primary:focus { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-outline-primary { color: var(--brand-strong); border-color: var(--brand); }
.btn-outline-primary:hover { background: var(--brand); border-color: var(--brand); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Alerts / toasts ---------- */
.alert { border: 1px solid transparent; border-radius: var(--radius-sm); }
.alert-success { background: var(--success-soft); color: #065f46; border-color: #a7f3d0; }
.alert-danger { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-soft); color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--info-soft); color: #075985; border-color: #bae6fd; }

/* ---------- Empty state / loading ---------- */
.empty-state { text-align: center; padding: 3rem 1rem; }
.empty-state i { font-size: 3rem; color: #cbd5e1; margin-bottom: 0.75rem; }
.empty-state h5 { color: var(--text-muted); }
.empty-state p { color: var(--text-muted); }

.skeleton {
  background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 50%, #eef2f7 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
  border-radius: 0.5rem;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Auth ---------- */
.auth-body { background: linear-gradient(160deg, var(--brand-ink) 0%, #134e4a 100%); min-height: 100vh; }
.auth-card {
  background: var(--surface);
  border: 0;
  border-radius: 1rem;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; }
.page-header .breadcrumb { margin: 0; }
.page-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Footer ---------- */
.app-footer { border-top: 1px solid var(--border); margin-top: 1rem; }
.app-footer .app-container { padding-top: 1rem; padding-bottom: calc(1rem + var(--bottomnav-h) + env(safe-area-inset-bottom)); }
@media (min-width: 992px) {
  .app-footer .app-container { padding-bottom: 1rem; }
}

/* ---------- Offline toast ---------- */
.offline-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 0.75rem);
  transform: translateX(-50%);
  z-index: 2000;
  background: var(--brand-ink);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 2rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Desktop (>= 992px): static sidebar ---------- */
@media (min-width: 992px) {
  .topbar-toggle { display: none; }
  .topbar { padding-left: 0; }
  .sidebar {
    transform: translateX(0);
    top: 0;
    width: var(--sidebar-w);
    box-shadow: none;
    border-right: 1px solid rgba(255,255,255,0.06);
  }
  .sidebar-close { display: none; }
  .sidebar-overlay { display: none !important; }
  .app-main:not(.app-main--public) { margin-left: var(--sidebar-w); }
  .bottom-nav { display: none; }
  .app-container { padding-bottom: 2rem; }
  .topbar-inner { padding: 0 1.25rem; }
  .topbar-nav { display: flex; }
}

/* ---------- Mobile form/touch ergonomics ---------- */
@media (max-width: 575.98px) {
  .form-control, .form-select { font-size: 16px; } /* prevent iOS zoom */
  .btn { min-height: 40px; }
  .table td, .table th { font-size: 0.84rem; }
  .page-header h1 { font-size: 1.25rem; }
  .stat-card .stat-value { font-size: 1.3rem; }
  .app-container { padding: 0.875rem 0.875rem calc(var(--bottomnav-h) + 1.25rem + env(safe-area-inset-bottom)); }
}

/* ---------- Accessibility ---------- */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ---------- Print ---------- */
@media print {
  .topbar, .sidebar, .sidebar-overlay, .bottom-nav, .btn, .no-print { display: none !important; }
  .app-main { margin-left: 0; }
}

/* ---------- Public hero (landing) responsive ---------- */
.hero .container { padding-top: 2rem; padding-bottom: 2rem; }
.hero h1.display-4 { font-size: 2rem; line-height: 1.2; }
.hero p.lead { font-size: 1.05rem; line-height: 1.65; }
.hero .bi-wifi.display-1 { font-size: 3rem; }
.hero .d-flex a.btn { flex: 1 1 100%; }
@media (min-width: 576px) {
  .hero .container { padding-top: 3rem; padding-bottom: 3rem; }
  .hero h1.display-4 { font-size: 2.5rem; }
  .hero .d-flex a.btn { flex: 0 1 auto; }
}
@media (min-width: 992px) {
  .hero h1.display-4 { font-size: 3.5rem; }
  .hero p.lead { font-size: 1.25rem; }
  .hero .bi-wifi.display-1 { font-size: 5rem; }
  .hero .container { padding-top: 4rem; padding-bottom: 4rem; }
}

/* ---------- Utilities ---------- */
.cursor-pointer { cursor: pointer; }
.text-xs { font-size: 0.75rem; }
.rounded-lg { border-radius: var(--radius); }
.border-left-primary { border-left: 4px solid var(--brand); }
.border-left-success { border-left: 4px solid var(--success); }
.border-left-warning { border-left: 4px solid var(--warning); }
.border-left-info { border-left: 4px solid var(--info); }
