/* Zonke Contractor Portal. Mobile-first; no branding yet (neutral palette). */
:root {
  --bg: #f4f5f7;
  --paper: #ffffff;
  --ink: #1c2128;
  --muted: #67707b;
  --line: #c9ced5;
  --fill: #e8eaee;
  --strong: #26303b;
  --on-strong: #ffffff;
  --accent: #2c6bd6;
  --ok: #2b7a4b;
  --warn: #a1580a;
  --approve: #3f7d58;
  --reject: #a5473f;
  --scrim: rgba(14, 18, 24, 0.45);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13171c;
    --paper: #1c2229;
    --ink: #e5e8ec;
    --muted: #98a1ac;
    --line: #3a434e;
    --fill: #29303a;
    --strong: #dde2e8;
    --on-strong: #14181d;
    --accent: #7ea9f2;
    --ok: #6cc08f;
    --warn: #e3a650;
    --approve: #4c9467;
    --reject: #c0605a;
    --scrim: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; }
.muted, .meta { color: var(--muted); }
.meta { font-size: 0.8125rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* App bar */
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: env(safe-area-inset-top, 0) max(8px, env(safe-area-inset-right, 0)) 0 max(8px, env(safe-area-inset-left, 0));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.bar:empty { display: none; }
.bar h1 { font-size: 1.0625rem; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: var(--radius);
  background: none; color: var(--ink); cursor: pointer;
}
.iconbtn:hover { background: var(--fill); }
.iconbtn svg, .big svg, .tick svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Page */
.page {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right, 0)) calc(24px + env(safe-area-inset-bottom, 0)) max(16px, env(safe-area-inset-left, 0));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sect {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); padding-top: 8px; border-top: 1px solid var(--line);
}

/* Buttons */
.btn, .auth button, .auth a[href].button {
  min-height: 48px; width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 16px;
  border: 1.5px solid var(--strong); border-radius: var(--radius);
  background: transparent; color: var(--ink);
  font: 600 1rem var(--font); text-decoration: none; cursor: pointer;
}
.btn.primary, .auth button[type="submit"] { background: var(--strong); color: var(--on-strong); }
.btn.ghost { border-color: transparent; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions.sticky {
  position: sticky; bottom: 0;
  /* sits at the bottom of the screen, flush with the page edges */
  margin: auto -16px calc(-24px - env(safe-area-inset-bottom, 0)); padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0));
  background: var(--paper); border-top: 1px solid var(--line);
}

/* Forms */
.field, .auth form p { display: flex; flex-direction: column; gap: 6px; margin: 0; }
label { font-size: 0.875rem; font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--ink);
  font: 1rem var(--font);
}
input[type="checkbox"] { width: auto; min-height: 0; }
input[readonly] { background: var(--fill); color: var(--muted); }
.hint, .helptext, .auth .helptext { font-size: 0.8125rem; color: var(--muted); font-weight: 400; }
.helptext ul { margin: 4px 0 0; padding-left: 18px; }
.field.err input, .field.err select, .field.err textarea { border-color: var(--warn); }
.errmsg, .errorlist { color: var(--warn); font-size: 0.8125rem; font-weight: 500; }
.errorlist { list-style: none; margin: 0; padding: 0; }
.errbox { border: 1.5px solid var(--warn); border-radius: var(--radius); padding: 12px 14px; color: var(--warn); }

/* allauth pages (log in, sign up, codes, MFA) */
.auth form { display: flex; flex-direction: column; gap: 16px; }
.auth h1 { font-size: 1.375rem; }
.auth > p, .auth form + p { color: var(--muted); }
.auth a { text-underline-offset: 3px; }
.auth form p:empty { display: none; }
/* Django's password rules list ends up outside its <p>; tuck it under the password field */
.auth form > ul:not(.errorlist) { margin: -10px 0 0; padding-left: 18px; font-size: 0.8125rem; color: var(--muted); }
.auth input[name="code"] { font: 600 1.5rem ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.4em; text-align: center; }

