/* ============================================================
   BOSSINGS FINANCIAL SYSTEM — Main Theme
   Dark theme, mobile-first (Tecno BF7: 720x1612, 20:9)
   ============================================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
  /* Colors — Dark Theme */
  --bg-primary:    #0d1117;
  --bg-secondary:  #161b22;
  --bg-tertiary:   #1c2128;
  --bg-surface:    #21262d;
  --bg-elevated:   #2d333b;
  --bg-hover:      #2d333b;

  --text-primary:    #e6edf3;
  --text-secondary:  #8b949e;
  --text-tertiary:   #6e7681;
  --text-muted:      #484f58;

  --accent-blue:     #58a6ff;
  --accent-green:    #3fb950;
  --accent-amber:    #d29922;
  --accent-red:      #f85149;
  --accent-purple:   #bc8cff;
  --accent-cyan:     #39d2c0;
  --accent-orange:   #f0883e;

  /* Semantic Colors */
  --color-success:   var(--accent-green);
  --color-warning:   var(--accent-amber);
  --color-danger:    var(--accent-red);
  --color-info:      var(--accent-blue);
  --color-pending:   var(--accent-amber);
  --color-confirmed: var(--accent-green);
  --color-rejected:  var(--accent-red);

  /* Borders */
  --border-default: #30363d;
  --border-subtle:  #21262d;
  --border-focus:   var(--accent-blue);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  --shadow-overlay: 0 16px 48px rgba(0,0,0,0.6);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  --text-xs:  0.6875rem;  /* 11px */
  --text-sm:  0.8125rem;  /* 13px */
  --text-base: 0.9375rem; /* 15px */
  --text-lg:  1.0625rem;  /* 17px */
  --text-xl:  1.25rem;    /* 20px */
  --text-2xl: 1.5rem;     /* 24px */
  --text-3xl: 1.875rem;   /* 30px */

  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Layout */
  --sidebar-width: 240px;
  --sidebar-collapsed: 56px;
  --header-height: 48px;
  --nav-z: 100;
  --modal-z: 200;
  --toast-z: 300;
  --overlay-z: 150;

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  height: 100dvh;
  width: 100vw;
}

/* --- Remove ALL spinner arrows from number inputs --- */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* --- App Shell Layout --- */
#app-shell {
  display: flex;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* --- Sidebar Navigation --- */
#sidebar {
  width: var(--sidebar-width);
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: var(--nav-z);
  transition: transform var(--transition-normal);
  overflow-y: auto;
  overflow-x: hidden;
}

#sidebar .sidebar-header {
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}

#sidebar .brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

#sidebar .brand-icon {
  width: 32px;
  height: 32px;
  background: var(--accent-cyan);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--bg-primary);
  flex-shrink: 0;
}

#sidebar .brand-text {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  line-height: 1.2;
}

#sidebar .brand-sub {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: var(--font-normal);
}

/* Nav sections */
.nav-section {
  padding: var(--space-3) var(--space-2);
}

.nav-section-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--bg-surface);
  color: var(--accent-cyan);
}

.nav-item .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-base);
}

.nav-item .nav-badge {
  margin-left: auto;
  background: var(--accent-red);
  color: #fff;
  font-size: 10px;
  font-weight: var(--font-bold);
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* Sidebar footer — user info */
.sidebar-footer {
  margin-top: auto;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-default);
  flex-shrink: 0;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--accent-cyan);
  flex-shrink: 0;
}

.user-info {
  overflow: hidden;
}

.user-name {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* --- Main Content Area --- */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Mobile header (hidden on desktop) */
#mobile-header {
  display: none;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-default);
  align-items: center;
  padding: 0 var(--space-4);
  flex-shrink: 0;
}

#mobile-header .hamburger {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--space-1);
  line-height: 1;
}

#mobile-header .mobile-title {
  flex: 1;
  text-align: center;
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

/* Network indicator */
.network-pill {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.network-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
}

.network-pill.online .dot { background: var(--color-success); }
.network-pill.offline .dot {
  background: var(--color-danger);
  animation: pulse-dot 1.5s infinite;
}
.network-pill.syncing .dot {
  background: var(--color-warning);
  animation: pulse-dot 1s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Page container area */
#page-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-6);
  scroll-behavior: smooth;
}

/* Individual pages — only active is visible */
.page {
  display: none;
  animation: fadeIn var(--transition-normal);
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Page header row */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

/* --- Overlay for mobile sidebar --- */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: calc(var(--nav-z) - 1);
}

/* --- Login screen (full-page, covers app shell) --- */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: calc(var(--modal-z) + 50);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

#login-screen.hidden {
  display: none;
}

/* License activation screen */
#license-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: calc(var(--modal-z) + 50);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

#license-screen.hidden {
  display: none;
}

/* --- Responsive: Mobile (< 768px) --- */
@media (max-width: 767px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }

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

  #sidebar.open ~ #sidebar-overlay {
    display: block;
  }

  #mobile-header {
    display: flex;
  }

  #page-container {
    padding: var(--space-4);
  }

  .page-title {
    font-size: var(--text-xl);
  }
}

/* --- Tablet (768px - 1024px) --- */
@media (min-width: 768px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 200px;
  }
}

/* --- Safe area insets (notch phones) --- */
@supports (padding: env(safe-area-inset-top)) {
  #sidebar {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  #mobile-header {
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-height) + env(safe-area-inset-top));
  }
}

/* --- Keyboard handling for 20:9 screens --- */
@media (max-height: 500px) and (max-width: 767px) {
  #sidebar { display: none; }
  #page-container { padding: var(--space-2); }
  .page-header { margin-bottom: var(--space-3); }
}

/* --- Utility Classes --- */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-info { color: var(--color-info); }
.text-muted { color: var(--text-secondary); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.w-full { width: 100%; }
.font-mono { font-family: var(--font-mono); }
