/* ============ HQ CRM — dark UI ============ */
:root {
  --bg: #0b0f14;
  --panel: #111823;
  --panel2: #16202e;
  --line: #1f2b3a;
  --text: #e6edf5;
  --muted: #8fa3b8;
  --dim: #64748b;
  --acc: #38bdf8;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--acc) 55%, transparent); outline-offset: 0; border-color: var(--acc); }
input[type="checkbox"] { width: auto; accent-color: var(--acc); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
a { color: var(--acc); }
::-webkit-scrollbar { height: 10px; width: 10px; }
::-webkit-scrollbar-thumb { background: #24344a; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- app shell ---------- */
#app { display: none; min-height: 100%; }
header.top {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-row {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px 6px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; letter-spacing: .3px; white-space: nowrap; }
.brand .logo {
  width: 28px; height: 28px; border-radius: 8px; flex: 0 0 auto;
  background: linear-gradient(135deg, #38bdf8, #7cc242 45%, #f59e0b 75%, #a78bfa);
  display: grid; place-items: center; font-size: 13px; font-weight: 800; color: #0b0f14;
}
.pills { display: flex; gap: 6px; overflow-x: auto; flex: 1; padding-bottom: 2px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pill {
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
  padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); font-weight: 600; font-size: 13px; transition: .15s;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--acc); }
.pill:hover { color: var(--text); border-color: #2d415c; }
.pill.active { color: var(--text); border-color: var(--acc); background: color-mix(in srgb, var(--acc) 12%, transparent); }
.userbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--muted); font-size: 13px; }
.userbox .avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--panel2);
  border: 1px solid var(--line); display: grid; place-items: center; font-weight: 700; font-size: 12px; color: var(--text);
}
.tabs { display: flex; gap: 2px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 9px 13px; color: var(--muted); font-weight: 600; font-size: 13px;
  border-bottom: 2px solid transparent; white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-color: var(--acc); }
.tab .badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
main { padding: 18px; max-width: 1500px; margin: 0 auto; }

/* ---------- generic bits ---------- */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
h2.page { font-size: 19px; margin-bottom: 4px; }
.sub { color: var(--muted); font-size: 13px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel2); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 13px;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #33496a; }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #06202e; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn.ghost { background: transparent; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.chip.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, var(--line)); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); }
.chip.bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.chip.acc  { color: var(--acc);  border-color: color-mix(in srgb, var(--acc) 35%, var(--line)); }
.pri-high { color: var(--bad); } .pri-medium { color: var(--warn); } .pri-low { color: var(--dim); }
.empty { color: var(--dim); text-align: center; padding: 34px 10px; font-size: 13px; }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 14px 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 22px; font-weight: 800; letter-spacing: .3px; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.alert { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.dash-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; align-items: start; }
.list { display: flex; flex-direction: column; }
.list .item {
  display: flex; gap: 10px; align-items: center; padding: 9px 4px;
  border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer;
}
.list .item:last-child { border-bottom: 0; }
.list .item:hover { background: color-mix(in srgb, var(--panel2) 60%, transparent); }
.bizdot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 9px 0; font-size: 13px; }
.bar-row .lbl { width: 130px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .track { flex: 1; height: 10px; border-radius: 5px; background: var(--panel2); overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 5px; }
.bar-row .val { width: 84px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.attention .item { cursor: default; }
.attention .why { color: var(--warn); font-size: 12px; }

/* ---------- kanban ---------- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 14px; align-items: flex-start; }
.col {
  flex: 0 0 268px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); max-height: calc(100vh - 220px); display: flex; flex-direction: column;
}
.col.drag-over { border-color: var(--acc); background: color-mix(in srgb, var(--acc) 6%, var(--panel)); }
.col-head { padding: 11px 13px 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.col-head .name { font-weight: 700; font-size: 13px; }
.col-head .sum { color: var(--muted); font-size: 11px; white-space: nowrap; }
.col-body { padding: 4px 9px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.deal-card {
  background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--acc);
  border-radius: 9px; padding: 10px 11px; cursor: grab; transition: .12s;
}
.deal-card:hover { border-color: #33496a; border-left-color: var(--acc); transform: translateY(-1px); }
.deal-card.dragging { opacity: .45; }
.deal-card .t { font-weight: 600; font-size: 13px; line-height: 1.35; }
.deal-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; font-size: 12px; color: var(--muted); }
.deal-card .val { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.deal-card .foot { display: flex; justify-content: space-between; margin-top: 5px; font-size: 11px; color: var(--dim); }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: color-mix(in srgb, var(--panel2) 55%, transparent); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.tbl-wrap { overflow-x: auto; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; color: var(--dim); font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 4px 0; }
.cal-cell {
  min-height: 96px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  padding: 6px; font-size: 12px; cursor: pointer; transition: .12s; overflow: hidden;
}
.cal-cell:hover { border-color: #33496a; }
.cal-cell.other { opacity: .38; }
.cal-cell.today { border-color: var(--acc); }
.cal-cell .d { color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.cal-cell.today .d { color: var(--acc); }
.cal-job {
  display: block; width: 100%; text-align: left; border-radius: 5px; padding: 2px 6px; margin-bottom: 3px;
  font-size: 11px; font-weight: 600; color: #0b0f14; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-job.done { opacity: .5; text-decoration: line-through; }
.crew-lane { margin-bottom: 14px; }
.crew-lane h4 { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* ---------- tasks ---------- */
.task-group h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 18px 0 6px; }
.task { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--line); font-size: 13px; }
.task input[type="checkbox"] { width: 16px; height: 16px; }
.task.done .t { text-decoration: line-through; color: var(--dim); }
.task .due { font-size: 12px; color: var(--muted); white-space: nowrap; }
.task .due.over { color: var(--bad); font-weight: 700; }

