:root {
  --bg: #f7f7f5; --panel: #ffffff; --ink: #1f2328; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-soft: #e8efff; --error: #b42318;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }
button { font: inherit; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: #c7cbd1; }
button.link { border: 0; background: none; color: var(--muted); padding: 2px 4px; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; }

.login { display: grid; place-items: center; height: 100vh; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: 300px; display: grid; gap: 10px; }
.login h1 { font-size: 20px; margin: 0 0 6px; }
.login input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.login button { background: var(--accent); color: #fff; border-color: var(--accent); padding: 8px; }

.app { display: grid; grid-template-columns: 240px 1fr auto; height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; overflow-y: auto; display: flex; flex-direction: column; }
.brand { font-weight: 700; font-size: 16px; padding: 0 8px 12px; }
.side-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 8px 4px; }
.side nav a { display: block; padding: 5px 8px; border-radius: 6px; color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side nav a:hover { background: var(--bg); }
.side nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side nav a .del { float: right; color: var(--muted); visibility: hidden; }
.side nav a:hover .del { visibility: visible; }
.me { margin-top: auto; padding: 12px 8px 0; color: var(--muted); font-size: 13px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bar h2 { font-size: 16px; margin: 0 8px 0 0; }
.bar input { font: inherit; padding: 5px 9px; border: 1px solid var(--line); border-radius: 6px; width: 220px; }
.grow { flex: 1; }
.filters { padding: 6px 14px; display: flex; gap: 6px; flex-wrap: wrap; min-height: 0; }
.filters:empty { display: none; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.grid { flex: 1; min-height: 0; }
.ag-theme-quartz { --ag-font-size: 13px; --ag-row-height: 34px; --ag-header-height: 36px; --ag-borders: solid 1px;
  --ag-cell-horizontal-border: solid 1px #dfe3e8; --ag-header-column-border: 1px solid #dfe3e8; --ag-header-column-border-height: 100%; }
/* editable cells stay white; a formula is lavender with ƒ, a locked field grey with a lock, a lookup has ↗ */
.ag-cell.computed { background: #f6f4fc; color: #5b5675; }
.ag-cell.readonly { background: #f3f4f6; color: #6b7280; }
.h-computed .ag-header-cell-text::before { content: "ƒ"; font-style: italic; font-weight: 700; color: #8763e2; margin-right: 6px; }
.h-readonly .ag-header-cell-text::before { content: "🔒"; font-size: 10px; margin-right: 5px; }
.h-lookup .ag-header-cell-text::before { content: "↗"; color: var(--accent); font-weight: 700; margin-right: 5px; }
.ag-header-cell.h-computed { background: #f3f0fb; }
.ag-header-cell.h-readonly { background: #f1f2f4; }
.legend { margin-top: auto; padding: 14px 8px 0; font-size: 12px; color: var(--muted); line-height: 1.7; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid #d6d9de; vertical-align: -2px; margin-right: 6px; font-style: normal; }
.tag { display: inline-block; border-radius: 4px; padding: 0 6px; margin-right: 4px; line-height: 20px; font-size: 12px; }
.link-tag { background: #eef2f7; }

.panel { width: 420px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 0 16px 16px; }
.panel-head { position: sticky; top: 0; background: var(--panel); display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 15px; }
.field { padding: 7px 0; border-bottom: 1px solid #f1f2f4; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.field .lock { font-size: 11px; }
.field .val { white-space: pre-wrap; word-break: break-word; min-height: 1.2em; }
.history { font-size: 12.5px; }
.history div { padding: 5px 0; border-bottom: 1px solid #f1f2f4; }
.popover { position: fixed; right: 16px; top: 52px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; max-height: 70vh; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.08); z-index: 10; width: 280px; }
.popover label { display: block; padding: 3px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 20; }

/* option pills and the picker, after Baserow */
.pills { display: inline-flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; vertical-align: middle; }
.pill { display: inline-block; border-radius: 999px; padding: 0 10px; line-height: 22px; font-size: 13px; white-space: nowrap; }
.has-picker { padding-right: 30px; }
.chevron { display: none; position: absolute; right: 6px; top: 50%; transform: translateY(-50%); align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 4px; color: #4b5563; cursor: pointer; margin-left: 4px; }
.chevron:hover { background: #eef0f2; }
.ag-cell-focus .chevron { display: inline-flex; }
.ag-cell-focus.has-picker { border: 2px solid #5b8def !important; border-radius: 4px; }
.picker { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12); overflow: hidden; }
.picker-search svg { flex: none; display: block; }
.picker-search { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); color: #5b8def; }
.picker-search input { border: 0; outline: none; font: inherit; flex: 1; color: var(--ink); }
.picker-list { max-height: 280px; overflow-y: auto; padding: 4px 0; }
.picker-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; min-height: 36px; cursor: pointer; }
.picker-item.active { background: #f3f4f6; }
.picker-item .pill { font-size: 14px; line-height: 26px; padding: 0 12px; }
.picker-empty { display: inline-block; height: 22px; }
.picker-check { color: #5b8def; font-weight: 700; }
.picker-none { padding: 10px 12px; color: var(--muted); }

/* filter panel */
button.on { background: var(--accent-soft); border-color: #b9ccf7; color: var(--accent); }
.filters .chip { cursor: pointer; }
.filters .muted { font-size: 12px; align-self: center; }
.filter-panel { width: 640px; max-width: calc(100vw - 32px); right: auto; left: 260px; padding: 12px; }
.fp-row { display: flex; align-items: flex-start; gap: 6px; padding: 4px 0; }
.fp-lead { width: 64px; flex: none; color: var(--muted); padding-top: 6px; }
.fp-lead select { width: 64px; }
.fp-row select, .fp-row input { font: inherit; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.fp-field { width: 190px; }
.fp-op { width: 120px; }
.fp-value { flex: 1; min-width: 0; padding-top: 0; }
.fp-value input { width: 100%; }
.fp-pills { display: flex; flex-wrap: wrap; gap: 4px; padding-top: 4px; }
.fp-pill { cursor: pointer; opacity: .45; border-radius: 999px; outline-offset: 1px; }
.fp-pill.on { opacity: 1; outline: 2px solid #5b8def; }
.fp-group { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fafafa; }
.fp-del { padding-top: 6px; }
.fp-empty { padding: 4px 0 8px; }
.fp-foot { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 8px; }
.col-filter { padding: 10px 12px; width: 420px; }
.cf-title { font-weight: 600; margin-bottom: 6px; }
.cf-note { font-size: 12px; padding: 4px 0; }
.col-filter .fp-op { width: 130px; }

.link-open { cursor: pointer; }
.link-open:hover { background: #dde5f0; color: var(--accent); }
.record { position: fixed; inset: 0; background: rgba(17,24,39,.25); display: grid; place-items: center; z-index: 30; }
.record-card { background: var(--panel); border-radius: 10px; width: min(560px, calc(100vw - 32px)); max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 16px 48px rgba(0,0,0,.18); }
.record-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.record-name { flex: 1; min-width: 0; }
.record-name .muted { font-size: 12px; }
.record-head h3 { margin: 2px 0 0; font-size: 17px; word-break: break-word; }
.record-head button { font-size: 16px; }
.record-body { overflow-y: auto; padding: 4px 16px 14px; }
.val .link-tag { margin-bottom: 3px; }
.fp-value.ta { position: relative; }
.ta-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.ta-chips:not(:empty) { margin-bottom: 4px; }
.ta-chip b { margin-left: 5px; cursor: pointer; color: var(--muted); font-weight: 400; }
.ta-chip b:hover { color: var(--ink); }
.ta-list { margin-top: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.1); max-height: 260px; overflow-y: auto; }
.ta-item { padding: 6px 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ta-item.cur, .ta-item:hover { background: var(--accent-soft); }
.peers { display: flex; gap: 4px; }
.peer { width: 26px; height: 26px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; cursor: default; }
.ag-cell .peer-tag { position: absolute; top: 0; right: 0; font-size: 10px; line-height: 14px; color: #fff; padding: 0 5px; border-bottom-left-radius: 4px; pointer-events: none; z-index: 2; white-space: nowrap; }
.cell-link { color: var(--accent); text-decoration: none; }
.cell-link:hover { text-decoration: underline; }
.legend + .me { margin-top: 0; }
.file-tag { background: #fdf2e9; cursor: pointer; }
.file-tag:hover { background: #fbe3cf; }
.viewer { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: grid; place-items: center; z-index: 40; }
.viewer-card { background: var(--panel); border-radius: 10px; width: min(1000px, calc(100vw - 32px)); height: calc(100vh - 48px); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,.25); }
.viewer-head { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.viewer-head b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-head a { color: var(--accent); text-decoration: none; font-size: 13px; }
.viewer-head button { font-size: 16px; }
.viewer-body { flex: 1; min-height: 0; background: #525659; display: grid; place-items: center; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body p { color: #fff; }
.login .google { display: block; text-align: center; padding: 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); text-decoration: none; background: #fff; }
.login .google:hover { border-color: #c7cbd1; }
.people { left: 16px; right: auto; top: auto; bottom: 56px; width: 380px; }
.people-head { display: flex; flex-direction: column; padding: 4px 0 8px; border-bottom: 1px solid var(--line); }
.person { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.person .invite-url { width: 100%; font-size: 12px; }
.history .hist div { padding: 1px 0; border: 0; }
.history .hist { padding: 6px 0; border-bottom: 1px solid #f1f2f4; }
.hist s { color: #9ca3af; }
.hist .revert { font-size: 12px; padding: 2px 0; }
.hist.is-reverted { opacity: .6; }
.journal .record-card { width: min(760px, calc(100vw - 32px)); height: 80vh; }
.journal-filters { padding: 8px 16px; display: flex; gap: 8px; border-bottom: 1px solid var(--line); }
.journal-list { overflow-y: auto; padding: 0 16px 14px; }
.hist .revert { color: var(--accent, #2563eb); }
.ag-floating-bottom .ag-row { background: #f8fafc; }
.ag-floating-bottom .ag-cell { color: #6b7280; font-size: 12px; font-weight: 500; box-shadow: none; }
.ag-floating-bottom .ag-row .ag-cell .sum { white-space: nowrap; }
.ag-floating-bottom { border-top: 2px solid #dfe3e8 !important; }
.val.can-edit { cursor: text; border-radius: 6px; margin: 0 -6px; padding: 2px 6px; }
.val.can-edit:hover, .val.can-edit:focus { background: #f3f6fb; outline: none; }
.val.editing { background: none; padding: 0 6px; }
.field-input { width: 100%; font: inherit; padding: 5px 8px; border: 1px solid #93b4f5; border-radius: 6px; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
textarea.field-input { resize: vertical; }
.picker-inline { position: relative; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,.1); background: var(--panel); }
.field .lock.lk { color: #2563eb; font-weight: 700; }
.people { width: 440px; }
.person-add { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.person-add input[name=email] { flex: 1 1 100%; }
.person-add input[name=name] { flex: 1; min-width: 0; }
.person select { font-size: 12px; }
.person { flex-wrap: wrap; }
.person > div:first-child { flex: 1; min-width: 0; }
.person > div:first-child div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person > span { white-space: nowrap; flex: none; }
.form-btns { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; }
.form-btns button { text-align: left; background: var(--accent-soft); border-color: #b9ccf7; color: var(--accent); font-weight: 600; }
.form-modal .record-card { width: min(620px, calc(100vw - 32px)); max-height: 88vh; }
.form-field label { font-size: 13px; color: var(--ink); font-weight: 600; }
.form-field .req { color: var(--error); }
.form-field .hint { font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.form-field input, .form-field textarea, .form-field select { width: 100%; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.form-field input:focus, .form-field textarea:focus, .form-field select:focus, .form-pick:focus { outline: none; border-color: #93b4f5; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-pick { display: flex; align-items: center; justify-content: space-between; min-height: 34px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.form-pick .chevron { position: static; display: inline-flex; transform: none; }
.form-results { border: 1px solid var(--line); border-top: 0; border-radius: 0 0 6px 6px; max-height: 220px; overflow-y: auto; }
.form-results:empty { display: none; }
.form-result { padding: 6px 8px; cursor: pointer; }
.form-result:hover { background: var(--accent-soft); }
.form-link .link-tag { display: inline-flex; align-items: center; gap: 4px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 0 4px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:disabled { opacity: .6; }
.form-done { padding: 16px 0 4px; line-height: 1.6; }
.form-done .pills { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
