:root {
  --primary: #7c3aed;
  --primary-light: #a78bfa;
  --primary-dark: #5b21b6;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 72px;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 600px; margin: 0 auto; padding: 16px; }

/* Bottom Nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 4px 0 env(safe-area-inset-bottom, 8px);
  z-index: 100;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 8px 4px; border: none; background: none;
  color: var(--text-muted); font-size: 10px; cursor: pointer;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--primary); }
.nav-btn svg { width: 22px; height: 22px; }

/* Header */
.screen-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding: 8px 0;
}
.screen-header h1 { font-size: 1.5rem; font-weight: 700; }
.screen-header .subtitle { font-size: 0.85rem; color: var(--text-muted); }

/* Cards */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.card-title { font-weight: 600; font-size: 0.95rem; }

/* Stat Cards */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--border);
  text-align: center;
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: var(--bg-input); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--text);
}

/* Floating Action Button */
.fab {
  position: fixed; bottom: 84px; right: 20px; width: 56px; height: 56px;
  border-radius: 50%; background: var(--primary); color: #fff;
  border: none; font-size: 1.5rem; cursor: pointer; z-index: 90;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s;
}
.fab:active { transform: scale(0.9); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.95rem; color: var(--text);
  background: var(--bg-input); transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* Duration Presets */
.presets { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.preset-btn {
  padding: 6px 14px; border: 1px solid var(--border);
  border-radius: 20px; background: var(--bg-input); color: var(--text);
  font-size: 0.8rem; cursor: pointer; transition: all 0.2s;
}
.preset-btn.active, .preset-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Progress Bar */
.progress-bar {
  width: 100%; height: 8px; background: var(--bg-input);
  border-radius: 4px; overflow: hidden; margin: 8px 0;
}
.progress-fill {
  height: 100%; border-radius: 4px;
  background: var(--success); transition: width 0.5s ease;
}
.progress-fill.low { background: var(--warning); }
.progress-fill.depleted { background: var(--danger); }

/* Status Badges */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-depleted { background: #fef3c7; color: #92400e; }
.badge-expired { background: #fee2e2; color: #991b1b; }
.badge-draft { background: #e0e7ff; color: #3730a3; }
.badge-sent { background: #dbeafe; color: #1e40af; }
.badge-paid { background: #d1fae5; color: #065f46; }
.badge-overdue { background: #fee2e2; color: #991b1b; }

@media (prefers-color-scheme: dark) {
  .badge-active { background: #064e3b; color: #6ee7b7; }
  .badge-depleted { background: #78350f; color: #fcd34d; }
  .badge-expired { background: #7f1d1d; color: #fca5a5; }
  .badge-draft { background: #312e81; color: #a5b4fc; }
  .badge-sent { background: #1e3a5f; color: #93c5fd; }
  .badge-paid { background: #064e3b; color: #6ee7b7; }
  .badge-overdue { background: #7f1d1d; color: #fca5a5; }
}

/* Client Card Color Indicator */
.client-indicator {
  width: 4px; border-radius: 4px; margin-right: 12px; flex-shrink: 0;
}
.indicator-green { background: var(--success); }
.indicator-yellow { background: var(--warning); }
.indicator-gray { background: var(--text-light); }

/* Tabs */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab-btn {
  flex: 1; padding: 10px 8px; border: none; background: none;
  color: var(--text-muted); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all 0.2s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Alerts */
.alert-card {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: var(--radius-sm); margin-bottom: 8px;
  font-size: 0.85rem;
}
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-danger { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) {
  .alert-warning { background: #78350f; color: #fcd34d; }
  .alert-danger { background: #7f1d1d; color: #fca5a5; }
}

/* Search */
.search-bar {
  width: 100%; padding: 10px 14px 10px 38px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.95rem; color: var(--text);
  background: var(--bg-input); margin-bottom: 12px;
}
.search-bar:focus { outline: none; border-color: var(--primary); }
.search-wrap { position: relative; }
.search-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-light);
}

/* Filter Row */
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 4px; }
.filter-btn {
  padding: 6px 14px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--bg-input); color: var(--text-muted); font-size: 0.8rem;
  font-weight: 500; cursor: pointer; white-space: nowrap; transition: all 0.2s;
}
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Activity Feed */
.activity-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 6px; flex-shrink: 0;
}
.activity-time { color: var(--text-light); font-size: 0.75rem; margin-top: 2px; }

/* Invoice Print View */
.invoice-print {
  background: #fff; color: #1e293b; padding: 32px; max-width: 700px; margin: 0 auto;
}
.invoice-print .inv-header { display: flex; justify-content: space-between; margin-bottom: 32px; }
.invoice-print .inv-title { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.invoice-print .inv-meta { text-align: right; font-size: 0.85rem; color: #64748b; }
.invoice-print table { width: 100%; border-collapse: collapse; margin: 24px 0; }
.invoice-print th { text-align: left; padding: 10px 12px; border-bottom: 2px solid #e2e8f0; font-size: 0.8rem; color: #64748b; text-transform: uppercase; }
.invoice-print td { padding: 10px 12px; border-bottom: 1px solid #e2e8f0; }
.invoice-print .inv-total { text-align: right; font-size: 1.2rem; font-weight: 700; margin-top: 16px; }

/* Modal / Overlay */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-content {
  background: var(--bg-card); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto;
  padding: 24px; animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 1.2rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border: none; background: var(--bg-input);
  border-radius: 50%; font-size: 1.1rem; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
}

/* Empty state */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; }

/* List Item */
.list-item {
  display: flex; align-items: center; padding: 12px 16px;
  background: var(--bg-card); border-radius: var(--radius-sm);
  margin-bottom: 8px; box-shadow: var(--shadow); border: 1px solid var(--border);
  cursor: pointer; transition: box-shadow 0.2s;
}
.list-item:hover { box-shadow: var(--shadow-lg); }
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 0.9rem; }
.list-item-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* Section heading */
.section-title {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px; margin: 16px 0 8px;
}

/* Toggle */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.toggle-label { font-size: 0.9rem; }
.toggle-sub { font-size: 0.75rem; color: var(--text-muted); }

/* Settings Section */
.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 12px; }

/* Back button */
.back-btn {
  display: inline-flex; align-items: center; gap: 4px; border: none;
  background: none; color: var(--primary); font-size: 0.9rem; font-weight: 600;
  cursor: pointer; padding: 4px 0; margin-bottom: 12px;
}

/* Action buttons row */
.action-row { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }

/* Responsive */
@media (min-width: 480px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

@media print {
  body { padding: 0; background: #fff; }
  #bottom-nav, .back-btn, .action-row, .fab, .no-print { display: none !important; }
  #app { max-width: 100%; padding: 0; }
}
