/* ============================================================
   Invo India — Premium App CSS
   Modern ERP UI — Glassmorphism, Dark Mode, Animations
   ============================================================ */

/* ─── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── GST-Free Mode — Hide tax fields when disabled ────────── */
body[data-gst="0"] .gst-field { display: none !important; }


/* ─── CSS Variables — Light Theme ──────────────────────────── */
:root {
  --primary:         #6C63FF;
  --primary-dark:    #5a52d5;
  --primary-light:   #8b85ff;
  --primary-rgb:     108, 99, 255;

  --accent:          #00D4AA;
  --accent-dark:     #00b891;
  --accent-rgb:      0, 212, 170;

  --success:         #22c55e;
  --warning:         #f59e0b;
  --danger:          #ef4444;
  --info:            #3b82f6;
  --purple:          #a855f7;
  --pink:            #ec4899;
  --orange:          #f97316;

  --bg-body:         #f0f2f7;
  --bg-card:         #ffffff;
  --bg-sidebar:      #1a1a2e;
  --bg-sidebar-item: rgba(255,255,255,0.08);
  --bg-navbar:       #ffffff;
  --bg-input:        #f8f9fc;
  --bg-table-head:   #f1f3f9;

  --text-primary:    #1a1a2e;
  --text-secondary:  #64748b;
  --text-muted:      #94a3b8;
  --text-sidebar:    rgba(255,255,255,0.85);
  --text-sidebar-active: #ffffff;

  --border-color:    #e2e8f0;
  --border-light:    #f1f5f9;

  --sidebar-width:   260px;
  --sidebar-collapsed-width: 68px;
  --navbar-height:   64px;

  --shadow-sm:   0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:      0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-md:   0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-lg:   0 20px 25px -5px rgba(0,0,0,0.08), 0 10px 10px -5px rgba(0,0,0,0.04);
  --shadow-xl:   0 25px 50px -12px rgba(0,0,0,0.15);

  --radius-sm:   6px;
  --radius:      10px;
  --radius-md:   14px;
  --radius-lg:   20px;
  --radius-xl:   28px;

  --transition:  all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.12s ease;
  --transition-slow: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);

  --glass-bg:        rgba(255, 255, 255, 0.85);
  --glass-border:    rgba(255, 255, 255, 0.3);
  --glass-shadow:    0 8px 32px rgba(31, 38, 135, 0.1);
  --glass-blur:      blur(12px);
}

/* ─── Dark Mode Variables ───────────────────────────────────── */
:root[data-theme="dark"],
:root[data-bs-theme="dark"],
html[data-theme="dark"],
html[data-bs-theme="dark"],
[data-theme="dark"],
[data-bs-theme="dark"] {
  --bg-body:         #0f0f1a;
  --bg-card:         #1a1a2e;
  --bg-sidebar:      #0d0d1a;
  --bg-sidebar-item: rgba(255,255,255,0.07);
  --bg-navbar:       #1a1a2e;
  --bg-input:        #16213e;
  --bg-table-head:   #16213e;

  --text-primary:    #e2e8f0;
  --text-secondary:  #94a3b8;
  --text-muted:      #64748b;

  --border-color:    #2d3748;
  --border-light:    #1e293b;

  --bs-body-bg:      #0f0f1a;
  --bs-body-color:   #e2e8f0;
  --bs-card-bg:      #1a1a2e;
  --bs-card-color:   #e2e8f0;
  --bs-border-color: #2d3748;
  --bs-tertiary-bg:  #16213e;

  --glass-bg:        rgba(26, 26, 46, 0.9);
  --glass-border:    rgba(255,255,255,0.08);
  --glass-shadow:    0 8px 32px rgba(0, 0, 0, 0.4);

  --shadow-sm:   0 1px 3px rgba(0,0,0,0.3);
  --shadow:      0 4px 6px -1px rgba(0,0,0,0.4);
  --shadow-md:   0 10px 15px -3px rgba(0,0,0,0.5);
  --shadow-lg:   0 20px 25px -5px rgba(0,0,0,0.6);
}

/* ─── Dark Mode Bootstrap Utility Overrides ─────────────────── */
:root[data-theme="dark"] .bg-white,
:root[data-bs-theme="dark"] .bg-white,
[data-theme="dark"] .bg-white,
[data-bs-theme="dark"] .bg-white {
  background-color: var(--bg-card) !important;
  color: var(--text-primary) !important;
}

:root[data-theme="dark"] .bg-light,
:root[data-bs-theme="dark"] .bg-light,
[data-theme="dark"] .bg-light,
[data-bs-theme="dark"] .bg-light {
  background-color: var(--bg-input) !important;
  color: var(--text-primary) !important;
}

:root[data-theme="dark"] .text-dark,
:root[data-bs-theme="dark"] .text-dark,
[data-theme="dark"] .text-dark,
[data-bs-theme="dark"] .text-dark {
  color: var(--text-primary) !important;
}

:root[data-theme="dark"] .card-header.bg-white,
:root[data-bs-theme="dark"] .card-header.bg-white,
[data-theme="dark"] .card-header.bg-white,
[data-bs-theme="dark"] .card-header.bg-white {
  background-color: transparent !important;
}



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

html { scroll-behavior: smooth; font-size: 15px; overflow-x: hidden; width: 100%; max-width: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ─── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ─── Typography ────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
}
.text-muted { color: var(--text-muted) !important; }
.text-secondary-color { color: var(--text-secondary) !important; }
a { color: var(--primary); text-decoration: none; transition: var(--transition-fast); }
a:hover { color: var(--primary-dark); }
code, kbd, pre { font-family: 'JetBrains Mono', monospace; }

