@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
@import './animations.css';
@import './base.css';

/*
  ATLANCE DESIGN SYSTEM TOKENS
  Merged from AR Collections + Billing India
  Single source of truth for all modules
*/

:root {
  /* ===== BACKGROUNDS ===== */
  --bg-base: #000000;           /* Pure black - page bg */
  --bg-surface: #111111;        /* Cards, panels — visible on black canvas */
  --bg-elevated: #171717;       /* Modals, dropdowns */
  --bg-hover: #1a1a1a;          /* Hover states */
  --bg-active: #222222;         /* Active/pressed */

  /* ===== TEXT ===== */
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #88888f;
  --text-tertiary: #8a8a94;
  --text-dim: #8a8a94;

  /* ===== BORDERS ===== */
  --border-subtle: #1a1a1a;     /* Subtle dividers on cards */
  --border-default: #3d3d3d;
  --border-strong: #4a4a4a;
  --border-focus: #3b82f6;

  /* ===== ACCENT (Blue) ===== */
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-muted: #1a1a1a;      /* Neutral dark - sidebar active */

  /* ===== BRAND (Purple - Atlance) ===== */
  --brand-primary: #8b5cf6;
  --brand-secondary: #6366f1;
  --brand-glow: rgba(139, 92, 246, 0.15);
  --brand-glow-strong: rgba(139, 92, 246, 0.3);
  --brand-primary-50: rgba(139, 92, 246, 0.5);
  --brand-primary-20: rgba(139, 92, 246, 0.2);
  --brand-primary-12: rgba(139, 92, 246, 0.12);
  --brand-primary-08: rgba(139, 92, 246, 0.08);
  --brand-primary-06: rgba(139, 92, 246, 0.06);
  --brand-primary-04: rgba(139, 92, 246, 0.04);
  --brand-accent: #22d3ee;

  /* ===== SEMANTIC COLORS ===== */
  --success: #22c55e;
  --success-muted: #14532d;
  --success-dim: rgba(34,197,94,0.10);
  --success-border: rgba(34,197,94,0.25);
  --warning: #eab308;
  --warning-muted: #422006;
  --warning-dim: rgba(234,179,8,0.08);
  --warning-border: rgba(234,179,8,0.25);
  --error: #ef4444;
  --error-muted: #450a0a;
  --error-dim: rgba(239,68,68,0.10);
  --error-border: rgba(239,68,68,0.25);
  --info: #3b82f6;
  --info-muted: #1e3a5f;
  --info-dim: rgba(59,130,246,0.10);
  --info-border: rgba(59,130,246,0.25);

  /* ===== AGING BUCKETS (from AR) ===== */
  --aging-current: #fafafa;
  --aging-1-30: #fde047;
  --aging-31-60: #fdba74;
  --aging-61-90: #fb923c;
  --aging-91-120: #f87171;
  --aging-120-plus: #ef4444;

  /* ===== SEGMENTS (from AR) ===== */
  --segment-enterprise: #a855f7;
  --segment-sme: #3b82f6;
  --segment-smb: #22c55e;
  --segment-partner: #f97316;

  /* ===== FLOW COLORS (AR/AP/Cash — used across dashboards) ===== */
  --color-positive: #4ade80;        /* Inflow, AR, gain */
  --color-negative: #f87171;        /* Outflow, AP, loss */
  --color-caution: #fbbf24;         /* Warnings, adjustments */
  --color-accent-warm: #f97316;     /* Burn, spend, orange indicators */
  --color-positive-12: rgba(74,222,128,0.12);
  --color-negative-12: rgba(248,113,113,0.12);
  --color-caution-12: rgba(250,204,21,0.12);

  /* ===== REGION COLORS ===== */
  --region-india: #f97316;
  --region-usa: #3b82f6;
  --region-uk: #a855f7;
  --region-mena: #10b981;

  /* ===== TYPOGRAPHY ===== */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --text-2xs: 0.625rem;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-lg: 1rem;
  --text-xl: 1.125rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;

  --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;

  /* ===== BORDER RADIUS ===== */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* ===== SHADOWS ===== */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
  --shadow-modal: 0 25px 50px rgba(0,0,0,0.6);

  /* ===== TRANSITIONS ===== */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;

  /* ===== BREAKPOINTS (reference only — media queries use px) ===== */
  --bp-mobile: 640px;
  --bp-tablet: 1024px;
  --bp-desktop: 1280px;

  /* ===== Z-INDEX ===== */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal: 300;
  --z-toast: 400;
}

