:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --accent: #f59e0b;
  --accent-ink: #92400e;
  --accent-soft: #fef3c7;
  --green: #059669;
  --green-soft: #d1fae5;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 18px;
}
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }
.brand-sub { color: var(--text-muted); font-size: 13px; }

.role-switch { display: flex; align-items: center; gap: 10px; }
.role-label { color: var(--text-muted); font-size: 13px; }
.role-tabs {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.role-tab {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}
.role-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Layout */
.app { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }

.banner {
  background: var(--accent-soft);
  border: 1px solid #fde68a;
  color: var(--accent-ink);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.banner b { font-weight: 700; }

/* KPI */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.kpi-label { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin-top: 4px; }
.kpi-value.green { color: var(--green); }
.kpi-value.red { color: var(--red); }

/* Section header */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-title { font-size: 16px; font-weight: 700; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f9fafb; border-color: #d1d5db; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #d97706; border-color: #d97706; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }

/* Jobs list */
.jobs-list { display: flex; flex-direction: column; gap: 10px; }
.job-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s;
}
.job-row:hover { border-color: #d1d5db; }
.job-main { flex: 1; min-width: 0; }
.job-name { font-weight: 700; font-size: 15px; }
.job-meta { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.job-metrics { display: flex; gap: 26px; align-items: center; }
.metric { text-align: right; }
.metric-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; }
.metric-value { font-weight: 700; font-size: 14px; }
.metric-value.pos { color: var(--green); }
.metric-value.neg { color: var(--red); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge.in-progress { background: var(--blue-soft); color: #1d4ed8; }
.badge.won { background: var(--green-soft); color: #047857; }
.badge.lost { background: var(--red-soft); color: #b91c1c; }

/* Detail view */
.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.back-btn { margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 600; }
td.num, th.num { text-align: right; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }

input[type="text"], input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
}
input[type="number"] { width: 90px; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input:disabled { background: var(--bg); color: var(--text-muted); }

.hidden { display: none !important; }
[hidden] { display: none !important; }
.muted { color: var(--text-muted); }
.empty { text-align: center; padding: 40px; color: var(--text-muted); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 11px 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  z-index: 100;
}

/* Selects */
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
}

/* Category badges */
.cat-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.cat-labor { background: #dbeafe; color: #1d4ed8; }
.cat-materials { background: #fef3c7; color: #92400e; }
.cat-equipment { background: #ede9fe; color: #6d28d9; }
.cat-overhead { background: #e5e7eb; color: #374151; }

/* Category breakdown */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-top: 4px; }
.cat-card { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.cat-card-label { margin-bottom: 8px; }
.cat-card-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); padding: 2px 0; }
.cat-card-row span { font-weight: 700; color: var(--text); }

/* Change orders */
.co-item { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.co-item:last-child { border-bottom: none; }
.co-main { flex: 1; display: flex; align-items: center; gap: 10px; }
.co-title { font-weight: 600; }
.co-amount { font-weight: 700; }
.co-actions { display: flex; gap: 6px; }
.co-add { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.co-add input { flex: 1; max-width: 260px; }
.co-add #coAmount { max-width: 130px; }

/* Invoices */
.inv-item { display: flex; align-items: center; gap: 16px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.inv-item:last-child { border-bottom: none; }
.inv-number { font-weight: 700; min-width: 90px; }
.inv-amount { font-weight: 700; margin-left: auto; }

/* Auth */
.user-box { display: flex; align-items: center; gap: 10px; }
.user-email { color: var(--text-muted); font-size: 13px; }
.auth-wrap { max-width: 420px; margin: 50px auto; padding: 0 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.auth-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; margin-bottom: 22px; }
.auth-title { font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.auth-sub { color: var(--text-muted); margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.auth-alt { margin-top: 18px; font-size: 14px; text-align: center; color: var(--text-muted); }
.auth-alt a { color: var(--accent-ink); font-weight: 600; text-decoration: none; }
.auth-error { color: var(--red); margin-top: 12px; font-size: 13px; text-align: center; }

@media (max-width: 700px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .job-row { flex-wrap: wrap; }
  .job-metrics { width: 100%; justify-content: space-between; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
}