/* ---------- drawers & modals ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(3, 7, 12, .62); z-index: 60;
  display: none; backdrop-filter: blur(2px);
}
.overlay.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 96vw); z-index: 70;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  transform: translateX(102%); transition: transform .22s ease; display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; gap: 10px; }
.drawer-body { padding: 16px 18px 40px; overflow-y: auto; flex: 1; }
.drawer h3 { font-size: 16px; line-height: 1.3; }
.x { color: var(--dim); font-size: 20px; padding: 2px 8px; border-radius: 6px; }
.x:hover { color: var(--text); background: var(--panel2); }
.modal-wrap {
  position: fixed; inset: 0; z-index: 80; display: none;
  align-items: flex-start; justify-content: center; padding: 6vh 14px;
  background: rgba(3, 7, 12, .62); backdrop-filter: blur(2px); overflow-y: auto;
}
.modal-wrap.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 620px; box-shadow: var(--shadow); padding: 20px;
}
.modal h3 { margin-bottom: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 14px; }
.form-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.section { margin-top: 22px; }
.section > h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--dim); margin-bottom: 8px; }

/* timeline */
.tl { display: flex; flex-direction: column; gap: 10px; }
.tl .ev { display: flex; gap: 10px; font-size: 13px; }
.tl .ico {
  width: 26px; height: 26px; flex: 0 0 auto; border-radius: 50%;
  background: var(--panel2); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 12px;
}
.tl .who { color: var(--muted); font-size: 11px; margin-top: 1px; }

/* line items editor */
.li-row { display: grid; grid-template-columns: 1fr 64px 96px 30px; gap: 8px; margin-bottom: 8px; align-items: center; }
.li-head { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .5px; }
.totals { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }
.totals .trow { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 16px; font-weight: 800; }

/* photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.photo-grid .ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-grid .del {
  position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.65);
  border-radius: 5px; padding: 1px 6px; font-size: 11px; color: #fff;
}

/* toast */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1c2a3d; border: 1px solid #2f4763; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow); animation: pop .18s ease;
}
.toast.err { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); color: var(--bad); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- login ---------- */
#login {
  position: fixed; inset: 0; z-index: 200; background: var(--bg);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
#login.open { display: flex; }
.login-card { width: 100%; max-width: 380px; }
.login-card .logo-big {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 14px;
  background: linear-gradient(135deg, #38bdf8, #7cc242 45%, #f59e0b 75%, #a78bfa);
  display: grid; place-items: center; font-weight: 800; font-size: 22px; color: #0b0f14;
}
.login-err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; }

/* ---------- print (invoice) ---------- */
#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; color: #111; background: #fff; font-size: 13px; }
  #print-root .inv-head { display: flex; justify-content: space-between; margin-bottom: 28px; }
  #print-root h1 { font-size: 22px; }
  #print-root table { width: 100%; border-collapse: collapse; margin-top: 16px; }
  #print-root th { text-align: left; border-bottom: 2px solid #111; padding: 6px 4px; font-size: 11px; text-transform: uppercase; }
  #print-root td { border-bottom: 1px solid #ccc; padding: 8px 4px; }
  #print-root .r { text-align: right; }
  #print-root .tot { margin-top: 14px; margin-left: auto; width: 260px; }
  #print-root .tot div { display: flex; justify-content: space-between; padding: 3px 0; }
  #print-root .grand { font-weight: 800; font-size: 16px; border-top: 2px solid #111; padding-top: 6px !important; }
  #print-root .payto { margin-top: 30px; padding: 12px; border: 1px solid #999; border-radius: 6px; }
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .dash-grid { grid-template-columns: 1fr; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .top-row { padding: 8px 12px 4px; }
  .brand span.word { display: none; }
  .cal-cell { min-height: 64px; }
  .userbox .uname { display: none; }
}
