/* ============================================================
   INVOICE GEN PRO — Main Stylesheet
   Light Mode: #FFFDF7 bg, #1A1A2E text, #D4A853 gold, #1A9E8F teal
   Dark Mode:  #0D1117 bg, #E6EDF3 text, #4F9CF9 blue, #F5A623 amber
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
  --bg: #FFFDF7;
  --bg2: #EBEBEB;
  --bg3: #E0E0E0;
  --text: #1A1A2E;
  --text2: #4A4A5E;
  --text3: #8888AA;
  --accent: #0B1957;
  --accent2: #0B1957;
  --accent-rgb: 11,25,87;
  --border: rgba(11,25,87,0.12);
  --border2: rgba(11,25,87,0.22);
  --card: rgba(255,255,255,0.7);
  --glass: rgba(255,253,247,0.85);
  --shadow: 0 4px 24px rgba(11,25,87,0.08);
  --shadow-lg: 0 8px 48px rgba(11,25,87,0.14);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --transition: 0.3s cubic-bezier(.4,0,.2,1);
  --font-heading: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0D1117;
  --bg2: #161B22;
  --bg3: #1C2128;
  --text: #E6EDF3;
  --text2: #8B949E;
  --text3: #6E7681;
  --accent: #6B7FD9;
  --accent2: #6B7FD9;
  --accent-rgb: 107,127,217;
  --border: rgba(230,237,243,0.1);
  --border2: rgba(230,237,243,0.2);
  --card: rgba(22,27,34,0.85);
  --glass: rgba(13,17,23,0.90);
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 48px rgba(0,0,0,0.5);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
  line-height: 1.6;
}

/* ---- ANIMATED GRADIENT MESH BACKGROUND ---- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 30%, rgba(var(--accent-rgb),0.08) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 80% 70%, rgba(var(--accent-rgb),0.05) 0%, transparent 60%),
    radial-gradient(ellipse 80% 30% at 50% 100%, rgba(var(--accent-rgb),0.04) 0%, transparent 50%);
  animation: meshShift 20s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}

@keyframes meshShift {
  0%   { transform: scale(1) rotate(0deg); }
  50%  { transform: scale(1.05) rotate(1deg); }
  100% { transform: scale(1) rotate(-1deg); }
}

/* ---- GRAIN OVERLAY ---- */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1;
  opacity: 0.4;
}

#app { position: relative; z-index: 2; }

/* ---- CUSTOM CURSOR ---- */
.cursor-dot {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  position: fixed;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 9999;
  transition: transform 0.1s;
  box-shadow: 0 0 12px rgba(var(--accent-rgb),0.6);
}
.cursor-ring {
  width: 28px; height: 28px;
  border: 1.5px solid rgba(var(--accent-rgb),0.5);
  border-radius: 50%;
  position: fixed;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 9998;
  transition: transform 0.15s, width 0.2s, height 0.2s, border-color 0.2s;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }

/* ---- TYPOGRAPHY ---- */
h1,h2,h3,h4 { font-family: var(--font-heading); line-height: 1.2; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); }
h2 { font-size: clamp(1.4rem, 3vw, 2rem); }
h3 { font-size: 1.2rem; }

/* ---- LAYOUT ---- */
.container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }
.page-section { padding: 40px 0; }

/* ---- NAVBAR ---- */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  transition: all var(--transition);
}
.navbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}
.navbar-brand .brand-dot {
  width: 10px; height: 10px;
  background: var(--accent2);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { transform: scale(1); opacity:1; }
  50% { transform: scale(1.4); opacity:0.7; }
}
.navbar-actions { display: flex; align-items: center; gap: 12px; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 0 rgba(var(--accent-rgb),0.4);
}
.btn-primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 4px 20px rgba(var(--accent-rgb),0.35), 0 0 0 0 rgba(var(--accent-rgb),0.4);
}
.btn-primary:focus-visible {
  animation: glowPulse 1.5s infinite;
}
@keyframes glowPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb),0.4); }
  50% { box-shadow: 0 0 0 8px rgba(var(--accent-rgb),0); }
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border2);
}
.btn-secondary:hover {
  background: var(--bg2);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline:hover {
  background: var(--accent);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(var(--accent-rgb),0.3);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(239,68,68,0.3);
}
.btn-danger:hover { background: rgba(239,68,68,0.1); }

.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-icon { padding: 8px; width: 38px; height: 38px; justify-content: center; }

/* ---- THEME TOGGLE ---- */
.theme-toggle {
  width: 50px; height: 26px;
  background: var(--bg3);
  border-radius: 13px;
  border: 1.5px solid var(--border2);
  cursor: pointer;
  position: relative;
  transition: all var(--transition);
  flex-shrink: 0;
}
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: var(--accent);
  border-radius: 50%;
  transition: all var(--transition);
  box-shadow: 0 0 6px rgba(var(--accent-rgb),0.5);
}
[data-theme="dark"] .theme-toggle::after { left: 26px; }