/* =============================================
   MODAL SYSTEM
   Generic modal styles for all Atlance modules
   ============================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-4);
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal), 0 0 0 1px rgba(139, 92, 246, 0.1);
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0;
}

.modal-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: 2px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  margin: -4px -8px 0 0;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-5) var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.2);
}

/* =============================================
   BUTTON SYSTEM
   Generic button styles for all Atlance modules
   ============================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 16px;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  font-family: inherit;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: #7c3aed;
  border-color: #7c3aed;
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-color: var(--border-default);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-active);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--error) 85%, black);
  border-color: color-mix(in srgb, var(--error) 85%, black);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--text-xs);
}

/* =============================================
   FORM ELEMENTS
   Generic form styles for all Atlance modules
   ============================================= */

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

/* =============================================
   BADGES
   Generic badge styles for all Atlance modules
   ============================================= */

.badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-md);
}

/* =============================================
   UTILITY CLASSES
   Common utilities for all Atlance modules
   ============================================= */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.font-mono { font-family: var(--font-mono); }
.tnum { font-variant-numeric: tabular-nums; }

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-dim);
  font-size: var(--text-sm);
}

/* =============================================
   SCROLLBAR — Atlance standard
   Hairline scrollbar: 2px visible line, spaced from edges
   Apply with class .atlance-scroll or use globally via *
   ============================================= */

*::-webkit-scrollbar { width: 2px; height: 2px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 1px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); }
*::-webkit-scrollbar-corner { background: transparent; }

/* =============================================
   DATA TABLE
   Clean table — no boxy Excel grid
   ============================================= */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  padding: 10px 14px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-align: left;
}

.data-table th:first-child {
  text-align: left;
}

.data-table td {
  padding: 11px 14px;
  text-align: left;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
}

.data-table td:first-child {
  text-align: left;
  font-weight: 500;
  color: var(--text-primary);
}

/* Alignment utility classes for data-table columns */
.data-table th.num,
.data-table td.num {
  text-align: right;
}

.data-table th.center,
.data-table td.center {
  text-align: center;
}

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.data-table .total-row td {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: none;
  font-weight: 700;
  color: var(--text-primary);
}

/* =============================================
   CONTENT CARD
   Reusable surface card for content sections.
   NO overflow:hidden — preserves position:sticky
   ============================================= */

.content-card {
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

/* KPI strip inside content card — blend into card surface */
.content-card .kpi-strip {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.04);
}

/* =============================================
   KPI STRIP
   Horizontal metric bar
   ============================================= */

.kpi-strip {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border-radius: 8px;
  padding: 12px 20px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.kpi-strip-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-right: 6px;
}

.kpi-strip-sub {
  font-size: 10px;
  color: var(--text-dim);
  margin-right: 20px;
}

.kpi-separator {
  height: 22px;
  width: 1px;
  background: rgba(255, 255, 255, 0.06);
  margin: 0 24px;
}

.kpi-config-btn {
  font-size: 11px;
  color: #71717a;
  cursor: pointer;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  transition: all 0.15s;
}

.kpi-config-btn:hover {
  color: #a1a1aa;
  border-color: rgba(255, 255, 255, 0.15);
}

.kpi-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.kpi-group-label {
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-group-value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* =============================================
   INLINE HEALTH BAR
   Compact horizontal health indicator
   ============================================= */

.health-bar-inline {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 28px;
  padding: 0;
}

.health-bar-inline-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  min-width: 65px;
}

