@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

@font-face {
  font-family: 'TheSeasons';
  src: url("../fonts/theseasons-reg.2bf14fe51912.otf") format('opentype');
  font-weight: normal;
  font-style: normal;
}

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

:root {
  --icon-accounts:    color(display-p3 .00 .28 1.00);
  --icon-tasks:       color(display-p3 .08 .72 .00);
  --icon-pipelines:   color(display-p3 .98 .54 .00);
  --icon-opps:        color(display-p3 .98 .04 .00);
  --icon-dashboard:   color(display-p3 .00 .62 .94);
  --icon-changelogs:  color(display-p3 .50 .50 .54);
  --icon-chat:        color(display-p3 .58 .22 .92);
  --icon-contacts:    color(display-p3 .18 .5 .75);

  --bg:             #ffffff;
  --bg-warm:        #f5f0ea70;
  --bg-subtle:      #f9fafb;
  --border:         #e8e4de;
  --border-subtle:  #f0ece6;
  --text:           #111827;
  --muted:          #6b7280;
  --faint:          #9ca3af;
  --hover:          #f0ece6;
  --surface-2:      #f0ece6;
  --danger:         #dc2626;
  --success:        #16a34a;
  --primary:        #3b82f6;
  --radius:         8px;
  --font:           'Inter', system-ui, -apple-system, sans-serif;
}

html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg-warm); color: var(--text); line-height: 1.5; }
a { color: var(--text); text-decoration: underline; }
a:hover { text-decoration: underline; }

/* ── Sidebar layout ──────────────────────────────────────── */
.app-wrap { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 196px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-warm);
  overflow: visible;
  transition: width .18s ease;
  z-index: 100;
}
.sb-collapsed .sidebar { width: 44px; overflow: hidden; }

/* Panel resize (right sidebar) */
.panel-resize {
  width: 8px; flex-shrink: 0; cursor: col-resize;
  position: relative; z-index: 101;
}
.panel-resize::after {
  content: ''; position: absolute;
  top: 0; bottom: 0; left: 3px;
  width: 2px; background: var(--border);
  transition: width .15s, background .15s, left .15s;
}
.panel-resize:hover::after,
.panel-resize.active::after {
  width: 4px; left: 2px;
  background: var(--primary);
}
.panel-resizing { cursor: col-resize; user-select: none; }
.panel-resizing .account-panel { transition: none; }
.panel-collapsed .panel-resize,
.panel-collapsed .account-panel { display: none; }
.panel-full .page,
.panel-full .panel-resize { display: none; }
.panel-full .account-panel { flex: 1; width: auto; }

/* Sidebar header */
.sidebar-header {
  display: flex; align-items: center;
  height: 44px; padding: 0 8px;
  gap: 8px; flex-shrink: 0;
}

.sidebar-toggle {
  width: 17px; height: 17px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border-subtle); cursor: pointer;
  color: var(--muted); border-radius: var(--radius);
}
.sidebar-toggle:hover { background: var(--hover); color: var(--text); }
.sidebar-toggle svg { width: 10px; height: 10px; }
.sb-collapsed .sidebar-toggle svg { transform: rotate(180deg); }

.sidebar-brand {
  font-family: 'TheSeasons', serif;
  font-size: 22px; font-weight: normal; line-height: 1;
  color: var(--text); text-decoration: none;
  white-space: nowrap; display: flex; align-items: baseline; gap: 3px;
}
.sidebar-brand:hover { text-decoration: none; color: var(--text); }
.sidebar-brand em { font-style: normal; font-family: 'TheSeasons', serif; font-size: 14px; color: var(--muted); }
.sb-collapsed .sidebar-brand { display: none; }

/* Sidebar search */
.sidebar-search-wrap {
  height: 44px; padding: 8px 8px 8px 8px;
  flex-shrink: 0; position: relative;
}
.sidebar-search-form { position: relative; }
.sidebar-search-icon {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 12px; height: 12px; pointer-events: none;
  stroke: var(--faint); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round; fill: none;
}
.sidebar-search-wrap input[type=search] {
  width: 100%; height: 28px; padding: 0 8px 0 26px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-family: var(--font);
  background: var(--bg-subtle); color: var(--text);
}
.sidebar-search-wrap input[type=search]:focus { outline: none; border-color: var(--text); background: var(--bg); }
.sidebar-search-wrap input[type=search]::placeholder { color: var(--faint); }
.sb-collapsed .sidebar-search-wrap { display: flex; align-items: center; justify-content: flex-start; padding: 0 8px; }
.sb-collapsed .sidebar-search-wrap input[type=search] { display: none; }
.sb-collapsed .sidebar-search-form { display: flex; align-items: center; justify-content: flex-start; width: 100%; height: 100%; }
.sb-collapsed .sidebar-search-icon { position: static; transform: none; stroke: var(--muted); }
.sb-collapsed .search-icon-badge {
  width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.sidebar-search-results {
  position: absolute; top: calc(100% - 8px); left: 8px;
  width: 480px; background: var(--bg); border: 1px solid var(--border);
  z-index: 200; display: none; max-height: 360px; overflow-y: auto;
}
.sidebar-search-results.open { display: block; }

/* Sidebar nav */
.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 0; }

.sidebar-link {
  display: flex; align-items: center;
  height: 30px; padding: 0 8px; gap: 7px;
  color: var(--muted); text-decoration: none;
  font-size: 12px; white-space: nowrap;
  cursor: pointer; background: none; border: none;
  width: 100%; font-family: var(--font);
}
.sidebar-link:hover { color: var(--text); background: var(--hover); text-decoration: none; }
.sidebar-link.active { color: var(--text); font-weight: 500; background: var(--surface-2); }