/* ---- CARDS ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  transition: all var(--transition);
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-body { padding: 24px; }
.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  display: flex; align-items: center; gap: 8px;
}

/* ---- FORM ELEMENTS ---- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-label .required { color: var(--danger); }

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1.5px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: all var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb),0.15);
}
.form-control:hover:not(:focus) { border-color: var(--border2); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

/* Color picker */
.color-input-wrap { display: flex; align-items: center; gap: 10px; }
input[type="color"] {
  width: 40px; height: 40px;
  border: 2px solid var(--border2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
  padding: 2px;
}

/* ---- GRID LAYOUTS ---- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ---- MAIN LAYOUT ---- */
#app { min-height: 100vh; }

/* Auth screens */
.auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.5s cubic-bezier(.16,1,.3,1) forwards;
}
.auth-logo {
  text-align: center;
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}
.auth-sub {
  text-align: center;
  color: var(--text3);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

/* Dashboard */
.dashboard-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 64px);
}
@media (max-width: 900px) { .dashboard-layout { grid-template-columns: 1fr; } }

.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
}
.sidebar-nav { list-style: none; }
.sidebar-nav li a, .sidebar-nav li button {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  color: var(--text2);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.sidebar-nav li a:hover, .sidebar-nav li button:hover {
  background: var(--bg3);
  color: var(--accent);
  border-left-color: var(--accent);
}
.sidebar-nav li.active a {
  background: var(--bg3);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}
.sidebar-icon { font-size: 1.1rem; width: 20px; text-align: center; }

.main-content { padding: 32px; overflow-x: hidden; }

/* ---- INVOICE BUILDER ---- */
.builder-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.builder-title {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  color: var(--text);
}

.section-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}

/* Logo upload */
.logo-upload-area {
  border: 2px dashed var(--border2);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.logo-upload-area:hover, .logo-upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb),0.05);
}
.logo-upload-area img { max-width: 140px; max-height: 70px; object-fit: contain; }
.logo-upload-hint { color: var(--text3); font-size: 0.82rem; margin-top: 8px; }
.logo-upload-area input[type="file"] { display: none; }

/* ---- LINE ITEMS TABLE ---- */
.items-table-wrap { overflow-x: auto; }
.items-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 900px;
}
.items-table th {
  background: var(--bg2);
  color: var(--text2);
  font-weight: 600;
  padding: 10px 8px;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  border-bottom: 2px solid var(--border2);
}
.items-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.items-table tr.item-row:hover td { background: rgba(var(--accent-rgb),0.03); }
.items-table td .form-control {
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.drag-handle {
  cursor: grab; color: var(--text3); font-size: 1rem;
  padding: 4px; border-radius: 4px;
  transition: color var(--transition);
}
.drag-handle:hover { color: var(--accent); }
.drag-handle:active { cursor: grabbing; }
.item-row.dragging { opacity: 0.5; background: rgba(var(--accent-rgb),0.08); }
.section-row td {
  background: rgba(var(--accent-rgb),0.06);
  font-weight: 600;
  color: var(--accent);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 8px;
}

/* ---- TOTALS PANEL ---- */
.totals-panel { max-width: 400px; margin-left: auto; }
.totals-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.totals-row .label { color: var(--text2); }
.totals-row .value { font-weight: 500; }
.totals-grand {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  border-top: 2px solid var(--accent);
  margin-top: 4px;
}
.amount-words-display {
  font-style: italic;
  color: var(--text2);
  font-size: 0.82rem;
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent2);
}

