/* Whitby Place — QuickBooks-inspired accounting UI */

/* ============================================================
   CSS Reset + Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
	--sidebar-bg: #1a3038;
	--sidebar-width: 220px;
	--topbar-height: 52px;
	--accent: #2a7d4f;
	--accent-hover: #1e5f3a;
	--accent-light: #e8f5ee;
	--danger: #c0392b;
	--warning: #e67e22;
	--text-primary: #1a1a2e;
	--text-secondary: #6c757d;
	--text-muted: #adb5bd;
	--border: #dee2e6;
	--bg-page: #f4f6f9;
	--bg-card: #ffffff;
	--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body { height: 100%; font-family: var(--font); font-size: 14px; color: var(--text-primary); background: var(--bg-page); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   App Shell Layout
   ============================================================ */
.app-shell {
	display: flex;
	height: 100vh;
	overflow: hidden;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
	width: var(--sidebar-width);
	background: var(--sidebar-bg);
	color: #fff;
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
	overflow-y: auto;
}

.sidebar-logo {
	padding: 18px 16px 14px;
	border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo .logo-text {
	font-size: 16px;
	font-weight: 700;
	color: #fff;
	letter-spacing: -0.3px;
}

.sidebar-logo .logo-sub {
	font-size: 11px;
	color: rgba(255,255,255,0.45);
	margin-top: 2px;
}

.sidebar-section-label {
	padding: 16px 16px 4px;
	font-size: 10px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.8px;
	color: rgba(255,255,255,0.35);
}

.sidebar-nav a {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 9px 16px;
	color: rgba(255,255,255,0.65);
	font-size: 13.5px;
	transition: background 0.12s, color 0.12s;
	border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
	background: rgba(255,255,255,0.07);
	color: #fff;
	text-decoration: none;
}

.sidebar-nav a.active {
	background: rgba(255,255,255,0.1);
	color: #fff;
	border-left-color: #4caf7d;
}

.sidebar-nav .nav-icon {
	font-size: 16px;
	width: 20px;
	text-align: center;
	flex-shrink: 0;
}

/* ============================================================
   Main content area
   ============================================================ */
.main-area {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.topbar {
	height: var(--topbar-height);
	background: var(--bg-card);
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	padding: 0 24px;
	gap: 16px;
	flex-shrink: 0;
}

.topbar-title {
	font-size: 16px;
	font-weight: 600;
	color: var(--text-primary);
	flex: 1;
}

.topbar-actions {
	display: flex;
	align-items: center;
	gap: 8px;
}

.page-content {
	flex: 1;
	overflow-y: auto;
	padding: 24px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 7px 14px;
	border-radius: 5px;
	font-size: 13.5px;
	font-weight: 500;
	cursor: pointer;
	border: 1px solid transparent;
	transition: background 0.12s, border-color 0.12s;
	text-decoration: none;
	line-height: 1.4;
}

.btn-primary {
	background: var(--accent);
	color: #fff;
	border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; color: #fff; }

.btn-secondary {
	background: #fff;
	color: var(--text-primary);
	border-color: var(--border);
}
.btn-secondary:hover { background: #f8f9fa; text-decoration: none; }

.btn-danger {
	background: #fff;
	color: var(--danger);
	border-color: #f5c6cb;
}
.btn-danger:hover { background: #fdf2f2; text-decoration: none; }

.btn-success {
	background: #fff;
	color: #1a7f37;
	border-color: #b6e3c1;
}
.btn-success:hover { background: #f0fdf4; text-decoration: none; }

.btn-sm {
	padding: 4px 10px;
	font-size: 12.5px;
}

.btn-icon {
	padding: 6px 10px;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
	background: var(--bg-card);
	border: 1px solid var(--border);
	border-radius: 6px;
}

.card-header {
	padding: 14px 18px;
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.card-title {
	font-size: 14px;
	font-weight: 600;
	color: var(--text-primary);
}

.card-body {
	padding: 18px;
}

/* ============================================================
   Tables
   ============================================================ */
.data-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13.5px;
}

.data-table thead th {
	background: #f8f9fa;
	border-bottom: 2px solid var(--border);
	padding: 9px 12px;
	text-align: left;
	font-size: 11.5px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--text-secondary);
	white-space: nowrap;
}

.data-table thead th.text-right { text-align: right; }

.data-table tbody tr {
	border-bottom: 1px solid #f0f2f4;
	transition: background 0.08s;
}

.data-table tbody tr:hover { background: #f8faf9; }
.data-table tbody tr:last-child { border-bottom: none; }

.data-table td {
	padding: 9px 12px;
	vertical-align: middle;
}

.data-table td.text-right { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.text-muted { color: var(--text-secondary); }
.data-table td.monospace { font-family: "SF Mono", "Fira Code", monospace; font-size: 13px; }

.data-table .amount-debit  { color: #1a1a2e; }
.data-table .amount-credit { color: var(--text-secondary); }

/* Subtotal / total rows */
.data-table tfoot td {
	padding: 9px 12px;
	border-top: 2px solid var(--border);
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

/* ============================================================
   Status Badges
   ============================================================ */
.badge {
	display: inline-block;
	padding: 2px 8px;
	border-radius: 10px;
	font-size: 11.5px;
	font-weight: 500;
}

.badge-cleared   { background: #d4edda; color: #155724; }
.badge-pending   { background: #fff3cd; color: #856404; }
.badge-unreviewed { background: #f8d7da; color: #721c24; }
.badge-imported  { background: #d1ecf1; color: #0c5460; }
.badge-reviewed  { background: #d4edda; color: #155724; }
.badge-parsed    { background: #fff3cd; color: #856404; }
.badge-asset     { background: #cce5ff; color: #004085; }
.badge-liability { background: #f8d7da; color: #721c24; }
.badge-equity    { background: #d1ecf1; color: #0c5460; }
.badge-revenue   { background: #d4edda; color: #155724; }
.badge-expense   { background: #ffeeba; color: #856404; }
.badge-currency-cad { background: #d4edda; color: #155724; }
.badge-currency-usd { background: #cce5ff; color: #004085; }

/* ============================================================
   Forms
   ============================================================ */
.form-group {
	margin-bottom: 16px;
}

.form-label {
	display: block;
	font-size: 13px;
	font-weight: 500;
	color: var(--text-primary);
	margin-bottom: 5px;
}

.form-control {
	width: 100%;
	padding: 7px 10px;
	border: 1px solid #ced4da;
	border-radius: 4px;
	font-size: 13.5px;
	font-family: var(--font);
	color: var(--text-primary);
	background: #fff;
	transition: border-color 0.15s;
}

.form-control:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px rgba(42, 125, 79, 0.12);
}

.form-control-sm { padding: 5px 8px; font-size: 13px; }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint {
	font-size: 12px;
	color: var(--text-muted);
	margin-top: 4px;
}

.field-error {
	font-size: 12px;
	color: var(--danger);
	margin-top: 4px;
}

.form-row {
	display: grid;
	gap: 16px;
	grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

/* ============================================================
   Postings Table (transaction entry)
   ============================================================ */
.postings-table {
	width: 100%;
	border-collapse: collapse;
	margin-bottom: 8px;
}

.postings-table th {
	background: #f8f9fa;
	padding: 8px 10px;
	font-size: 11.5px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.4px;
	color: var(--text-secondary);
	border-bottom: 1px solid var(--border);
	text-align: left;
}

.postings-table td {
	padding: 6px 4px;
	vertical-align: middle;
}

.postings-table .posting-row:hover { background: #f8faf9; }

.postings-table input, .postings-table select {
	width: 100%;
	padding: 5px 8px;
	border: 1px solid #ced4da;
	border-radius: 4px;
	font-size: 13px;
	font-family: var(--font);
}

.postings-table input:focus, .postings-table select:focus {
	outline: none;
	border-color: var(--accent);
}

.balance-indicator {
	font-size: 12.5px;
	font-weight: 500;
	padding: 4px 10px;
	border-radius: 4px;
}

.balance-ok      { background: #d4edda; color: #155724; }
.balance-off     { background: #f8d7da; color: #721c24; }

/* ============================================================
   Dashboard / Stat Cards
   ============================================================ */
.stat-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	gap: 16px;
	margin-bottom: 24px;
}

.stat-card {
	background: var(--bg-card);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 18px;
}

.stat-label {
	font-size: 12px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--text-secondary);
	margin-bottom: 6px;
}

.stat-value {
	font-size: 24px;
	font-weight: 700;
	color: var(--text-primary);
	font-variant-numeric: tabular-nums;
}

.stat-value.negative { color: var(--danger); }

.stat-sub {
	font-size: 12px;
	color: var(--text-muted);
	margin-top: 4px;
}

/* ============================================================
   Page header
   ============================================================ */
.page-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 20px;
}

.page-header h1 {
	font-size: 20px;
	font-weight: 700;
	color: var(--text-primary);
}

/* ============================================================
   Filter Bar
   ============================================================ */
.filter-bar {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 0;
	margin-bottom: 12px;
	flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input[type="text"],
.filter-bar input[type="date"],
.filter-bar input[type="search"] {
	width: auto;
	padding: 6px 10px;
	border: 1px solid var(--border);
	border-radius: 4px;
	font-size: 13px;
	background: #fff;
}

/* ============================================================
   Account tree indentation
   ============================================================ */
.account-depth-0 { font-weight: 600; }
.account-depth-1 { padding-left: 18px; }
.account-depth-2 { padding-left: 36px; }
.account-depth-3 { padding-left: 54px; }
.account-depth-4 { padding-left: 72px; }
.account-depth-5 { padding-left: 90px; }

/* ============================================================
   Account picker popover
   ============================================================ */
.account-picker-dropdown {
	position: absolute;
	top: 100%;
	left: 0;
	z-index: 100;
	background: #fff;
	border: 1px solid var(--border, #dee2e6);
	border-radius: 6px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
	padding: 6px;
	width: 280px;
	max-height: 300px;
	overflow-y: auto;
}

.account-picker-list {
	list-style: none;
	padding: 0;
	margin: 0;
}

.account-picker-list li {
	padding: 5px 8px;
	font-size: 12px;
	cursor: pointer;
	border-radius: 4px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.account-picker-list li:hover {
	background: #e9ecef;
}

/* ============================================================
   Flash messages
   ============================================================ */
.flash { padding: 10px 16px; border-radius: 5px; margin-bottom: 16px; font-size: 13.5px; }
.flash-notice  { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.flash-alert   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* ============================================================
   Empty state
   ============================================================ */
.empty-state {
	text-align: center;
	padding: 48px 24px;
	color: var(--text-muted);
}

.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; margin-bottom: 16px; }

/* ============================================================
   Utilities
   ============================================================ */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 12.5px; }
.mt-4        { margin-top: 4px; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mt-24       { margin-top: 24px; }
.mb-16       { margin-bottom: 16px; }
.mb-24       { margin-bottom: 24px; }
.gap-8       { gap: 8px; }
.flex        { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.hidden      { display: none; }

.monospace   { font-family: "SF Mono", "Fira Code", monospace; }
.pl-16       { padding-left: 18px; }
.pl-32       { padding-left: 36px; }
.border-top  { border-top: 1px solid var(--border); }
.border-bottom-double { border-bottom: 3px double var(--text-primary); }

/* Amount display helpers */
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-positive { color: var(--text-primary); }
.amount-negative { color: var(--text-secondary); }

/* ============================================================
   Responsive tweaks
   ============================================================ */
/* ============================================================
   Drop Zone (file upload)
   ============================================================ */
.drop-zone {
	position: relative;
	border: 2px dashed var(--border);
	border-radius: 6px;
	padding: 36px 24px;
	text-align: center;
	cursor: pointer;
	transition: border-color 0.15s, background 0.15s;
	background: #fafbfc;
}

.drop-zone:hover,
.drop-zone.drag-over {
	border-color: var(--accent);
	background: var(--accent-light);
}

.drop-zone.has-file {
	border-style: solid;
	border-color: var(--accent);
	background: var(--accent-light);
}

.drop-zone-icon {
	font-size: 28px;
	color: var(--text-muted);
	margin-bottom: 8px;
}

.drop-zone-text {
	font-size: 13.5px;
	color: var(--text-secondary);
}

.drop-zone-input {
	position: absolute;
	inset: 0;
	opacity: 0;
	cursor: pointer;
	width: 100%;
	height: 100%;
}

@media (max-width: 900px) {
	:root { --sidebar-width: 48px; }
	.sidebar-logo .logo-text,
	.sidebar-logo .logo-sub,
	.sidebar-section-label,
	.sidebar-nav a span:not(.nav-icon) { display: none; }
	.sidebar-nav a { justify-content: center; padding: 12px; }
	.sidebar-nav .nav-icon { width: auto; }
}

/* ============================================================
   Pagination (Pagy)
   ============================================================ */
.pagy nav,
nav.pagy {
	display: flex;
	gap: 4px;
	align-items: center;
	justify-content: center;
}
.pagy nav a,
.pagy nav span,
nav.pagy a,
nav.pagy span {
	display: inline-block;
	padding: 4px 10px;
	font-size: 12.5px;
	border: 1px solid var(--border);
	border-radius: 4px;
	color: var(--text);
	text-decoration: none;
	background: var(--bg);
}
.pagy nav a:hover,
nav.pagy a:hover {
	background: var(--bg-secondary, #f8f9fa);
	text-decoration: none;
}
.pagy nav a[aria-current],
nav.pagy a[aria-current],
.pagy nav .current,
nav.pagy .current {
	background: var(--accent);
	color: #fff;
	border-color: var(--accent);
}
.pagy nav .disabled,
nav.pagy .disabled {
	opacity: 0.4;
	pointer-events: none;
}

/* ============================================================
   Login Page
   ============================================================ */
.login-page {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 100vh;
	background: var(--bg-page);
}
.login-card {
	background: var(--bg-card);
	border-radius: 12px;
	box-shadow: 0 4px 24px rgba(0,0,0,0.08);
	padding: 48px 40px;
	max-width: 400px;
	width: 100%;
	text-align: center;
}
.login-logo .logo-text {
	font-size: 28px;
	font-weight: 700;
	color: var(--sidebar-bg);
	margin-bottom: 8px;
}
.login-subtitle {
	color: var(--text-secondary);
	font-size: 15px;
	margin-bottom: 32px;
}
.login-buttons {
	display: flex;
	flex-direction: column;
	gap: 12px;
}
.btn-login {
	display: block;
	width: 100%;
	padding: 12px 20px;
	border-radius: 6px;
	font-size: 15px;
	font-weight: 500;
	cursor: pointer;
	border: 1px solid var(--border);
	background: var(--bg-card);
	color: var(--text-primary);
	transition: background 0.15s, box-shadow 0.15s;
}
.btn-login:hover {
	background: var(--bg-page);
	box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.btn-google { border-left: 3px solid #4285f4; }

/* Read-only user: hide write-action buttons. Read-only access has its
 * controller-level enforcement via enforce_readonly; this is just UI
 * polish so readonly users don't see actions they can't take. Form
 * fields stay enabled so the user can still scroll through and select
 * text — they just can't submit. Tag write-action buttons explicitly
 * with one of these classes; benign submits (filters, entity switcher)
 * stay visible. For write actions styled as btn-secondary, wrap in the
 * `admin_only do` helper instead of relying on this rule. */
body.readonly-user .btn-primary,
body.readonly-user .btn-danger,
body.readonly-user .btn-success {
	display: none !important;
}

/* Filter chips use .btn-primary to mark the active filter — read-safe
 * navigation, so override the readonly hide rule above. */
body.readonly-user .filter-chips .btn-primary {
	display: inline-block !important;
}

/* Sidebar user info */
.sidebar-user {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	border-top: 1px solid rgba(255,255,255,0.1);
	margin-top: auto;
}
.sidebar-user-avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: rgba(255,255,255,0.2);
}
.sidebar-user-info {
	flex: 1;
	min-width: 0;
}
.sidebar-user-name {
	color: #fff;
	font-size: 13px;
	font-weight: 500;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.sidebar-user-email {
	color: rgba(255,255,255,0.5);
	font-size: 11px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.sidebar-logout {
	color: rgba(255,255,255,0.5);
	font-size: 12px;
	text-decoration: none;
}
.sidebar-logout:hover {
	color: #fff;
	text-decoration: none;
}

/* Chat assistant */
.chat-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 32px);
  max-width: 860px;
  margin: 0 auto;
}
.chat-page-header {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-message { display: flex; flex-direction: column; gap: 6px; }
.chat-message-user { align-self: flex-end; max-width: 80%; }
.chat-message-assistant { align-self: stretch; }

/* All chat content sits on white cards — same surface as the rest of
 * the app. User vs assistant differentiated by alignment + border,
 * not background color. */
.chat-block-text {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-primary);
}
.chat-block-text > *:first-child { margin-top: 0; }
.chat-block-text > *:last-child  { margin-bottom: 0; }
.chat-block-text p   { margin: 0 0 10px 0; }
.chat-block-text h1, .chat-block-text h2, .chat-block-text h3 {
  margin: 18px 0 8px 0; font-weight: 600;
}
.chat-block-text h1 { font-size: 18px; }
.chat-block-text h2 { font-size: 16px; }
.chat-block-text h3 { font-size: 14px; }
.chat-block-text ul, .chat-block-text ol { margin: 0 0 10px 0; padding-left: 22px; }
.chat-block-text li { margin: 2px 0; }
.chat-block-text code {
  background: var(--bg-page);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.chat-block-text pre {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 12px;
}
.chat-block-text pre code { background: transparent; padding: 0; }
.chat-block-text table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.chat-block-text th, .chat-block-text td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.chat-block-text thead th {
  background: var(--bg-page);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
.chat-block-text td:has(+ td:last-child),
.chat-block-text td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.chat-block-text blockquote {
  border-left: 3px solid var(--border);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-secondary);
}

/* Tool pills — kept tiny by default. Average user shouldn't think
 * about them; power users can click to expand. */
.chat-tool-pill {
  display: inline-block;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  margin: 2px 4px 2px 0;
  color: var(--text-muted);
  vertical-align: middle;
  max-width: 100%;
}
.chat-tool-pill[open] {
  display: block;
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--bg-card);
}
.chat-tool-pill summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
}
.chat-tool-pill summary::-webkit-details-marker { display: none; }
.chat-tool-pill code { color: var(--text-secondary); font-weight: 500; background: transparent; padding: 0; }
.chat-tool-pill-icon { font-size: 10px; }
.chat-tool-pill-body { margin-top: 6px; }
.chat-tool-pill-body pre {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11px;
  color: var(--text-secondary);
  max-height: 320px;
  overflow: auto;
}
.chat-tool-pill-error { border-color: #d04a4a; }
.chat-tool-pill-error[open] { background: #fff4f4; }
.chat-tool-pill-thinking { font-style: italic; }

.chat-form {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
}

/* Chat actions are read-safe — keep visible for readonly users.
 * (Asking questions and creating new chats doesn't mutate the books;
 * write tools are still gated server-side via AuthorizedScope#can_propose?) */
body.readonly-user .chat-page-header .btn-primary,
body.readonly-user .chat-form .btn-primary,
body.readonly-user .chat-form button[type="submit"] {
  display: inline-block !important;
}

.chat-session-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.chat-session-list li {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-session-list li:last-child { border-bottom: none; }
.chat-session-meta { color: var(--text-muted); font-size: 12px; }

/* Chat suggestions — Accept/Reject cards inline in the chat */
.chat-suggestion {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 8px 0;
  font-size: 14px;
}
.chat-suggestion-rejected {
  border-color: var(--text-muted);
  opacity: 0.7;
}
.chat-suggestion-applied {
  border-color: #2a7d4f;
  background: #f0f9f3;
}
.chat-suggestion-failed {
  border-color: #d04a4a;
  background: #fff4f4;
}
.chat-suggestion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.chat-suggestion-icon { color: var(--accent); }
.chat-suggestion-kind { font-weight: 600; }
.chat-suggestion-status {
  margin-left: auto;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-page);
  font-size: 10px;
}
.chat-suggestion-status-applied { background: var(--accent-light); color: var(--accent); }
.chat-suggestion-status-rejected { color: var(--text-muted); }
.chat-suggestion-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 6px;
}
.chat-suggestion-rationale {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 10px;
}
.chat-suggestion-rationale p:last-child { margin-bottom: 0; }
.chat-suggestion-preview {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.chat-suggestion-preview summary {
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
}
.chat-suggestion-preview pre {
  margin: 8px 0 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11px;
  color: var(--text-secondary);
  max-height: 280px;
  overflow: auto;
}
.chat-suggestion-actions {
  display: flex;
  gap: 8px;
}
.chat-suggestion-applied,
.chat-suggestion-rejected,
.chat-suggestion-failed {
  font-size: 12px;
  color: var(--text-secondary);
}
body.readonly-user .chat-suggestion-actions { display: none; }

/* Make the .btn-sm rule match the rest of the app */
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Chat thinking blocks — italic gray, expanded by default during
 * streaming, user can collapse with the disclosure triangle. Less
 * prominent than text/tool blocks since thinking is meta-content. */
.chat-thinking {
  margin: 4px 0 8px 0;
  font-size: 12px;
  color: var(--text-muted);
}
.chat-thinking summary {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  font-style: italic;
}
.chat-thinking-icon {
  display: inline-block;
  animation: chat-thinking-pulse 1.6s ease-in-out infinite;
}
.chat-thinking-body {
  margin-top: 4px;
  padding: 6px 12px;
  border-left: 2px solid var(--border);
  font-style: italic;
  white-space: pre-wrap;
}
.chat-thinking-body p { margin: 0 0 6px 0; }
.chat-thinking-body p:last-child { margin-bottom: 0; }
@keyframes chat-thinking-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* Loading dots for assistant messages while waiting on first content */
.chat-loading-dots {
  display: inline-flex;
  gap: 5px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: fit-content;
}
.chat-loading-dots span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chat-loading-bounce 1.2s ease-in-out infinite both;
}
.chat-loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-loading-dots span:nth-child(3) { animation-delay: 0.30s; }
@keyframes chat-loading-bounce {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* Chat index — same horizontal centering as the chat-page show view. */
.chat-index {
  max-width: 860px;
  margin: 0 auto;
}