.link-icon {
  width: 17px; height: 17px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px; border: 1px solid transparent;
  color: var(--faint);
}
.link-icon svg {
  width: 13px; height: 13px;
  stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
  fill: none; flex-shrink: 0;
}
#nav-accounts .link-icon {
  color: var(--icon-accounts);
  background: color-mix(in display-p3, var(--icon-accounts) 22%, white);
  border-color: color-mix(in display-p3, var(--icon-accounts) 38%, white);
}
#nav-tasks .link-icon {
  color: var(--icon-tasks);
  background: color-mix(in display-p3, var(--icon-tasks) 22%, white);
  border-color: color-mix(in display-p3, var(--icon-tasks) 38%, white);
}
#nav-pipelines .link-icon {
  color: var(--icon-pipelines);
  background: color-mix(in display-p3, var(--icon-pipelines) 22%, white);
  border-color: color-mix(in display-p3, var(--icon-pipelines) 38%, white);
}
#nav-opportunities .link-icon {
  color: var(--icon-opps);
  background: color-mix(in display-p3, var(--icon-opps) 22%, white);
  border-color: color-mix(in display-p3, var(--icon-opps) 38%, white);
}
#nav-dashboard .link-icon {
  color: var(--icon-dashboard);
  background: color-mix(in display-p3, var(--icon-dashboard) 22%, white);
  border-color: color-mix(in display-p3, var(--icon-dashboard) 38%, white);
}
#nav-changelogs .link-icon {
  color: var(--icon-changelogs);
  background: color-mix(in display-p3, var(--icon-changelogs) 22%, white);
  border-color: color-mix(in display-p3, var(--icon-changelogs) 38%, white);
}
#nav-chat .link-icon {
  color: var(--icon-chat);
  background: color-mix(in display-p3, var(--icon-chat) 22%, white);
  border-color: color-mix(in display-p3, var(--icon-chat) 38%, white);
}
.sidebar-new-link .link-icon { font-size: 13px; color: var(--muted); }
.user-initial { font-size: 11px; font-weight: 600; }

.link-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sb-collapsed .link-label { display: none; }

/* Sidebar footer */
.sidebar-footer { border-top: 1px solid var(--border-subtle); padding: 6px 0; flex-shrink: 0; }

.sidebar-user-wrap { position: relative; }
.sidebar-user-btn {
  display: flex; align-items: center;
  height: 34px; padding: 0 8px; gap: 0;
  background: none; border: none; cursor: pointer;
  font-size: 13px; font-family: var(--font);
  color: var(--muted); white-space: nowrap;
  width: 100%; text-align: left;
}
.sidebar-user-btn:hover { color: var(--text); background: var(--hover); }

.sidebar-user-dropdown {
  position: absolute; bottom: calc(100% + 4px); left: 8px; right: 8px;
  background: var(--bg); border: 1px solid var(--border);
  display: none; z-index: 200; min-width: 140px;
}
.sidebar-user-dropdown.open { display: block; }
.sidebar-dropdown-header { padding: 6px 10px; font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--bg-subtle); }
.sidebar-dropdown-item { display: block; padding: 7px 10px; font-size: 13px; color: var(--text); }
.sidebar-dropdown-item:hover { background: var(--hover); text-decoration: none; }

