/* ============================================
   EXPENSEFLOW - PROFESSIONAL CORPORATE DESIGN
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Outfit:wght@400;600;700;800&display=swap');

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

:root {
  /* Colors - Deep Corporate Blue */
  --ink: #0f172a;
  --surface: #f1f5f9;
  --card: #ffffff;
  --accent: #0369a1; /* Blue 700 */
  --accent-light: #e0f2fe;
  --accent-glow: rgba(3, 105, 161, 0.1);
  --accent-gradient: linear-gradient(135deg, #0369a1 0%, #075985 100%);
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #be123c;
  --success: #15803d;
  --warning: #b45309;
  
  /* Layout - Professional Square */
  --sidebar-width: 260px;
  --header-h: 64px;
  --radius: 2px;      /* Very square */
  --radius-sm: 1px;
  
  /* Shadows - Subtle & Disciplined */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-premium: 0 0 0 1px rgba(0,0,0,0.05), 0 1px 3px 0 rgba(0,0,0,0.1);
  
  /* Animations */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition: all 0.2s var(--ease);
}

html, body {
  height: 100%;
  font-family: 'Inter', sans-serif;
  background: var(--surface);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  width: 100%;
}

h1, h2, h3, h4, .font-outfit { font-family: 'Outfit', sans-serif; letter-spacing: -0.02em; }

/* --- PROFESSIONAL BACKGROUND --- */
.bg-blobs {
  position: fixed; inset: 0; z-index: -1;
  background: #f8fafc;
  opacity: 0.5;
}
.bg-blobs::after {
  content: '';
  position: absolute; inset: 0;
  background-image: radial-gradient(var(--border) 0.5px, transparent 0.5px);
  background-size: 24px 24px;
}

/* --- LAYOUT --- */
.app-layout { display: flex; min-height: 100vh; }

/* --- SIDEBAR --- */
.sidebar {
  width: var(--sidebar-width);
  background: #0f172a;
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 1000;
  transition: transform 0.3s var(--ease);
}
.sidebar.open { transform: translateX(0) !important; }

.sidebar-logo {
  padding: 24px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.sidebar-logo-icon svg { width: 18px; height: 18px; fill: white; }
.sidebar-logo-text {
  font-size: 1.1rem; font-weight: 700; color: white;
  letter-spacing: 0.02em; text-transform: uppercase;
}
.sidebar-logo-text span { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar-section-label {
  padding: 20px 24px 8px;
  font-size: 0.65rem; font-weight: 800; text-transform: uppercase;
  color: rgba(255,255,255,0.4); letter-spacing: 0.15em;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; color: rgba(255,255,255,0.6);
  font-weight: 500; font-size: 0.9rem;
  transition: var(--transition);
  text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: white; }
.nav-item.active { 
  background: rgba(255,255,255,0.05); 
  color: white; 
  border-left: 3px solid var(--accent);
  padding-left: 21px;
}
.nav-item svg, .btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.5; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 24px; border-top: 1px solid rgba(255,255,255,0.05);
}
.sidebar-user {
  display: flex; align-items: center; gap: 12px;
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: 0.8rem;
}

/* --- MAIN CONTENT --- */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1; display: flex; flex-direction: column;
  min-height: 100vh;
  position: relative;
  max-width: 100%;
  overflow-x: hidden;
  transition: margin-left 0.3s var(--ease);
}

.top-bar {
  height: var(--header-h);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 32px;
  z-index: 90;
}

#sidebarToggle { display: none; }

.top-bar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-content { padding: 32px; }

/* --- PAGE HEADERS --- */
.page-header {
  margin-bottom: 32px;
}
.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.page-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
}
.page-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

/* --- CARDS --- */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

