:root {
  --bg: #fcfaf6;
  --sand: #f7f2ea;
  --sand-2: #efe7da;
  --line: #e6ddd0;
  --text: #1f1813;
  --muted: #6f655c;
  --ink: #12161b;
  --accent: #f76210;
  --accent-soft: #fdeadf;
  --green: #2f7d4f;
  --green-soft: #e3f1e8;
  --red: #b4372b;
  --red-soft: #f8e3e0;
  --amber: #9a6a00;
  --amber-soft: #f8eed2;
  --blue: #2e5f8a;
  --blue-soft: #e2ecf5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 24, 19, .06), 0 4px 16px rgba(31, 24, 19, .06);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: ui-serif, "New York", Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; font-family: var(--sans); }
[hidden] { display: none !important; }

/* layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--sand); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--serif); font-size: 18px; padding: 2px 8px 8px; }
.brand b { font-weight: 600; color: var(--accent); }
.menu { display: flex; flex-direction: column; gap: 1px; }
.menu .group { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.menu a { display: flex; align-items: center; justify-content: space-between; text-decoration: none; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.menu a.sub { padding-left: 22px; }
.menu a:hover { background: var(--sand-2); }
.menu a.on { background: #fff; box-shadow: var(--shadow); font-weight: 600; }
.menu .count { font-size: 12px; background: var(--accent); color: #fff; border-radius: 99px; padding: 0 7px; font-weight: 600; }
.me { margin-top: auto; font-size: 13px; color: var(--muted); padding: 8px 10px; border-top: 1px solid var(--line); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; display: flex; gap: 10px; align-items: center; padding: 12px 28px; background: rgba(252, 250, 246, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1; max-width: 520px; }
.search input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 60vh; overflow: auto; }
.search-results a { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; text-decoration: none; border-bottom: 1px solid var(--sand); }
.search-results a:hover, .search-results a.sel { background: var(--sand); }
.search-results small { color: var(--muted); }
.new-menu { position: relative; margin-left: auto; }
.pop { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 170px; padding: 6px; z-index: 30; }
.pop button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.pop button:hover { background: var(--sand); }

#view { padding: 26px 28px 80px; outline: none; max-width: 1240px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumb a { color: var(--muted); }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 9px; cursor: pointer; text-decoration: none; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #cfc3b3; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #2a3038; border-color: #2a3038; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--red); }
.btn-small { padding: 5px 10px; font-size: 13.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 20px; padding: 4px 8px; cursor: pointer; }
.link { background: none; border: 0; padding: 0; color: var(--blue); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* cards and grids */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card + .card { margin-top: 14px; }
.card h2, .card h3 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .btn { margin-left: auto; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.grid > .card + .card { margin-top: 0; }
.empty { color: var(--muted); padding: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 24px; font-family: var(--serif); margin-top: 2px; }
.stat .delta { font-size: 12.5px; color: var(--muted); }

/* lists */
.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 9px 12px; background: var(--sand); border-bottom: 1px solid var(--line); white-space: nowrap; }
.list td { padding: 10px 12px; border-bottom: 1px solid var(--sand); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr.click { cursor: pointer; }
.list tbody tr.click:hover { background: #fffdf9; }
.list .title { font-weight: 600; }
.items { list-style: none; margin: 0; padding: 0; }
.items li { padding: 9px 0; border-bottom: 1px solid var(--sand); display: flex; gap: 10px; align-items: baseline; }
.items li:last-child { border-bottom: 0; }
.items li > .grow { flex: 1; min-width: 0; }
.items a { text-decoration: none; }
.items a:hover { text-decoration: underline; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button, .tabs a { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 13px; cursor: pointer; font-size: 14px; text-decoration: none; }
.tabs .on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* pills */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--sand-2); color: var(--text); white-space: nowrap; }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.orange { background: var(--accent-soft); color: #b44408; }
.prio-high { color: var(--red); font-weight: 600; }

/* next step bar */
.next { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--ink); color: #fff; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.next .label { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: #f9a46f; }
.next .text { flex: 1; min-width: 200px; }
.next .btn { background: var(--accent); border-color: var(--accent); color: #fff; }

.steps { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: thin; }
.steps button { flex: 0 0 auto; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.steps button.done { background: var(--green-soft); color: var(--green); border-color: transparent; }
.steps button.on { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }

/* forms */
.drawer-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(18, 22, 27, .35); display: flex; justify-content: flex-end; }
.drawer { background: var(--bg); width: min(560px, 100%); height: 100%; overflow-y: auto; padding: 22px 24px 30px; box-shadow: -10px 0 40px rgba(0, 0, 0, .15); display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.drawer-head h2 { flex: 1; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: 13px; font-weight: 500; }
.field .hint { font-size: 12.5px; color: var(--muted); }
.field .err { font-size: 12.5px; color: var(--red); }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=time], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-height: 40px; font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; grid-column: 1 / -1; position: sticky; bottom: -30px; background: var(--bg); padding: 12px 0; }
.form-actions .btn-danger { margin-left: auto; }

/* lines editor */
.lines { width: 100%; border-collapse: collapse; }
.lines td, .lines th { padding: 4px; vertical-align: top; }
.lines th { font-size: 12.5px; color: var(--muted); text-align: left; font-weight: 500; }
.lines input { min-height: 36px; padding: 6px 8px; font-size: 15px; }
.lines .qty { width: 70px; }
.lines .rate { width: 120px; }
.lines .amt { width: 110px; text-align: right; padding-top: 12px; }
.totals { margin-left: auto; width: min(320px, 100%); }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-weight: 700; font-size: 17px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 12px 18px; border-left: 2px solid var(--sand-2); margin-left: 4px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--sand-2); }
.timeline li.note::before { background: var(--accent); }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline .what { white-space: pre-wrap; }

/* tours */
.tours { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.tour { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.tour .frame { aspect-ratio: 16 / 10; background: var(--ink); position: relative; }
.tour .frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.tour .poster { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #fff; border: 0; background: radial-gradient(circle at 30% 20%, #2c333b, #12161b); cursor: pointer; width: 100%; }
.tour .poster b { font-family: var(--serif); font-size: 18px; }
.tour .poster span { font-size: 13px; color: #f9a46f; }
.tour .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.tour .body .row { justify-content: space-between; }

/* calendar */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-head h2 { min-width: 170px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.cal .dow { background: var(--sand); font-size: 12px; color: var(--muted); padding: 6px 8px; }
.cal .day { background: #fff; min-height: 104px; padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.cal .day.other { background: #fbf9f5; color: #b5aba0; }
.cal .day.today .d { background: var(--accent); color: #fff; border-radius: 99px; padding: 0 6px; }
.cal .day.busy { background: #fffaf4; }
.cal .d { font-size: 12.5px; font-weight: 600; align-self: flex-start; }
.cal .ev { font-size: 12px; border-radius: 5px; padding: 2px 6px; background: var(--blue-soft); color: var(--blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 0; text-align: left; cursor: pointer; }
.cal .ev.scan { background: var(--accent-soft); color: #9c3b06; }
.cal .ev.away { background: var(--sand-2); color: var(--muted); }
.cal .ev.editing { background: var(--green-soft); color: var(--green); }
.week .day { min-height: 220px; }

/* chart */
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--red); }
.toast button { background: none; border: 0; color: #f9a46f; font-weight: 600; cursor: pointer; }

/* document preview */
.doc-preview { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 0; overflow: auto; }
.paper { width: 100%; max-width: 794px; margin: 0 auto; padding: 44px 48px; color: #1f1813; font-size: 13.5px; }

.only-phone { display: none; }

@media (max-width: 1000px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-side { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .2); }
  .side.open { transform: none; }
  .only-phone { display: flex; }
  .top { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  #new-btn { padding: 8px 12px; }
  #view { padding: 18px 16px 100px; }
  h1 { font-size: 22px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-3.stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .stats .stat { padding: 10px; }
  .stats .stat .value { font-size: 17px; }
  .stats .stat .label, .stats .stat .delta { font-size: 11.5px; }
  .form { grid-template-columns: 1fr; }
  .drawer { padding: 18px 16px 24px; padding-top: max(18px, env(safe-area-inset-top)); }
  .bottom { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: rgba(252, 250, 246, .97); border-top: 1px solid var(--line); justify-content: space-around; padding: 6px 4px max(6px, env(safe-area-inset-bottom)); backdrop-filter: blur(8px); }
  .bottom a { display: flex; flex-direction: column; align-items: center; font-size: 11px; text-decoration: none; color: var(--muted); padding: 2px 6px; min-width: 56px; }
  .bottom a span { font-size: 18px; line-height: 1.2; }
  .bottom a.on { color: var(--accent); }
  .list.responsive thead { display: none; }
  .list.responsive, .list.responsive tbody, .list.responsive tr, .list.responsive td { display: block; width: 100%; }
  .list.responsive tr { padding: 10px 12px; border-bottom: 1px solid var(--sand); }
  .list.responsive td { padding: 1px 0; border: 0; }
  .list.responsive td:empty { display: none; }
  .list.responsive td[data-label]:not(.first)::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; }
  .cal .day { min-height: 62px; padding: 3px; }
  .cal .ev { font-size: 10.5px; padding: 1px 3px; }
  .cal .dow { padding: 4px; font-size: 11px; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1.4fr auto auto; gap: 4px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--sand); }
  .lines td { padding: 0; }
  .lines td:first-child { grid-column: 1 / -1; }
  .lines .qty, .lines .rate { width: 100%; }
  .lines .amt { display: none; }
  .paper { padding: 22px 18px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* printable documents */
.paper { line-height: 1.45; }
.p-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 18px; border-bottom: 2px solid #12161b; margin-bottom: 20px; }
.p-logo { height: 46px; width: auto; display: block; }
.p-tag { font-size: 11.5px; color: #6f655c; margin-top: 6px; letter-spacing: .02em; }
.p-title { text-align: right; }
.p-kind { font-family: var(--serif); font-size: 26px; letter-spacing: .04em; }
.paper .p-kind { max-width: 340px; }
.p-num { font-weight: 700; color: #f76210; margin-top: 2px; }
.p-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; }
.p-section .p-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 6px; }
.p-label { font-size: 11px; letter-spacing: .1em; color: #6f655c; font-weight: 700; margin-bottom: 5px; }
.p-strong { font-weight: 600; }
.p-muted { color: #6f655c; font-size: 12px; }
.p-pre { white-space: pre-wrap; }
.p-kv { border-collapse: collapse; }
.p-kv td { padding: 1px 12px 1px 0; vertical-align: top; }
.p-kv .p-k { color: #6f655c; white-space: nowrap; }
.p-lines { width: 100%; border-collapse: collapse; margin: 6px 0 12px; }
.p-lines th { font-size: 11px; letter-spacing: .08em; color: #6f655c; text-align: left; border-bottom: 1px solid #1f1813; padding: 6px 8px 6px 0; }
.p-lines td { border-bottom: 1px solid #e6ddd0; padding: 8px 8px 8px 0; vertical-align: top; }
.p-lines .r, .p-sums .r { text-align: right; white-space: nowrap; }
.p-sums { margin-left: auto; min-width: 280px; border-collapse: collapse; }
.p-sums td { padding: 3px 0 3px 18px; }
.p-sums td:first-child { padding-left: 0; color: #6f655c; }
.p-grand td { font-weight: 700; font-size: 15px; border-top: 2px solid #12161b; padding-top: 8px; color: #1f1813 !important; }
.p-section { margin-top: 20px; break-inside: avoid; }
.p-section p { margin: 4px 0; }
.p-thanks { margin-top: 26px; font-family: var(--serif); font-size: 15px; }
.p-foot { margin-top: 26px; padding-top: 10px; border-top: 1px solid #e6ddd0; font-size: 10.5px; color: #6f655c; }
.p-signs { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; }
.p-line { border-bottom: 1px solid #1f1813; height: 40px; margin-bottom: 6px; }
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 16px; align-items: start; }
.doc-layout .doc-preview { position: sticky; top: 76px; }
@media (max-width: 1100px) { .doc-layout { grid-template-columns: minmax(0, 1fr); } .doc-layout .doc-preview { position: static; } }
@media (max-width: 767px) { .p-cols, .p-section .p-cols { grid-template-columns: 1fr; } .p-signs { grid-template-columns: 1fr; } .p-head { flex-direction: column; } .p-title { text-align: left; } }