/* Search result shared styles */
.search-result-item { padding: 6px 10px; border-bottom: 1px solid var(--border-subtle); display: block; color: var(--text); }
.search-result-item:hover { background: var(--hover); text-decoration: none; }
.search-result-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 1px; }
.search-result-type { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; }
.search-result-breadcrumb { font-size: 11px; color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-breadcrumb::before { content: '›'; margin-right: 4px; color: var(--faint); }
.search-result-date { font-size: 11px; color: var(--faint); margin-left: auto; white-space: nowrap; }
.search-result-title { font-size: 13px; font-weight: 500; }
.search-result-sub { font-size: 12px; color: var(--muted); }
.search-result-snippet { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-snippet mark { background: transparent; color: var(--text); font-weight: 600; padding: 0; }

/* Mobile top bar */
.mobile-topbar {
  display: none; position: fixed; top: 0; left: 0; right: 0;
  height: 44px; background: var(--bg-warm); border-bottom: none;
  align-items: center; gap: 10px; padding: 0 12px; z-index: 90;
}
.mobile-brand {
  font-family: 'TheSeasons', serif; font-size: 20px; color: var(--text);
  display: flex; align-items: baseline; gap: 3px;
}
.mobile-brand em { font-style: normal; font-size: 13px; color: var(--muted); }
.mobile-hamburger {
  background: none; border: none; cursor: pointer;
  color: var(--text); padding: 4px; display: flex; align-items: center;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.25); z-index: 95;
}
.sidebar-overlay.open { display: block; }

/* ── Layout ──────────────────────────────────────────────── */
.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-warm); }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex-shrink: 0;
  min-height: 48px;
  gap: 12px;
  background: var(--bg-warm);
}
.topbar-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.topbar-title svg {
  width: 16px; height: 16px;
  stroke: var(--muted); fill: none;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.content-row { display: flex; flex: 1; min-height: 0; gap: 8px; padding: 0 8px 8px; }
.page {
  flex: 1; min-width: 0; padding: 20px 24px; overflow-y: auto;
  background: var(--bg); border-radius: var(--radius);
}
.page-header { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.page-title { font-size: 14px; font-weight: 600; color: var(--text); }

/* ── Toolbar ─────────────────────────────────────────────── */
.toolbar { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { width: 200px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px; font-family: var(--font); font-weight: 500;
  cursor: pointer; border-radius: var(--radius);
  white-space: nowrap; line-height: 1.4; text-decoration: none;
}
.btn:hover { background: var(--hover); text-decoration: none; color: var(--text); border-color: var(--border); }
.btn-primary { background: var(--text); color: #fff; border-color: var(--text); }
.btn-primary:hover { background: #374151; border-color: #374151; color: #fff; }
.btn-danger { background: var(--bg); color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: var(--bg-subtle); border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-secondary { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--hover); border-color: #d1d5db; text-decoration: none; color: var(--text); }
.btn-ghost { background: none; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--hover); border-color: var(--border); color: var(--text); text-decoration: none; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 10px; }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=date], input[type=search], select, textarea {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  color-scheme: light dark;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text); }
input[readonly], select[disabled] { background: var(--bg-subtle); color: var(--muted); }
textarea { height: auto; padding: 6px 8px; resize: vertical; min-height: 64px; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr;                     gap: 8px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr;                gap: 8px; }
.form-row-4 { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr;            gap: 8px; }
.form-row-addr { display: grid; grid-template-columns: 3fr 2fr 1fr 1fr 1fr 1fr; gap: 8px; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 2px; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 9px 14px;
  font-size: 12px; font-weight: 500;
  color: var(--muted); background: transparent;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer; user-select: none;
  letter-spacing: .02em;
}
th:hover { color: var(--text); }
th a { color: inherit; text-decoration: none; display: block; margin: -9px -14px; padding: 9px 14px; }
th a:hover { color: var(--text); }
td { padding: 9px 14px; vertical-align: middle; height: 46px; }
td a { text-decoration: none; color: var(--text); }
td a:hover { color: var(--primary); text-decoration: none; }
tbody tr { border-radius: var(--radius); }
tbody tr td:first-child { border-radius: var(--radius) 0 0 var(--radius); }
tbody tr td:last-child  { border-radius: 0 var(--radius) var(--radius) 0; }

/* ── Page breadcrumb (form headers) ─────────────────────── */
.page-breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.page-breadcrumb a { color: var(--muted); }
.page-breadcrumb a:hover { color: var(--text); }
tbody tr { border-bottom: 1px solid var(--border-subtle); }
tbody tr:last-child { border-bottom: none; }
tbody tr { border-left: 2px solid transparent; }
tbody tr:hover { border-left-color: var(--text); }
.tr-link { cursor: pointer; }
.table-filter { display: flex; gap: 6px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.table-filter input[type=search] { width: 220px; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid;
  border-radius: var(--radius);
  font-size: 11px; font-weight: 500;
  white-space: nowrap;
}
.badge-green  { color: var(--success); border-color: #86efac; background: none; }
.badge-blue   { color: #1d4ed8; border-color: #93c5fd; background: none; }
.badge-yellow { color: #92400e; border-color: #fcd34d; background: none; }
.badge-red    { color: var(--danger); border-color: #fca5a5; background: none; }
.badge-gray   { color: var(--muted); border-color: var(--border); background: none; }
.badge-purple { color: #6d28d9; border-color: #c4b5fd; background: none; }
.badge-teal   { color: #0f766e; border-color: #5eead4; background: none; }

/* ── Tag picker ──────────────────────────────────────────── */
.tag-picker {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px;
  font-size: 12px; cursor: pointer; user-select: none;
  background: var(--surface-2); transition: background .1s, border-color .1s;
}
.tag-chip input[type="checkbox"] { display: none; }
.tag-chip.selected, .tag-chip:has(input:checked) {
  background: #dbeafe; border-color: #93c5fd; color: #1d4ed8;
}
.tag-new-input {
  border: 1px dashed var(--border); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; width: 120px;
  background: transparent; outline: none;
}
.tag-new-input:focus { border-color: var(--primary); }

/* ── Markdown body ───────────────────────────────────────── */
.markdown-body { font-size: 13px; line-height: 1.55; }
.markdown-body p { margin: 0 0 .5em; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body ul, .markdown-body ol { margin: 0 0 .5em; padding-left: 1.5em; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin: .75em 0 .35em; font-size: 1em; font-weight: 600;
}
.markdown-body h1 { font-size: 1.25em; }
.markdown-body h2 { font-size: 1.15em; }
.markdown-body code {
  background: var(--surface-2); padding: 1px 4px; border-radius: 3px; font-size: 12px;
}
.markdown-body pre {
  background: var(--surface-2); padding: 8px 10px; border-radius: var(--radius);
  overflow-x: auto; margin: .5em 0;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  border-left: 3px solid var(--border); margin: .5em 0; padding: 2px 10px; color: var(--muted);
}
.markdown-body table { border-collapse: collapse; margin: .5em 0; }
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border); padding: 4px 8px; font-size: 12px;
}
.markdown-body a { color: var(--primary); }
.markdown-body a.chat-panel-link { cursor: pointer; text-decoration: underline dotted; }
.markdown-body a.chat-panel-link .chat-account-thumb {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-right: 3px;
  position: relative;
  top: -1px;
}
.markdown-body a.chat-panel-link .chat-account-thumb img {
  width: 16px;
  height: 16px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
  display: block;
}
.markdown-body a.chat-panel-link .chat-account-thumb--placeholder {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-2);
  display: inline-block;
}

/* ── Note cards ──────────────────────────────────────────── */
.note-list { display: flex; flex-direction: column; gap: 8px; }
.note-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); overflow: hidden;
  cursor: pointer; user-select: none;
}
.note-card:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.note-card-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 0;
}
.note-card-body {
  position: relative; padding: 0 14px 12px;
}
.note-card.overflowing .note-card-body { padding-bottom: 4px; }
.note-card-preview {
  max-height: calc(1.55em * 6 + .5em); overflow: hidden;
}
.note-card-fade {
  height: 3.5em; margin-top: -3.5em; position: relative; z-index: 1;
  background: linear-gradient(to bottom, transparent 0%, var(--bg) 90%);
  pointer-events: none; display: none;
}
.note-view-more {
  display: none; text-align: left;
  padding: 6px 0 12px; font-size: 12px; color: var(--primary);
  letter-spacing: .02em; cursor: pointer;
}
.note-view-more:hover { text-decoration: underline; }
.note-card.overflowing .note-card-fade { display: block; }
.note-card.overflowing .note-view-more { display: block; }
.note-card.overflowing { cursor: pointer; }
.note-card:not(.overflowing) { cursor: default; user-select: text; }
.note-card.expanded .note-card-body { display: none; }
.note-card-full {
  display: none; padding: 0 14px 14px;
  user-select: text; cursor: text;
}
.note-card.expanded .note-card-full { display: block; }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 16px; gap: 0; }
.tab {
  padding: 6px 14px;
  font-size: 13px; font-weight: 500;
  color: var(--muted); cursor: pointer;
  border: none; background: none;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--text); }
a.tab { text-decoration: none; display: inline-block; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Field value (read-only display) ─────────────────── */
.field-value {
  padding: 5px 8px;
  font-size: 13px;
  color: var(--text);
  min-height: 30px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.4;
}

/* ── Dialogs ─────────────────────────────────────────────── */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0; max-width: 540px; width: 94vw;
  max-height: 90vh; overflow-y: auto;
}
dialog::backdrop { background: rgba(0,0,0,.3); }
.dialog-header {
  padding: 10px 14px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 600; color: var(--text);
  position: sticky; top: 0; z-index: 1;
}
.dialog-body { padding: 14px; }
.dialog-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border); background: var(--bg-subtle);
  display: flex; justify-content: flex-end; gap: 6px;
  position: sticky; bottom: 0;
}
.dialog-close { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); line-height: 1; padding: 2px 4px; }
.dialog-close:hover { color: var(--text); }