/* --- STAT CARDS --- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); margin-bottom: 32px; }
.stat-card {
  background: white;
  padding: 24px;
  display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2.5; }
.stat-icon.blue { background: #f0f9ff; color: #0369a1; }
.stat-icon.pending { background: #fffbeb; color: #b45309; }
.stat-icon.approved { background: #f0fdf4; color: #15803d; }
.stat-icon.rejected { background: #fef2f2; color: #be123c; }

.stat-num { font-size: 1.5rem; font-weight: 700; color: var(--ink); }
.stat-label { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; }

/* --- BUTTONS --- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius);
  font-weight: 600; font-size: 0.875rem;
  transition: var(--transition);
  cursor: pointer; border: 1px solid transparent;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent); color: white;
}
.btn-primary:hover { background: #075985; }

.btn-secondary {
  background: white; color: var(--ink); border-color: var(--border);
}
.btn-secondary:hover { background: #f8fafc; border-color: var(--muted); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-icon { padding: 10px; width: 42px; height: 42px; justify-content: center; }

/* --- TABLES --- */
.table-wrap {
  background: white; border: 1px solid var(--border);
  overflow: hidden;
  width: 100%;
}
table { width: 100%; border-collapse: collapse; }
th {
  background: #f8fafc; padding: 12px 24px; text-align: left;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
td { padding: 16px 24px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* --- BADGES --- */
.badge {
  padding: 4px 8px; border-radius: 0; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  display: inline-flex; align-items: center; gap: 4px;
}
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dcfce7; color: #166534; }
.badge-rejected { background: #fee2e2; color: #991b1b; }

/* --- ALERTS --- */
.alert {
  padding: 16px 24px;
  border-left: 4px solid var(--danger);
  background: #fff1f2;
  color: #9f1239;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  animation: fadeIn 0.3s var(--ease);
}
.alert-success {
  background: #f0fdf4;
  border-left-color: var(--success);
  color: #166534;
}
.alert svg { width: 20px; height: 20px; flex-shrink: 0; }

/* --- FORM CONTROLS --- */
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 0.75rem; font-weight: 700; color: var(--ink); text-transform: uppercase; margin-bottom: 8px; }
.form-control {
  width: 100%; padding: 10px 12px; border-radius: var(--radius);
  background: white; border: 1px solid var(--border);
  font-size: 0.9rem; transition: var(--transition);
}
.form-control:focus {
  border-color: var(--accent); outline: none; box-shadow: 0 0 0 1px var(--accent);
}

/* --- PAGINATION --- */
.pagination { display: flex; gap: 4px; }
.page-btn {
  padding: 6px 12px; border: 1px solid var(--border);
  background: white; color: var(--ink); text-decoration: none; font-size: 0.85rem;
}
.page-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* --- MODALS --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  display: none; align-items: center; justify-content: center; z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white; width: 100%; max-width: 500px;
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.modal-header { padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-weight: 700; color: var(--ink); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 12px; }

/* --- TOAST NOTIFICATIONS --- */
.toast-container {
  position: fixed; bottom: 32px; right: 32px;
  display: flex; flex-direction: column; gap: 12px;
  z-index: 2000;
}
.toast {
  background: var(--ink); color: white;
  padding: 16px 24px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 12px;
  min-width: 300px; max-width: 450px;
  animation: slideIn 0.3s var(--ease);
  transition: all 0.3s var(--ease);
  font-weight: 600; font-size: 0.9rem;
  border-left: 4px solid var(--accent);
}
.toast.danger, .toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.info { border-left-color: var(--accent); }
.toast svg { width: 20px; height: 20px; flex-shrink: 0; }

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

/* --- RESPONSIVENESS --- */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 280px;
  }
  
  .sidebar {
    transform: translateX(-100%);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  #sidebarToggle {
    display: flex;
    margin-right: 12px;
  }
  
  .top-bar {
    padding: 0 16px;
    width: 100%;
    max-width: 100vw;
  }

  .view-layout, .resp-grid-2 {
    grid-template-columns: 1fr !important;
  }

  .view-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 20px;
  }

  .view-header-total {
    text-align: left !important;
  }

  .resp-grid-3 {
    grid-template-columns: 1fr !important;
  }
  
  .page-content {
    padding: 16px;
  }

  .card {
    padding: 16px !important;
  }

  .form-control {
    padding: 8px 10px !important;
    font-size: 0.85rem !important;
  }

  .btn {
    padding: 8px 16px !important;
    font-size: 0.85rem !important;
  }

  .form-label {
    font-size: 0.7rem !important;
    margin-bottom: 6px !important;
  }

  .upload-zone {
    padding: 20px 12px !important;
  }

  .upload-zone p {
    font-size: 0.75rem !important;
  }

  .view-header h1 {
    font-size: 1.5rem !important;
  }

  .badge {
    padding: 2px 6px;
    font-size: 0.65rem;
  }
  
  /* Dashboard Grid */
  .dashboard-grid, 
  .view-layout,
  div[style*="display: grid; grid-template-columns: 1fr 340px"] {
    grid-template-columns: 1fr !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important; /* Critical for containing overflow */
  }

  /* Target the direct children of the layout which hold the cards */
  .view-layout > div {
    min-width: 0 !important;
    width: 100% !important;
  }

  .card {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: auto !important; /* Fallback for wide tables */
    min-width: 0 !important;
  }
  
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  
  .page-header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .page-header-row .btn {
    width: 100%;
    justify-content: center;
  }
  
  .table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    width: 100% !important;
    max-width: 100% !important;
    display: block !important;
  }
  
  table {
    min-width: 800px !important; /* Increased to fit more buttons */
  }

  th:last-child, td:last-child {
    min-width: 220px; /* Ensure space for Review, Approve, Reject */
  }

  .form-grid-2 {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: 1fr !important;
  }
  
  .top-bar-title {
    font-size: 1rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
  }

  .btn span { display: none; } /* Hide text on very small screens if icons exist */
  
  .welcome-banner h1 {
    font-size: 1.5rem !important;
  }
}