/* ═══════════════════════════════════════════════════════════════
   LAYOUT
═══════════════════════════════════════════════════════════════ */

.app-wrapper {
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: var(--transition-slow);
  overflow: hidden;
  box-shadow: 4px 0 24px rgba(0,0,0,0.15);
}

.sidebar.collapsed { width: var(--sidebar-collapsed-width); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  min-height: var(--navbar-height);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-brand .brand-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  padding: 6px;
  flex-shrink: 0;
}

.sidebar-brand .brand-text {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  background: linear-gradient(135deg, #fff, rgba(255,255,255,0.7));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: var(--transition);
}

.sidebar-brand .brand-version {
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  font-weight: 500;
  margin-top: 1px;
  white-space: nowrap;
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .brand-version { opacity: 0; width: 0; overflow: hidden; }

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 0; }

.nav-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.3);
  padding: 16px 20px 6px;
  white-space: nowrap;
  overflow: hidden;
  transition: var(--transition);
}
.sidebar.collapsed .nav-section-title { padding: 16px 0 6px; text-align: center; font-size: 8px; }

.nav-item { padding: 2px 10px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-sidebar);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.nav-link:hover {
  background: var(--bg-sidebar-item);
  color: #fff;
  transform: translateX(2px);
}

.nav-link.active {
  background: linear-gradient(135deg, rgba(var(--primary-rgb), 0.8), rgba(var(--primary-rgb), 0.5));
  color: #fff;
  box-shadow: 0 4px 15px rgba(var(--primary-rgb), 0.4);
}

.nav-link .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.nav-link .nav-text {
  flex: 1;
  transition: var(--transition);
  overflow: hidden;
}

.nav-link .nav-badge {
  background: var(--danger);
  color: #fff;
  border-radius: 20px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  transition: var(--transition);
  flex-shrink: 0;
}

.nav-link .nav-arrow {
  font-size: 11px;
  transition: var(--transition);
  flex-shrink: 0;
  color: rgba(255,255,255,0.4);
}

.nav-link.has-submenu.open .nav-arrow { transform: rotate(90deg); }

.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .nav-arrow { opacity: 0; width: 0; overflow: hidden; }

.sidebar.collapsed .nav-link { justify-content: center; gap: 0; padding: 10px 0; }
.sidebar.collapsed .nav-link:hover { transform: none; }

/* Submenu */
.nav-submenu {
  display: none;
  padding-left: 32px;
  overflow: hidden;
}
.nav-submenu.open { display: block; animation: slideDown 0.2s ease; }
.nav-submenu .nav-link {
  font-size: 13px;
  padding: 7px 10px;
  color: rgba(255,255,255,0.6);
}
.nav-submenu .nav-link:hover,
.nav-submenu .nav-link.active { color: #fff; }
.sidebar.collapsed .nav-submenu { display: none !important; }

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
}
.sidebar-user:hover { background: var(--bg-sidebar-item); }
.sidebar-user img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid rgba(var(--primary-rgb), 0.5);
}
.sidebar-user .user-info { overflow: hidden; flex: 1; }
.sidebar-user .user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user .user-role {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  white-space: nowrap;
}
.sidebar.collapsed .sidebar-user .user-info { display: none; }

/* ─── Main Content ──────────────────────────────────────────── */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-body);
  color: var(--text-primary);
  transition: var(--transition-slow);
}
.main-wrapper.expanded { margin-left: var(--sidebar-collapsed-width); }

/* ─── Top Navbar ────────────────────────────────────────────── */
.top-navbar {
  height: var(--navbar-height);
  background: var(--bg-navbar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 900;
  backdrop-filter: blur(10px);
  transition: background 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.navbar-toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: var(--transition);
  flex-shrink: 0;
}
.navbar-toggle-btn:hover { background: var(--bg-input); color: var(--primary); }

/* Global Search */
.global-search {
  flex: 1;
  max-width: 400px;
}
.global-search .search-input-wrapper {
  position: relative;
}
.global-search input {
  width: 100%;
  padding: 9px 16px 9px 40px;
  border: 1.5px solid var(--border-color);
  border-radius: 50px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
}
.global-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.12);
  background: var(--bg-card);
}
.global-search .search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 15px;
}
.search-results-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  z-index: 9999;
  max-height: 360px;
  overflow-y: auto;
  display: none;
}
.search-results-dropdown.show { display: block; animation: fadeInDown 0.15s ease; }

/* Navbar Right */
.navbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.navbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: var(--transition);
  position: relative;
  font-size: 18px;
}
.navbar-btn:hover { background: var(--bg-input); color: var(--primary); }

.notification-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 18px;
  height: 18px;
  background: var(--danger);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  border: 2px solid var(--bg-navbar);
}

/* Company Switcher */
.company-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1.5px solid var(--border-color);
  border-radius: 50px;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-card);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.company-switcher:hover { border-color: var(--primary); background: rgba(var(--primary-rgb), 0.04); }
.company-switcher img { width: 20px; height: 20px; border-radius: 4px; object-fit: cover; }

/* User Avatar Dropdown */
.navbar-user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  cursor: pointer;
  border: 2px solid var(--border-color);
  transition: var(--transition);
}
.navbar-user-avatar:hover { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15); }

/* ─── Page Content ──────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 24px;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
}

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

/* Breadcrumb */
.breadcrumb {
  background: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
}
.breadcrumb-item { color: var(--text-secondary); }
.breadcrumb-item.active { color: var(--primary); font-weight: 500; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════
   CARDS
═══════════════════════════════════════════════════════════════ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  overflow: hidden;
}

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

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.card-body { padding: 20px; }

.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  background: transparent;
}