/* ── Kanban ──────────────────────────────────────────────── */
.kanban { display: flex; gap: 0; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.kanban-col { flex: 0 0 260px; border-right: 1px solid var(--border); border-top: 1px solid var(--border); }
.kanban-col:last-child { border-right: none; }
.kanban-col-header { padding: 10px 14px; font-size: 12px; font-weight: 600; color: var(--faint); display: flex; justify-content: space-between; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.kanban-col-body { padding: 0 10px 10px; min-height: 48px; display: flex; flex-direction: column; gap: 6px; }
.kanban-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 11px 13px; cursor: grab; }
.kanban-card:hover { border-color: var(--text); }
.kanban-card-ghost { opacity: .35; background: var(--hover); border-radius: 8px; }
.kanban-card-dragging { opacity: .9; box-shadow: 0 4px 16px rgba(0,0,0,.12); cursor: grabbing; border-radius: 8px; }
.kanban-col-body.sortable-over { background: var(--hover); border-radius: 8px; }
.kanban-card-name { font-size: 13px; font-weight: 600; margin-bottom: 8px; line-height: 1.35; }
.kanban-card-fields { display: flex; flex-direction: column; gap: 5px; }
.kanban-card-field { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.kanban-field-icon { flex-shrink: 0; color: var(--faint); display: flex; align-items: center; }
.kanban-col--slim { flex: 0 0 40px; border-right: 1px solid var(--border); }
.kanban-col--slim .kanban-col-header { flex-direction: column; align-items: center; justify-content: flex-start; padding: 8px 4px; gap: 6px; }
.kanban-col--slim .kanban-col-count { font-size: 13px; font-weight: 700; color: var(--text); }
.kanban-col--slim .kanban-col-body { min-height: 24px; padding: 2px; }
.kanban-col-name-slim { font-size: 10px; writing-mode: vertical-rl; transform: rotate(180deg); color: var(--faint); text-transform: uppercase; letter-spacing: .04em; overflow: hidden; max-height: 100px; text-overflow: ellipsis; white-space: nowrap; }
.kanban-col-body { max-height: calc(100vh - 220px); overflow-y: auto; }
.kanban-wrap { display: flex; align-items: stretch; gap: 4px; }
.kanban { flex: 1; min-width: 0; }
.kanban-arrow { flex-shrink: 0; width: 32px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; font-size: 20px; color: var(--muted); transition: color .15s, background .15s, opacity .15s; }
.kanban-arrow:hover { color: var(--text); background: var(--hover); }
.kanban-jumpbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; padding: 0 2px; }
.kanban-jump-pill { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); background: none; border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; cursor: pointer; white-space: nowrap; }
.kanban-jump-pill:hover { color: var(--text); border-color: var(--text); }

/* ── Section heading ─────────────────────────────────────── */
.section-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--faint);
  margin: 16px 0 8px;
  padding-bottom: 4px; border-bottom: 1px solid var(--border);
}

