:root {
  --bg: #0E0E10;
  --bg2: #16161A;
  --card: #1C1C21;
  --card2: #24242B;
  --line: #2E2E36;
  --text: #ECE9E2;
  --muted: #9A978F;
  --faint: #6B6962;
  --gold: #C9A96E;
  --gold2: #E2C893;
  --gold-dim: rgba(201, 169, 110, 0.14);
  --danger: #E5675A;
  --ok: #6CC08B;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
a { color: var(--gold2); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

.view {
  min-height: 100vh;
  padding: calc(var(--safe-top) + 6px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
  max-width: 820px;
  margin: 0 auto;
}
.view.no-tabs { padding-bottom: calc(var(--safe-bottom) + 28px); }
.loading, .empty { color: var(--muted); text-align: center; padding: 48px 12px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; opacity: .6; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  margin: 0 -16px 8px; padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: rgba(14, 14, 16, 0.86);
  backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid transparent;
  margin-top: calc(-1 * (var(--safe-top) + 6px));
}
.topbar .title { flex: 1; min-width: 0; text-align: center; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 20px; border: 0; background: var(--card);
  display: inline-flex; align-items: center; justify-content: center; flex: none; cursor: pointer;
}
.iconbtn svg { width: 20px; height: 20px; }
.iconbtn.gold { background: var(--gold); color: #17140E; }
.iconbtn.ghost { background: transparent; }
.spacer40 { width: 40px; flex: none; }

h1.page { font-size: 30px; line-height: 1.15; margin: 10px 0 4px; font-weight: 750; letter-spacing: -0.02em; }
.sub { color: var(--muted); margin: 0 0 14px; white-space: pre-wrap; word-break: break-word; }
.section-title { color: var(--gold); font-weight: 650; font-size: 15px; letter-spacing: .02em; text-transform: uppercase; margin: 22px 2px 10px; display: flex; align-items: center; justify-content: space-between; }
.section-title a { text-transform: none; font-size: 14px; letter-spacing: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--card2); color: var(--text);
}
.btn svg { width: 18px; height: 18px; }
.btn.gold { background: var(--gold); color: #17140E; }
.btn.danger { background: rgba(229, 103, 90, .16); color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }

/* ---------- cards ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (min-width: 640px) { .grid2.jobs { grid-template-columns: repeat(3, 1fr); } }
.jobcard { position: relative; min-height: 118px; display: flex; flex-direction: column; cursor: pointer; border: 1px solid var(--line); }
.jobcard:active { background: var(--card2); }
.jobcard .name { font-weight: 700; font-size: 17px; line-height: 1.2; padding-right: 20px; word-break: break-word; }
.jobcard .desc { color: var(--muted); font-size: 13px; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.jobcard .foot { margin-top: auto; padding-top: 10px; font-size: 12px; color: var(--faint); }
.jobcard .pin { position: absolute; top: 12px; right: 12px; color: var(--gold); }
.jobcard .pin svg { width: 16px; height: 16px; }
.jobcard.new { align-items: center; justify-content: center; color: var(--gold); border: 1.5px dashed rgba(201,169,110,.45); background: transparent; font-weight: 600; gap: 6px; }

.search {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; margin: 6px 0 14px; outline: none;
}
.search:focus { border-color: var(--gold); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; min-height: 104px; display: flex; flex-direction: column; }
.tile:active { background: var(--card2); }
.tile .t { color: var(--gold); font-weight: 650; display: flex; align-items: center; gap: 8px; }
.tile .t svg { width: 18px; height: 18px; }
.tile .big { font-size: 24px; font-weight: 700; margin-top: 8px; }
.tile .small { color: var(--muted); font-size: 13px; margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- lists (generic rows) ---------- */
.rows { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.rowi { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; min-height: 56px; }
.rowi:first-child { border-top: 0; }
.rowi:active { background: var(--card2); }
.rowi .main { flex: 1; min-width: 0; }
.rowi .main .t { font-weight: 600; word-break: break-word; }
.rowi .main .m { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rowi .chev { color: var(--faint); }
.rowi .chev svg, .more svg { width: 18px; height: 18px; }
.more { border: 0; background: transparent; color: var(--muted); padding: 8px; margin: -8px -6px -8px 0; cursor: pointer; }

/* ---------- to-dos ---------- */
.todolist { margin: 18px 0 8px; }
.listhead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.listname {
  font-weight: 750; font-size: 18px; padding: 2px 8px; border-radius: 6px; border-left: 4px solid transparent;
  cursor: pointer; word-break: break-word;
}
.listname.plain { padding-left: 0; border-left: 0; }
.listcount { color: var(--muted); font-size: 13px; margin-left: auto; white-space: nowrap; }
.todo { display: flex; gap: 12px; padding: 9px 2px; align-items: flex-start; }
.todo + .todo { border-top: 1px solid rgba(46,46,54,.6); }
.check {
  width: 26px; height: 26px; border-radius: 7px; border: 2px solid #5A5850; background: transparent;
  flex: none; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; margin-top: 1px; color: var(--ok);
}
.check svg { width: 16px; height: 16px; }
.check.done { border-color: var(--ok); background: rgba(108,192,139,.12); }
.todo .body { flex: 1; min-width: 0; cursor: pointer; }
.todo .title { word-break: break-word; }
.todo.completed .title { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(154,151,143,.5); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 5px; font-size: 13px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--card2); border-radius: 999px; padding: 2px 8px 2px 3px; font-size: 12.5px; color: var(--text); }
.chip.plainchip { padding: 2px 8px; color: var(--muted); }
.chip.overdue { color: var(--danger); background: rgba(229,103,90,.12); }
.chip.today { color: var(--gold2); background: var(--gold-dim); }
.chip svg { width: 13px; height: 13px; }
.avatar {
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 700; color: #111; flex: none; text-transform: uppercase;
}
.avatar.lg { width: 36px; height: 36px; font-size: 14px; }
.avatar.md { width: 30px; height: 30px; font-size: 12px; }
.addtodo { color: var(--gold2); padding: 10px 2px 4px 38px; cursor: pointer; font-weight: 500; }
.completed-toggle { display: flex; align-items: center; gap: 12px; padding: 8px 2px; color: var(--muted); cursor: pointer; }
.completed-toggle .check { border-color: rgba(108,192,139,.5); }
.byline { font-size: 12.5px; color: var(--faint); margin-top: 3px; }

/* to-do detail */
.detail-grid { display: grid; grid-template-columns: 96px 1fr; gap: 12px 12px; margin: 16px 0; align-items: start; }
.detail-grid .k { color: var(--muted); font-weight: 600; font-size: 14px; text-align: right; padding-top: 2px; }
.detail-grid .v { word-break: break-word; }
.notes { white-space: pre-wrap; word-break: break-word; }
.completebtn { display: inline-flex; align-items: center; gap: 10px; border: 1.5px solid var(--line); background: transparent; border-radius: 12px; padding: 10px 14px; cursor: pointer; font-weight: 600; }
.completebtn.done { border-color: rgba(108,192,139,.5); color: var(--ok); }
.timeline { margin-top: 18px; border-top: 1px solid var(--line); }
.tl { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.tl .who { font-weight: 650; }
.tl .when { color: var(--muted); font-size: 13px; margin-left: 6px; font-weight: 400; }
.tl .txt { white-space: pre-wrap; word-break: break-word; margin-top: 4px; }
.tl.event { align-items: center; color: var(--muted); font-size: 14px; }
.tl.event .ico { width: 30px; display: flex; justify-content: center; }
.tl.event .ico svg { width: 18px; height: 18px; }
.tl.event b { color: var(--text); }

.composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 14px; }
.composer textarea { flex: 1; }

/* ---------- forms ---------- */
label.f { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
input.i, textarea.i, select.i {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 13px; outline: none;
  font-size: 16px; /* prevents iOS zoom */
}
textarea.i { min-height: 96px; resize: vertical; }
input.i:focus, textarea.i:focus, select.i:focus { border-color: var(--gold); }
input[type="date"].i { min-height: 46px; -webkit-appearance: none; }
.err { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }
.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick button {
  border: 1.5px solid var(--line); background: var(--bg2); border-radius: 999px; padding: 6px 12px 6px 6px;
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
}
.pick button.on { border-color: var(--gold); background: var(--gold-dim); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; position: relative; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--bg2) inset; }
.swatch.none { background: var(--bg2); border: 2px dashed var(--line); }
.swatch.none.on { border: 2px solid #fff; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; }

/* ---------- sheets ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100; animation: fade .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0; padding: 10px 18px calc(var(--safe-bottom) + 18px);
  animation: up .22s cubic-bezier(.2,.8,.2,1); max-width: 720px; margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet .sh-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.sheet .sh-head h2 { font-size: 19px; margin: 0; }
.sheet .menu { margin: 6px -6px 0; }
.sheet .menu button {
  width: 100%; display: flex; align-items: center; gap: 14px; background: transparent; border: 0; padding: 14px 8px;
  text-align: left; cursor: pointer; border-radius: 10px; font-size: 16px;
}
.sheet .menu button:active { background: var(--card2); }
.sheet .menu button svg { width: 20px; height: 20px; color: var(--gold); }
.sheet .menu button.danger, .sheet .menu button.danger svg { color: var(--danger); }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: rgba(22,22,26,.92); border-top: 1px solid var(--line);
  backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--faint); font-size: 11px; font-weight: 600; }
.tabbar a svg { width: 23px; height: 23px; }
.tabbar a.on { color: var(--gold); }
.tabbar .badge { position: absolute; transform: translate(12px, -10px); background: var(--danger); color: #fff; border-radius: 9px; font-size: 10px; padding: 0 5px; line-height: 16px; }
.tabbar a > span.wrap { position: relative; display: inline-flex; }

/* ---------- docs ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 14px; color: var(--muted); margin: 4px 0 8px; }
.crumbs a { color: var(--gold2); }
.fileicon { width: 46px; height: 46px; border-radius: 10px; flex: none; display: flex; align-items: center; justify-content: center; background: var(--card2); overflow: hidden; color: var(--muted); font-size: 10px; font-weight: 800; flex-direction: column; gap: 1px; }
.fileicon svg { width: 22px; height: 22px; }
.fileicon img { width: 100%; height: 100%; object-fit: cover; }
.fileicon.folder svg { width: 28px; height: 28px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 8px 0 14px; }
.photo-grid .ph { aspect-ratio: 1; background: var(--card2); border-radius: 8px; overflow: hidden; cursor: pointer; position: relative; }
.photo-grid .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }

.lightbox { position: fixed; inset: 0; background: #000; z-index: 200; display: flex; flex-direction: column; }
.lightbox .lb-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: calc(var(--safe-top) + 8px) 12px 8px; }
.lightbox .lb-top .name { flex: 1; text-align: center; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox .lb-img { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; touch-action: pinch-zoom pan-x pan-y; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble { background: var(--card); border-radius: 16px; padding: 8px 12px; word-break: break-word; }
.bubble .txt { white-space: pre-wrap; }
.msg.mine .bubble { background: #3A3122; }
.bubble .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.bubble img { display: block; max-width: 220px; max-height: 260px; border-radius: 10px; margin-top: 4px; cursor: pointer; }
.bubble .filelink { display: inline-flex; align-items: center; gap: 6px; }
.chatbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 12px calc(var(--safe-bottom) + 8px); background: rgba(22,22,26,.96); border-top: 1px solid var(--line);
}
.chatbar textarea { flex: 1; min-height: 42px; max-height: 140px; padding: 10px 12px; border-radius: 20px; }
.daysep { text-align: center; color: var(--faint); font-size: 12px; margin: 8px 0 2px; }

/* ---------- activity ---------- */
.dayhead { display: flex; align-items: center; gap: 10px; margin: 22px 0 8px; }
.dayhead .pill { background: #E9E5DB; color: #17140E; font-weight: 800; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; padding: 5px 10px; border-radius: 6px; white-space: nowrap; }
.dayhead .ln { flex: 1; height: 1px; background: var(--line); }
.act { display: flex; gap: 12px; padding: 10px 0; cursor: pointer; }
.act .time { color: var(--muted); font-size: 12.5px; }
.act .job { color: var(--gold); font-size: 13px; }
.act .line1 { word-break: break-word; }
.act .line1 b { font-weight: 650; }
.act .quote { color: var(--muted); font-size: 14px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.filters button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; font-size: 14px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.filters button.on { border-color: var(--gold); color: var(--gold2); background: var(--gold-dim); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  background: #F1EEE6; color: #17140E; padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 300;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.4); font-size: 15px;
}

/* ---------- auth ---------- */
.auth { max-width: 380px; margin: 0 auto; padding-top: 12vh; }
.brand { text-align: center; margin-bottom: 28px; }
.brand img { width: 76px; height: 76px; border-radius: 18px; }
.brand h1 { margin: 14px 0 2px; font-size: 26px; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; color: var(--gold2); }
.brand p { color: var(--muted); margin: 0; }
.install-tip { margin-top: 26px; color: var(--muted); font-size: 14px; text-align: center; }
