*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-900: #123f26;
  --green-700: #1b5e3a;
  --green-600: #217a49;
  --green-500: #2c9c5e;
  --green-100: #e3f4ea;
  --green-50: #f2faf5;
  --ink: #14181b;
  --muted: #6b7480;
  --line: #e4e8ec;
  --bg: #f5f7f6;
  --card: #ffffff;
  --amber: #b45309; --amber-bg: #fef3c7;
  --red: #b91c1c; --red-bg: #fee2e2;
  --blue: #1d4ed8; --blue-bg: #dbeafe;
  --grey-bg: #eef1f4;
  --mono: ui-monospace, 'Cascadia Code', Consolas, monospace;
}

html { height: 100%; }
body { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--ink); line-height: 1.5; -webkit-font-smoothing: antialiased; min-height: 100%; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 0.9rem; border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.65rem; background: #fff; color: var(--ink); width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--green-100); border-color: var(--green-500); }
label { display: block; font-size: 0.78rem; font-weight: 600; margin: 0.7rem 0 0.2rem; color: var(--ink); }
label .opt { color: var(--muted); font-weight: 400; }

/* ===== APP SHELL ===== */
.shell { display: flex; min-height: 100vh; }

aside.sidebar {
  width: 230px; flex-shrink: 0;
  background: var(--green-900);
  color: #d7e8dd;
  display: flex; flex-direction: column;
  padding: 1.2rem 0.8rem 1rem;
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 0.5rem 1.1rem; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #2c9c5e, #1b5e3a); display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; font-size: 1rem; flex-shrink: 0; }
.brand-name { font-weight: 800; font-size: 1rem; color: #fff; letter-spacing: -0.01em; line-height: 1.2; }
.brand-sub { font-size: 0.66rem; color: #8fb89e; }

.side-nav { list-style: none; display: flex; flex-direction: column; gap: 1px; }
.side-nav a { display: flex; align-items: center; gap: 10px; width: 100%; color: #c2d8ca; font-size: 0.88rem; font-weight: 500; padding: 0.52rem 0.75rem; border-radius: 8px; transition: background 0.12s, color 0.12s; }
.side-nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.side-nav a.active { background: var(--green-600); color: #fff; font-weight: 600; }
.side-nav .ico { width: 18px; text-align: center; font-size: 0.9rem; }
.side-sep { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.1em; color: #7ba58b; padding: 0.9rem 0.75rem 0.3rem; }

.clock-widget { margin-top: auto; background: rgba(255,255,255,0.06); border-radius: 10px; padding: 0.7rem 0.8rem; font-size: 0.78rem; }
.clock-widget b { color: #fff; display: block; font-size: 0.8rem; margin-bottom: 0.15rem; }
.clock-widget button { width: 100%; margin-top: 0.45rem; border: 0; border-radius: 7px; padding: 0.45rem; font-weight: 700; font-size: 0.8rem; }
.clock-widget button.on { background: var(--green-500); color: #fff; }
.clock-widget button.off { background: #e05252; color: #fff; }

.side-foot { padding: 0.7rem 0.5rem 0; font-size: 0.72rem; color: #8fb89e; }
.side-foot b { color: #fff; display: block; font-size: 0.78rem; }
.side-foot a { text-decoration: underline; cursor: pointer; }

main { flex: 1; padding: 1.4rem 1.8rem 5rem; max-width: 1250px; min-width: 0; }

/* topbar */
.topbar { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.3rem; gap: 1rem; flex-wrap: wrap; }
.topbar h1 { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.01em; }
.topbar .crumb { font-size: 0.78rem; color: var(--muted); }
.top-actions { display: flex; gap: 0.55rem; flex-wrap: wrap; align-items: center; }

/* global search */
.gsearch { position: relative; }
.gsearch input { width: 230px; }
.gsearch .results { position: absolute; top: 105%; right: 0; width: 340px; max-height: 400px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.12); z-index: 200; }
.gsearch .results a { display: block; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line); font-size: 0.85rem; }
.gsearch .results a:hover { background: var(--green-50); }
.gsearch .results .sub { display: block; font-size: 0.72rem; color: var(--muted); }
.gsearch .results .tag { font-size: 0.62rem; text-transform: uppercase; font-weight: 700; color: var(--green-600); margin-right: 0.4rem; }

/* ===== COMPONENTS ===== */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 0.48rem 0.9rem; font-size: 0.84rem; font-weight: 600; transition: border-color 0.12s, background 0.12s; color: var(--ink); display: inline-block; }
.btn:hover { border-color: var(--green-500); }
.btn.primary { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.btn.primary:hover { background: var(--green-700); }
.btn.danger { background: #fff; border-color: #f3b9b9; color: var(--red); }
.btn.sm { padding: 0.28rem 0.6rem; font-size: 0.76rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.9rem; margin-bottom: 1.4rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; }
.kpi .label { font-size: 0.72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.kpi .num { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; margin-top: 0.15rem; }
.kpi .sub { font-size: 0.76rem; margin-top: 0.1rem; color: var(--muted); }
.up { color: var(--green-600); } .down { color: var(--red); } .warn { color: var(--amber); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 1.3rem; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 0.85rem 1.2rem; border-bottom: 1px solid var(--line); gap: 0.6rem; flex-wrap: wrap; }
.panel-head h2 { font-size: 0.98rem; font-weight: 700; }
.panel-head .hint { font-size: 0.76rem; color: var(--muted); }
.panel-body { padding: 1.1rem 1.2rem; }
.panel-body.tight { padding: 0.6rem 1.2rem; }
.panel.scroll-x { overflow-x: auto; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.tbl th { text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0.6rem 1.2rem; border-bottom: 1px solid var(--line); background: #fafbfb; white-space: nowrap; }
.tbl td { padding: 0.7rem 1.2rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.rowlink { cursor: pointer; }
.tbl tbody tr.rowlink:hover { background: var(--green-50); }
.tbl td .sub { display: block; font-size: 0.74rem; color: var(--muted); }

.pill { display: inline-block; padding: 0.15rem 0.58rem; border-radius: 999px; font-size: 0.7rem; font-weight: 700; white-space: nowrap; }
.pill.green { background: var(--green-100); color: var(--green-700); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.blue { background: var(--blue-bg); color: var(--blue); }
.pill.grey { background: var(--grey-bg); color: var(--muted); }

.money { font-family: var(--mono); font-weight: 600; }
.empty { padding: 2rem 1.2rem; text-align: center; color: var(--muted); font-size: 0.88rem; }
.hint-text { font-size: 0.78rem; color: var(--muted); }

.filter-row { display: flex; gap: 0.45rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.filter-row button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 0.32rem 0.85rem; font-size: 0.78rem; font-weight: 600; }
.filter-row button.active { background: var(--green-600); color: #fff; border-color: var(--green-600); }
.filter-row input[type="search"] { width: 220px; }

/* planner */
.planner { display: grid; border-top: 1px solid var(--line); font-size: 0.78rem; min-width: 860px; }
.planner .cell { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0.5rem 0.55rem; min-height: 64px; }
.planner .head { min-height: 0; background: #fafbfb; font-weight: 700; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.planner .head.today { color: var(--green-700); background: var(--green-50); }
.planner .head .hol { color: var(--amber); font-size: 0.62rem; text-transform: none; letter-spacing: 0; margin-top: 2px; }
.planner .crew { background: #fafbfb; font-weight: 700; color: var(--ink); font-size: 0.78rem; }
.planner .crew span { display: block; font-weight: 500; font-size: 0.68rem; color: var(--muted); }
.job-block { border-radius: 7px; padding: 0.32rem 0.5rem; font-size: 0.72rem; font-weight: 600; margin-bottom: 0.3rem; border-left: 3px solid var(--green-600); background: var(--green-100); color: var(--green-900); cursor: pointer; }
.job-block .t { font-weight: 500; opacity: 0.8; }
.job-block.b { border-left-color: var(--blue); background: var(--blue-bg); color: #12336b; }
.job-block.a { border-left-color: var(--amber); background: var(--amber-bg); color: #6b3d05; }
.job-block.done { opacity: 0.55; text-decoration: line-through; }
.job-block:hover { filter: brightness(0.96); }

/* line editor (quotes/invoices) */
.line-editor { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 0.5rem; }
.line-row { display: grid; grid-template-columns: 1fr 90px 110px 110px 34px; gap: 0.5rem; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line); align-items: start; }
.line-row.head { background: #fafbfb; font-size: 0.7rem; text-transform: uppercase; font-weight: 700; color: var(--muted); padding: 0.45rem 0.7rem; }
.line-row textarea { font-size: 0.78rem; margin-top: 0.3rem; }
.line-row .del { border: 0; background: none; color: var(--red); font-size: 1rem; padding-top: 0.4rem; }
.line-totals { padding: 0.7rem 1rem; text-align: right; font-size: 0.88rem; background: var(--green-50); }
.line-totals b { font-size: 1rem; }

/* checklist */
.check-row { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.4rem 0; font-size: 0.87rem; border-bottom: 1px dashed var(--line); }
.check-row:last-child { border-bottom: 0; }
.check-row input[type="checkbox"] { width: auto; margin-top: 0.28rem; accent-color: var(--green-600); }
.check-row .who { font-size: 0.7rem; color: var(--muted); }
.check-row.done label { text-decoration: line-through; color: var(--muted); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(10,20,14,0.5); z-index: 300; display: flex; align-items: flex-start; justify-content: center; padding: 3rem 1rem; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; padding: 1.4rem 1.5rem 1.5rem; box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
.modal.wide { max-width: 860px; }
.modal h2 { font-size: 1.15rem; font-weight: 800; margin-bottom: 0.3rem; }
.modal .lead { font-size: 0.84rem; color: var(--muted); margin-bottom: 0.5rem; }
.modal-actions { display: flex; gap: 0.6rem; margin-top: 1.2rem; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.msg-err { background: var(--red-bg); color: var(--red); border-radius: 9px; padding: 0.55rem 0.8rem; font-size: 0.83rem; margin-top: 0.8rem; }
.msg-ok { background: var(--green-100); color: var(--green-700); border-radius: 9px; padding: 0.55rem 0.8rem; font-size: 0.83rem; margin-top: 0.8rem; }
.copybox { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.copybox input { font-family: var(--mono); font-size: 0.76rem; }

/* toast */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #14181b; color: #fff; font-size: 0.85rem; padding: 0.7rem 1.2rem; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 500; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* login */
.auth-back { position: fixed; inset: 0; background: var(--green-900); z-index: 400; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { background: #fff; border-radius: 16px; width: 100%; max-width: 400px; padding: 2rem; }
.auth-card .brand { padding-bottom: 0.8rem; }
.auth-card .brand-name { color: var(--ink); }
.auth-card .brand-sub { color: var(--muted); }
.auth-card h1 { font-size: 1.25rem; font-weight: 800; margin-bottom: 0.2rem; }
.auth-card p { font-size: 0.85rem; color: var(--muted); }
.auth-card button { width: 100%; margin-top: 1.2rem; border: 0; background: var(--green-600); color: #fff; font-weight: 700; font-size: 0.95rem; padding: 0.7rem; border-radius: 10px; }
.auth-card button:hover { background: var(--green-700); }

/* detail two-col */
.detail-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1.3rem; align-items: start; }
.detail-grid .side .panel { margin-bottom: 0.9rem; }

/* chat */
.chat-box { display: flex; flex-direction: column; height: 60vh; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: 0.6rem; }
.chat-msg { max-width: 78%; }
.chat-msg .bubble { background: var(--grey-bg); border-radius: 12px; padding: 0.5rem 0.8rem; font-size: 0.87rem; white-space: pre-wrap; word-break: break-word; }
.chat-msg.mine { align-self: flex-end; }
.chat-msg.mine .bubble { background: var(--green-100); }
.chat-msg .meta { font-size: 0.68rem; color: var(--muted); margin: 0.1rem 0.3rem; }
.chat-input { display: flex; gap: 0.6rem; padding: 0.8rem 1.2rem; border-top: 1px solid var(--line); }

/* photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.7rem; }
.photo-grid .ph { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.photo-grid img { width: 100%; height: 110px; object-fit: cover; display: block; cursor: pointer; }
.photo-grid .cap { font-size: 0.68rem; padding: 0.25rem 0.4rem; color: var(--muted); }
.photo-grid .del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.55); color: #fff; border: 0; border-radius: 6px; font-size: 0.7rem; padding: 0.1rem 0.4rem; }

/* status stepper for hand-holding */
.next-step { background: var(--green-50); border: 1px solid var(--green-100); border-radius: 10px; padding: 0.7rem 1rem; font-size: 0.85rem; margin-bottom: 1rem; }
.next-step b { color: var(--green-700); }

/* mobile */
.mobile-top { display: none; }
@media (max-width: 900px) {
  aside.sidebar { position: fixed; left: -240px; transition: left 0.2s; height: 100vh; }
  aside.sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,0.4); }
  .mobile-top { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 1rem; background: var(--green-900); color: #fff; position: sticky; top: 0; z-index: 90; }
  .mobile-top .burger { background: none; border: 0; color: #fff; font-size: 1.3rem; }
  .mobile-top .t { font-weight: 800; font-size: 0.95rem; }
  main { padding: 1rem 0.9rem 5rem; }
  .cards { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .gsearch input { width: 140px; }
  .gsearch .results { width: 300px; }
  .line-row { grid-template-columns: 1fr 60px 80px 80px 30px; }
  .tbl th, .tbl td { padding: 0.55rem 0.7rem; }
}