/* Glassmorphism Card */
.card-glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* Stat Cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-card:hover::before { transform: scaleX(1); }

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.bg-primary-soft { background: rgba(var(--primary-rgb), 0.12); color: var(--primary); }
.stat-icon.bg-success-soft { background: rgba(34,197,94, 0.12);         color: var(--success); }
.stat-icon.bg-warning-soft { background: rgba(245,158,11, 0.12);        color: var(--warning); }
.stat-icon.bg-danger-soft  { background: rgba(239,68,68, 0.12);         color: var(--danger); }
.stat-icon.bg-info-soft    { background: rgba(59,130,246, 0.12);        color: var(--info); }
.stat-icon.bg-purple-soft  { background: rgba(168,85,247, 0.12);        color: var(--purple); }
.stat-icon.bg-accent-soft  { background: rgba(var(--accent-rgb), 0.12); color: var(--accent); }
.stat-icon.bg-orange-soft  { background: rgba(249,115,22, 0.12);        color: var(--orange); }

.stat-info { flex: 1; min-width: 0; }

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-change {
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}
.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════
   FORMS
═══════════════════════════════════════════════════════════════ */

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control, .form-select {
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  transition: var(--transition);
  outline: none;
  width: 100%;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
  background: var(--bg-card);
}

.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-valid   { border-color: var(--success); }

.invalid-feedback {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

.input-group {
  display: flex;
  align-items: stretch;
}
.input-group .form-control { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .input-group-text {
  background: var(--bg-input);
  border: 1.5px solid var(--border-color);
  border-left: none;
  padding: 10px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
  font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════════════════ */

.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius);
  padding: 9px 18px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
  outline: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.35);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  box-shadow: 0 6px 20px rgba(var(--primary-rgb), 0.45);
  transform: translateY(-1px);
  color: #fff;
}

.btn-success {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  border-color: #22c55e;
  box-shadow: 0 4px 12px rgba(34,197,94, 0.3);
}
.btn-success:hover { box-shadow: 0 6px 20px rgba(34,197,94, 0.4); transform: translateY(-1px); color: #fff; }

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  border-color: #ef4444;
  box-shadow: 0 4px 12px rgba(239,68,68, 0.3);
}
.btn-danger:hover { box-shadow: 0 6px 20px rgba(239,68,68, 0.4); transform: translateY(-1px); color: #fff; }

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border-color: #f59e0b;
}
.btn-warning:hover { transform: translateY(-1px); color: #fff; }

.btn-outline-primary {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline-primary:hover {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
  transform: translateY(-1px);
}

.btn-outline-secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-color);
}
.btn-outline-secondary:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: var(--radius-sm); }
.btn-lg { padding: 13px 28px; font-size: 16px; border-radius: var(--radius-md); }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: var(--radius); }

/* ═══════════════════════════════════════════════════════════════
   TABLES
═══════════════════════════════════════════════════════════════ */

.table-responsive { border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border-color); }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  margin: 0;
}

.table thead th {
  background: var(--bg-table-head);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13.5px;
  color: var(--text-primary);
  vertical-align: middle;
}

.table tbody tr {
  transition: var(--transition-fast);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(var(--primary-rgb), 0.03); }

