/* =========================================================
   QuickBooks PHP — Application Stylesheet
   ========================================================= */

:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #eff6ff;
  --secondary:      #64748b;
  --success:        #16a34a;
  --warning:        #d97706;
  --danger:         #dc2626;
  --info:           #0891b2;
  --body-bg:        #f1f5f9;
  --sidebar-bg:     #0f172a;
  --sidebar-width:  260px;
  --topbar-height:  60px;
  --card-bg:        #ffffff;
  --card-border:    #e2e8f0;
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --border:         #e2e8f0;
  --radius:         10px;
  --shadow:         0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:      0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
  --transition:     all .2s ease;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--body-bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .3s cubic-bezier(.4,0,.2,1), width .3s ease;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: var(--topbar-height);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: white; flex: 1; min-width: 0;
}
.sidebar-logo-text {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--info));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: white; flex-shrink: 0;
}
.sidebar-logo { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; }
.sidebar-brand-text { min-width: 0; }
.brand-name {
  display: block;
  font-size: 13px; font-weight: 700;
  color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { font-size: 10px; color: rgba(255,255,255,.4); }

/* ---- Sidebar body: scrollable area ---- */
.sidebar-body {
  flex: 1;
  overflow-y: scroll;        /* always show scrollbar track so it doesn't jump */
  overflow-x: hidden;
  padding: 8px 0 16px;
  min-height: 0;             /* crucial: lets flex child shrink below content size */
  /* Windows thin scrollbar override */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.25) rgba(255,255,255,.05);
}

/* Webkit scrollbar — visible, styled */
.sidebar-body::-webkit-scrollbar {
  width: 6px;
}
.sidebar-body::-webkit-scrollbar-track {
  background: rgba(255,255,255,.04);
  border-radius: 0;
}
.sidebar-body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.22);
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.05);
}
.sidebar-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,.38);
}

/* Scroll hint arrow — fades in when content is scrollable */
.sidebar-body-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-scroll-hint {
  position: absolute;
  bottom: 0; left: 0; right: 6px;
  height: 36px;
  background: linear-gradient(to bottom, transparent, rgba(15,23,42,.95));
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  opacity: 1;
  transition: opacity .3s;
  z-index: 10;
}
.sidebar-scroll-hint span {
  font-size: 10px;
  color: rgba(255,255,255,.35);
  letter-spacing: .06em;
  animation: bounceDown 1.8s ease-in-out infinite;
}
@keyframes bounceDown {
  0%,100% { transform: translateY(0); opacity:.35; }
  50%      { transform: translateY(3px); opacity:.7; }
}


.sidebar-nav { list-style: none; padding: 0; margin: 0; }

.nav-section {
  padding: 14px 20px 6px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: rgba(255,255,255,.3);
}

.nav-item .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.65);
  text-decoration: none; font-size: 13.5px; font-weight: 500;
  border-radius: 0; transition: var(--transition);
  position: relative;
}
.nav-item .nav-link:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item .nav-link.active {
  color: white; background: rgba(37,99,235,.35);
}
.nav-item .nav-link.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--primary); border-radius: 0 2px 2px 0;
}
.nav-item .nav-link i:first-child { font-size: 16px; width: 20px; flex-shrink: 0; }
.nav-item .nav-link span { flex: 1; }

.submenu-arrow {
  font-size: 11px !important; width: auto !important;
  transition: transform .2s ease;
}
.has-submenu.open > .nav-link .submenu-arrow { transform: rotate(90deg); }

.submenu {
  list-style: none; padding: 0; margin: 0;
  background: rgba(0,0,0,.15); max-height: 0; overflow: hidden;
  transition: max-height .3s ease;
}
.has-submenu.open .submenu { max-height: 500px; }
.submenu li a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 20px 7px 50px;
  color: rgba(255,255,255,.55); font-size: 13px;
  text-decoration: none; transition: var(--transition);
}
.submenu li a:hover { color: white; background: rgba(255,255,255,.05); }
.submenu li a.active { color: white; }
.submenu li a i { font-size: 13px; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 12px 16px;
  flex-shrink: 0;   /* never squish — always visible at bottom */
  background: var(--sidebar-bg);
  z-index: 2;
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--info));
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 12px; font-weight: 700; flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-info { flex: 1; min-width: 0; }
.user-name { display: block; color: white; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: rgba(255,255,255,.4); }
.user-actions { display: flex; gap: 6px; }
.user-actions a { color: rgba(255,255,255,.4); font-size: 16px; transition: color .2s; }
.user-actions a:hover { color: white; }

.sidebar-toggle-btn {
  background: none; border: none; color: rgba(255,255,255,.6);
  font-size: 18px; padding: 4px; cursor: pointer; display: none;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 1039; backdrop-filter: blur(2px);
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh; display: flex; flex-direction: column;
  transition: margin-left .3s ease;
}

/* =========================================================
   TOPBAR
   ========================================================= */