/* Messages and banners */
.messages { display: flex; flex-direction: column; gap: 8px; }
.message { background: var(--strong); color: var(--on-strong); border-radius: var(--radius); padding: 12px 14px; font-weight: 500; }
.message.error { background: var(--warn); }
.banner {
  border: 1.5px solid var(--line); background: var(--fill); border-radius: var(--radius);
  padding: 12px 14px; font-size: 0.875rem; display: flex; flex-direction: column; gap: 4px;
}
.empty {
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 28px 20px;
  text-align: center; display: flex; flex-direction: column; gap: 8px; color: var(--muted);
}
.empty b { color: var(--ink); font-size: 1.0625rem; }

/* Welcome */
.welcome { justify-content: center; min-height: 100dvh; }
.welcome .logo { display: block; width: min(100%, 260px); height: auto; margin: 0 auto 8px; border-radius: var(--radius); }
.welcome h2 { font-size: 1.5rem; text-align: center; }
.welcome h2 + p { text-align: center; }
.welcome .actions { margin-top: 24px; }

/* Home */
.home .greet { font-size: 1.25rem; font-weight: 700; }
.bigbtns { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; min-height: 360px; }
.big {
  min-height: 160px; border: 2px solid var(--strong); border-radius: 18px;
  background: var(--paper); color: var(--ink); text-decoration: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  font-size: 1.1875rem; font-weight: 700;
}
.big.primary { background: var(--strong); color: var(--on-strong); }
.big svg { width: 36px; height: 36px; stroke-width: 1.8; }
.big small { font-size: 0.8125rem; font-weight: 400; opacity: 0.75; }

/* Waiting page */
.done { align-items: center; text-align: center; justify-content: center; }
.done .tick { width: 72px; height: 72px; border: 2px solid var(--strong); border-radius: 50%; display: grid; place-items: center; }
.done .tick svg { width: 34px; height: 34px; }
.done .actions { width: 100%; margin-top: 16px; }

/* Drawer */
.drawer-wrap { position: fixed; inset: 0; z-index: 20; }
.scrim { position: absolute; inset: 0; border: 0; padding: 0; background: var(--scrim); cursor: pointer; }
.drawer {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: min(80%, 320px);
  background: var(--paper); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  animation: slide-in 0.18s ease-out;
}
@keyframes slide-in { from { transform: translateX(-100%); } }
.drawer .who { display: flex; gap: 12px; align-items: center; padding: 24px 20px 18px; border-bottom: 1px solid var(--line); }
.drawer .who-text { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--fill); display: grid; place-items: center; font-weight: 700; flex: none; }
.drawer > a, .drawer-out button {
  display: flex; align-items: center; min-height: 52px; margin: 2px 8px; padding: 0 14px;
  border: 0; border-radius: var(--radius); background: none; color: var(--ink);
  font: 500 1rem var(--font); text-decoration: none; text-align: left; cursor: pointer; width: calc(100% - 16px);
}
.drawer > a:hover, .drawer-out button:hover { background: var(--fill); }
.drawer-out { margin-top: auto; border-top: 1px solid var(--line); padding: 8px 0; }

