/* ============================================================
   css/style.css — Global SaaS CRM Stylesheet
   Responsive: 320px to 4K, Dark Mode, Print, Accessibility
   ============================================================ */

/* ============================================================
   CSS VARIABLES
   ============================================================ */
:root {
  /* Layout */
  --sidebar-width: 260px;
  --header-height: 56px;
  --container-max: 1400px;
  
  /* Colors - Light Theme */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --info: #0ea5e9;
  --info-light: #e0f2fe;
  
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-header: rgba(255,255,255,0.95);
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;
  
  --border-color: #e2e8f0;
  --border-light: #f1f5f9;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.08);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.12);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --transition: 0.2s ease;
}

/* ============================================================
   DARK THEME
   ============================================================ */
[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #1e293b;
  --bg-header: rgba(15,23,42,0.95);
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --border-color: #334155;
  --border-light: #1e293b;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.4);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.5);
  
  --primary-light: #312e81;
  --success-light: #064e3b;
  --warning-light: #78350f;
  --danger-light: #7f1d1d;
  --info-light: #0c4a6e;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  font-family: var(--font-family);
  cursor: pointer;
}

img {
  max-width: 100%;
  height: auto;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  height: 100vh;
  margin: 0;
  padding: 20px;
  background: var(--bg-body);
}

/* ============================================================
   MAIN APP
   ============================================================ */
#appMain {
  display: none;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  box-shadow: var(--shadow-lg);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 1000;
  padding: 16px 0;
  transition: transform var(--transition);
  border-right: 1px solid var(--border-color);
}

.sidebar .brand {
  padding: 8px 20px 20px;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar .section-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 14px 20px 6px;
  font-weight: 700;
}

.sidebar .nav-item {
  padding: 2px 12px;
}

.sidebar .nav-link {
  color: var(--text-secondary);
  font-weight: 500;
  border-radius: 10px;
  padding: 9px 14px;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
}

.sidebar .nav-link:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.sidebar .nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

/* ============================================================
   MAIN AREA
   ============================================================ */
.main-area {
  margin-left: var(--sidebar-width);
  padding: 16px;
  min-height: 100vh;
  transition: margin var(--transition);
}

body.sidebar-hidden .main-area {
  margin-left: 0 !important;
}

/* ============================================================
   TOPBAR (Old / Fallback)
   ============================================================ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  background: var(--bg-header);
  backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 10px 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

/* ============================================================
   GLOBAL HEADER
   ============================================================ */
.global-top-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  height: var(--header-height);
}

/* ============================================================
   GLOBAL BOTTOM MENU
   ============================================================ */
.global-bottom-menu {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: var(--bg-card);
  border-radius: 30px;
  box-shadow: var(--shadow-xl);
  padding: 10px 20px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  border: 1px solid var(--border-color);
}

/* ============================================================
   CARD WIDGET
   ============================================================ */
.card-widget {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
  margin-bottom: 16px;
}

.card-widget:hover {
  box-shadow: var(--shadow-md);
}

/* ============================================================
   CONTENT AREA
   ============================================================ */
#contentArea {
  padding-top: calc(var(--header-height) + 16px) !important;
  min-height: calc(100vh - var(--header-height));
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
  background: var(--primary);
  border: none;
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  transition: all var(--transition);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

.btn-outline-primary {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  transition: all var(--transition);
}

.btn-outline-primary:hover {
  background: var(--primary-light);
}

/* ============================================================
   FORMS
   ============================================================ */
.form-control, 
.form-select {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  transition: all var(--transition);
  background: var(--bg-card);
  color: var(--text-primary);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
  outline: none;
}

/* ============================================================
   TABLES
   ============================================================ */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--bg-body);
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}

