:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --line: #e2e8f0;
  
  /* HSL Brand Colors */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-dark: #1e3a8a;
  
  --success: #10b981;
  --success-light: #ecfdf5;
  --success-dark: #065f46;
  
  --warning: #f59e0b;
  --warning-light: #fff7ed;
  --warning-dark: #9a3412;
  
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --danger-dark: #991b1b;
  
  --sidebar-bg: #0f172a;
  --sidebar-active: #1e293b;
  --sidebar-text: #cbd5e1;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --shadow-lg: 0 10px 15px -3px rgba(15,23,42,0.08), 0 4px 6px -4px rgba(15,23,42,0.08);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

h1, h2, h3, h4, .brand {
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.hidden {
  display: none !important;
}

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

/* Utility CSS */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.w-full { width: 100%; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.p-16 { padding: 16px; }

/* Layout */
.app-container {
  display: flex;
  width: 100vw;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,0.05);
  transition: var(--transition);
}

.sidebar-brand {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary) 0%, #3b82f6 100%);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(to right, #ffffff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-user {
  padding: 16px 20px;
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--sidebar-active);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.05);
}

.user-badge-role {
  font-size: 11px;
  color: #94a3b8;
}

.sidebar-nav {
  flex: 1;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  color: var(--sidebar-text);
  border: 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: var(--transition);
  width: 100%;
}

.nav-item:hover {
  background: rgba(255,255,255,0.04);
  color: #fff;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

/* Main Section */
.main-content {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
}

/* Topbar */
.topbar {
  height: 72px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 90;
}

.page-info h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
}

.page-info p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.company-filter-wrap {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.filter-tab {
  background: transparent;
  border: 0;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.filter-tab:hover {
  color: var(--text-main);
}

.filter-tab.active {
  background: #fff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Cards & Panels */
.content-area {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  flex: 1;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Metrics */
.metric-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-main);
  margin: 8px 0;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.metric-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.metric-footer {
  font-size: 12px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: var(--success-dark); }
.badge-warning { background: var(--warning-light); color: var(--warning-dark); }
.badge-danger { background: var(--danger-light); color: var(--danger-dark); }
.badge-secondary { background: #f1f5f9; color: #475569; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}

.btn:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(37,99,235,0.2);
}

.btn-secondary {
  background: #fff;
  color: var(--text-main);
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  background: #f8fafc;
  box-shadow: none;
  border-color: #cbd5e1;
}

.btn-secondary.active-filter {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-success {
  background: var(--success);
}

.btn-success:hover {
  background: #059669;
  box-shadow: 0 4px 12px rgba(16,185,129,0.2);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  background: #fff;
  color: var(--text-main);
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* Tables */
.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
  background: #fff;
}

th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  padding: 14px 16px;
  border-bottom: 2px solid var(--line);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  color: #334155;
  font-weight: 500;
}

tr:last-child td {
  border-bottom: 0;
}

tr:hover td {
  background: #fdfdfd;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.3s ease;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Modal Styling */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-content {
  background: #fff;
  border-radius: var(--radius-lg);
  width: min(650px, 100%);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalOpen 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid var(--line);
}

@keyframes modalOpen {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  padding: 24px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #f8fafc;
}

/* Digital Challan Sheet Styles */
.challan-sheet {
  border: 2px solid #0f172a;
  padding: 32px;
  background: #fff;
  border-radius: var(--radius-md);
  color: #000;
}

.challan-header {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid #0f172a;
  padding-bottom: 20px;
  margin-bottom: 24px;
}

.challan-logo-side h2 {
  font-size: 24px;
  font-weight: 800;
  color: #0f172a;
}

.challan-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
  margin-bottom: 28px;
}

.challan-card {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 16px;
  font-size: 13px;
  background: #f8fafc;
  color: #334155;
}

.challan-card strong {
  display: block;
  margin-bottom: 6px;
  color: #0f172a;
  font-size: 14px;
}

.challan-sign-row {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px dashed #cbd5e1;
  font-size: 13px;
  font-weight: 600;
}

/* Interactive Graph Simulation */
.chart-container {
  height: 200px;
  position: relative;
  margin-top: 10px;
}

/* Activity Feed Items */
.activity-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.activity-item:last-child {
  border-bottom: 0;
}
.activity-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}

/* Company Registry Cards */
.company-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.company-card:hover {
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}
.company-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}
.company-details-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.detail-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}
.detail-val {
  font-size: 13px;
  color: var(--text-main);
  font-weight: 600;
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-box {
  background: #fff;
  border-radius: var(--radius-lg);
  width: min(440px, 100%);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  padding: 36px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.login-title-wrap {
  text-align: center;
  margin-bottom: 28px;
}

.login-title-wrap h2 {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
}

.login-title-wrap p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Guide overlay info */
.guide-banner {
  position: fixed;
  bottom: 24px;
  left: 24px;
  background: #0f172a;
  color: #fff;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  max-width: 320px;
  border: 1px solid var(--primary);
}

.guide-banner h4 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14px;
  color: #fcd34d;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.guide-banner p {
  font-size: 12px;
  line-height: 1.4;
  color: #e2e8f0;
}

/* AI Estimator Canvas */
.ai-scan-box {
  border: 2px dashed #cbd5e1;
  background: #f8fafc;
  border-radius: var(--radius-md);
  padding: 40px;
  text-align: center;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
}

.ai-scan-box:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.scanner-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(to right, transparent, var(--primary), transparent);
  box-shadow: 0 0 8px var(--primary);
  animation: scan 2s linear infinite;
  display: none;
}