/* ═══════════════════════════════════════════════════════════════
   BADGES
═══════════════════════════════════════════════════════════════ */

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.badge-soft-success { background: rgba(34,197,94, 0.12);  color: #16a34a; }
.badge-soft-warning { background: rgba(245,158,11, 0.12); color: #d97706; }
.badge-soft-danger  { background: rgba(239,68,68, 0.12);  color: #dc2626; }
.badge-soft-info    { background: rgba(59,130,246, 0.12); color: #2563eb; }
.badge-soft-primary { background: rgba(var(--primary-rgb), 0.12); color: var(--primary); }
.badge-soft-secondary { background: rgba(100,116,139,0.12); color: #475569; }
.badge-soft-purple  { background: rgba(168,85,247,0.12);  color: #9333ea; }

/* ═══════════════════════════════════════════════════════════════
   ALERTS
═══════════════════════════════════════════════════════════════ */

.alert {
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid;
  animation: slideInDown 0.3s ease;
}

.alert-success { background: rgba(34,197,94,0.1);  border-color: rgba(34,197,94,0.2);  color: #15803d; }
.alert-danger  { background: rgba(239,68,68,0.1);  border-color: rgba(239,68,68,0.2);  color: #b91c1c; }
.alert-warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.2); color: #b45309; }
.alert-info    { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.2); color: #1d4ed8; }

[data-theme="dark"] .alert-success { color: #86efac; }
[data-theme="dark"] .alert-danger  { color: #fca5a5; }
[data-theme="dark"] .alert-warning { color: #fcd34d; }
[data-theme="dark"] .alert-info    { color: #93c5fd; }

/* ═══════════════════════════════════════════════════════════════
   DROPDOWN MENUS
═══════════════════════════════════════════════════════════════ */

.dropdown-menu {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  padding: 6px;
  min-width: 200px;
  animation: fadeInDown 0.15s ease;
}

.dropdown-item {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-primary);
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  text-decoration: none;
}
.dropdown-item:hover { background: rgba(var(--primary-rgb), 0.07); color: var(--primary); }
.dropdown-item.danger:hover { background: rgba(239,68,68,0.07); color: var(--danger); }

.dropdown-divider { border-top: 1px solid var(--border-color); margin: 4px 0; }
.dropdown-header { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); padding: 4px 12px 8px; }

/* ═══════════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════════ */

.modal-backdrop { background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
}

.modal-header {
  border-bottom: 1px solid var(--border-color);
  padding: 20px 24px;
}

.modal-title { font-size: 16px; font-weight: 700; }

.modal-body { padding: 24px; }

.modal-footer {
  border-top: 1px solid var(--border-color);
  padding: 16px 24px;
}

.btn-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  opacity: 1;
}
.btn-close:hover { background: var(--bg-input); color: var(--text-primary); }

/* ═══════════════════════════════════════════════════════════════
   CHARTS
═══════════════════════════════════════════════════════════════ */

.chart-wrapper { position: relative; }

/* ═══════════════════════════════════════════════════════════════
   LOADING / SPINNER
═══════════════════════════════════════════════════════════════ */

.spinner-border {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(var(--primary-rgb), 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}



/* ═══════════════════════════════════════════════════════════════
   ANIMATIONS
═══════════════════════════════════════════════════════════════ */

@keyframes fadeIn      { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInDown  { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInUp    { from { opacity: 0; transform: translateY(8px);  } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown   { from { opacity: 0; max-height: 0; } to { opacity: 1; max-height: 500px; } }
@keyframes slideInDown { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin        { to { transform: rotate(360deg); } }
@keyframes pulse       { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.animate-fade-in      { animation: fadeIn 0.4s ease; }
.animate-fade-in-up   { animation: fadeInUp 0.4s ease; }
.animate-fade-in-down { animation: fadeInDown 0.3s ease; }

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--border-color) 25%, var(--border-light) 50%, var(--border-color) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}

/* ═══════════════════════════════════════════════════════════════
   NOTIFICATION PANEL
═══════════════════════════════════════════════════════════════ */

.notification-dropdown {
  width: 360px;
  max-height: 480px;
  overflow-y: auto;
}

.notification-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition-fast);
}
.notification-item:hover { background: rgba(var(--primary-rgb), 0.05); }
.notification-item.unread { background: rgba(var(--primary-rgb), 0.04); }
.notification-item .notif-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.notification-item .notif-content { flex: 1; min-width: 0; }
.notification-item .notif-title { font-size: 13.5px; font-weight: 600; margin-bottom: 2px; }
.notification-item .notif-text { font-size: 12.5px; color: var(--text-muted); }
.notification-item .notif-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ═══════════════════════════════════════════════════════════════
   MOBILE OVERLAY
═══════════════════════════════════════════════════════════════ */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; animation: fadeIn 0.2s ease; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤1200px)
═══════════════════════════════════════════════════════════════ */

@media (max-width: 1200px) {
  :root { --sidebar-width: 240px; }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤991px)
═══════════════════════════════════════════════════════════════ */

@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0,0,0,0.3);
  }
  .main-wrapper { margin-left: 0 !important; }
  .page-content { padding: 16px; }
  .stat-value { font-size: 20px; }

  /* Tables — horizontal scroll on tablet */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
  }

  /* Modals — wider on tablet */
  .modal-dialog { margin: 16px; }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤768px)
═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Page content compact padding on mobile */
  .page-content {
    padding: 14px 12px 90px 12px !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  /* Hide desktop search, company label */
  .global-search { display: none; }
  .company-switcher span { display: none; }

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    width: 100%;
    max-width: 100%;
  }
  .page-header > div:last-child {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    width: 100%;
  }
  .page-header > div:last-child > .btn-primary,
  .page-header > div:last-child > a.btn-primary {
    color: #ffffff !important;
  }
  .page-header form {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    width: 100%;
  }
  .page-header form input[type="date"] {
    flex: 1 1 120px;
    min-width: 110px;
  }
  .page-title { font-size: 19px; }

  /* Navbar compact */
  .top-navbar { padding: 0 12px; gap: 8px; }

  /* Notification dropdown full width */
  .notification-dropdown {
    width: calc(100vw - 24px);
    max-width: 380px;
  }

  /* Dropdown menus shift left on right side */
  .navbar-right .dropdown-menu-end {
    right: -4px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE SMALL (≤576px)
═══════════════════════════════════════════════════════════════ */

@media (max-width: 576px) {
  html { font-size: 14px; }

  /* Spacing */
  .page-content {
    padding: 12px;
    /* Make room for bottom nav */
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
  .card-footer { padding: 10px 14px; }
  .stat-card {
    padding: 12px 10px;
    gap: 10px;
    border-radius: 12px;
  }
  .stat-value {
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .stat-icon {
    width: 38px;
    height: 38px;
    font-size: 16px;
    border-radius: 10px;
  }
  .stat-label {
    font-size: 10.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .stat-change {
    font-size: 10px;
  }

  /* Full-width buttons in page header */
  .page-header > div:last-child .btn {
    flex: 1;
    justify-content: center;
  }

  /* Stat cards in 2-column grid */
  .row.g-3 > .col-md-3,
  .row.g-4 > .col-md-3 {
    width: 50%;
  }

  /* Form columns full-width on mobile */
  .col-md-4, .col-md-6, .col-md-8 { width: 100%; }

  /* Badge sizes */
  .badge { font-size: 10.5px; }

  /* Buttons — bigger touch area */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }

  /* Modals — full screen on mobile */
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: flex-end;
  }
  .modal-content {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border: none;
    max-height: 92vh;
    overflow-y: auto;
  }
  .modal-body { padding: 16px; }
  .modal-header { padding: 16px; }
  .modal-footer { padding: 12px 16px; }

  /* DataTable controls compact */
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    width: 100%;
    text-align: left !important;
    margin-bottom: 8px;
  }
  .dataTables_wrapper .dataTables_filter input {
    width: 100% !important;
    margin-left: 0 !important;
    margin-top: 4px;
    display: block;
  }
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    width: 100%;
    text-align: center !important;
  }
  .dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 6px 10px !important;
    min-width: 36px;
    min-height: 36px;
  }

  /* Table action buttons smaller */
  .table tbody td .btn-sm {
    padding: 4px 8px;
    font-size: 11.5px;
  }
  .table tbody td { padding: 10px 12px; }
  .table thead th { padding: 10px 12px; font-size: 11px; }
}

/* ═══════════════════════════════════════════════════════════════
   TOUCH TARGETS — All tappable elements ≥44px
═══════════════════════════════════════════════════════════════ */

@media (pointer: coarse) {
  .navbar-btn { width: 44px; height: 44px; }
  .navbar-toggle-btn { width: 44px; height: 44px; }
  .nav-link { min-height: 44px; }
  .dropdown-item { min-height: 44px; }
  .form-control,
  .form-select { min-height: 44px; padding: 11px 14px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .btn-icon { width: 44px; height: 44px; }
  .navbar-user-avatar { width: 42px; height: 42px; }
}

/* ═══════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION BAR (Mobile only ≤768px)
═══════════════════════════════════════════════════════════════ */

.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-navbar);
    border-top: 1px solid var(--border-color);
    z-index: 950;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 500;
    padding: 6px 4px;
    border: none;
    background: transparent;
    transition: color 0.18s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav-item i {
    font-size: 21px;
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .mobile-nav-item:hover,
  .mobile-nav-item.active {
    color: var(--primary);
  }

  .mobile-nav-item.active i {
    transform: translateY(-2px);
  }

  /* Active indicator dot */
  .mobile-nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    width: 4px;
    height: 4px;
    background: var(--primary);
    border-radius: 50%;
    animation: fadeIn 0.2s ease;
  }

  /* Center Quick-Add button — special */
  .mobile-nav-item.quick-add-btn {
    color: #fff;
  }
  .mobile-nav-item.quick-add-btn i {
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.4);
    margin-top: -12px;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  }
  .mobile-nav-item.quick-add-btn:active i {
    transform: scale(0.92) rotate(45deg);
  }
  .mobile-nav-item.quick-add-btn::after { display: none; }
  .mobile-nav-item.quick-add-btn span { color: var(--text-muted); }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE SEARCH OVERLAY
═══════════════════════════════════════════════════════════════ */

.mobile-search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-body);
  z-index: 1100;
  flex-direction: column;
  animation: fadeIn 0.18s ease;
}

.mobile-search-overlay.show {
  display: flex;
}

.mobile-search-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-navbar);
}

