:root {
  --mks-dark: #0a3421;
  --mks-green: #296b3c;
  --mks-green-light: #3c8c4f;
  --mks-teal: #143d3e;
  --mks-gold: #b79847;
  --mks-gold-light: #d4bd7a;
  --bg: #f6f4ee;
  --card: #ffffff;
  --ink: #1c231e;
  --ink-soft: #5b655d;
  --line: #e2ddd0;
  --danger: #b3402f;
  --warn: #c9891f;
  --ok: #2f8f4e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(10, 52, 33, 0.06), 0 4px 16px rgba(10, 52, 33, 0.06);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

button { font-family: inherit; }
a { color: var(--mks-green); }

/* ---------- App shell ---------- */
#app { display: flex; min-height: 100vh; flex-direction: column; }

.topbar {
  background: var(--mks-dark);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.topbar img.logo { height: 40px; width: 40px; object-fit: contain; background: #fff; border-radius: 8px; padding: 2px; }
.topbar .brand { display: flex; flex-direction: column; line-height: 1.15; margin-right: auto; }
.topbar .brand b { font-size: 15px; letter-spacing: 0.2px; }
.topbar .brand span { font-size: 11px; color: var(--mks-gold-light); }
.topbar .menu-btn { display: none; background: none; border: none; color: #fff; font-size: 22px; padding: 4px 8px; cursor: pointer; }

.layout { display: flex; flex: 1; min-height: 0; }

/* ---------- Auth screen ---------- */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(160deg, var(--mks-dark), var(--mks-teal));
}
.auth-card {
  background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,0.3);
  padding: 32px 28px; width: 100%; max-width: 380px;
}
.auth-logo { display: block; width: 72px; height: 72px; object-fit: contain; margin: 0 auto 12px; }
.auth-card h1 { font-size: 19px; text-align: center; color: var(--mks-dark); margin: 0 0 4px; }
.auth-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; }
.auth-card a { color: var(--mks-green); font-weight: 600; }

.sidebar {
  width: 210px; flex-shrink: 0; background: #0e3d27; color: #dfeee2;
  padding: 14px 10px; display: flex; flex-direction: column; gap: 2px;
}
.sidebar a {
  color: #d9ecdd; text-decoration: none; padding: 10px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 10px;
}
.sidebar a:hover { background: rgba(255,255,255,0.07); }
.sidebar a.active { background: var(--mks-gold); color: var(--mks-dark); font-weight: 700; }
.sidebar .sidebar-foot { margin-top: auto; font-size: 11px; color: #9db9a3; padding: 10px 12px; line-height: 1.5; }

.main { flex: 1; min-width: 0; padding: 20px 24px 60px; overflow-x: hidden; }

/* ---------------- Help / tutorial ---------------- */
.help-step { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.help-step:last-child { border-bottom: none; }
.help-step-num {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--mks-green); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800;
}
.help-step-title { font-weight: 700; font-size: 13.5px; color: var(--mks-dark); margin-bottom: 2px; }
.help-step-body { font-size: 13px; color: var(--ink-soft); line-height: 1.5; }
.help-step-body b { color: var(--ink); }

.proto-banner {
  background: #fff6e0; border: 1px solid var(--mks-gold); color: #6b5316;
  padding: 8px 14px; border-radius: 8px; font-size: 12.5px; margin-bottom: 16px;
}

h1.page-title { font-size: 22px; margin: 0 0 4px; color: var(--mks-dark); }
.page-sub { color: var(--ink-soft); font-size: 13.5px; margin: 0 0 20px; }

/* ---------- Cards / KPIs ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border-left: 4px solid var(--mks-green); }
.kpi .num { font-size: 26px; font-weight: 800; color: var(--mks-dark); }
.kpi .label { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.kpi.warn { border-left-color: var(--warn); }
.kpi.ok { border-left-color: var(--ok); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--mks-dark); }

/* ---------- Job / property list ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.job-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; align-items: center; gap: 14px; cursor: pointer;
  border: 1px solid transparent; transition: border-color .12s;
}
.job-card:hover { border-color: var(--mks-green-light); }
.job-card .job-main { flex: 1; min-width: 0; }
.job-card .job-title { font-weight: 700; font-size: 14.5px; color: var(--mks-dark); }
.job-card .job-addr { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.job-card .job-meta { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }
.job-card .job-total { font-weight: 700; color: var(--mks-green); font-size: 14px; white-space: nowrap; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.badge.not_started { background: #eceae1; color: #6c6558; }
.badge.in_progress { background: #fdecd2; color: #8a5a12; }
.badge.needs_review { background: #fde3df; color: #96311f; }
.badge.approved { background: #dcefe0; color: #1f6a37; }
.badge.done { background: #dcefe0; color: #1f6a37; }

.veteran-badge {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: fit-content; margin: -6px auto 18px; padding: 5px 14px;
  border: 1px solid var(--mks-gold); border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.3px; text-transform: uppercase;
  color: #6b5316; background: #fff6e0;
}
.veteran-badge svg { flex-shrink: 0; }

/* ---------- Job detail ---------- */
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--mks-green); text-decoration: none; font-size: 13px; font-weight: 600; margin-bottom: 12px; }

