:root {
  --ink: #1b1b1d;
  --paper: #efeee9;
  --card: #ffffff;
  --line: #dedcd4;
  --muted: #6e6c66;
  --blue: #2b6cdf;
  --orange: #f08a24;
  --green: #1f9d55;
  --brown: #8a5a3b;
  --danger: #c8372d;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  font-size: 15px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 28px;
  padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.topbar .brand img { height: 36px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500;
}
.topbar nav a.on { background: var(--paper); color: var(--ink); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 14px; }
.stripe { display: flex; height: 3px; }
.stripe i { flex: 1; }
.stripe i:nth-child(1) { background: var(--blue); }
.stripe i:nth-child(2) { background: var(--orange); }
.stripe i:nth-child(3) { background: var(--green); }
.stripe i:nth-child(4) { background: var(--brown); }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card.pad { padding: 18px; }
.section-label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 26px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c9c6bc; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #333; }
.btn.danger { color: var(--danger); }
.btn.primary.danger-fill { background: var(--danger); border-color: var(--danger); }
.btn.primary.danger-fill:disabled { opacity: .4; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--paper); color: var(--ink); }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=time], select, textarea {
  height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; min-width: 0;
}
textarea { height: auto; padding: 10px; line-height: 1.45; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(43,108,223,.35); border-color: var(--blue); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.field > span.hint { font-weight: 400; }
.form-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.form-grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.form-grid select, .form-grid input[type=text], .form-grid textarea { width: 100%; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a {
  padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a.on { color: var(--ink); border-color: var(--ink); }
.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; background: var(--paper); font-size: 12px; text-align: center; margin-left: 4px; }
.badge.red { background: #f7dcd9; color: var(--danger); }

.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 1px solid rgba(0,0,0,.35); flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 13px; font-weight: 500;
}
.chip .n { color: var(--muted); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.on .n { color: rgba(255,255,255,.7); }

/* ---------- jobs ---------- */
.program { margin-bottom: 26px; }
.program h2 { font-size: 18px; margin: 0 0 10px; display: flex; gap: 8px; align-items: baseline; }
.program h2 .muted { font-size: 14px; font-weight: 400; }
.job-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.job-card { padding: 16px; text-decoration: none; display: block; transition: border-color .12s; }
.job-card:hover { border-color: #bdb9ad; }
.job-card .name { font-weight: 700; font-size: 17px; }
.statusbar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--paper); margin: 12px 0 8px; }
.statusbar i { display: block; height: 100%; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin: 0 0 6px; }

/* ---------- job page ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.progress { height: 6px; background: var(--paper); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress i { display: block; height: 100%; background: var(--green); }

#map { height: calc(100vh - 330px); min-height: 460px; border-radius: var(--radius); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 12px 14px; font-size: 14px; min-width: 210px; }
.leaflet-popup-content h4 { margin: 0 0 8px; font-size: 15px; }
.leaflet-popup-content select { width: 100%; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #faf9f6; position: sticky; top: 0; }
table.list td { padding: 9px 14px; border-bottom: 1px solid #efede6; vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr:hover td { background: #fbfaf7; }
table.list select { height: 32px; }
.table-wrap { max-height: calc(100vh - 330px); overflow: auto; border-radius: var(--radius); }

.issue { display: flex; gap: 12px; padding: 11px 14px; border-bottom: 1px solid #efede6; align-items: flex-start; }
.issue:last-child { border-bottom: 0; }
.sev { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 5px; flex: none; margin-top: 1px; }
.sev.error { background: #f7dcd9; color: var(--danger); }
.sev.warning { background: #fde9d2; color: #a85b10; }
.sev.info { background: #e3ecfb; color: var(--blue); }

/* ---------- lists & statuses ---------- */
.split { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.side-list a { display: block; padding: 10px 14px; text-decoration: none; border-bottom: 1px solid #efede6; }
.side-list a:last-child { border-bottom: 0; }
.side-list a.on { background: var(--paper); font-weight: 600; }
.status-row { display: grid; grid-template-columns: 26px 44px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 14px; border-bottom: 1px solid #efede6; }
.status-row input[type=color] { width: 40px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer; }
.status-row .default { font-size: 12px; color: var(--muted); display: flex; gap: 5px; align-items: center; white-space: nowrap; }
.drag { color: var(--muted); cursor: grab; text-align: center; user-select: none; }

/* ---------- modal, toast, login ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(27,27,29,.35); z-index: 2000; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow: auto; }
.modal { width: 100%; max-width: 620px; background: var(--card); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal header { padding: 18px 20px 0; display: flex; align-items: center; }
.modal header h3 { margin: 0; font-size: 19px; flex: 1; }
.modal .body { padding: 16px 20px; }
.modal footer { padding: 14px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }

.drop {
  border: 2px dashed #cfcbc0; border-radius: 12px; padding: 26px; text-align: center; color: var(--muted); cursor: pointer; background: #faf9f6;
}
.drop.over { border-color: var(--blue); background: #eef3fc; }
.file-row { display: grid; grid-template-columns: 1fr 170px 28px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid #efede6; font-size: 14px; }
.file-row .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.result-file { padding: 12px 0; border-bottom: 1px solid #efede6; }
.result-file:last-child { border-bottom: 0; }
.warn { color: #a85b10; font-size: 13px; margin-top: 4px; }
.err { color: var(--danger); font-size: 14px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: all .2s; z-index: 3000; pointer-events: none; font-size: 14px; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--danger); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .box { width: 100%; max-width: 380px; }
.login .logo { text-align: center; margin-bottom: 22px; }
.login .logo img { width: 240px; }
.login .logo .stripe { width: 110px; margin: 12px auto 0; border-radius: 2px; overflow: hidden; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .split, .form-grid.two { grid-template-columns: 1fr; }
  .topbar { gap: 12px; padding: 10px 14px; }
  .topbar .who { display: none; }
  main { padding: 16px; }
}

/* ---------- form builder ---------- */
.builder { display: grid; grid-template-columns: 330px minmax(0, 1fr) 340px; gap: 14px; align-items: start; }
.b-tree { position: sticky; top: 78px; max-height: calc(100vh - 100px); overflow: auto; padding: 6px 0; }
.b-row { display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: pointer; border-top: 2px solid transparent; font-size: 14px; }
.b-row:hover { background: #faf9f6; }
.b-row.on { background: #eef3fc; }
.b-row.container .b-label { font-weight: 700; }
.b-row .drag { cursor: grab; }
.b-row.drop-before, .b-add.drop-before { border-top-color: var(--blue); }
.b-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 22px; padding: 0 5px; border-radius: 6px; background: var(--paper); font-size: 11px; font-weight: 700; color: var(--muted); flex: none; }
.b-flag { flex: none; font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.b-flag.cond { color: var(--blue); border-color: #c5d6f5; }
.b-add { padding: 6px 12px; color: var(--blue); font-size: 13px; font-weight: 600; cursor: pointer; border-top: 2px solid transparent; }
.b-add:hover { text-decoration: underline; }
.b-editor { min-height: 300px; }
.b-ed-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.rules { background: #faf9f6; border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 8px; }
.rule { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1.2fr) 26px; gap: 6px; align-items: center; }
.rule select, .rule input { width: 100%; }
.rule select, .rule input { height: 32px; font-size: 13px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px; font-weight: 400; color: var(--ink); }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.type-btn { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-weight: 600; text-align: left; }
.type-btn:hover:not(:disabled) { border-color: var(--ink); }
.type-btn:disabled { opacity: .4; cursor: default; }

.b-preview { position: sticky; top: 78px; }
.phone { background: var(--paper); border: 10px solid var(--ink); border-radius: 38px; height: calc(100vh - 110px); max-height: 760px; overflow: auto; padding: 0 14px 20px; }
.phone-bar { width: 90px; height: 22px; background: var(--ink); border-radius: 0 0 14px 14px; margin: 0 auto 12px; position: sticky; top: 0; z-index: 2; }
.pv-title { font-weight: 700; font-size: 18px; margin: 2px 4px 10px; }
.pv-field { background: #fff; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; border: 2px solid transparent; }
.pv-field.pv-on, .pv-section.pv-on { border-color: var(--blue); }
.pv-section { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 4px 6px; cursor: pointer; border-bottom: 2px solid transparent; }
.pv-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.pv-req { color: var(--orange); font-size: 10px; text-transform: uppercase; margin-left: 4px; }
.pv-help { font-size: 11px; color: var(--muted); margin-top: 4px; }
.pv-field input, .pv-field select, #pv-status { width: 100%; height: 34px; font-size: 14px; }
.pv-seg { display: flex; background: var(--paper); border-radius: 8px; padding: 2px; }
.pv-seg button { flex: 1; border: 0; background: none; padding: 6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.pv-seg button.on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.15); font-weight: 600; }
.pv-mock { font-size: 14px; color: var(--muted); }
.pv-photos { display: flex; gap: 8px; }
.pv-photos span { width: 64px; height: 64px; border: 1px dashed #cfcbc0; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--blue); }
.pv-repeat { border-left: 3px solid var(--line); padding-left: 8px; }
.pv-repeat .pv-field { background: var(--paper); }
.pv-add { color: var(--blue); font-size: 13px; font-weight: 600; margin-top: 6px; }
.pv-note { font-size: 11px; color: var(--muted); text-align: center; margin-top: 14px; }
@media (max-width: 1180px) { .builder { grid-template-columns: 300px 1fr; } .b-preview { display: none; } }
.rules select[data-match] { width: auto; display: inline-block; margin: 0 4px; }

/* ---------- location page ---------- */
.loc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.ans-section { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 16px 16px 6px; border-top: 1px solid var(--line); }
.ans-section:first-child { border-top: 0; }
.ans-row { display: grid; grid-template-columns: minmax(140px, 34%) minmax(0, 1fr); gap: 14px; padding: 10px 16px; border-bottom: 1px solid #f1efe9; align-items: start; }
.ans-label { color: var(--muted); font-size: 14px; }
.ans-value { font-size: 14px; word-break: break-word; }
.ans-repeat { grid-template-columns: 1fr; }
.ans-item { display: flex; gap: 10px; background: #faf9f6; border-radius: 10px; margin-top: 8px; padding: 4px 0; }
.ans-item .ans-row { border-bottom-color: #efede6; padding: 7px 12px; }
.ans-item-n { width: 30px; text-align: center; font-weight: 700; color: var(--muted); padding-top: 9px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; background: var(--paper); cursor: zoom-in; border: 1px solid var(--line); }
.thumbs img.missing { cursor: default; }
@media (max-width: 980px) { .loc-grid { grid-template-columns: 1fr; } }
.ans-value select { min-width: 240px; }

/* Workbook builder */
.wb-questions { display: grid; gap: 10px; max-height: 46vh; overflow: auto; }
.wb-q { border-color: #f0c36d; background: #fffaf0; }
.wb-q-title { font-weight: 600; margin-bottom: 6px; }
.wb-opt { padding: 4px 0; align-items: flex-start; gap: 8px; }
table.list tr.jf-group td { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: #faf9f6; padding: 14px 14px 6px; border-bottom: 1px solid var(--line); }
table.list tr.jf-group:hover td { background: #faf9f6; }
table.list select.jf-cat { height: 28px; font-size: 12px; margin-right: 4px; }