.mobile-search-header .search-input-wrapper {
  flex: 1;
  position: relative;
}

.mobile-search-header input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 1.5px solid var(--border-color);
  border-radius: 50px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

.mobile-search-header input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.12);
}

.mobile-search-header .search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 15px;
}

.mobile-search-cancel {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 2px;
  white-space: nowrap;
  font-family: inherit;
}

.mobile-search-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

/* Mobile Search Icon in Navbar */
.mobile-search-btn {
  display: none;
}

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

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR — Mobile Close Button
═══════════════════════════════════════════════════════════════ */

.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 14px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s ease;
  z-index: 10;
}

.sidebar-close-btn:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

@media (max-width: 991px) {
  .sidebar-brand { position: relative; }
  .sidebar-close-btn { display: flex; }
}

/* ═══════════════════════════════════════════════════════════════
   SAFE AREA INSETS (Notched phones — iOS, Android)
═══════════════════════════════════════════════════════════════ */

.top-navbar {
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
}

@media (max-width: 768px) {
  .top-navbar {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}

/* ═══════════════════════════════════════════════════════════════
   SWIPE INDICATOR (visual feedback during swipe)
═══════════════════════════════════════════════════════════════ */

.swipe-indicator {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
  z-index: 998;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.swipe-indicator.visible { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════
   ULTRA-SMALL SCREENS (≤360px — budget Androids, iPhone 4/5)
═══════════════════════════════════════════════════════════════ */

@media (max-width: 360px) {
  html { font-size: 13px; }

  /* Navbar — squeeze everything */
  .top-navbar { padding: 0 8px; gap: 4px; height: 56px; }
  :root { --navbar-height: 56px; }
  .navbar-toggle-btn { width: 38px; height: 38px; }
  .navbar-btn { width: 36px; height: 36px; font-size: 16px; }
  .navbar-user-avatar { width: 34px; height: 34px; }
  .notification-badge { width: 15px; height: 15px; font-size: 8px; top: 3px; right: 3px; }

  /* Bottom nav — tighter labels */
  .mobile-bottom-nav { height: calc(58px + env(safe-area-inset-bottom, 0px)); }
  .mobile-nav-item { font-size: 9.5px; gap: 2px; padding: 4px 2px; }
  .mobile-nav-item i { font-size: 18px; }
  .mobile-nav-item.quick-add-btn i {
    width: 40px;
    height: 40px;
    font-size: 19px;
    margin-top: -10px;
  }

  /* Page content */
  .page-content {
    padding: 10px 8px;
    padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  }
  .page-title { font-size: 17px; }
  .card-body { padding: 10px; }
  .card-header { padding: 10px 12px; }

  /* Stat cards — force 2-column but smaller */
  .stat-card { padding: 10px; gap: 8px; }
  .stat-icon { width: 38px; height: 38px; font-size: 16px; }
  .stat-value { font-size: 16px; }
  .stat-label { font-size: 10px; }

  /* Dropdown menus go full width */
  .dropdown-menu {
    min-width: calc(100vw - 16px) !important;
    right: 8px !important;
    left: 8px !important;
    transform: none !important;
  }

  /* Buttons at smallest */
  .btn { font-size: 13px; padding: 8px 12px; }
  .btn-sm { font-size: 11px; padding: 5px 9px; }
  .page-header > div:last-child .btn { font-size: 12px; }

  /* Tables even smaller padding */
  .table tbody td { padding: 8px 8px; font-size: 12px; }
  .table thead th { padding: 8px 8px; font-size: 10px; }
}

/* ═══════════════════════════════════════════════════════════════
   LINE-ITEMS TABLE — Horizontal scroll on ALL mobile
   (invoice/quotation/bill create & edit forms)
═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Wrap the items table in an overflow scroll container */
  #itemsTable,
  table#itemsTable,
  .items-table-wrapper {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  #itemsTable thead,
  #itemsTable tbody,
  #itemsTable tr {
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  /* Minimum widths per column so they don't squish */
  #itemsTable th:first-child,
  #itemsTable td:first-child { min-width: 160px; }      /* Item name */
  #itemsTable th:nth-child(2),
  #itemsTable td:nth-child(2) { min-width: 80px; }      /* HSN/SAC */
  #itemsTable th:nth-child(3),
  #itemsTable td:nth-child(3) { min-width: 60px; }      /* Qty */
  #itemsTable th:nth-child(4),
  #itemsTable td:nth-child(4) { min-width: 100px; }     /* Unit price */
  #itemsTable th:nth-child(5),
  #itemsTable td:nth-child(5) { min-width: 90px; }      /* Discount */
  #itemsTable th:nth-child(6),
  #itemsTable td:nth-child(6) { min-width: 80px; }      /* GST Rate */
  #itemsTable th:nth-child(7),
  #itemsTable td:nth-child(7) { min-width: 110px; }     /* Taxable Amount */
  #itemsTable th:last-child,
  #itemsTable td:last-child { min-width: 40px; }        /* Delete btn */

  /* Wrap the entire table card body in a scroll container */
  .items-card .card-body,
  #itemsTable {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Line item inputs — smaller on mobile */
  #itemsTable .form-control-sm { font-size: 12px; padding: 5px 8px; }
  #itemsTable .form-select-sm  { font-size: 12px; padding: 5px 8px; }

  /* Item description textarea hidden by default on mobile for space */
  #itemsTable .item-description-input { display: none !important; }

  /* Invoice summary totals — allow text wrap */
  .invoice-totals-table td { white-space: normal; word-break: break-word; }
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD STAT CARDS — Better small screen grid
═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  /* Fix the stat cards row so they always show 2 per row */
  .row > [class*="col-"] .stat-card {
    min-width: 0;
  }

  /* Prevent any horizontal overflow on the main content */
  .page-content {
    overflow-x: hidden;
  }

  /* Tables inside cards should always scroll */
  .card .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Ensure no element bleeds outside its card */
  .card { overflow: hidden; }
}

/* ═══════════════════════════════════════════════════════════════
   UTILITY CLASSES
═══════════════════════════════════════════════════════════════ */

.fw-600 { font-weight: 600 !important; }
.fw-700 { font-weight: 700 !important; }
.fw-800 { font-weight: 800 !important; }
.text-xs  { font-size: 11px !important; }
.text-sm  { font-size: 12.5px !important; }
.text-base { font-size: 14px !important; }
.text-primary-color { color: var(--primary) !important; }
.text-success-color { color: var(--success) !important; }
.text-danger-color  { color: var(--danger) !important; }
.text-warning-color { color: var(--warning) !important; }
.gap-6  { gap: 6px !important; }
.gap-8  { gap: 8px !important; }
.gap-10 { gap: 10px !important; }
.gap-12 { gap: 12px !important; }
.gap-16 { gap: 16px !important; }
.rounded-xl { border-radius: var(--radius-xl) !important; }
.border-0 { border: none !important; }
.bg-card  { background: var(--bg-card) !important; }
.no-wrap  { white-space: nowrap; }

/* ============================================================
   SPLIT PANE LAYOUT (Master-Detail)
   ============================================================ */
.split-layout {
    display: flex;
    height: calc(100vh - var(--navbar-height));
    margin: -24px; /* offset .page-content padding */
    overflow: hidden;
}
.split-list-pane {
    width: 350px;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
}
.split-detail-pane {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-body);
    position: relative;
    padding: 24px;
}
.split-list-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 10;
}
.split-list-item {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.2s;
    display: block;
    text-decoration: none;
    color: inherit;
}
.split-list-item:hover {
    background: var(--bg-input);
}
.split-list-item.active {
    background: rgba(var(--primary-rgb), 0.08);
    border-left: 3px solid var(--primary);
    padding-left: 17px;
}
.split-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}
@media (max-width: 991px) {
    .split-layout { flex-direction: column; }
    .split-list-pane { width: 100%; border-right: none; border-bottom: 1px solid var(--border-color); max-height: 40vh; }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE MASTER-DETAIL NAVIGATION PATTERN
   List page  → show only list, hide empty detail pane
   Detail page → show only detail, hide list pane (back btn added via JS)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Full-screen split layout on mobile */
  .split-layout {
    flex-direction: row;       /* keep side by side... */
    height: calc(100vh - var(--navbar-height));
    margin: -16px;
    overflow: hidden;
    position: relative;
  }

  /* List pane — full width, slides left when detail is active */
  .split-list-pane {
    width: 100%;
    min-width: 100%;
    max-height: none;
    height: 100%;
    overflow-y: auto;
    border-right: none;
    border-bottom: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  }

  /* Detail pane — full width, slides in from right */
  .split-detail-pane {
    width: 100%;
    min-width: 100%;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px calc(80px + env(safe-area-inset-bottom, 0px));
    position: absolute;
    top: 0;
    left: 0;
    transform: translateX(100%);  /* hidden off-screen right by default */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-body);
    z-index: 10;
  }

  /* When detail is active: list slides left, detail slides in */
  .split-layout.detail-active .split-list-pane {
    transform: translateX(-100%);
  }
  .split-layout.detail-active .split-detail-pane {
    transform: translateX(0);
  }

  /* Mobile Back Button — shown in detail pane on mobile */
  .mobile-detail-back {
    display: flex !important;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: var(--primary);
    font-size: 15px;
    font-weight: 600;
    padding: 0 0 16px 0;
    cursor: pointer;
    text-decoration: none;
  }
  .mobile-detail-back i { font-size: 20px; }

  /* Empty state in index pages — hide on mobile */
  .split-empty-state { display: none; }

  /* List items — bigger touch targets */
  .split-list-item {
    padding: 14px 16px;
    min-height: 70px;
    position: relative;
  }
  .split-list-item::after {
    content: '›';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 22px;
    color: var(--border-color);
    line-height: 1;
  }

  /* Split list header — more compact */
  .split-list-header {
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 20;
  }

  /* Page header in detail view — stacked on mobile */
  .split-detail-pane .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding-bottom: 12px;
  }

  /* ─── MOBILE ACTION BAR ─────────────────────────────────────
     Inline action buttons — flows with page content (no fixed positioning)
     so it doesn't overlap the PDF card or block scrolling
  ─────────────────────────────────────────────────────────── */
  .split-detail-pane .page-header > div:last-child {
    display: flex !important;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    margin-top: 4px;
  }

  /* Edit button */
  .split-detail-pane .page-header > div:last-child a[href*="edit"] {
    flex: 1;
    min-width: 80px;
    justify-content: center;
  }

  /* Print/PDF — primary action */
  .split-detail-pane .page-header > div:last-child a[href*="print"] {
    flex: 1;
    min-width: 120px;
    justify-content: center;
    text-align: center;
  }

  /* Convert to Invoice / Mark as Sent form */
  .split-detail-pane .page-header > div:last-child form:not(.d-inline) {
    flex: 1;
    display: flex;
  }
  .split-detail-pane .page-header > div:last-child form:not(.d-inline) button {
    width: 100%;
  }

  /* Delete button */
  .split-detail-pane .page-header > div:last-child form.d-inline {
    flex: 0 0 auto;
  }

  /* All action buttons — touch-friendly height */
  .split-detail-pane .page-header > div:last-child .btn {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
  }
}