@keyframes scan {
  0% { top: 0%; }
  50% { top: 100%; }
  100% { top: 0%; }
}

/* ==================== RESPONSIVE DESIGN (MOBILE & TABLET) ==================== */
@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 260px;
    z-index: 1001; /* Higher than topbar */
    transition: transform 0.3s ease;
  }
  
  .sidebar.active {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
  
  .sidebar-toggle-btn {
    display: inline-flex !important;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-main);
    padding: 8px;
    margin-right: 12px;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
  }
  
  .sidebar-toggle-btn:hover {
    background: var(--bg);
  }
  
  /* Sidebar Overlay when open */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: block;
    transition: opacity 0.3s ease;
  }
  
  .sidebar-overlay.hidden {
    display: none !important;
  }
  
  /* Topbar responsiveness */
  .topbar {
    padding: 0 16px;
    height: auto;
    min-height: 72px;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 12px;
    padding-bottom: 12px;
  }
  
  .page-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .page-info-text {
    display: flex;
    flex-direction: column;
  }
  
  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
  
  .company-filter-wrap {
    width: 100%;
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  
  .filter-tab {
    flex: 1;
    text-align: center;
  }
  
  /* Content Area */
  .content-area {
    padding: 16px;
    gap: 16px;
  }
}

@media (max-width: 576px) {
  /* Grid layouts */
  .grid-4, .grid-2 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  
  /* Tables */
  .table-container th, .table-container td {
    padding: 10px 8px !important;
    font-size: 12px !important;
  }
  
  /* Buttons and controls */
  .btn {
    padding: 8px 12px !important;
    font-size: 12px !important;
  }
  
  /* Login form container */
  #login-container {
    width: 100% !important;
    padding: 20px !important;
  }
  
  .login-card {
    padding: 24px 16px !important;
  }
}

/* @media print for saving/printing clean challan PDFs */
@media print {
  body * {
    visibility: hidden !important;
  }
  #digitalChallanPreviewCard, #digitalChallanPreviewCard * {
    visibility: visible !important;
  }
  #digitalChallanPreviewCard {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
    background: #fff !important;
  }
  /* Hide UI elements and buttons during print/PDF generation */
  #digitalChallanPreviewCard > div:first-child,
  #chShareSection,
  .btn,
  button,
  .sidebar,
  .topbar {
    display: none !important;
  }
}