/* ── Alert ───────────────────────────────────────────────── */
.alert { padding: 7px 10px; border: 1px solid; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.alert-danger { color: var(--danger); border-color: #fca5a5; background: var(--bg-subtle); }

/* ── Login ───────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg-subtle); }
.login-card { width: 340px; background: var(--bg); border: 1px solid var(--border); padding: 24px; }
.login-title { font-size: 15px; font-weight: 600; text-align: center; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 13px; text-align: center; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 14px; }

/* ── Misc ────────────────────────────────────────────────── */
.text-muted  { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.flex  { display: flex; }
.gap-1 { gap: 6px; }
.ml-auto { margin-left: auto; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--muted); font-size: 13px; border: 1px dashed var(--border); margin-top: 8px; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--text); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row td { text-align: center; padding: 20px; color: var(--muted); }

/* ── Toast ───────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 4px; z-index: 999; }
.toast { padding: 7px 12px; border: 1px solid; font-size: 13px; font-weight: 500; animation: slideIn .15s ease; max-width: 320px; border-radius: var(--radius); background: var(--bg); display: flex; align-items: center; gap: 6px; }
.toast-icon { flex-shrink: 0; }
.toast-msg { flex: 1; }
.toast-close { background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1; padding: 0 0 0 4px; color: inherit; opacity: .5; flex-shrink: 0; }
.toast-close:hover { opacity: 1; }
.toast-success { color: var(--success); border-color: #86efac; }
.toast-error   { color: var(--danger); border-color: #fca5a5; }
@keyframes slideIn { from { transform: translateX(100%); opacity:0; } to { transform:translateX(0); opacity:1; } }

/* ── Pagination ──────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 12px; }
.pagination a, .pagination button { padding: 3px 8px; border: 1px solid var(--border-subtle); background: transparent; cursor: pointer; font-size: 12px; font-family: var(--font); border-radius: var(--radius); color: var(--muted); text-decoration: none; }
.pagination a:hover, .pagination button:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.pagination button.active { background: var(--text); color: #fff; border-color: var(--text); }
.pagination button:disabled { opacity: .35; cursor: default; }

/* ── Account header ──────────────────────────────────────── */
.account-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.account-thumb { width: 40px; height: 40px; border: 1px solid var(--border); background: var(--bg-subtle); object-fit: cover; }
.account-thumb-placeholder { width: 40px; height: 40px; border: 1px solid var(--border); background: var(--bg-subtle); display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 14px; }

/* ── Detail grid ─────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail-field label { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; font-weight: 600; }
.detail-field .val { font-size: 13px; }

/* ── Mobile card layout for tables ──────────────────────── */
.mobile-label { display: none; }

/* ── Revenue tier ────────────────────────────────────────── */
.rev-tier { font-size: 12px; color: var(--muted); white-space: nowrap; }
.rev-tier .rev-sign { color: var(--text); margin-right: 1px; }

/* ── Contacts expand ─────────────────────────────────────── */
td.contacts-td { cursor: pointer; }
.contacts-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: none; cursor: pointer;
  padding: 0; font-family: var(--font); font-size: 12px;
  color: var(--muted);
}
.contacts-count { font-size: 12px; font-weight: 600; color: var(--text); min-width: 8px; }
.contacts-toggle:hover .contacts-count { color: var(--text); }

.contacts-badge {
  width: 14px; height: 14px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.contacts-badge svg {
  stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round; fill: none;
}

.contacts-cell { display: inline-flex; align-items: center; gap: 6px; }

.contacts-inline {
  display: inline-block;
  white-space: nowrap;
  font-size: 13px; vertical-align: middle;
  visibility: hidden;
}
.contacts-cell.open .contacts-inline { visibility: visible; }
.contacts-cell.open .contacts-badge .pm-v { display: none; }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — MID-SIZE (≤ 1100px): collapse wide grids
   ══════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .form-row-4    { grid-template-columns: 1fr 1fr; }
  .form-row-addr { grid-template-columns: 1fr 1fr; }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 768px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }

  /* Mobile top bar */
  .mobile-topbar { display: flex; }

  /* Sidebar: off-canvas overlay */
  .app-wrap { display: block; padding-top: 44px; }

  .sidebar {
    position: fixed; top: 0; left: 0;
    height: 100vh; width: 220px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    overflow-y: auto; overflow-x: hidden;
    z-index: 100;
  }
  .sidebar.mobile-open { transform: translateX(0); }

  /* Reset collapsed state on mobile — sidebar always appears full */
  .sb-collapsed .sidebar { width: 220px; overflow-y: auto; overflow-x: hidden; }
  .sb-collapsed .sidebar-brand { display: flex; }
  .sb-collapsed .link-label { display: block; }
  .sb-collapsed .sidebar-search-wrap { display: block; }
  .sb-collapsed .sidebar-toggle svg { transform: none; }

  /* Page layout */
  .page { padding: 14px 12px; }
  .page-header { flex-wrap: wrap; gap: 8px; }

  /* Forms: stack columns */
  .form-row, .form-row-3, .form-row-4, .form-row-addr { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }

  /* Tabs: horizontal scroll */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; gap: 0; }
  .tab { flex-shrink: 0; padding: 8px 12px; }

  /* Toolbar / filters */
  .table-filter, .toolbar { flex-direction: column; align-items: stretch; }
  .table-filter form, .toolbar form { flex-direction: column !important; align-items: stretch !important; }
  .table-filter input[type=search], .toolbar input[type=search] { width: 100% !important; }
  .table-filter select { width: 100%; }

  /* Pagination */
  .pagination { justify-content: center; gap: 6px; }

  /* Buttons: bigger touch targets */
  .btn { padding: 7px 12px; min-height: 36px; }
  .btn-sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }

  /* Toast: full width on mobile */
  #toast-container { left: 10px; right: 10px; bottom: 10px; }
  .toast { max-width: 100%; }

  /* Login */
  .login-card { width: 100%; max-width: 340px; margin: 0 16px; }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — PHONE (≤ 480px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .page { padding: 10px 8px; }
  .page-title { font-size: 14px; }

  /* Tables → card layout */
  .table-wrap.responsive-cards table thead { display: none; }
  .table-wrap.responsive-cards table,
  .table-wrap.responsive-cards table tbody,
  .table-wrap.responsive-cards table tr,
  .table-wrap.responsive-cards table td {
    display: block; width: 100%;
  }
  .table-wrap.responsive-cards table tr {
    border: 1px solid var(--border);
    margin-bottom: 8px;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: var(--radius);
  }
  .table-wrap.responsive-cards table tr:hover td { background: transparent; }
  .table-wrap.responsive-cards table td {
    border-bottom: none;
    padding: 2px 0;
    height: auto;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .table-wrap.responsive-cards table td:empty { display: none; }
  .table-wrap.responsive-cards .mobile-label {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: .04em;
    min-width: 72px;
    flex-shrink: 0;
  }
  /* First cell in card = primary row */
  .table-wrap.responsive-cards table td:first-child {
    font-weight: 500;
    padding-bottom: 4px;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--border-subtle);
  }
  /* Action buttons in card */
  .table-wrap.responsive-cards table td:last-child {
    padding-top: 6px;
    margin-top: 2px;
    border-top: 1px solid var(--border-subtle);
    flex-wrap: wrap;
  }
  .table-wrap.responsive-cards .loading-row {
    display: table-cell !important;
    text-align: center;
  }

  /* Account header compact */
  .account-thumb, .account-thumb-placeholder { width: 32px; height: 32px; }
  .account-header { gap: 8px; }

  /* Dialog full-screen on phone */
  dialog { max-width: 100%; width: 100%; max-height: 100vh; margin: 0; position: fixed; top: 0; left: 0; }

  /* Kanban */
  .kanban-card { padding: 8px 10px; }
}