/* Desktop: hide the mobile back button */
@media (min-width: 769px) {
  .mobile-detail-back { display: none !important; }
  .split-empty-state { display: flex; }
}

/* Print Styles for Reports */
@media print {
  body { background-color: #fff !important; color: #000 !important; }
  .sidebar, .top-navbar, .sidebar-overlay, .btn, footer, .page-header form, .quick-add-btn,
  .mobile-bottom-nav, .mobile-search-overlay, .swipe-indicator {
    display: none !important;
  }
  .main-wrapper {
    margin-left: 0 !important;
    padding: 0 !important;
  }
  .page-content {
    padding: 0 !important;
    margin: 0 !important;
  }
  .card {
    border: none !important;
    box-shadow: none !important;
    margin-bottom: 0 !important;
  }
  .card-header {
    background-color: transparent !important;
    border-bottom: 2px solid #000 !important;
  }
  .table {
    border-color: #000 !important;
  }
  th, td {
    color: #000 !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   PDF LIVE VIEWER — Desktop iframe + Mobile PDF Card
   Desktop: full 900px interactive iframe preview
   Mobile: scaled thumbnail preview + View/Download buttons
═══════════════════════════════════════════════════════════════ */

/* ─── Mobile PDF Card (hidden on desktop) ─────────────────── */
.pdf-mobile-card {
  display: none;
}

@media (max-width: 768px) {
  /* Hide the desktop iframe on mobile — can't render PDFs */
  .pdf-viewer-iframe-wrap { display: none !important; }

  /* Show the mobile card instead */
  .pdf-mobile-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  }

  /* Scaled-down thumbnail preview — renders the HTML invoice at 50% zoom */
  .pdf-mobile-card-preview {
    position: relative;
    width: 100%;
    height: 280px;
    overflow: hidden;
    background: #f5f5f5;
    border-bottom: 1px solid var(--border-color);
  }

  [data-theme="dark"] .pdf-mobile-card-preview {
    background: #1a1a2e;
  }

  .pdf-mobile-card-preview iframe {
    width: 200%;
    height: 560px;
    border: none;
    transform: scale(0.5);
    transform-origin: top left;
    pointer-events: none;  /* prevent accidental taps on preview */
  }

  /* Gradient overlay on preview — indicates it's a preview, not interactive */
  .pdf-mobile-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(to top, var(--bg-card), transparent);
    pointer-events: none;
  }

  /* Action buttons below the preview */
  .pdf-mobile-card-actions {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .pdf-mobile-card-actions .btn {
    min-height: 48px;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .pdf-mobile-card-actions .btn-primary {
    box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.3);
  }
}

@media (min-width: 769px) {
  .pdf-viewer-iframe-wrap { display: block; }
  .pdf-mobile-card { display: none !important; }
}


/* ═══════════════════════════════════════════════════════════════
   MOBILE — Dedicated Mobile Layout (MIM — Mobile Item Manager)
   All styles apply to max-width: 768px only.
   Desktop table (.desktop-items-card) is hidden via JS on mobile.
═══════════════════════════════════════════════════════════════ */

/* ── Form bottom padding so Save button clears bottom nav ── */
@media (max-width: 768px) {
  form { padding-bottom: calc(90px + env(safe-area-inset-bottom, 16px)); }

  /* Summary / Notes full width */
  .col-lg-7, .col-lg-5 { flex: 0 0 100% !important; max-width: 100% !important; }

  /* Page header stacks */
  .page-header { flex-direction: column; gap: 10px; align-items: flex-start !important; }
}

/* ═══════════════════════════════════════════════════
   MOBILE ITEM LIST (card list)
═══════════════════════════════════════════════════ */
.mobile-item-list {
  display: flex;
  flex-direction: column;
}
.mobile-item-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.mobile-item-card:active { background: var(--bg-input); }

.mic-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(var(--primary-rgb, 99,102,241), 0.12);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}
.mic-info { flex: 1; min-width: 0; }
.mic-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.mic-meta { font-size: 12px; color: var(--text-muted); }
.mic-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}
.mic-amount { font-size: 15px; font-weight: 800; color: var(--primary); }
.mic-arrow  { color: var(--text-muted); font-size: 12px; }