.health-bar-inline-track {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: var(--bg-hover);
  overflow: hidden;
  display: flex;
}

.health-bar-inline-meta {
  font-size: 10px;
}

/* =============================================
   RESPONSIVE UTILITIES
   Mobile-first: hide/show, stack, scroll
   Breakpoints: 640px (mobile), 1024px (tablet)
   ============================================= */

/* Wrapper for horizontal scroll on mobile */
.scroll-x-mobile {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
  .hide-mobile { display: none !important; }
  .full-mobile { width: 100% !important; }
  .stack-mobile { flex-direction: column !important; }

  /* Data table: horizontal scroll on mobile */
  .data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(var(--space-4) * -1);
    padding: 0 var(--space-4);
  }
  .data-table { min-width: 600px; }

  /* KPI strip stacks vertically on mobile */
  .kpi-strip {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
    padding: var(--space-3);
  }
  .kpi-separator { display: none; }
  .kpi-group {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  /* Modal full-width on mobile */
  .modal { border-radius: var(--radius-lg); }
}

@media (max-width: 1024px) {
  .hide-tablet { display: none !important; }
}

@media (min-width: 1025px) {
  .hide-desktop { display: none !important; }
}

/* =============================================
   MOBILE HEADER & DRAWER
   Hamburger menu, slide-out sidebar, overlay
   ============================================= */

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-strong);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 500;
}

.mobile-hamburger {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-hamburger svg {
  width: 24px;
  height: 24px;
}

.mobile-brand {
  font-size: 18px;
  font-weight: var(--font-bold);
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 600;
}

.mobile-overlay.open {
  display: block;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-strong);
  z-index: 700;
  transform: translateX(-100%);
  transition: transform var(--transition-slow);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-drawer.open {
  transform: translateX(0);
}

/* Horizontal scroll tabs (hidden scrollbar) */
.scroll-x-tabs {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scroll-x-tabs::-webkit-scrollbar {
  display: none;
}

@media (max-width: 768px) {
  .mobile-header { display: flex; }
}

/* =============================================
   DESKTOP-GATE
   "Use desktop" overlay for data-heavy dashboards.
   Inline version in each index.html for FOUC-free
   rendering. This is the canonical reference.
   ============================================= */

.desktop-gate {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-base, #000);
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  font-family: var(--font-sans, 'Inter', system-ui, sans-serif);
}

.desktop-gate .mg-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
}

.desktop-gate .mg-icon svg {
  width: 24px;
  height: 24px;
  color: var(--brand-primary, #8b5cf6);
}

.desktop-gate h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary, #fafafa);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.desktop-gate p {
  font-size: 14px;
  color: var(--text-muted, #71717a);
  margin: 0 0 32px;
  max-width: 300px;
  line-height: 1.6;
}

.desktop-gate .mg-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 260px;
}

.desktop-gate a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
}

.desktop-gate .mg-primary {
  background: var(--text-primary, #fafafa);
  color: var(--bg-base, #0a0a0a);
}

.desktop-gate .mg-primary:hover {
  background: #e4e4e7;
}

.desktop-gate .mg-brand {
  position: absolute;
  bottom: 32px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 500;
}

@media (max-width: 1023px) {
  .desktop-gate { display: flex; }
  .desktop-gate ~ #root { display: none !important; }
}

/* =============================================
   ATLANCE BRAND — Shimmer Animation
   Shared across all dashboards & static pages
   ============================================= */

@keyframes atlance-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.atlance-brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--brand-primary) 0%, var(--brand-accent) 40%, rgba(255,255,255,0.9) 50%, var(--brand-accent) 60%, var(--brand-primary) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: atlance-shimmer 4s ease-in-out infinite;
  text-decoration: none;
}

.atlance-brand:hover {
  filter: brightness(1.15);
}