/* ── Account Panel (permanent right column) ─────────────── */
.account-panel {
  width: var(--panel-width, 500px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Panel header — close btn, avatar, name, subtitle */
.account-panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 20px 12px 8px;
  gap: 10px;
  flex-shrink: 0;
}
.account-panel-close {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: var(--radius);
  cursor: pointer; color: var(--faint); flex-shrink: 0;
}
.account-panel-close:hover { background: var(--hover); color: var(--text); }
.account-panel-close svg { width: 14px; height: 14px; }
#panel-expand, #panel-shrink { margin-left: auto; }
.panel-header-identity {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
}
.panel-header-avatar {
  width: 36px; height: 36px; border-radius: 4px; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; overflow: hidden;
}
.panel-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.panel-header-text { min-width: 0; }
.panel-header-name {
  font-size: 15px; font-weight: 600; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel-header-sub {
  font-size: 11px; color: var(--muted); line-height: 1.3;
}

.account-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Panel empty state */
.panel-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--faint);
  font-size: .85rem;
  text-align: center;
  padding: 2rem;
}
.panel-progress {
  height: 2px;
  background: transparent;
  position: relative;
  flex-shrink: 0;
}
.panel-progress.active {
  background: var(--border);
}
.panel-progress.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 30%;
  background: var(--primary);
  border-radius: 1px;
  animation: panel-progress 0.8s ease-in-out infinite;
}
@keyframes panel-progress {
  0%   { left: 0; width: 30%; }
  50%  { left: 40%; width: 40%; }
  100% { left: 100%; width: 0%; }
}
.panel-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
  flex-wrap: wrap;
  width: 100%;
}
.panel-breadcrumb:empty { display: none; }
#panel-breadcrumb-bar:empty { display: none; }
#panel-breadcrumb-bar { width: 100%; }
.panel-breadcrumb a { color: var(--primary); cursor: pointer; }
.panel-breadcrumb a:hover { text-decoration: underline; }
.panel-breadcrumb-sep { color: var(--faint); }
.panel-breadcrumb-current { color: var(--text); font-weight: 500; }

/* Panel tabs — button-style like Twenty */
.panel-tabs {
  display: flex;
  flex-shrink: 0;
  padding: 4px 12px;
  gap: 2px;
  background: var(--bg);
  align-items: center;
  position: relative;
  z-index: 2;
  border-bottom: 1px solid var(--border-subtle);
}
.panel-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  font-size: 12px;
  white-space: nowrap;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  border: none;
  border-bottom: 2px solid transparent;
  flex-shrink: 0;
  background: none;
}
.panel-tab:hover { color: var(--text); text-decoration: none; }
.panel-tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
}
.panel-tabs-more {
  padding: 6px 8px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  background: none;
  border: none;
  flex-shrink: 0;
  position: relative;
}
.panel-tabs-more:hover { color: var(--text); }
.panel-tabs-overflow {
  display: none;
  position: absolute;
  right: 0; top: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  z-index: 10;
  min-width: 140px;
  padding: 4px;
}
.panel-tabs-overflow.open { display: block; }
.panel-tabs-overflow .panel-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-bottom: none;
  border-radius: var(--radius);
  width: 100%;
  text-align: left;
}
.panel-tabs-overflow .panel-tab:hover { background: var(--hover); }
.panel-tabs-overflow .panel-tab.active { font-weight: 600; }

/* Chat shortcut — pushed to the far right of the tab bar */
.panel-tab-chat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background .15s, color .15s;
}
.panel-tab-chat:hover { background: var(--hover); color: var(--text); text-decoration: none; }

/* Panel chat tab — iframe fills the panel body */
.account-panel-body:has(.panel-chat-wrap) {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-chat-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.panel-chat-iframe {
  flex: 1;
  border: 0;
  width: 100%;
  min-height: 0;
}

/* Embedded "New chat" button inside the input area */
.chat-new-btn-embedded {
  width: 100%;
  margin-bottom: 6px;
  font-size: 12px;
}

/* Panel content area */
.panel-content { padding: 0; }

/* ── Panel widget (collapsible sections) ─────────── */
.pw {
  border-bottom: 1px solid var(--border-subtle);
}
.pw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  user-select: none;
}
.pw-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.pw-toggle {
  color: var(--faint);
  transition: transform .15s;
}
.pw.collapsed .pw-toggle { transform: rotate(-90deg); }
.pw.collapsed .pw-body { display: none; }
.pw-body { padding: 0 16px 10px; }
.pw-actions {
  display: flex; gap: 4px; align-items: center;
}
.pw-actions .pw-btn {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: var(--radius);
  cursor: pointer; color: var(--muted);
}
.pw-actions .pw-btn:hover { background: var(--hover); color: var(--text); }

