/* ============================================================
   BidPilot App Styles
   Matches landing page design: dark theme, orange accents
   ============================================================ */

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

:root {
  --orange: #E8650A;
  --orange-light: #FF8C2E;
  --orange-dim: rgba(232, 101, 10, 0.15);
  --dark: #0D0D0D;
  --dark-surface: #161616;
  --dark-card: #1C1C1C;
  --dark-hover: #242424;
  --border: #2a2a2a;
  --border-light: #333;
  --gray-text: #8A8A8A;
  --light-text: #C4C4C4;
  --white: #F5F5F5;
  --green: #22C55E;
  --green-dim: rgba(34, 197, 94, 0.15);
  --blue: #3B82F6;
  --blue-dim: rgba(59, 130, 246, 0.15);
  --red: #EF4444;
  --red-dim: rgba(239, 68, 68, 0.15);
  --yellow: #EAB308;
  --yellow-dim: rgba(234, 179, 8, 0.15);
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--dark);
  color: var(--white);
  overflow-x: hidden;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: 'Space Grotesk', sans-serif;
}

/* Grain overlay */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: 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;
}

/* ---- Layout ---- */
.app-layout {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 2;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--dark-surface);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -0.5px;
  padding: 0 24px;
  margin-bottom: 32px;
  text-decoration: none;
  display: block;
}

.sidebar-logo span {
  color: var(--orange);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--gray-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}

.sidebar-link:hover {
  background: var(--dark-hover);
  color: var(--light-text);
}

.sidebar-link.active {
  background: var(--orange-dim);
  color: var(--orange);
}

.sidebar-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.sidebar-footer a {
  color: var(--gray-text);
  text-decoration: none;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-footer a:hover {
  color: var(--orange);
}

/* Main content */
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 32px 40px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -1px;
}

.page-header p {
  color: var(--gray-text);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
}

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

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

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

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

.btn-secondary:hover {
  background: var(--dark-hover);
  border-color: var(--border-light);
}

.btn-ghost {
  background: transparent;
  color: var(--gray-text);
  padding: 8px 12px;
}

.btn-ghost:hover {
  color: var(--white);
  background: var(--dark-hover);
}

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

/* ---- Cards ---- */
.card {
  background: var(--dark-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

/* ---- Stat Cards ---- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--dark-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 24px;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--gray-text);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -1px;
}

.stat-card .stat-value.orange { color: var(--orange); }
.stat-card .stat-value.green { color: var(--green); }
.stat-card .stat-value.blue { color: var(--blue); }

/* ---- Tables ---- */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

table td {
  padding: 14px 16px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  color: var(--light-text);
}

table tr:hover td {
  background: var(--dark-surface);
}

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

/* ---- Status Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-draft { background: var(--blue-dim); color: var(--blue); }
.badge-sent { background: var(--yellow-dim); color: var(--yellow); }
.badge-accepted { background: var(--green-dim); color: var(--green); }
.badge-rejected { background: var(--red-dim); color: var(--red); }
.badge-expired { background: rgba(107, 114, 128, 0.15); color: #9CA3AF; }

/* ---- Forms ---- */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--light-text);
  margin-bottom: 6px;
}

.form-group .hint {
  font-size: 0.75rem;
  color: var(--gray-text);
  margin-top: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--dark-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--white);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--orange);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238A8A8A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* ---- Modal ---- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--dark-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--gray-text);
  cursor: pointer;
  font-size: 1.5rem;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--white);
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ---- Quote Detail ---- */
.quote-header-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

.quote-info-block h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-text);
  margin-bottom: 8px;
}

.quote-info-block p {
  color: var(--light-text);
  font-size: 0.9rem;
  line-height: 1.5;
}

.quote-totals {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.quote-totals .total-row {
  display: flex;
  gap: 32px;
  font-size: 0.9rem;
}

.quote-totals .total-row .label {
  color: var(--gray-text);
  min-width: 100px;
  text-align: right;
}

.quote-totals .total-row .value {
  min-width: 100px;
  text-align: right;
  font-weight: 600;
}

.quote-totals .total-row.grand .value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.3rem;
  color: var(--orange);
}

.ai-summary {
  background: var(--orange-dim);
  border: 1px solid rgba(232, 101, 10, 0.2);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
}

