:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2563eb;
  --radius: 8px;
}

* { 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.6;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1.5rem 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 1rem;
}

.sidebar-brand h2 {
  font-size: 1.1rem;
  color: #fff;
  font-weight: 600;
}

.sidebar-brand p {
  font-size: 0.75rem;
  color: var(--sidebar-text);
  margin-top: 0.25rem;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.5rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar nav a:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
}

.sidebar nav a.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 500;
}

.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.75rem;
}

.sidebar-footer a {
  color: var(--sidebar-text);
  text-decoration: none;
}

/* Main content */
.main {
  margin-left: 240px;
  flex: 1;
  padding: 2rem 3rem;
  max-width: 1200px;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text);
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.card h3 {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.card a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}

.card a:hover { text-decoration: underline; }

.big-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Metrics summary */
.metrics-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

/* Section */
.section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* Steps */
.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.step {
  text-align: center;
  padding: 1.5rem 1rem;
}

.step-num {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.step h4 {
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.step p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Filters */
.filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.filters a {
  padding: 0.4rem 1rem;
  border-radius: 20px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.filters a:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.filters a.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Post list / cards */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.post-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.post-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.post-body {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.post-actions {
  display: flex;
  gap: 0.5rem;
}

.post-time {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-fb-groups, .badge-fb-marketplace {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-linkedin {
  background: #e0e7ff;
  color: #4338ca;
}

.badge-x {
  background: #f1f5f9;
  color: #334155;
}

.badge-gbp {
  background: #dcfce7;
  color: #166534;
}

.badge-type {
  background: #fef3c7;
  color: #92400e;
}

/* Post detail / editor */
.post-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.post-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.post-editor textarea {
  width: 100%;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.7;
  resize: vertical;
  margin: 0.75rem 0;
}

.post-editor textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.editor-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.post-notes {
  margin-top: 1.5rem;
  padding: 1rem;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
}

.post-notes h4 {
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-approve {
  background: var(--success);
  color: #fff;
}

.btn-approve:hover { background: #15803d; }

/* Back link */
.back-link {
  margin-bottom: 1.5rem;
}

.back-link a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
}

.back-link a:hover { color: var(--primary); }

/* Reports */
.report-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.report-card h3 {
  font-size: 1rem;
  font-weight: 600;
}

.report-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  line-height: 1.8;
}

.report-content h1 { font-size: 1.5rem; margin-bottom: 1rem; }
.report-content h2 { font-size: 1.2rem; margin-top: 1.5rem; }
.report-content h3 { font-size: 1rem; margin-top: 1rem; }
.report-content ul, .report-content ol { margin-left: 1.5rem; margin-bottom: 1rem; }
.report-content p { margin-bottom: 0.75rem; }

/* Table */
.activity-table {
  overflow-x: auto;
}

.activity-table table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.activity-table th,
.activity-table td {
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.activity-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.total-cell { font-weight: 600; }

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

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.form-group select,
.form-group textarea,
.form-group input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
}

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

.help-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Corrections list */
.corrections-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.correction-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.correction-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.diff-original {
  padding: 0.5rem;
  background: #fef2f2;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.diff-edited {
  padding: 0.5rem;
  background: #f0fdf4;
  border-radius: 4px;
  font-size: 0.85rem;
}

/* Empty state */
.empty {
  color: var(--text-muted);
  font-style: italic;
  padding: 2rem;
  text-align: center;
}

/* Refresh bar */
.refresh-bar {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.refresh-bar button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Accordion card (details/summary) */
details.accordion-card summary {
  cursor: pointer;
  list-style: none;
  outline: none;
}

details.accordion-card summary::-webkit-details-marker,
details.accordion-card summary::marker {
  display: none;
  content: '';
}

details.accordion-card[open] summary {
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

details.accordion-card .accordion-body {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.6;
}

details.accordion-card .accordion-body p {
  margin-bottom: 0.4rem;
}

details.accordion-card[open] {
  border-color: var(--primary);
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.08);
}

/* Error / flash boxes */
.error-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash-ok {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-weight: 500;
}

.flash-warn {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-weight: 500;
}

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.login-box h1 {
  text-align: center;
  margin-bottom: 0.25rem;
}

.login-box .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.login-box .form-group { margin-bottom: 1rem; }

.login-box .btn {
  width: 100%;
  padding: 0.7rem;
  font-size: 1rem;
}

.login-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Lead system */
.lead-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card-hot { border-left: 3px solid var(--danger); }
.card-warm { border-left: 3px solid var(--warning); }
.card-cold { border-left: 3px solid var(--text-muted); }

.lead-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.lead-hot { border-left: 3px solid var(--danger); }
.lead-warm { border-left: 3px solid var(--warning); }
.lead-cold { border-left: 3px solid var(--text-muted); }

.lead-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.lead-tier {
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tier-hot { background: #fef2f2; color: var(--danger); }
.tier-warm { background: #fffbeb; color: #b45309; }
.tier-cold { background: #f1f5f9; color: var(--text-muted); }

.lead-score {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.lead-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

.lead-status {
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-new { background: #dbeafe; color: #1d4ed8; }
.status-contacted { background: #fef3c7; color: #92400e; }
.status-quoted { background: #e0e7ff; color: #4338ca; }
.status-won { background: #dcfce7; color: #166534; }
.status-lost { background: #f1f5f9; color: var(--text-muted); }

.lead-card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.lead-service {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.lead-quick-info {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.lead-detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.lead-detail-header h1 { margin-bottom: 0; }

.lead-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.lead-contact, .lead-project {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.lead-contact h3, .lead-project h3 {
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.detail-row {
  padding: 0.4rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child { border-bottom: none; }
.detail-row a { color: var(--primary); text-decoration: none; }
.detail-row a:hover { text-decoration: underline; }

.status-buttons {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.status-buttons label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.form-link-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 0.75rem;
}

.form-link-box code {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary);
}

/* Intake form (public) */
.intake-page {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 2rem 1rem;
}

.intake-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.intake-box h1 {
  text-align: center;
  margin-bottom: 0.25rem;
}

.intake-box .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.intake-box .btn {
  width: 100%;
  padding: 0.7rem;
  font-size: 1rem;
}

.intake-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.success-message {
  text-align: center;
  padding: 2rem 0;
}

.success-message h2 {
  color: var(--success);
  margin-bottom: 0.5rem;
}

/* Proposals */
.proposal-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.proposal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.proposal-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.proposal-section h2 {
  margin-top: 0;
  margin-bottom: 1rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group { flex: 1; }

.line-item-row {
  margin-bottom: 0.5rem;
}

.checkbox-group {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.file-input {
  display: block;
  padding: 0.75rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  width: 100%;
  cursor: pointer;
  margin-top: 0.5rem;
}

.file-input:hover { border-color: var(--primary); }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.photo-thumb {
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  border: 1px solid var(--border);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Cost reference */
.cost-reference {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  font-size: 0.85rem;
}

.cost-reference a {
  color: var(--primary);
  font-weight: 500;
}

/* Live project-cost estimate on /intake */
.live-estimate {
  background: #fff7ed;
  border: 1px solid #fdba74;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}
.live-estimate .estimate-label {
  font-size: 0.8rem;
  color: #7c2d12;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}
.live-estimate .estimate-amount {
  font-size: 1.6rem;
  font-weight: 700;
  color: #9a3412;
  margin-bottom: 0.5rem;
}
.live-estimate .estimate-note {
  font-size: 0.85rem;
  color: #7c2d12;
  margin-bottom: 0.5rem;
}
.live-estimate .estimate-note a { color: #9a3412; font-weight: 600; }
.live-estimate .estimate-help {
  font-size: 0.85rem;
  color: #44403c;
  font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: relative;
    padding: 1rem 0;
  }

  .sidebar-footer { position: relative; }

  .main {
    margin-left: 0;
    padding: 1.5rem;
  }

  .cards {
    grid-template-columns: 1fr 1fr;
  }

  .metrics-summary {
    grid-template-columns: 1fr 1fr;
  }

  .steps {
    grid-template-columns: 1fr 1fr;
  }

  .report-card {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }
}

@media (max-width: 480px) {
  .cards, .metrics-summary, .steps, .lead-stats {
    grid-template-columns: 1fr;
  }

  .lead-detail-grid {
    grid-template-columns: 1fr;
  }
}
