:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8a90a2;
  --accent: #d97706;
  --accent2: #f59e0b;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#root { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.3px;
  color: var(--accent2);
}
.brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }

.nav { display: flex; gap: 4px; }
.nav button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.nav button.active { background: var(--panel2); color: var(--text); }
.nav button:hover { color: var(--text); }

.content { flex: 1; padding: 20px; max-width: 1200px; width: 100%; margin: 0 auto; }

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin: 0 0 10px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.field textarea { resize: vertical; min-height: 50px; font-family: inherit; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: rgba(255,255,255,0.02); }
td input, td select { width: 100%; background: var(--panel2); border: 1px solid var(--border); color: var(--text); padding: 6px 8px; border-radius: 6px; font-size: 13px; }

button {
  cursor: pointer;
  font-family: inherit;
}
.btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
}
.btn:hover { border-color: var(--accent2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1a1200; }
.btn-primary:hover { background: var(--accent2); }
.btn-danger { color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { background: transparent; border: none; color: var(--muted); padding: 4px 8px; font-size: 14px; }
.btn-icon:hover { color: var(--red); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-Draft { background: #2a2f3a; color: var(--muted); }
.badge-Submitted { background: #1e3a5f; color: #60a5fa; }
.badge-Awarded { background: #14432a; color: #4ade80; }
.badge-Lost { background: #431414; color: #f87171; }

.badge-job-Lead { background: #2a2f3a; color: var(--muted); }
.badge-job-EstimateSent { background: #1e3a5f; color: #60a5fa; }
.badge-job-Approved { background: #1e4a3a; color: #34d399; }
.badge-job-Scheduled { background: #3a2f5f; color: #a78bfa; }
.badge-job-InProgress { background: #4a2f14; color: #f59e0b; }
.badge-job-Completed { background: #14432a; color: #4ade80; }
.badge-job-Invoiced { background: #4a3a14; color: #fbbf24; }
.badge-job-Paid { background: #14432a; color: #22c55e; }
.badge-job-Lost { background: #431414; color: #f87171; }

.pipeline-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(180px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.pipeline-column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 180px;
  display: flex;
  flex-direction: column;
}
.pipeline-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.pipeline-column-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}
.job-card {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
}
.job-card:hover { border-color: var(--accent2); }
.job-card-title { font-weight: 600; font-size: 13px; }
.job-card-status-select {
  width: 100%;
  margin-top: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 4px;
}

.grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

.stat { background: var(--panel2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 4px; }
.stat .value { font-size: 20px; font-weight: 700; }
.stat .value.green { color: var(--green); }
.stat .value.red { color: var(--red); }

.top-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; }

.pill-group { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel2); color: var(--muted); font-size: 12px; cursor: pointer; }
.pill.active { background: var(--accent); color: #1a1200; border-color: var(--accent); font-weight: 700; }

.muted { color: var(--muted); }
.right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }

.price-box {
  background: var(--panel2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.price-box .big { font-size: 32px; font-weight: 800; color: var(--accent2); margin: 6px 0; }
.nudge-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 10px; }
.nudge-row button { width: 34px; height: 34px; border-radius: 6px; }

.link-btn { background: none; border: none; color: var(--blue); cursor: pointer; padding: 0; font-size: 13px; text-decoration: underline; }

.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

.variance-fast { color: var(--green); font-weight: 700; }
.variance-slow { color: var(--red); font-weight: 700; }
.variance-ok { color: var(--muted); }

.section-divider { border-top: 1px solid var(--border); margin: 16px 0; }

.close-x { position: absolute; top: 12px; right: 16px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; zIndex: 100;
  z-index: 100;
  padding: 16px;
}

.flex-3 { flex: 3; }
.flex-2 { flex: 2; }
.flex-1 { flex: 1; }

/* ---------------------------------------------------------------- responsive */

/* Tablet and below (phones + iPad in either orientation): touch-target sizing.
   Anything wider is assumed mouse-driven and keeps the denser desktop sizing. */
@media (max-width: 1024px) {
  .btn, .btn-sm {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 14px;
  }
  .btn-icon {
    min-width: 44px;
    min-height: 44px;
    font-size: 16px;
  }
  .nav button {
    min-height: 44px;
    padding: 10px 14px;
  }
  .pill {
    min-height: 40px;
    padding: 9px 14px;
    display: inline-flex;
    align-items: center;
  }
  .field input, .field select, .field textarea,
  td input, td select {
    min-height: 44px;
    font-size: 16px; /* prevents iOS Safari auto-zoom on focus */
    padding: 10px 12px;
  }
  .field textarea { min-height: 80px; }
  .job-card-status-select {
    min-height: 44px;
    font-size: 13px;
    padding: 8px 10px;
  }
  .nudge-row button { width: 44px; height: 44px; }
}

@media (max-width: 860px) {
  .flex-3, .flex-2, .flex-1 { flex: 1 1 100%; }
  .plan-tools-panel {
    position: sticky;
    top: 8px;
    z-index: 5;
    max-height: 60vh;
    overflow-y: auto;
  }
}

/* Phones: stack rows, compact chrome, single-column pipeline */
@media (max-width: 700px) {
  .content { padding: 12px; }
  .row { flex-direction: column; }
  .row > * { min-width: 0; }

  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .nav { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; width: 100%; order: 3; }
  .nav button { flex: 0 0 auto; white-space: nowrap; }

  .top-actions { flex-wrap: wrap; gap: 10px; }

  table:not(.responsive-cards) { display: block; overflow-x: auto; white-space: nowrap; }

  table.responsive-cards thead { display: none; }
  table.responsive-cards, table.responsive-cards tbody,
  table.responsive-cards tr, table.responsive-cards td { display: block; width: 100%; }
  table.responsive-cards tr {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    background: var(--panel2);
  }
  table.responsive-cards tr:last-child { margin-bottom: 0; }
  table.responsive-cards td {
    border-bottom: none;
    padding: 6px 2px;
    white-space: normal;
  }
  table.responsive-cards td:empty { display: none; }
  table.responsive-cards td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 3px;
  }

  .pipeline-board { grid-template-columns: 1fr; }
  .pipeline-column { min-width: 0; }

  .modal-overlay .panel { width: 100% !important; max-width: 100%; }
}