/* Add Item button */
.mobile-add-item-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  background: none;
  border: none;
  border-top: 1px solid var(--border-light);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.mobile-add-item-btn:active { background: var(--bg-input); }
.mobile-add-item-btn i { font-size: 18px; }

/* ═══════════════════════════════════════════════════
   ITEM BOTTOM SHEET
   Hidden on desktop — only activated on mobile (≤768px)
═══════════════════════════════════════════════════ */

/* Desktop: completely remove the sheet from layout */
.item-sheet { display: none; }
/* #mobileItemsCard is controlled by JS inline style on mobile; hidden by PHP inline style on desktop */
/* Do NOT use !important here — JS needs to override with display:block on mobile */

/* Mobile: show sheet and mobile card list */
@media (max-width: 768px) {
  .item-sheet {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 99999;
    pointer-events: none;
  }
  .item-sheet.open { pointer-events: all; }
}

/* Backdrop */
.item-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  transition: background 0.3s;
}
.item-sheet.open .item-sheet-backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Panel */
.item-sheet-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-card);
  border-radius: 22px 22px 0 0;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(110%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom, 16px);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.2);
}
.item-sheet.open .item-sheet-panel { transform: translateY(0); }

/* Drag handle */
.item-sheet-handle {
  width: 38px; height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 12px auto 2px;
  flex-shrink: 0;
}

