/* QuickQuote - Offline Estimate & Invoice Tool for Trades */
:root {
  --primary: #ca8a04;
  --primary-light: #eab308;
  --primary-dark: #a16207;
  --bg: #ffffff;
  --bg-card: #f9fafb;
  --bg-input: #f3f4f6;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --success: #16a34a;
  --info: #2563eb;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --bg-card: #1f2937;
    --bg-input: #374151;
    --text: #f3f4f6;
    --text-muted: #9ca3af;
    --border: #374151;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

* { 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);
  min-height: 100vh;
  padding-bottom: 70px;
  -webkit-tap-highlight-color: transparent;
}

/* Offline Banner */
.offline-banner {
  display: none;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 0.875rem;
  position: sticky;
  top: 0;
  z-index: 1000;
}
.offline-banner.visible { display: block; }

.online-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-left: 8px;
  vertical-align: middle;
}
.online-indicator.offline { background: var(--danger); }

/* Header */
.app-header {
  background: var(--bg-card);
  border-bottom: 2px solid var(--primary);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 999;
}
.offline-banner.visible + .app-header { top: auto; }
.app-header h1 {
  font-size: 1.125rem;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 998;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 4px;
  font-size: 0.625rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  touch-action: manipulation;
}
.bottom-nav button.active { color: var(--primary); }
.bottom-nav button svg { width: 24px; height: 24px; }

/* Screens */
.screen { display: none; padding: 16px; }
.screen.active { display: block; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.card:active { opacity: 0.9; }

/* Summary Cards */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
}
.summary-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}
.summary-card .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.938rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  min-width: 48px;
  touch-action: manipulation;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.85; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--bg-input); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-sm { padding: 8px 14px; font-size: 0.813rem; min-height: 40px; }
.btn-block { width: 100%; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

/* Quick Actions */
.quick-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.quick-actions .btn { flex: 1; min-width: 100px; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.813rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
  min-height: 48px;
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-group select { appearance: auto; }
.form-row {
  display: flex;
  gap: 10px;
}
.form-row .form-group { flex: 1; }

/* Status Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-draft { background: #6b7280; color: #fff; }
.badge-sent { background: #2563eb; color: #fff; }
.badge-approved { background: #16a34a; color: #fff; }
.badge-declined { background: #dc2626; color: #fff; }
.badge-converted { background: #7c3aed; color: #fff; }
.badge-paid { background: #16a34a; color: #fff; }
.badge-overdue { background: #dc2626; color: #fff; }
.badge-void { background: #6b7280; color: #fff; text-decoration: line-through; }
.badge-estimate { background: #6b7280; color: #fff; }
.badge-in-progress { background: #2563eb; color: #fff; }
.badge-invoiced { background: #7c3aed; color: #fff; }
.badge-closed { background: #374151; color: #fff; }

/* Aging Indicators */
.aging-current { color: var(--success); }
.aging-30 { color: var(--warning); }
.aging-60 { color: #f97316; }
.aging-90 { color: var(--danger); }

/* Line Items */
.line-items-list { margin-bottom: 14px; }
.line-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--bg-input);
  border-radius: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.line-item .li-desc { flex: 1; min-width: 120px; font-weight: 500; }
.line-item .li-meta { font-size: 0.813rem; color: var(--text-muted); }
.line-item .li-amount { font-weight: 700; white-space: nowrap; }
.line-item .li-remove {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Totals */
.totals-section {
  border-top: 2px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.938rem;
}
.totals-row.total {
  font-weight: 700;
  font-size: 1.125rem;
  border-top: 2px solid var(--primary);
  padding-top: 8px;
  margin-top: 4px;
}

/* List headers / filters */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.list-header h2 { font-size: 1.125rem; }

.filter-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}
.filter-bar button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.813rem;
  white-space: nowrap;
  cursor: pointer;
  min-height: 36px;
}
.filter-bar button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Search */
.search-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 12px;
  min-height: 48px;
}

/* Card details */
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-title { font-weight: 600; font-size: 1rem; }
.card-subtitle { font-size: 0.813rem; color: var(--text-muted); margin-top: 2px; }
.card-amount { font-weight: 700; font-size: 1.063rem; }

/* Detail view */
.detail-header {
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--primary);
}
.detail-header h2 { font-size: 1.25rem; color: var(--primary); }

.detail-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 0.875rem;
}
.detail-table th {
  text-align: left;
  padding: 8px;
  border-bottom: 2px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
}
.detail-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.detail-table .text-right { text-align: right; }

.detail-section {
  margin-bottom: 16px;
}
.detail-section h3 {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.detail-actions .btn { flex: 1; min-width: 120px; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal h3 { margin-bottom: 14px; color: var(--primary); }

/* Notes timeline */
.notes-timeline { list-style: none; }
.notes-timeline li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.notes-timeline .note-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Printable */
@media print {
  .bottom-nav, .app-header, .offline-banner, .detail-actions, .btn { display: none !important; }
  .screen { display: block !important; padding: 0; }
  body { padding-bottom: 0; }
}

/* Rate card picker */
.rate-card-picker {
  max-height: 300px;
  overflow-y: auto;
}
.rate-card-picker .rate-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  min-height: 48px;
}
.rate-card-picker .rate-item:active { background: var(--bg-input); }
.rate-card-picker .category-header {
  font-weight: 700;
  font-size: 0.813rem;
  text-transform: uppercase;
  color: var(--primary);
  padding: 8px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
}

/* Charts */
.chart-container { margin: 16px 0; overflow-x: auto; }
.chart-container svg { display: block; max-width: 100%; }

/* Section title */
.section-title {
  font-size: 0.938rem;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--text);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

/* Responsive */
@media (min-width: 600px) {
  .screen { max-width: 600px; margin: 0 auto; }
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Tabs */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 12px;
}
.tab-bar button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab-bar button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* Confirm dialog */
.confirm-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.confirm-actions .btn { flex: 1; }

/* Back button */
.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px 8px;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
}