.topbar {
  height: var(--topbar-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

#sidebarToggleMain {
  background: none; border: none; color: var(--text-secondary);
  font-size: 22px; padding: 4px; cursor: pointer;
  transition: color .2s; display: flex; align-items: center;
}
#sidebarToggleMain:hover { color: var(--primary); }

.breadcrumb { font-size: 13px; }
.breadcrumb-item a { color: var(--primary); text-decoration: none; }
.breadcrumb-item.active { color: var(--text-secondary); }

.topbar-search {
  position: relative; display: flex; align-items: center;
  background: var(--body-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; gap: 8px; width: 240px;
}
.topbar-search i { color: var(--text-muted); }
.topbar-search input {
  border: none; background: none; outline: none;
  font-size: 13px; width: 100%; color: var(--text-primary);
}
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: white; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-lg);
  display: none; z-index: 200; max-height: 300px; overflow-y: auto;
}
.search-results.show { display: block; }
.search-result-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; text-decoration: none; color: var(--text-primary);
  font-size: 13px; transition: background .15s;
}
.search-result-item:hover { background: var(--body-bg); }

.topbar-btn {
  background: none; border: none; color: var(--text-secondary);
  font-size: 18px; padding: 6px; cursor: pointer;
  border-radius: 8px; transition: all .2s;
  position: relative; display: flex; align-items: center;
}
.topbar-btn:hover { background: var(--body-bg); color: var(--primary); }

.notif-badge {
  position: absolute; top: 0; right: 0;
  background: var(--danger); color: white;
  font-size: 9px; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  padding: 0 4px; border: 2px solid white;
}

.notif-header { border-bottom: 1px solid var(--border); }
.notif-list { max-height: 320px; overflow-y: auto; }
.notif-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .15s;
}
.notif-item:hover { background: var(--body-bg); }
.notif-item.unread { background: var(--primary-light); }
.notif-item .notif-title { font-weight: 600; font-size: 13px; }
.notif-item .notif-msg { font-size: 12px; color: var(--text-secondary); }
.notif-item .notif-time { font-size: 11px; color: var(--text-muted); }

/* =========================================================
   PAGE CONTENT
   ========================================================= */
.page-content { flex: 1; padding: 24px; }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-header-title h1 { font-size: 22px; font-weight: 700; margin: 0; }
.page-header-title p { color: var(--text-secondary); font-size: 13px; margin: 4px 0 0; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.page-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
  display: flex; align-items: center;
  background: var(--card-bg);
}

/* =========================================================
   CARDS
   ========================================================= */
.card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card-header {
  background: transparent; border-bottom: 1px solid var(--border);
  padding: 16px 20px; display: flex; align-items: center; justify-content: space-between;
  font-weight: 600;
}
.card-body { padding: 20px; }
.card-footer { background: var(--body-bg); border-top: 1px solid var(--border); padding: 12px 20px; }