/* Header */
.item-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px 14px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 2;
}
.item-sheet-title { font-size: 17px; font-weight: 700; }
.item-sheet-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg-input);
  border: none;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  line-height: 1;
}

/* Body / fields */
.item-sheet-body { padding: 18px 18px 0; }

.item-sheet-field { margin-bottom: 16px; }
.item-sheet-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.item-sheet-input {
  min-height: 48px !important;
  font-size: 15px !important;
  border-radius: 10px !important;
}
textarea.item-sheet-input { min-height: 70px !important; resize: none; }

/* 3-column grid (HSN / Qty / Price) */
.item-sheet-row3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

/* 2-column grid (Discount / GST) */
.item-sheet-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 4px;
}
.item-sheet-row2 .input-group .form-select { max-width: 62px !important; min-width: 55px !important; }

/* Taxable preview */
.item-sheet-taxable {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: rgba(var(--primary-rgb, 99,102,241), 0.06);
  border-top: 1px solid var(--border-color);
  margin-top: 18px;
}
.item-sheet-taxable-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.item-sheet-taxable-val {
  font-size: 22px;
  font-weight: 900;
  color: var(--primary);
}

/* Footer buttons */
.item-sheet-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
}
.item-sheet-save {
  flex: 1;
  min-height: 52px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 12px !important;
}
.item-sheet-del {
  width: 52px;
  min-height: 52px;
  border-radius: 12px !important;
  flex-shrink: 0;
  font-size: 17px;
}

/* Item dropdown inside sheet (position:absolute, no clipping issue) */
#sh_dropdown.dropdown-menu {
  border-radius: 12px !important;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15) !important;
  border: 1px solid var(--border-color) !important;
  overflow: hidden;
}
#sh_dropdown .dropdown-item { padding: 12px 16px !important; font-size: 14px !important; }

/* ─────────────────────────────────────────────────────
   DESKTOP: Fix item dropdown clipping in .table-responsive
   On desktop, overflow must be visible so dropdown shows.
   On mobile, it reverts to overflow-x:auto (set in Bootstrap).
───────────────────────────────────────────────────── */
@media (min-width: 769px) {
  .desktop-items-card .table-responsive,
  .desktop-items-card .card-body {
    overflow: visible !important;
  }
  /* Ensure the dropdown renders above everything on desktop */
  .desktop-items-card .item-dropdown-menu {
    z-index: 9999 !important;
  }
}

/* ─────────────────────────────────────────────────────
   MOBILE: Journal Voucher Lines Table (#linesTable)
───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #linesTable thead { display: none !important; }
  #linesTable tbody,
  #linesTable tr.je-line {
    display: block !important;
    width: 100% !important;
  }
  #linesTable tr.je-line {
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px !important;
    padding: 14px !important;
    margin-bottom: 12px !important;
    position: relative !important;
  }
  #linesTable tr.je-line td {
    display: block !important;
    padding: 4px 0 !important;
    border: none !important;
    width: 100% !important;
  }
  #linesTable tr.je-line td:nth-child(3),
  #linesTable tr.je-line td:nth-child(4) {
    display: inline-block !important;
    width: 48% !important;
  }
  #linesTable tr.je-line td:nth-child(4) {
    float: right !important;
  }
  #linesTable tr.je-line td:last-child {
    position: absolute !important;
    top: 8px !important;
    right: 8px !important;
    width: auto !important;
    padding: 0 !important;
  }
  #linesTable tfoot,
  #linesTable tfoot tr,
  #linesTable tfoot td {
    display: block !important;
    width: 100% !important;
  }
}

/* End of app.css */