/* Lists: timesheets and tasks */
.list { display: flex; flex-direction: column; gap: 10px; }
.task, .row {
  width: 100%;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline;
  padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--paper); color: var(--ink); text-decoration: none;
}
a.task:hover, a.row:hover { border-color: var(--strong); }
.row.draft { border-style: dashed; border-color: var(--warn); }
.task .t-desc { font-weight: 500; overflow-wrap: anywhere; white-space: pre-line; }
.num { font-variant-numeric: tabular-nums; }
.task .num, .row .num { font-weight: 600; text-align: right; }
.task .edit { text-align: right; }
.tsid { font-weight: 700; font-variant-numeric: tabular-nums; }
.pill {
  justify-self: end; white-space: nowrap;
  font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted);
}
.pill.submitted { border-color: var(--accent); color: var(--accent); }
.pill.approved { border-color: var(--ok); color: var(--ok); }
.pill.rejected, .pill.wait { border-color: var(--warn); color: var(--warn); }
.kv {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 16px; align-items: center;
  margin: 0; padding: 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper);
}
.kv dt { color: var(--muted); font-size: 0.875rem; }
.kv dd { margin: 0; font-weight: 500; text-align: right; overflow-wrap: anywhere; }
.banner.rej { border-color: var(--warn); background: var(--paper); }
.banner.rej b { color: var(--warn); }
.btn.dashed { border-style: dashed; border-color: var(--line); }
.btn.dashed:hover { border-color: var(--strong); }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn.danger { border-color: var(--warn); color: var(--warn); }
.btn.danger:not(.ghost) { background: var(--warn); color: var(--paper); }
.btn.ghost.danger { border-color: transparent; }
.sum { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.9375rem; color: var(--muted); }
.sum b { color: var(--ink); font-size: 1.125rem; }
.center { text-align: center; }
.done h2 { font-size: 1.375rem; }

/* Invoice: timesheet picker */
.pick { display: flex; align-items: center; gap: 4px; padding-right: 12px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper); }
.pick:has(input:checked) { border-color: var(--strong); }
.pick-main {
  flex: 1; min-width: 0; padding: 12px 4px 12px 12px; cursor: pointer;
  display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 2px 12px; align-items: center;
  font-weight: 400; font-size: 1rem;
}
.pick-main input {
  grid-row: span 2; width: 22px; height: 22px; min-height: 0; margin: 0; padding: 0;
  appearance: none; border: 2px solid var(--strong); border-radius: 6px; background: var(--paper); cursor: pointer;
  display: grid; place-items: center;
}
.pick-main input:checked { background: var(--strong); }
.pick-main input:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--on-strong); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.pick-main .num { font-weight: 600; text-align: right; }
.link { color: var(--accent); font-weight: 600; font-size: 0.875rem; text-underline-offset: 3px; padding: 8px 4px; }
.hint a, .banner a { color: var(--accent); font-weight: 600; text-underline-offset: 3px; }
.comment { white-space: pre-line; overflow-wrap: anywhere; }
.banner .comment { color: var(--ink); }

/* Delete confirmation (no JavaScript needed) */
.confirm-wrap summary { list-style: none; }
.confirm-wrap summary::-webkit-details-marker { display: none; }
.confirm-wrap { display: flex; flex-direction: column-reverse; gap: 8px; }
.confirm-wrap .when-open, .confirm-wrap[open] .when-closed { display: none; }
.confirm-wrap[open] .when-open { display: inline; }
.confirm { border: 1.5px solid var(--warn); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }

/* Bottom sheet (task form) */
body:has(#sheet .sheet-wrap) { overflow: hidden; }
.sheet-wrap { position: fixed; inset: 0; z-index: 30; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 94dvh;
  display: flex; flex-direction: column;
  background: var(--paper); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  animation: slide-up 0.2s ease-out;
}
.sheet-wrap.again .sheet { animation: none; }
@keyframes slide-up { from { transform: translateY(100%); } }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet .bar { position: static; border-radius: 18px 18px 0 0; padding-left: 16px; border-bottom: 1px solid var(--line); }
.sheet .task-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.sheet .form-body { overflow-y: auto; padding: 16px; }
.form-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0)); border-top: 1px solid var(--line); background: var(--paper); }
.page > .task-form { display: flex; flex-direction: column; gap: 16px; }
.page > .task-form .form-foot { position: sticky; bottom: 0; margin: 0 -16px; }

@media (min-width: 720px) {
  .page { padding-top: 32px; }
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 520px; max-height: 90dvh; transform: translate(-50%, -50%); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; animation: none; }
  .sheet .grab { display: none; }
}