.job-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.job-header h1 { margin: 0; font-size: 21px; color: var(--mks-dark); }
.job-header .addr { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }
.scope-text { font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; margin: 10px 0 20px; max-width: 760px; }

table.items { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.items th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--ink-soft); border-bottom: 2px solid var(--line); padding: 6px 8px; }
table.items td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.items input[type=number] { width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
table.items tfoot td { font-weight: 700; border-bottom: none; }
table.items .totalrow td { border-top: 2px solid var(--mks-dark); font-size: 14.5px; color: var(--mks-dark); }

.task-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.task-row:last-child { border-bottom: none; }
.task-row .task-main { flex: 1; min-width: 0; }
.task-row .task-name { font-weight: 600; font-size: 14px; }
.task-row .task-sub { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.task-row .task-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

select.status-select { padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; }

.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.photo-thumb { position: relative; width: 68px; height: 68px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .tag { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(10,52,33,0.75); color: #fff; font-size: 9px; text-align: center; padding: 1px 0; text-transform: uppercase; }
.photo-add {
  width: 68px; height: 68px; border-radius: 8px; border: 1.5px dashed var(--mks-green-light);
  display: flex; align-items: center; justify-content: center; color: var(--mks-green); font-size: 22px; cursor: pointer; background: #f2f8f3;
}

.btn { display: inline-flex; align-items: center; gap: 6px; border: none; border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--mks-green); color: #fff; }
.btn-primary:hover { background: var(--mks-dark); }
.btn-gold { background: var(--mks-gold); color: var(--mks-dark); }
.btn-outline { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn-danger { background: #fbe8e5; color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12px; }

.notes-input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12.5px; font-family: inherit; resize: vertical; min-height: 32px; }

/* ---------- Rate sheet ---------- */
.rate-cat { margin-bottom: 22px; }
.rate-cat h3 { color: var(--mks-dark); border-bottom: 2px solid var(--mks-gold); padding-bottom: 6px; }
table.rates { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.rates th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--ink-soft); padding: 6px 8px; border-bottom: 2px solid var(--line); }
table.rates td { padding: 8px; border-bottom: 1px solid var(--line); }
table.rates td.rate { font-weight: 700; color: var(--mks-green); }

.menu-list { columns: 2; gap: 24px; }
.menu-list ul { margin: 0 0 12px; padding-left: 18px; font-size: 13px; color: var(--ink-soft); break-inside: avoid; }

/* ---------- Client view ---------- */
.client-hero { background: linear-gradient(135deg, var(--mks-dark), var(--mks-teal)); color: #fff; border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.client-hero h1 { margin: 0 0 4px; font-size: 20px; }
.client-hero .addr { color: var(--mks-gold-light); font-size: 14px; }

.progress-bar { height: 8px; background: #e6e2d4; border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress-bar > div { height: 100%; background: var(--mks-green); }

.photo-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-compare .col h4 { font-size: 11px; text-transform: uppercase; color: var(--ink-soft); margin: 0 0 6px; }
.photo-compare img { width: 100%; border-radius: 8px; object-fit: cover; aspect-ratio: 1; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,20,15,0.5); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 20px; max-width: 420px; width: 100%; max-height: 90vh; overflow: auto; }
.modal h3 { margin-top: 0; color: var(--mks-dark); }
.modal img.preview { width: 100%; border-radius: 8px; margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }

/* ---------- In-app camera capture ---------- */
.camera-modal { max-width: 480px; }
.camera-wrap { position: relative; width: 100%; border-radius: 8px; overflow: hidden; background: #000; aspect-ratio: 3/4; }
.camera-video, .camera-canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-actions-live, .camera-actions-preview { display: flex; gap: 8px; margin-top: 14px; }
.camera-actions-live .camera-shoot, .camera-actions-preview .camera-use { flex: 1; justify-content: center; }
.camera-actions-live .camera-fallback { flex: 1; justify-content: center; }
.camera-actions-preview .camera-retake { flex: 1; justify-content: center; }

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

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 58px; bottom: 0; z-index: 60; transform: translateX(-100%); transition: transform .18s; width: 220px; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 16px rgba(0,0,0,0.2); }
  .topbar .menu-btn { display: block; }
  .main { padding: 14px 14px 60px; }
  .menu-list { columns: 1; }
  .photo-compare { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .topbar .brand span { display: none; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  table.items { font-size: 12px; }
  table.items th:nth-child(2), table.items td:nth-child(2) { display: none; }
}