/* Stat Cards */
.stat-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; display: flex; align-items: flex-start; gap: 16px;
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-icon.blue   { background: #dbeafe; color: var(--primary); }
.stat-icon.green  { background: #dcfce7; color: var(--success); }
.stat-icon.orange { background: #ffedd5; color: var(--warning); }
.stat-icon.red    { background: #fee2e2; color: var(--danger); }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }
.stat-icon.teal   { background: #ccfbf1; color: #0d9488; }

.stat-info { flex: 1; min-width: 0; }
.stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin: 0; }
.stat-value { font-size: 22px; font-weight: 700; margin: 4px 0 2px; }
.stat-change { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* =========================================================
   TABLES
   ========================================================= */
.table-responsive { border-radius: var(--radius); }
.table { margin: 0; font-size: 13.5px; }
.table thead th {
  background: var(--body-bg); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-secondary); padding: 12px 16px;
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
.table tbody td { padding: 12px 16px; vertical-align: middle; border-color: var(--border); }
.table tbody tr:hover { background: rgba(37,99,235,.03); }
.table-actions { display: flex; gap: 4px; }
.table-actions .btn { padding: 4px 8px; font-size: 12px; }

/* =========================================================
   FORMS
   ========================================================= */
.form-label { font-weight: 500; font-size: 13px; color: var(--text-primary); margin-bottom: 4px; }
.form-control, .form-select {
  border-color: var(--border); border-radius: 8px;
  font-size: 13.5px; padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.input-group-text { background: var(--body-bg); border-color: var(--border); color: var(--text-secondary); }
.invalid-feedback { font-size: 12px; }
.form-text { font-size: 12px; color: var(--text-muted); }

/* Line item tables in invoice/bill forms */
.line-items-table { width: 100%; }
.line-items-table th { background: var(--body-bg); font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-secondary); padding: 8px 10px; }
.line-items-table td { padding: 4px 6px; vertical-align: middle; }
.line-items-table input, .line-items-table select { font-size: 13px; }

/* =========================================================
   BUTTONS
   ========================================================= */
.btn { border-radius: 8px; font-weight: 500; font-size: 13.5px; transition: var(--transition); }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { font-size: 12px; padding: 5px 10px; }
.btn-icon { width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }

/* =========================================================
   BADGES
   ========================================================= */
.badge { font-size: 11px; font-weight: 600; border-radius: 6px; padding: 3px 8px; }

/* =========================================================
   AUTH PAGE
   ========================================================= */
.auth-page {
  min-height: 100vh; margin: 0; padding: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  display: flex; align-items: stretch;
}
.auth-container { display: flex; width: 100%; min-height: 100vh; }
.auth-left {
  flex: 1; background: linear-gradient(145deg, #1e3a8a 0%, #0f172a 100%);
  padding: 60px 60px; display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.auth-left::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 30% 50%, rgba(59,130,246,.2) 0%, transparent 70%);
}
.auth-left-content { position: relative; z-index: 1; max-width: 420px; }
.auth-logo { font-size: 48px; color: var(--primary); }
.text-white-75 { color: rgba(255,255,255,.75); }
.auth-feature { color: rgba(255,255,255,.8); margin-bottom: 12px; font-size: 14px; }
.auth-right {
  width: 480px; background: white; display: flex;
  flex-direction: column; justify-content: center;
}
.auth-form-wrapper { padding: 48px 48px; }
.auth-footer { padding: 16px 48px; text-align: center; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand-icon {
  width: 44px; height: 44px; background: linear-gradient(135deg, var(--primary), var(--info));
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: white;
}

/* =========================================================
   FLASH / ALERTS
   ========================================================= */
.flash-container { padding: 0 0 0 0; }
.alert { border-radius: var(--radius); border: none; font-size: 13.5px; }
.alert-success { background: #f0fdf4; color: #166534; border-left: 4px solid var(--success); }
.alert-danger  { background: #fef2f2; color: #991b1b; border-left: 4px solid var(--danger); }
.alert-warning { background: #fffbeb; color: #92400e; border-left: 4px solid var(--warning); }
.alert-info    { background: #f0f9ff; color: #075985; border-left: 4px solid var(--info); }

/* =========================================================
   DASHBOARD CHARTS
   ========================================================= */
.chart-container { position: relative; }

/* =========================================================
   INVOICE PRINT
   ========================================================= */
@media print {
  .sidebar, .topbar, .page-header-actions, .btn, .breadcrumb, .page-footer, .flash-container { display: none !important; }
  .main-content { margin: 0 !important; }
  .page-content { padding: 0 !important; }
  .card { box-shadow: none !important; border: none !important; }
  body { background: white !important; }
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .sidebar-toggle-btn { display: flex; }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; }
  .auth-right { width: 100%; }
  .page-content { padding: 16px; }
}

@media (max-width: 575.98px) {
  .auth-form-wrapper { padding: 32px 24px; }
  .topbar { padding: 0 16px; }
  .page-content { padding: 12px; }
  .stat-card { flex-direction: column; }
}

/* =========================================================
   UTILITIES
   ========================================================= */
.text-money { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; }
.table-number { text-align: right; font-family: 'SF Mono', 'Fira Code', monospace; }
.fw-600 { font-weight: 600; }
.cursor-pointer { cursor: pointer; }
.border-start-primary { border-left: 4px solid var(--primary) !important; }
.border-start-success { border-left: 4px solid var(--success) !important; }
.border-start-danger  { border-left: 4px solid var(--danger) !important; }
.border-start-warning { border-left: 4px solid var(--warning) !important; }

/* POS Terminal */
.pos-terminal { background: #1a1a2e; min-height: 100vh; color: white; }
.pos-products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.pos-product-btn {
  background: #16213e; border: 1px solid #0f3460;
  border-radius: 10px; padding: 16px 10px; text-align: center;
  cursor: pointer; transition: all .2s; color: white;
}
.pos-product-btn:hover { background: #0f3460; transform: scale(1.02); }
.pos-cart { background: #0d0d1a; border-radius: 12px; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .3s ease; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.pulse { animation: pulse 2s ease-in-out infinite; }

/* Summary boxes */
.summary-box {
  background: var(--body-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 18px;
}
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 13.5px; }
.summary-row.total { font-weight: 700; font-size: 15px; border-top: 2px solid var(--border); margin-top: 4px; padding-top: 10px; }

/* Report specific */
.report-header { text-align: center; margin-bottom: 24px; }
.report-header h2 { font-size: 20px; font-weight: 700; }
.report-header p { color: var(--text-secondary); }
.report-group { margin-bottom: 20px; }
.report-group-title {
  background: var(--body-bg); padding: 8px 16px;
  font-weight: 700; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-secondary);
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.report-total-row { font-weight: 700; background: var(--body-bg) !important; }
.report-grand-total { background: var(--primary) !important; color: white !important; font-weight: 700; }
