:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #f1f5f9;
  --text-dark: #0f172a;
  --text-muted: #64748b;
  --bg-main: #f8fafc;
  --white: #ffffff;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  --radius-md: 12px;
  --radius-sm: 8px;
  
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  
  --radius-lg: 12px;
  
  --sidebar-width: 270px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-dark);
  font-size: 14px;
  line-height: 1.5;
}

/* Utilities */
.text-right { text-align: right; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-blue { color: var(--primary-color); }
.text-green { color: #059669; }
.text-muted { color: var(--text-muted); }
.mb-4 { margin-bottom: 24px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.p-0 { padding: 0 !important; }
.hidden-input { display: none; }

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: #0f172a; 
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 10;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.company-branding {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 20px;
}

#invoice-logo {
  max-width: 200px;
  max-height: 80px;
  object-fit: contain;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
}

.company-logo-placeholder {
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: white;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: center; align-items: center;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 12px;
}

.company-logo-placeholder.large {
  width: 60px;
  height: 60px;
  font-size: 24px;
  border-radius: var(--radius-lg);
}

.logo-container h2 { font-size: 18px; font-weight: 600; }

.sidebar-nav { padding: 20px 0; flex: 1; }

.nav-group-title {
  padding: 16px 24px 8px;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  letter-spacing: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 12px 24px;
  color: #cbd5e1;
  text-decoration: none;
  gap: 12px;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background-color: rgba(255,255,255,0.05);
  color: white;
}

.nav-item.active {
  background-color: rgba(37, 99, 235, 0.15);
  color: #60a5fa;
  border-left-color: #3b82f6;
}

.nav-item i { font-size: 16px; width: 24px; text-align: center; }

.sidebar-footer {
  padding: 24px;
  font-size: 12px;
  color: #64748b;
  text-align: center;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.top-header {
  height: 72px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.header-title h1 { font-size: 20px; font-weight: 600; color: var(--text-dark); }
.header-actions { display: flex; align-items: center; gap: 20px; }

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.btn-primary { background-color: var(--primary-color); color: white; box-shadow: 0 4px 14px 0 rgba(37, 99, 235, 0.39); }
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
.btn-secondary { background-color: var(--white); border: 1px solid var(--border-color); color: var(--text-dark); }
.btn-secondary:hover { background-color: var(--secondary-color); }
.btn-outline { background-color: transparent; border: 1px solid var(--border-color); color: var(--text-dark); }
.btn-outline:hover { background-color: var(--secondary-color); }
.btn-danger { background-color: var(--danger); color: white; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 6px; border-radius: 4px; transition: all 0.2s; }
.btn-icon:hover { color: var(--text-dark); background: var(--secondary-color); }

.btn-logout { background: transparent; border: 1px solid #fee2e2; color: #ef4444; padding: 10px; border-radius: var(--radius-sm); font-weight: 500; display: flex; align-items: center; justify-content: center; gap: 10px; transition: all 0.2s; cursor: pointer; }
.btn-logout:hover { background: #fee2e2; }
.sync-status-indicator { font-size: 11px; display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 4px; background: rgba(0,0,0,0.05); color: var(--text-muted); }
.sync-status-indicator i { font-size: 8px; color: #94a3b8; }
.sync-status-indicator.connected { color: #10b981; background: #ecfdf5; }
.sync-status-indicator.connected i { color: #10b981; }
.user-profile { display: flex; align-items: center; gap: 12px; }
.user-info { text-align: right; }
.avatar { width: 40px; height: 40px; background: var(--primary-color); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; }
body:not(.admin-mode) #btn-quick-expense { display: none !important; }

.view-container { padding: 32px; flex: 1; }
.view { display: none; animation: fadeIn 0.3s ease-in-out; }
.view.active { display: block; }

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

/* Dashboard Specifics */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 20px;
  border: 1px solid var(--border-color);
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon { width: 54px; height: 54px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.bg-blue { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.bg-green { background: rgba(16, 185, 129, 0.1); color: #10b981; }
.bg-purple { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.bg-danger { background: rgba(239, 68, 68, 0.1); color: #ef4444; }

.stat-details h3 { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text-dark); }

.dashboard-charts { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
.chart-container, .card { background: var(--white); border-radius: var(--radius-md); padding: 24px; box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); }
.card-header { margin-bottom: 20px; }
.card-header h2 { font-size: 18px; font-weight: 600; }
.card-body { padding-top: 0; }
.bg-light { background: #f8fafc; padding: 20px; border-radius: var(--radius-md); }

/* Forms & Inputs */
.form-group { margin-bottom: 16px; }
.flex-group { display: flex; gap: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text-muted); font-size: 13px; }
.form-control { width: 100%; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-size: 14px; transition: all 0.2s; background: var(--white); }
.form-control:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }
.input-light { border: none; background: transparent; font-size: 14px; font-weight: 500; color: var(--text-dark); border-bottom: 1px solid transparent; width: 150px; padding: 4px; }
.input-light:focus { outline: none; border-bottom: 1px solid var(--primary-color); }
.input-group { display: flex; align-items: center; }
.input-group .form-control { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-addon { padding: 10px 12px; background: var(--secondary-color); border: 1px solid var(--border-color); border-left: none; border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); color: var(--text-muted); }
.form-control.input-sm { width: 60px; padding: 6px 10px; }

/* Login Overlay */
.login-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-card {
  background: white;
  padding: 40px;
  border-radius: 20px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.3);
}
.login-logo {
  width: 60px;
  height: 60px;
  background: var(--primary-color);
  color: white;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  margin: 0 auto 20px;
}
.w-100 { width: 100%; }
.mb-3 { margin-bottom: 1rem; }
.mt-2 { margin-top: 0.5rem; }

/* Admin Only visibility */
.admin-only { display: none !important; }
body.admin-mode .admin-only { display: block !important; }
body.admin-mode .nav-item.admin-only { display: flex !important; }
body.admin-mode .admin-only-btn { display: inline-flex !important; }

/* Global Reset */
/* Upload Zone */
.expense-entry-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 32px; }
.upload-zone { border: 2px dashed var(--border-color); border-radius: var(--radius-md); padding: 40px 20px; text-align: center; background: #f8fafc; transition: all 0.3s; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary-color); background: #f0fdf4; }
.cloud-icon { font-size: 48px; color: #94a3b8; margin-bottom: 16px; }
.upload-zone h4 { font-size: 16px; margin-bottom: 8px; color: var(--text-dark); }
.upload-zone p { color: var(--text-muted); font-size: 13px; }

/* Invoice UI */
.invoice-wrapper { max-width: 1000px; margin: 0 auto; }
.invoice-container { background: white; padding: 48px; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); margin-bottom: 24px; min-height: 800px; }
.invoice-header { 
  display: flex; 
  justify-content: space-between; 
  margin-bottom: 40px; 
  border-bottom: 2px solid var(--secondary-color); 
  padding-bottom: 30px;
  align-items: flex-end; 
  min-height: 150px; /* Ensure space for logo and details */
}
.company-details { flex: 1; }
.company-details p { color: var(--text-muted); margin: 4px 0; line-height: 1.4; display: block; }
.invoice-title-text { font-size: 36px; font-weight: 700; color: var(--text-dark); letter-spacing: 2px; text-align: right; margin-bottom: 20px; }
.meta-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; justify-content: flex-end; }
.meta-row label { color: var(--text-muted); font-weight: 500; width: 80px; text-align: right; }
.bill-to-section { max-width: 400px; margin-bottom: 40px; }
.bill-to-section h3 { margin-bottom: 16px; border-bottom: 2px solid var(--primary-color); display: inline-block; padding-bottom: 4px; }

.items-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.items-table th { background: #f8fafc; padding: 12px; text-align: left; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid var(--border-color); border-top: 1px solid var(--border-color); }
.items-table td { padding: 12px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.item-amount { font-weight: 600; }
.invoice-summary-container { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 40px; }
.invoice-notes { flex: 1; max-width: 400px; }
.invoice-summary { width: 320px; background: #f8fafc; padding: 24px; border-radius: var(--radius-sm); border: 1px solid var(--border-color); }
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border-color); }
.summary-row.grand-total { font-size: 20px; font-weight: 700; color: var(--primary-color); border-top: 2px solid var(--border-color); margin-top: 8px; padding-top: 16px; border-bottom: none; }
.invoice-actions { display: flex; justify-content: flex-end; gap: 16px; }

/* Tables */
.table-responsive { overflow-x: auto; }
.data-table, .ledger-table, .report-mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .ledger-table th, .report-mini-table th { text-align: left; padding: 12px 16px; background: #f1f5f9; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border-color); }
.data-table td, .ledger-table td, .report-mini-table td { padding: 14px 16px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.data-table tr:hover, .ledger-table tr:hover { background: #f8fafc; }

/* Ledgers & Reports */
.ledger-container { background: white; border: 1px solid var(--border-color); border-radius: var(--radius-sm); overflow: hidden; }
.ledger-table th.text-right, .ledger-table td.text-right { text-align: right; }
.reports-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.report-table { background: white; border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 16px; }
.report-row { display: flex; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid #f1f5f9; }
.report-row.header { font-weight: 700; background: #f8fafc; border-bottom: 2px solid var(--border-color); color: var(--text-dark); }
.report-row.subtotal { font-weight: 600; border-top: 1px dashed var(--border-color); margin-top: 8px; }
.report-row.grand-total { font-weight: 700; font-size: 16px; border-top: 2px solid var(--text-dark); margin-top: 8px; padding-top: 16px; color: var(--primary-color); }

.filter-bar { display: flex; justify-content: space-between; align-items: center; background: #f8fafc; padding: 16px; border-radius: var(--radius-md); }
.search-box { position: relative; width: 300px; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-box input { width: 100%; padding: 10px 10px 10px 36px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: white; }

.badge { padding: 4px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }

.flex-between { display: flex; justify-content: space-between; align-items: center; }
.settings-grid { max-width: 600px; }