/* ── Panel field rows (icon | label | value) ─────── */
.pf {
  display: flex;
  align-items: baseline;
  padding: 5px 0;
  gap: 8px;
  font-size: 12px;
  min-height: 28px;
}
.pf-icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  position: relative; top: 1px;
}
.pf-icon svg { width: 14px; height: 14px; stroke-width: 1.6; }
.pf-label {
  width: 90px;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pf-value {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  white-space: normal;
  word-break: break-word;
}
.pf-value a { color: var(--text); }
.pf-value a:hover { color: var(--primary); }
.pf-empty { color: var(--faint); }

/* ── Description clamp ── */
.desc-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.desc-clamp.desc-expanded {
  -webkit-line-clamp: unset;
}
.desc-toggle {
  background: none;
  border: none;
  padding: 0;
  margin-top: 2px;
  font-size: 11px;
  color: var(--primary);
  cursor: pointer;
}

/* ── Inline-edit toggle (.pw-editing) ────────────── */
.pw .pf-input        { display: none; }
.pw .pf-edit-only    { display: none; }
.pw .pw-save-btn     { display: none; }
.pw.pw-editing .pf-input        { display: block; }
.pw.pw-editing .pf-display      { display: none; }
.pw.pw-editing .pf-edit-only    { display: flex; }
.pw.pw-editing .pw-save-btn     { display: flex; }
.pw.pw-editing .pw-edit-toggle  { color: var(--primary); }
.pw.pw-editing > .pw-body {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 0 15px 9px;
}

/* Ghost inputs — borderless, blend with the panel */
.pf-value .pf-input {
  width: 100%;
  font-size: 12px;
  padding: 1px 0;
  border: none;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  box-sizing: border-box;
  background: transparent;
  color: var(--text);
  height: auto;
  line-height: 1.4;
  transition: border-color .15s;
}
.pf-value select.pf-input {
  padding: 1px 0;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l3 3 3-3' stroke='%23999' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
  padding-right: 14px;
  cursor: pointer;
}
.pf-value textarea.pf-input {
  padding: 1px 0;
  resize: vertical;
  min-height: 36px;
  line-height: 1.4;
}
.pf-value .pf-input:hover {
  border-bottom-color: var(--border);
}
.pf-value .pf-input:focus {
  outline: none;
  border-bottom-color: var(--primary);
}
.pw.pw-editing .tag-picker.pf-input {
  display: flex;
  border-bottom: none;
}

/* ── Panel chips (for related records) ───────────── */
.p-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: var(--hover);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  margin: 2px 2px 2px 0;
}
.p-chip:hover { background: var(--surface-2); text-decoration: none; }
.p-chip-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Panel footer bar ────────────────────────────── */
.panel-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  background: var(--bg);
}