/* ---- HEALTH SCORE WIDGET ---- */
.health-score-widget {
  position: relative;
  text-align: center;
}
.health-gauge {
  position: relative;
  width: 120px; height: 120px;
  margin: 0 auto 12px;
}
.health-gauge svg { transform: rotate(-90deg); }
.health-gauge .score-text {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  transform: none;
  font-family: var(--font-heading);
}
.health-gauge .score-num {
  font-size: 1.8rem; font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.health-gauge .score-label { font-size: 0.7rem; color: var(--text3); }
.health-tips { list-style: none; text-align: left; font-size: 0.82rem; }
.health-tips li { 
  padding: 5px 0; color: var(--text2);
  display: flex; gap: 8px; align-items: flex-start;
}
.health-tips li .tip-icon { color: var(--accent2); flex-shrink: 0; }

/* ---- RISK BADGE ---- */
.risk-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.risk-low { background: rgba(34,197,94,0.15); color: #16a34a; }
.risk-medium { background: rgba(245,158,11,0.15); color: #d97706; }
.risk-high { background: rgba(239,68,68,0.15); color: #dc2626; }

/* ---- COUNTDOWN TIMER ---- */
.countdown-display {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}
.countdown-unit {
  text-align: center;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-width: 60px;
}
.countdown-number {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.countdown-label { font-size: 0.7rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; }

/* ---- PAYMENT MODAL ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  display: flex; align-items: flex-end;
  justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-sheet {
  width: 100%; max-width: 520px;
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 32px;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(.16,1,.3,1);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-handle {
  width: 40px; height: 4px;
  background: var(--border2);
  border-radius: 2px;
  margin: 0 auto 24px;
}
.modal-title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  text-align: center;
  margin-bottom: 4px;
}
.modal-sub { text-align: center; color: var(--text2); font-size: 0.9rem; margin-bottom: 24px; }

/* Payment Tabs */
.payment-tabs {
  display: flex; gap: 8px; margin-bottom: 24px;
}
.payment-tab {
  flex: 1; padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text2);
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.payment-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(var(--accent-rgb),0.08);
}
.payment-tab:hover:not(.active) { border-color: var(--border2); background: var(--bg2); }

.trust-badges {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.trust-badge {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.75rem; color: var(--text3);
}
.trust-badge .icon { color: var(--success); }

/* ---- INVOICE LIST ---- */
.invoice-list { display: flex; flex-direction: column; gap: 8px; }
.invoice-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  cursor: pointer;
  gap: 12px;
}
.invoice-item:hover {
  border-color: var(--accent);
  transform: translateX(4px);
  box-shadow: var(--shadow);
}
.invoice-item-info { flex: 1; min-width: 0; }
.invoice-item-num { font-weight: 600; font-size: 0.95rem; color: var(--text); }
.invoice-item-client { font-size: 0.82rem; color: var(--text2); margin-top: 2px; }
.invoice-item-meta { text-align: right; flex-shrink: 0; }
.invoice-item-amount { font-weight: 700; color: var(--accent); font-size: 1rem; }
.invoice-item-date { font-size: 0.78rem; color: var(--text3); margin-top: 2px; }

/* Status badges */
.status-badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.status-draft { background: rgba(245,158,11,0.15); color: #d97706; }
.status-paid { background: rgba(34,197,94,0.15); color: #16a34a; }
.status-overdue { background: rgba(239,68,68,0.15); color: #dc2626; }
.status-sent { background: rgba(79,156,249,0.15); color: #2563eb; }
.status-cancelled { background: rgba(107,114,128,0.15); color: #6b7280; }

/* ---- ANALYTICS CHARTS ---- */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-label { font-size: 0.78rem; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-value { font-family: var(--font-heading); font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.stat-sub { font-size: 0.8rem; color: var(--text3); margin-top: 4px; }

/* ---- VOICE BUTTON ---- */
.voice-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.1rem;
  transition: all var(--transition);
  position: relative;
}
.voice-btn.recording {
  background: var(--danger);
  animation: voicePulse 1s infinite;
}
@keyframes voicePulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 12px rgba(239,68,68,0); }
}

/* ---- PROFIT MARGIN ---- */
.margin-indicator {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.82rem;
}
.margin-bar {
  flex: 1; height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}
.margin-fill { height: 100%; border-radius: 3px; transition: width 0.5s; }

/* ---- SIGNATURE PAD ---- */
.signature-pad-wrap {
  border: 2px dashed var(--border2);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}
.signature-pad-wrap canvas {
  display: block; cursor: crosshair;
}
.sig-controls { padding: 8px 12px; display: flex; gap: 8px; border-top: 1px solid var(--border); }

/* ---- PREVIEW FRAME ---- */
.preview-frame {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
.preview-device-bar {
  display: flex; gap: 8px; padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.device-btn {
  padding: 4px 12px;
  border: 1px solid var(--border2);
  border-radius: 20px;
  background: none;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text2);
  transition: all var(--transition);
}
.device-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- ANIMATIONS ---- */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.animate-slide-up { animation: slideUp 0.5s cubic-bezier(.16,1,.3,1) both; }
.animate-fade { animation: fadeIn 0.4s ease both; }

/* Staggered children */
.stagger-children > * { animation: slideUp 0.5s cubic-bezier(.16,1,.3,1) both; }
.stagger-children > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.25s; }

/* ---- TOAST NOTIFICATIONS ---- */
.toast-container {
  position: fixed; top: 80px; right: 20px; z-index: 9000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  display: flex; align-items: center; gap: 10px;
  animation: slideInRight 0.3s ease;
  min-width: 280px; max-width: 400px;
  backdrop-filter: blur(10px);
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--accent); }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.toast-text { flex: 1; }

/* ---- MISC ---- */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text2); }
.text-sm { font-size: 0.82rem; }
.text-center { text-align: center; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 24px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .main-content { padding: 16px; }
  .builder-header { flex-direction: column; align-items: flex-start; }
  .modal-sheet { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .sidebar { display: none; }
  .sidebar.open { display: block; position: fixed; inset: 64px 0 0 0; z-index: 50; }
  .navbar-actions .btn-text { display: none; }
}

/* ---- LOADING SPINNER ---- */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { margin-bottom: 8px; }
.empty-state p { font-size: 0.9rem; color: var(--text3); }

/* ---- PAYMENT LINK BADGE ---- */
.payment-link-box {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  word-break: break-all;
}
.payment-link-box .link-text { flex: 1; color: var(--accent); }

/* Stripe card element */
#stripe-card-element {
  padding: 12px;
  border: 1.5px solid var(--border2);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

/* Confetti canvas */
#confetti-canvas {
  position: fixed; inset: 0; z-index: 9999;
  pointer-events: none;
}

/* ============================================================
   MOBILE RESPONSIVE FIXES
   ============================================================ */
@media (max-width: 768px) {
  .navbar {
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 8px;
  }
  .navbar-actions {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
    justify-content: flex-end;
  }
  .dashboard-layout {
    grid-template-columns: 1fr !important;
    min-height: auto;
  }
  .sidebar {
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-nav {
    display: flex !important;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px !important;
  }
  .sidebar-nav li button {
    font-size: 0.78rem !important;
    padding: 6px 10px !important;
    white-space: nowrap;
  }
  .grid-2, .grid-3 {
    grid-template-columns: 1fr !important;
  }
  .builder-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .builder-header > div:last-child {
    width: 100%;
    justify-content: flex-start;
  }
  .items-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .items-table {
    min-width: 700px;
  }
  .card-header {
    flex-wrap: wrap;
    gap: 8px;
  }
  .totals-panel {
    font-size: 0.9rem;
  }
  .modal-sheet {
    max-height: 92vh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0 !important;
  }
  .payment-tabs {
    flex-wrap: wrap;
  }
  .payment-tab {
    flex: 1;
    min-width: 80px;
    font-size: 0.82rem;
    padding: 8px 6px;
  }
  .preview-frame {
    height: 300px !important;
  }
  .health-score-widget {
    flex-direction: column;
    align-items: center;
  }
  .btn-lg {
    width: 100%;
    text-align: center;
  }
  .flex.gap-3.mt-4 {
    flex-direction: column;
  }
  .analytics-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

@media (max-width: 480px) {
  .navbar-brand {
    font-size: 1rem;
  }
  .builder-title {
    font-size: 1.3rem !important;
  }
  .analytics-grid {
    grid-template-columns: 1fr !important;
  }
  .countdown-display {
    gap: 8px;
  }
  .countdown-number {
    font-size: 1.8rem !important;
  }
}

/* Prevent horizontal scroll globally */
body {
  overflow-x: hidden;
}
.main-content {
  min-width: 0;
  overflow-x: hidden;
}
