/* ==========================================================================
   PayPilot — FinTech SaaS Design System & Stylesheet
   Pure CSS for GitHub Pages & Static Prototype
   ========================================================================== */

/* --- 1. CSS Custom Properties / Design Tokens --- */
:root {
  --primary: #1e3a8a;          /* Deep Navy */
  --primary-dark: #0f172a;     /* Midnight Slate */
  --primary-light: #3b82f6;    /* Vibrant Blue */
  --primary-soft: #eff6ff;     /* Soft Blue Tint */
  --accent: #2563eb;           /* Interactive Blue */
  --accent-hover: #1d4ed8;

  --success: #059669;          /* Emerald */
  --success-light: #ecfdf5;
  --success-text: #065f46;

  --warning: #d97706;          /* Amber */
  --warning-light: #fffbeb;
  --warning-text: #92400e;

  --danger: #dc2626;           /* Crimson */
  --danger-light: #fef2f2;
  --danger-text: #991b1b;

  --info: #0284c7;             /* Sky */
  --info-light: #f0f9ff;
  --info-text: #075985;

  --bg-app: #f8fafc;           /* App Canvas */
  --bg-card: #ffffff;          /* Card Background */
  --bg-subtle: #f1f5f9;        /* Hover / Zebra */
  --border-color: #e2e8f0;     /* Borders */
  --border-strong: #cbd5e1;

  --text-main: #0f172a;        /* High Contrast Headings */
  --text-body: #334155;        /* Body Text */
  --text-muted: #64748b;       /* Secondary Labels */
  --text-inverse: #ffffff;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.03);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  min-height: 100vh;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* --- 3. App Shell & Layout --- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Top Navbar (Mobile & Header Bar) */
.top-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 1.5rem;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
}

.brand-name {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary-dark);
  letter-spacing: -0.02em;
}

.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.demo-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-full);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background-color: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Sidebar Navigation */
.app-sidebar {
  width: 250px;
  background-color: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 30;
  transition: transform 0.25s ease;
}

.sidebar-nav {
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-body);
  transition: var(--transition);
  cursor: pointer;
}

.nav-item:hover {
  background-color: var(--bg-subtle);
  color: var(--primary);
}

.nav-item.active {
  background-color: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.nav-item-icon {
  font-size: 1.15rem;
  width: 24px;
  text-align: center;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background-color: #fee2e2;
  color: #b91c1c;
  font-weight: 700;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main-content {
  flex: 1;
  padding: 2rem 2rem 3rem 2rem;
  max-width: 1350px;
  width: 100%;
  margin: 0 auto;
}

/* Mobile Nav Toggle */
.mobile-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-main);
  padding: 0.25rem;
}

/* --- 4. Typography & Headers --- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.025em;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 1rem;
}

/* --- 5. FinTech Cards & Metric Grids --- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.metric-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition);
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.metric-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.metric-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.metric-icon-box {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.metric-subtext {
  font-size: 0.775rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.metric-trend-up {
  color: var(--success);
  font-weight: 600;
}

.metric-trend-down {
  color: var(--danger);
  font-weight: 600;
}

/* Generic Card */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

/* --- 6. Charts & Visualizations --- */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (max-width: 1024px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

.chart-wrapper {
  position: relative;
  min-height: 270px;
  max-height: 320px;
  width: 100%;
}

.status-bars {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1rem;
}

.status-bar-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.status-bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
}

.progress-track {
  width: 100%;
  height: 8px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* --- 7. Buttons & Form Elements --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--accent);
  color: var(--text-inverse);
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-body);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-subtle);
  color: var(--text-main);
}

.btn-success {
  background-color: var(--success);
  color: var(--text-inverse);
}
.btn-success:hover:not(:disabled) {
  background-color: #047857;
}

.btn-danger {
  background-color: var(--danger);
  color: var(--text-inverse);
}
.btn-danger:hover:not(:disabled) {
  background-color: #b91c1c;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.775rem;
  border-radius: var(--radius-sm);
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-main);
  transition: var(--transition);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

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

/* --- 8. Data Tables --- */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.data-table th {
  padding: 0.85rem 1rem;
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 0.95rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-body);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: capitalize;
  letter-spacing: 0.02em;
}

.badge-draft { background-color: #f1f5f9; color: #475569; }
.badge-sent { background-color: var(--primary-soft); color: var(--primary); }
.badge-paid { background-color: var(--success-light); color: var(--success-text); }
.badge-overdue { background-color: var(--danger-light); color: var(--danger-text); }
.badge-pending { background-color: var(--warning-light); color: var(--warning-text); }
.badge-approved { background-color: var(--success-light); color: var(--success-text); }
.badge-rejected { background-color: var(--danger-light); color: var(--danger-text); }

/* --- 9. Line Items Builder --- */
.line-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

.line-items-table th {
  padding: 0.5rem;
  font-size: 0.8rem;
  text-align: left;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}

.line-items-table td {
  padding: 0.5rem 0.25rem;
}

.calculation-summary {
  margin-top: 1.5rem;
  margin-left: auto;
  max-width: 320px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.875rem;
  color: var(--text-body);
}

.calc-row.total {
  border-top: 2px solid var(--border-color);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
}

/* --- 10. Printable Invoice Document --- */
.invoice-sheet {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-md);
  max-width: 850px;
  margin: 0 auto 2rem auto;
}

.invoice-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin: 1.5rem 0;
}

/* --- 11. Modal & Toast Notifications --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(15px);
  transition: var(--transition);
}

.modal-overlay.active .modal-dialog {
  transform: translateY(0);
}

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 110;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toast {
  padding: 0.75rem 1.25rem;
  background-color: var(--primary-dark);
  color: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: slideIn 0.25s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* --- 12. Smart AI / Risk Widget --- */
.ai-risk-card {
  background: linear-gradient(135deg, #f0fdf4 0%, #e0f2fe 100%);
  border: 1px solid #bae6fd;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.ai-risk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.ai-badge {
  background-color: #0369a1;
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
}

/* --- 13. Responsive Breakpoints --- */
@media (max-width: 868px) {
  .app-sidebar {
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
  }

  .app-sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .mobile-toggle {
    display: block;
  }

  .main-content {
    padding: 1.25rem;
  }

  .invoice-meta-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* --- 14. Print Media Stylesheet --- */
@media print {
  .top-header, .app-sidebar, .page-header, .no-print, .btn, .toast-container {
    display: none !important;
  }
  body, .main-content {
    background-color: white !important;
    padding: 0 !important;
  }
  .invoice-sheet {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
}