/* ── Panel cards (for notes, activity etc) ───────── */
.panel-card {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.panel-card:last-child { border-bottom: none; }
.panel-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.panel-card-title {
  font-weight: 500;
  font-size: 12px;
}
.panel-card-meta {
  font-size: 11px;
  color: var(--muted);
}
.panel-card-body {
  font-size: 12px;
  margin-top: 3px;
  color: var(--muted);
}

/* Tablet: narrow panel */
@media (max-width: 1100px) {
  .account-panel { width: 360px; }
  .pf-label { width: 72px; }
}
/* Mobile: hide panel */
@media (max-width: 768px) {
  .account-panel { display: none; }
}

/* ── Chat page ───────────────────────────────────────────── */
/* Let .page hand off full height to the chat layout */
.page:has(.chat-page) {
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-thread-container {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.chat-thread {
  height: 100%;
  overflow-y: auto;
  padding: 24px 32px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Scroll-to-bottom button */
.chat-scroll-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  transition: color .15s, box-shadow .15s;
}
.chat-scroll-btn:hover { color: var(--text); box-shadow: 0 3px 12px rgba(0,0,0,.15); }

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
  user-select: none;
}
.chat-empty-hint { font-size: .8rem; color: var(--faint); }

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 16px;
}
.chat-suggestion-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: .78rem;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.chat-suggestion-chip:hover { background: var(--hover); border-color: var(--border-subtle); }

/* Messages */
.chat-message {
  display: flex;
  max-width: 720px;
}
.chat-message--user {
  align-self: flex-end;
  flex-direction: column;
  align-items: flex-end;
}
.chat-message--assistant {
  align-self: flex-start;
  flex-direction: column;
}

.chat-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: .85rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-message--user .chat-bubble {
  background: var(--text);
  color: var(--bg);
  border-bottom-right-radius: 3px;
}
.chat-message--assistant .chat-bubble {
  background: var(--surface-2);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

/* Action buttons — below the assistant bubble */
.chat-actions {
  display: flex;
  gap: 2px;
  margin-top: 3px;
  opacity: 0.35;
  transition: opacity .15s;
}
.chat-message--assistant:hover .chat-actions,
.chat-actions:focus-within { opacity: 1; }
.chat-copy-btn {
  display: inline-flex;
  align-items: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.chat-copy-btn:hover { background: var(--hover); color: var(--text); }
.chat-copy-btn.copied { color: var(--success, #4caf50); }
.chat-token-count {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  margin-left: auto;
  padding: 3px 2px;
}

/* User message edit button */
.chat-user-actions {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  opacity: 0;
  transition: opacity .15s;
}
.chat-message--user:hover .chat-user-actions { opacity: 1; }
.chat-edit-btn {
  display: inline-flex;
  align-items: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.chat-edit-btn:hover { background: var(--hover); color: var(--text); }

/* Code block copy header */
.chat-code-block {
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: .8rem;
}
.chat-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.chat-code-lang {
  font-size: 11px;
  color: var(--muted);
  text-transform: lowercase;
}
.chat-code-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font);
  transition: background .15s, color .15s;
}
.chat-code-copy:hover { background: var(--hover); color: var(--text); }
.chat-code-block pre { margin: 0; border-radius: 0; border: none; }

/* Error bubble */
.chat-error-bubble { color: var(--danger, #e53935); background: var(--surface-2); }

/* Stop button state */
.chat-send-btn.is-stop { background: var(--danger, #e53935); border-color: var(--danger, #e53935); }

/* Thinking indicator */
.chat-thinking {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  min-height: 36px;
}
.chat-thinking span {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--faint);
  border-radius: 50%;
  animation: chat-bounce 1.2s infinite ease-in-out;
}
.chat-thinking span:nth-child(2) { animation-delay: .2s; }
.chat-thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .5; }
  40%            { transform: scale(1);  opacity: 1;   }
}

/* Tool indicator */
.chat-message--tool {
  align-self: flex-start;
}
.chat-tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--text-faint);
  background: var(--surface);
  border: 1px solid var(--border);
}
.chat-tool-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--faint);
  border-top-color: var(--text-faint);
  border-radius: 50%;
  animation: chat-spin .8s linear infinite;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }
.chat-tool-done { font-weight: 600; color: var(--success, #4caf50); }
.chat-tool-err  { font-weight: 600; color: var(--danger, #e53935); }

/* Proposal confirmation cards */
.chat-proposal {
  background: var(--surface-2, var(--surface));
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  max-width: 500px;
  font-size: .83rem;
  transition: opacity .2s;
}
.chat-proposal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .8rem;
}
.chat-proposal-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hover);
  border-radius: 4px;
  font-size: .7rem;
  flex-shrink: 0;
}
.chat-proposal-name { color: var(--text); }
.chat-proposal-body {
  padding: 10px 14px 9px;
  border-bottom: 1px solid var(--border);
}
.chat-proposal-title {
  font-weight: 600;
  font-size: .88rem;
  color: var(--text);
  line-height: 1.3;
}
.chat-proposal-subtitle {
  font-size: .78rem;
  color: var(--muted);
  margin-top: 2px;
}
.chat-proposal-params {
  width: 100%;
  border-collapse: collapse;
}
.chat-proposal-params tr + tr td { border-top: 1px solid var(--border); }
.chat-proposal-param-key {
  padding: 6px 14px;
  color: var(--muted);
  white-space: nowrap;
  vertical-align: top;
  font-size: .77rem;
  width: 28%;
  font-weight: 500;
}
.chat-proposal-param-val {
  padding: 6px 14px 6px 0;
  color: var(--text);
  vertical-align: top;
  word-break: break-word;
  white-space: pre-wrap;
  max-height: 160px;
  overflow-y: auto;
}
.chat-proposal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 9px 14px;
  border-top: 1px solid var(--border);
}
.chat-proposal-cancel {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 11px;
  font-size: .8rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1.4;
}
.chat-proposal-cancel:hover { background: var(--hover); color: var(--text); }
.chat-proposal-run {
  background: var(--primary, #1976d2);
  border: 1px solid var(--primary, #1976d2);
  border-radius: 5px;
  padding: 4px 13px;
  font-size: .8rem;
  color: #fff;
  cursor: pointer;
  font-weight: 500;
  line-height: 1.4;
}
.chat-proposal-run:hover { filter: brightness(1.08); }
.chat-proposal-status {
  padding: 8px 14px;
  font-size: .77rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  font-style: italic;
}
.chat-proposal--confirmed { opacity: .65; }
.chat-proposal--cancelled { opacity: .4; }

/* Input area */
.chat-input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 12px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}

/* Account selector row */
.chat-account-row { display: flex; align-items: center; }

.chat-account-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  max-width: 360px;
}
.chat-account-search-icon {
  width: 13px; height: 13px;
  flex-shrink: 0;
  color: var(--faint);
  pointer-events: none;
  transition: color .15s;
}
.chat-account-search:focus-within .chat-account-search-icon { color: var(--muted); }
.chat-account-input {
  flex: 1;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  outline: none;
  padding: 4px 0;
  font-family: var(--font);
  font-size: .8rem;
  color: var(--text);
  background: transparent;
  transition: border-color .15s;
}
.chat-account-input:focus { border-bottom-color: var(--primary); }
.chat-account-input::placeholder { color: var(--faint); }

.chat-account-dropdown {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  max-height: 240px;
  overflow-y: auto;
  z-index: 200;
}

.chat-account-selected { display: flex; align-items: center; }

.chat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  color: var(--text);
}
.chat-chip-thumb { display: inline-flex; align-items: center; }
.chat-chip-label { font-weight: 500; }
.chat-chip-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--muted);
  line-height: 1;
}
.chat-chip-remove:hover { color: var(--danger); }
.chat-chip-remove svg { width: 11px; height: 11px; }

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font);
  font-size: .85rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  outline: none;
  overflow-y: hidden;
  min-height: 46px;
}
.chat-textarea:focus { border-color: var(--primary); }

.chat-send-btn {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; }


.chat-result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
.chat-result-item:hover,
.chat-result-item.focused { background: var(--hover); }

.chat-result-name { font-size: .85rem; font-weight: 500; }
.chat-result-sub  { font-size: .75rem; color: var(--muted); }
.chat-result-empty {
  padding: 10px 12px;
  font-size: .8rem;
  color: var(--muted);
}

/* Embedded chat (?embedded=1): hide search input but keep account chip visible */
.chat-page--embedded .chat-account-search { display: none; }
.chat-page--embedded .chat-chip-remove { display: none; }
.chat-page--embedded .chat-input-area { padding: 8px 12px 10px; }