.table tr:hover td {
  background: var(--bg-body);
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ============================================================
   TOAST
   ============================================================ */
.global-toast {
  animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }

/* ============================================================
   COMING SOON
   ============================================================ */
.coming-soon-badge {
  background: linear-gradient(135deg, #f59e0b, #ff8c00);
  color: #fff;
  font-size: 9px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 4px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

/* ============================================================
   RESPONSIVE — TABLET (768px - 1024px)
   ============================================================ */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 220px;
  }
  
  .card-widget {
    padding: 16px;
  }
  
  .table th,
  .table td {
    padding: 10px 12px;
  }
}

/* ============================================================
   RESPONSIVE — MOBILE (< 768px)
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }
  
  /* Sidebar hidden by default on mobile */
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    z-index: 2000;
  }
  
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  
  /* Main area full width */
  .main-area {
    margin-left: 0 !important;
    padding: 10px;
  }
  
  /* Header */
  .global-top-header {
    padding: 0 8px;
    height: 48px;
    gap: 6px;
  }
  
  .global-top-header .hb {
    font-size: 12px;
    margin-right: 4px;
  }
  
  .global-top-header .hlt {
    display: none;
  }
  
  .global-top-header .hl {
    padding: 5px 7px;
    font-size: 11px;
  }
  
  .global-top-header .hl i {
    font-size: 14px;
    margin-right: 0;
  }
  
  /* Bottom menu */
  .global-bottom-menu {
    bottom: 10px;
    padding: 8px 12px;
    gap: 4px;
  }
  
  .global-bottom-menu .bottom-tab {
    padding: 6px 10px;
    font-size: 11px;
  }
  
  /* Content area */
  #contentArea {
    padding-top: calc(48px + 10px) !important;
  }
  
  /* Cards */
  .card-widget {
    padding: 14px;
    border-radius: var(--radius-md);
  }
  
  /* Tables - horizontal scroll */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Forms */
  .form-control,
  .form-select {
    font-size: 16px; /* Prevent iOS zoom */
    padding: 12px 14px;
  }
  
  /* Modals */
  .modal-overlay > div {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 10px;
    padding: 20px !important;
  }
  
  /* Hide on mobile */
  .hide-mobile {
    display: none !important;
  }
}

/* ============================================================
   RESPONSIVE — SMALL MOBILE (< 480px)
   ============================================================ */
@media (max-width: 480px) {
  .global-bottom-menu {
    bottom: 6px;
    padding: 6px 8px;
    border-radius: 20px;
  }
  
  .global-bottom-menu .bottom-tab {
    padding: 5px 8px;
    font-size: 10px;
    gap: 4px;
  }
  
  .global-bottom-menu .bottom-tab i {
    font-size: 12px;
  }
  
  .card-widget {
    padding: 12px;
    border-radius: 10px;
  }
  
  /* Stack grid columns */
  .row > [class*="col-"] {
    width: 100%;
    margin-bottom: 10px;
  }
  
  /* Profile */
  .prof-cover {
    height: 120px !important;
  }
  
  .prof-avatar {
    width: 64px !important;
    height: 64px !important;
    font-size: 20px !important;
  }
  
  .prof-name {
    font-size: 18px !important;
  }
}

/* ============================================================
   RESPONSIVE — LARGE SCREENS (> 1600px)
   ============================================================ */
@media (min-width: 1600px) {
  :root {
    --sidebar-width: 280px;
  }
  
  .container,
  .kn-wrap,
  .plan-wrap,
  .prof-wrap {
    max-width: 1500px;
  }
}

/* ============================================================
   RESPONSIVE — 4K SCREENS (> 2560px)
   ============================================================ */
@media (min-width: 2560px) {
  :root {
    --sidebar-width: 320px;
  }
  
  body {
    font-size: 16px;
  }
  
  .container,
  .kn-wrap,
  .plan-wrap,
  .prof-wrap {
    max-width: 2000px;
  }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  .sidebar,
  .global-top-header,
  .global-bottom-menu,
  .topbar,
  button,
  .no-print {
    display: none !important;
  }
  
  .main-area {
    margin-left: 0 !important;
  }
  
  #contentArea {
    padding-top: 0 !important;
  }
  
  body {
    background: #fff;
    color: #000;
    font-size: 12px;
  }
  
  .card-widget {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
  
  .table {
    font-size: 10px;
  }
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