.ai-summary .ai-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.ai-summary p {
  color: var(--light-text);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ---- Quote Actions ---- */
.quote-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- Generate Page ---- */
.generate-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
}

.generate-result {
  position: sticky;
  top: 32px;
}

/* ---- Loading & Empty ---- */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-text);
}

.loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top: 3px solid var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
  color: var(--light-text);
}

.empty-state p {
  color: var(--gray-text);
  font-size: 0.9rem;
  margin-bottom: 24px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--dark-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 0.85rem;
  color: var(--light-text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  animation: slideIn 0.2s ease-out;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }

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

/* ---- Service List (Pricing Page) ---- */
.service-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.service-item {
  display: grid;
  grid-template-columns: 1fr 120px 120px 100px 80px;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--dark-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 0.15s;
}

.service-item:hover {
  border-color: var(--border-light);
}

.service-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.service-category {
  font-size: 0.75rem;
  color: var(--gray-text);
  margin-top: 2px;
}

.service-price {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--orange);
}

.service-unit {
  font-size: 0.8rem;
  color: var(--gray-text);
}

.service-material {
  font-size: 0.8rem;
  color: var(--light-text);
}

.service-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

/* ---- Clickable row ---- */
.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--dark-hover);
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .generate-layout { grid-template-columns: 1fr; }
  .generate-result { position: static; }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .main-content {
    margin-left: 0;
    padding: 20px 16px;
  }

  .mobile-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--dark-surface);
    border-top: 1px solid var(--border);
    z-index: 10;
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
  }

  .mobile-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    color: var(--gray-text);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: 8px;
  }

  .mobile-nav a.active {
    color: var(--orange);
  }

  .mobile-nav a svg {
    width: 20px;
    height: 20px;
  }

  .stat-cards { grid-template-columns: repeat(2, 1fr); }

  .form-row, .form-row-3 {
    grid-template-columns: 1fr;
  }

  .service-item {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .service-actions {
    justify-content: flex-start;
  }

  .quote-header-info {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  body {
    padding-bottom: 72px;
  }
}

.mobile-nav {
  display: none;
}

/* ============================================================
   INTAKE LINK CARD (Dashboard)
   ============================================================ */

.intake-link-card {
  background: linear-gradient(135deg, rgba(232,101,10,0.06) 0%, rgba(59,130,246,0.06) 100%);
  border: 1px solid rgba(232,101,10,0.2);
  margin-bottom: 24px;
}

.intake-link-inner {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  justify-content: space-between;
}

.intake-link-left { flex: 1; min-width: 0; }

.intake-link-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--orange-dim);
  color: var(--orange);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 3px 10px;
  border-radius: 99px;
  margin-bottom: 10px;
}

.intake-link-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--white);
  margin-bottom: 6px;
}

.intake-link-desc {
  font-size: 0.85rem;
  color: var(--gray-text);
  line-height: 1.6;
  margin-bottom: 16px;
}

.intake-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.intake-url-input {
  flex: 1;
  min-width: 0;
  background: var(--dark) !important;
  border: 1px solid var(--border-light) !important;
  color: var(--light-text) !important;
  font-size: 0.82rem !important;
  font-family: 'Space Grotesk', monospace;
  padding: 8px 12px !important;
  border-radius: 8px !important;
  cursor: text;
}

.intake-url-input:focus {
  border-color: var(--orange) !important;
  outline: none;
}

@media (max-width: 640px) {
  .intake-link-inner { flex-direction: column; }
  .intake-link-right { align-self: flex-start; }
  .intake-url-row { flex-direction: column; align-items: stretch; }
  .intake-url-input { font-size: 0.75rem !important; }
}

/* ============================================================
   SETTINGS PAGE
   ============================================================ */

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-field {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.form-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--light-text);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.input {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  background: var(--dark-surface);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  color: var(--white);
  transition: border-color 0.15s;
  outline: none;
}

.input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-dim);
}

.input-textarea {
  min-height: 90px;
  resize: vertical;
  line-height: 1.5;
}

.field-hint {
  font-size: 0.78rem;
  color: var(--gray-text);
  margin-top: 5px;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .form-row-2 { grid-template-columns: 1fr; }
}

/* badge for intake source */
.badge-intake {
  background: rgba(232, 101, 10, 0.15);
  color: var(--orange);
}
