/* Rev IT CRM: macOS-style three-pane layout. Follows the system light/dark setting. */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --accent: #0a66e4;
  --accent-text: #fff;
  --bg: #ececec;
  --window: #ffffff;
  --sidebar: rgba(234, 234, 237, 0.92);
  --sidebar-hover: rgba(0, 0, 0, 0.05);
  --sidebar-active: rgba(0, 0, 0, 0.1);
  --list: #ffffff;
  --detail: #ffffff;
  --group: #f5f5f7;
  --text: #1d1d1f;
  --muted: #86868b;
  --border: rgba(0, 0, 0, 0.1);
  --input: rgba(0, 0, 0, 0.05);
  --shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.15), 0 10px 40px rgba(0, 0, 0, 0.12);
  --ok: #1e8e3e; --ok-bg: #e6f4ea;
  --bad: #c5221f; --bad-bg: #fce8e6;
  --warn: #8a5300; --warn-bg: #fef3e0;
  --company: #3478f6; --school: #34a853; --charity: #a855f7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #0a84ff;
    --bg: #161618;
    --window: #1e1e1e;
    --sidebar: rgba(40, 40, 44, 0.94);
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(255, 255, 255, 0.12);
    --list: #232325;
    --detail: #1e1e1e;
    --group: #2a2a2d;
    --text: #f2f2f7;
    --muted: #98989d;
    --border: rgba(255, 255, 255, 0.1);
    --input: rgba(255, 255, 255, 0.08);
    --shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.12), 0 10px 40px rgba(0, 0, 0, 0.5);
    --ok: #4cd964; --ok-bg: rgba(76, 217, 100, 0.15);
    --bad: #ff6961; --bad-bg: rgba(255, 105, 97, 0.15);
    --warn: #ffb340; --warn-bg: rgba(255, 179, 64, 0.15);
  }
  .pill-customer { color: #5eaaff; }
  .pill-supplier { color: #ffb340; }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 13px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 15px; font-weight: 700; margin: 0; }
h2 { font-size: 14px; margin: 0 0 10px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; } .pre { white-space: pre-line; } .mt { margin-top: 10px; }
.icon { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
[hidden] { display: none !important; }

/* ── Window ─────────────────────────────────────────────── */
body.app { padding: 14px; height: 100vh; overflow: hidden; }
.window { display: flex; height: 100%; border-radius: 12px; overflow: hidden; background: var(--window); box-shadow: var(--shadow); }
@media (max-width: 900px) { body.app { padding: 0; } .window { border-radius: 0; } }

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar { width: 220px; flex: none; display: flex; flex-direction: column; background: var(--sidebar); backdrop-filter: blur(20px); border-right: 1px solid var(--border); }
.sidebar-brand { display: flex; align-items: center; gap: 9px; height: 52px; padding: 0 16px; font-weight: 700; font-size: 14px; }
.brand-mark { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: linear-gradient(180deg, #2f80ff, #0a5fd8); color: #fff; font-weight: 800; font-size: 13px; }
.brand-mark-lg { width: 56px; height: 56px; border-radius: 14px; font-size: 28px; margin: 0 auto 12px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
.sidebar-section { font-size: 11px; font-weight: 600; color: var(--muted); padding: 14px 8px 4px; }
.side-item { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 8px; border-radius: 6px; color: var(--text); }
.side-item:hover { background: var(--sidebar-hover); text-decoration: none; }
.side-item.active { background: var(--sidebar-active); font-weight: 600; }
.side-item .icon { color: var(--accent); }
.side-item.indent { padding-left: 22px; }
.side-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.sidebar-foot { padding: 10px 16px 14px; border-top: 1px solid var(--border); font-size: 12px; }
.side-user { margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-version { color: var(--muted); font-size: 11px; margin-top: 6px; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* ── Toolbars ───────────────────────────────────────────── */
.pane-toolbar { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; border-bottom: 1px solid var(--border); flex: none; }
.toolbar-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.toolbar-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-spacer { flex: 1; }

/* ── List pane (middle column) ──────────────────────────── */
.list-pane { width: 320px; flex: none; display: flex; flex-direction: column; background: var(--list); border-right: 1px solid var(--border); }
.list-toolbar { flex-direction: column; align-items: stretch; height: auto; padding: 12px 12px 10px; gap: 8px; }
.search-field { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px; border-radius: 7px; background: var(--input); color: var(--muted); }
.search-field:focus-within { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.search-field input { flex: 1; border: 0; background: transparent; outline: none; font: inherit; color: var(--text); padding: 0; min-width: 0; }
.item-list { flex: 1; overflow-y: auto; padding: 6px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.list-row:hover { background: var(--sidebar-hover); text-decoration: none; }
.list-row.selected { background: var(--accent); color: var(--accent-text); }
.list-row.selected .row-sub { color: rgba(255, 255, 255, 0.85); }
.list-row.inactive .row-title { opacity: 0.6; }
.row-text { display: flex; flex-direction: column; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar, .big-avatar { display: grid; place-items: center; flex: none; border-radius: 50%; color: #fff; font-weight: 600; background: var(--muted); }
.avatar { width: 30px; height: 30px; font-size: 11px; }
.type-company { background: var(--company); } .type-school { background: var(--school); } .type-charity { background: var(--charity); }
.list-empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.list-footer { padding: 8px 12px; border-top: 1px solid var(--border); display: flex; justify-content: center; }

/* Segmented control */
.segmented { display: inline-flex; padding: 2px; border-radius: 7px; background: var(--input); }
.segmented a { padding: 2px 12px; border-radius: 5px; color: var(--text); font-size: 12px; }
.segmented a:hover { text-decoration: none; }
.segmented a.on { background: var(--window); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); font-weight: 600; }

/* ── Detail pane (right) ────────────────────────────────── */
.detail-pane, .content-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--detail); }
.detail-scroll { display: flex; flex-direction: column; height: 100%; }
.detail-empty { margin: auto; color: var(--muted); font-size: 18px; font-weight: 500; }
.detail-body { flex: 1; overflow-y: auto; padding: 28px 32px 40px; max-width: 760px; width: 100%; }
.detail-head { display: flex; align-items: center; gap: 18px; margin-bottom: 24px; }
.big-avatar { width: 64px; height: 64px; font-size: 22px; }
.detail-name { font-size: 22px; font-weight: 700; margin: 0 0 6px; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.inactive-reason { margin: 6px 0 0; }
.back-link { display: none; align-items: center; gap: 2px; }
.group { background: var(--group); border-radius: 10px; padding: 4px 16px; margin-bottom: 8px; }
.group-title { font-size: 13px; margin: 12px 0 8px; }
.field { display: grid; grid-template-columns: 120px 1fr; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: 0; }
.field .label { color: var(--muted); text-align: right; }
.field .value { min-width: 0; overflow-wrap: anywhere; }
.hint { color: var(--muted); font-size: 11px; margin: 0 4px 22px; }
.notes-form textarea { width: 100%; resize: vertical; font: inherit; color: var(--text); background: var(--window); border: 1px solid var(--border); border-radius: 8px; padding: 10px; outline: none; }
.notes-form textarea:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.notes-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 12px; }
.meta { display: grid; grid-template-columns: 120px 1fr; gap: 4px 16px; color: var(--muted); font-size: 11px; margin: 20px 0 0; }
.meta dt { text-align: right; } .meta dd { margin: 0; }

/* ── Plain content pages (Xero Sync etc.) ───────────────── */
.content-scroll { flex: 1; overflow-y: auto; padding: 20px 24px 40px; }
.lead { margin: 0 0 16px; }
.card { background: var(--group); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.table-card { padding: 0; overflow-x: auto; }
.table-card .pad { padding: 14px 18px 0; margin: 0 0 8px; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.table-head h2 { margin: 0; }
.narrow { max-width: 520px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 16px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11px; font-weight: 600; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.rule-table td { padding: 7px 6px; }
.empty { padding: 24px; text-align: center; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; } .btn-row form { margin: 0; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot-ok { background: #34c759; } .dot-bad { background: #ff3b30; }

/* ── Buttons, pills, alerts ─────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--window); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06); }
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn .icon { width: 13px; height: 13px; }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-danger-outline { color: var(--bad); }
.btn-block { width: 100%; height: 34px; }
.pill { display: inline-block; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 19px; background: var(--input); color: var(--text); }
.pill-company { background: color-mix(in srgb, var(--company) 15%, transparent); color: var(--company); }
.pill-school { background: color-mix(in srgb, var(--school) 15%, transparent); color: var(--school); }
.pill-charity { background: color-mix(in srgb, var(--charity) 15%, transparent); color: var(--charity); }
.pill-customer { background: color-mix(in srgb, #0a84ff 14%, transparent); color: #0a6ad6; }
.pill-supplier { background: color-mix(in srgb, #ff9500 16%, transparent); color: #b86200; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.pill-muted { background: var(--input); color: var(--muted); }
.alert { padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--bad-bg); color: var(--bad); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }

/* ── Sign-in page ───────────────────────────────────────── */
body.plain { display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--window); border-radius: 14px; box-shadow: var(--shadow); padding: 32px 28px 22px; text-align: center; }
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card p { margin: 0 0 18px; }
.login-version { color: var(--muted); font-size: 11px; margin: 18px 0 0 !important; }

/* ── Narrow screens: one pane at a time ─────────────────── */
@media (max-width: 1000px) { .sidebar { width: 190px; } .list-pane { width: 280px; } }
@media (max-width: 760px) {
  .sidebar { display: none; }
  .list-pane { width: 100%; border-right: 0; }
  .has-selection .list-pane { display: none; }
  body:not(.has-selection) .detail-pane { display: none; }
  .back-link { display: inline-flex; }
  .detail-body { padding: 20px 16px 32px; }
  .field, .meta { grid-template-columns: 90px 1fr; }
}

/* ── People & forms (Build 1004) ────────────────────────── */
.type-person { background: linear-gradient(180deg, #a1a1a6, #7c7c80); }
.toolbar-row { display: flex; align-items: center; justify-content: space-between; }
.icon-btn { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; color: var(--text); }
.icon-btn:hover { background: var(--input); text-decoration: none; }
.detail-sub { margin: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 2px 8px; position: relative; }
.section-head h3 { font-size: 13px; margin: 0; }
.empty-note { margin: 0 4px 12px; }
.small-avatar { width: 24px; height: 24px; font-size: 10px; }
.membership { padding-top: 10px; }
.membership-head { display: flex; align-items: center; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.membership-head form { margin: 0; }
.membership-name { font-weight: 600; color: var(--text); }
.link-btn.danger { color: var(--bad); }
.people-group { padding: 4px 8px; }
.person-line { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; color: var(--text); }
.person-line + .person-line { border-top: 1px solid var(--border); border-radius: 0; }
.person-line:hover { background: var(--sidebar-hover); text-decoration: none; }

/* Inputs */
.field-input { align-items: center; padding: 6px 0; }
.field-input .label { padding-top: 0; }
.edit-form input, .membership input, .popover input, .popover select {
  width: 100%; height: 30px; padding: 0 9px; font: inherit; color: var(--text); background: var(--window);
  border: 1px solid var(--border); border-radius: 6px; outline: none;
}
.edit-form input:focus, .membership input:focus, .popover input:focus, .popover select:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.field-error { display: block; color: var(--bad); font-size: 12px; margin-top: 4px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 12px 0; }
.danger-zone { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--border); }

/* "Add to Organisation" popover */
.add-org { position: relative; }
.add-org > summary { list-style: none; }
.add-org > summary::-webkit-details-marker { display: none; }
.add-org[open] > summary { background: var(--input); }
.popover { position: absolute; right: 0; top: 34px; z-index: 10; width: 320px; padding: 14px; border-radius: 12px; background: var(--window); box-shadow: var(--shadow); }
.stack { display: block; margin-bottom: 10px; }
.stack > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.alert-info { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); }

/* ── Billing contacts (Build 1005) ──────────────────────── */
.type-generic { background: linear-gradient(180deg, #5ac8fa, #2b9bd6); }
.billing-group { padding: 4px 8px; }
.billing-line { display: flex; align-items: center; gap: 10px; padding: 8px; }
.billing-line + .billing-line { border-top: 1px solid var(--border); }
.billing-line .row-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.line-actions { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.line-actions form { margin: 0; }
.plain-link { color: inherit; }
.inline-edit { display: flex; flex: 1; gap: 6px; flex-wrap: wrap; }
.inline-edit input { flex: 1; min-width: 140px; height: 28px; padding: 0 8px; font: inherit; color: var(--text); background: var(--window); border: 1px solid var(--border); border-radius: 6px; }
.or-divider { display: flex; align-items: center; gap: 8px; margin: 6px 0 12px; color: var(--muted); font-size: 11px; }
.or-divider::before, .or-divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.push-warning { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.push-warning form { margin: 0; flex: none; }
summary.btn.disabled { opacity: 0.6; }
.popover button[disabled] { opacity: 0.5; cursor: not-allowed; }
@media (max-width: 760px) { .billing-line { flex-wrap: wrap; } .line-actions { width: 100%; justify-content: flex-end; } }

/* ── Other organisations (Build 1006) ───────────────────── */
.type-other { background: linear-gradient(180deg, #b0b0b5, #8e8e93); }
.pill-other { background: var(--input); color: var(--muted); }
.field-note { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ── New organisation (Build 1007) ──────────────────────── */
.type-picker { flex-wrap: wrap; }
.type-picker label { padding: 3px 12px; border-radius: 5px; cursor: pointer; font-size: 12px; }
.type-picker label.on { background: var(--window); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); font-weight: 600; }
.type-picker input { position: absolute; opacity: 0; pointer-events: none; }
.type-picker label:focus-within { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); }

/* ── International (Build 1008) ─────────────────────────── */
.type-international { background: linear-gradient(180deg, #30d0c6, #12a399); }
.pill-international { background: color-mix(in srgb, #12a399 15%, transparent); color: #0c8a82; }
@media (prefers-color-scheme: dark) { .pill-international { color: #4fe0d6; } }
.check-line { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check-line input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.intl-toggle { display: flex; align-items: center; gap: 10px; margin: -12px 4px 18px; }
.inline-details { display: inline-block; margin-left: 10px; position: relative; }
.inline-details > summary { list-style: none; display: inline; }
.inline-details > summary::-webkit-details-marker { display: none; }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form select, .popover select { height: 30px; padding: 0 8px; font: inherit; color: var(--text); background: var(--window); border: 1px solid var(--border); border-radius: 6px; }
.popover-left { left: 0; right: auto; }
.edit-form select { width: 100%; height: 30px; padding: 0 8px; font: inherit; color: var(--text); background: var(--window); border: 1px solid var(--border); border-radius: 6px; }

/* ── Website & domains (Build 1010) ─────────────────────── */
.web-group .field-input { align-items: start; }
.web-group .field-input .label { padding-top: 6px; }
.inline-row { display: flex; gap: 6px; align-items: center; }
.inline-row input { flex: 1; min-width: 0; height: 30px; padding: 0 9px; font: inherit; color: var(--text); background: var(--window); border: 1px solid var(--border); border-radius: 6px; outline: none; }
.inline-row input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--window); border: 1px solid var(--border); }
.chip form { margin: 0; }
.chip-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; border-radius: 50%; }
.chip-x:hover { color: var(--bad); background: var(--bad-bg); }
.suggest { margin-top: 6px; }