/* Sidebar Overlay */
.sidebar-overlay {
  position: fixed; inset: 0; 
  background: rgba(15, 23, 42, 0.5); 
  z-index: 999; 
  backdrop-filter: blur(4px); 
  animation: fadeIn 0.3s;
}

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

/* --- FLATPICKR CUSTOMIZATION --- */
.flatpickr-calendar {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  border: 1px solid var(--border) !important;
  font-family: inherit !important;
}
.flatpickr-day.selected, 
.flatpickr-day.startRange, 
.flatpickr-day.endRange, 
.flatpickr-day.selected.inRange, 
.flatpickr-day.startRange.inRange, 
.flatpickr-day.endRange.inRange, 
.flatpickr-day.selected:focus, 
.flatpickr-day.startRange:focus, 
.flatpickr-day.endRange:focus, 
.flatpickr-day.selected:hover, 
.flatpickr-day.startRange:hover, 
.flatpickr-day.endRange:hover, 
.flatpickr-day.selected.prevMonthDay, 
.flatpickr-day.startRange.prevMonthDay, 
.flatpickr-day.endRange.prevMonthDay, 
.flatpickr-day.selected.nextMonthDay, 
.flatpickr-day.startRange.nextMonthDay, 
.flatpickr-day.endRange.nextMonthDay {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}
.flatpickr-day.inRange {
  background: var(--accent-light) !important;
  border-color: transparent !important;
  box-shadow: none !important;
}
.flatpickr-months .flatpickr-month {
  background: var(--accent) !important;
  color: #fff !important;
  fill: #fff !important;
}
.flatpickr-current-month .flatpickr-monthDropdown-months {
  background: var(--accent) !important;
}
.flatpickr-weekdays {
  background: var(--accent) !important;
}
span.flatpickr-weekday {
  background: var(--accent) !important;
  color: rgba(255, 255, 255, 0.7) !important;
}
.flatpickr-day.today {
  border-color: var(--accent) !important;
}
.flatpickr-day.today:hover {
  background: var(--accent) !important;
  color: #fff !important;
}
