/* Longnotes styles: warm archival paper & ink, light + dark themes, concentric rounded boxes, high contrast. */
:root {
	--bg: #f8f7f4;
	--surface: #ffffff;
	--surface-2: #efede8;
	--surface-hover: #e7e4dc;
	--ink: #1a1917;
	--ink-muted: #5c5953;
	--border: #cfc9be;
	--border-strong: #9f988c;
	--accent: #1e293b;
	--accent-ink: #ffffff;
	--amber: #b45309;
	--amber-soft: #fef3c7;
	--highlight: rgba(217, 155, 22, 0.24);
	--highlight-active: rgba(217, 155, 22, 0.48);
	--danger: #b42318;
	--danger-soft: #fee4e2;
	--ok: #135e29;
	--ok-soft: #e6f4ea;
	--diff-add-bg: #e6f4ea;
	--diff-add-hi: #b7e4c7;
	--diff-add-ink: #135e29;
	--diff-del-bg: #fce8e6;
	--diff-del-hi: #f6b8b2;
	--diff-del-ink: #9b1c1c;
	--focus: #1e293b;
	--radius-panel: 10px;
	--radius-control: 6px;
	--font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
	--font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
	--weight-body: 400;
	--weight-med: 500;
	--weight-bold: 600;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme='light']) {
		--bg: #141413;
		--surface: #1d1d1b;
		--surface-2: #272623;
		--surface-hover: #32302c;
		--ink: #edece8;
		--ink-muted: #a8a49c;
		--border: #494640;
		--border-strong: #6e6a61;
		--accent: #e5e1d8;
		--accent-ink: #141413;
		--amber: #e59a3a;
		--amber-soft: #3a2912;
		--highlight: rgba(229, 154, 58, 0.24);
		--highlight-active: rgba(229, 154, 58, 0.48);
		--danger: #f97066;
		--danger-soft: #3b1918;
		--ok: #7be098;
		--ok-soft: #15321f;
		--diff-add-bg: #163020;
		--diff-add-hi: #215133;
		--diff-add-ink: #8be2a4;
		--diff-del-bg: #3b1a1a;
		--diff-del-hi: #642626;
		--diff-del-ink: #f59b9b;
		--focus: #e59a3a;
		--weight-body: 300;
		--weight-med: 400;
		--weight-bold: 500;
		color-scheme: dark;
	}
}

:root[data-theme='dark'] {
	--bg: #141413;
	--surface: #1d1d1b;
	--surface-2: #272623;
	--surface-hover: #32302c;
	--ink: #edece8;
	--ink-muted: #a8a49c;
	--border: #494640;
	--border-strong: #6e6a61;
	--accent: #e5e1d8;
	--accent-ink: #141413;
	--amber: #e59a3a;
	--amber-soft: #3a2912;
	--highlight: rgba(229, 154, 58, 0.24);
	--highlight-active: rgba(229, 154, 58, 0.48);
	--danger: #f97066;
	--danger-soft: #3b1918;
	--ok: #7be098;
	--ok-soft: #15321f;
	--diff-add-bg: #163020;
	--diff-add-hi: #215133;
	--diff-add-ink: #8be2a4;
	--diff-del-bg: #3b1a1a;
	--diff-del-hi: #642626;
	--diff-del-ink: #f59b9b;
	--focus: #e59a3a;
	--weight-body: 300;
	--weight-med: 400;
	--weight-bold: 500;
	color-scheme: dark;
}

* {
	box-sizing: border-box;
}

html,
body,
#app {
	margin: 0;
	padding: 0;
	height: 100%;
	background: var(--bg);
	color: var(--ink);
	font-family: var(--font-sans);
	font-weight: var(--weight-body);
	font-size: 15px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

/* iOS Home Screen standalone top strip (DECISIONS.md, Clients). */
.ios-status-strip {
	display: none;
}
@media (display-mode: standalone) {
	.ios-status-strip {
		display: block;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		height: 11px;
		background: var(--bg);
		background-clip: text;
		z-index: 1000;
		pointer-events: none;
	}
}

:focus-visible {
	outline: 2px solid var(--focus);
	outline-offset: 2px;
}

button,
input,
textarea,
select {
	font: inherit;
	color: inherit;
}

button {
	cursor: pointer;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--ink);
	border-radius: var(--radius-control);
	padding: 6px 11px;
	font-size: 13.5px;
	font-weight: var(--weight-med);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	line-height: 1.25;
	transition:
		background-color 120ms ease,
		border-color 120ms ease;
}

button:hover:not(:disabled) {
	background: var(--surface-hover);
	border-color: var(--border-strong);
}

button:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

button.primary {
	background: var(--accent);
	color: var(--accent-ink);
	border-color: var(--accent);
}

button.primary:hover:not(:disabled) {
	opacity: 0.9;
	background: var(--accent);
}

button.ghost {
	background: transparent;
	border-color: transparent;
}

button.ghost:hover:not(:disabled) {
	background: var(--surface-2);
	border-color: transparent;
}

button.danger {
	color: var(--danger);
	border-color: var(--danger);
	background: var(--surface);
}

button.danger:hover:not(:disabled) {
	background: var(--danger-soft);
}

button.small {
	padding: 4px 8px;
	font-size: 12.5px;
}

button.icon-btn {
	padding: 6px;
	min-width: 32px;
	min-height: 32px;
}

svg.icon {
	width: 16px;
	height: 16px;
	flex: none;
	display: block;
}

input[type='text'],
input[type='email'],
input[type='search'],
textarea,
select {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-control);
	padding: 8px 10px;
	width: 100%;
	font-size: 15px;
}

input:hover:not(:disabled),
textarea:hover:not(:disabled),
select:hover:not(:disabled) {
	border-color: var(--border-strong);
}

select {
	appearance: base-select;
	padding-right: 26px;
}

.field {
	display: flex;
	flex-direction: column;
	gap: 5px;
	margin-bottom: 14px;
}

.field label {
	font-size: 13px;
	font-weight: var(--weight-med);
	color: var(--ink-muted);
}

.field-error {
	font-size: 12.5px;
	color: var(--danger);
	min-height: 16px;
}

.mono {
	font-family: var(--font-mono);
}

.muted {
	color: var(--ink-muted);
}

.badge {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 2px 7px;
	font-size: 11.5px;
	font-weight: var(--weight-med);
	border-radius: 5px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	color: var(--ink-muted);
	white-space: nowrap;
}

.badge.amber {
	background: var(--amber-soft);
	border-color: var(--amber);
	color: var(--amber);
}

.badge.ok {
	background: var(--ok-soft);
	border-color: var(--ok);
	color: var(--ok);
}

.badge.danger {
	background: var(--danger-soft);
	border-color: var(--danger);
	color: var(--danger);
}

/* Update bar */
.update-bar {
	position: fixed;
	bottom: 16px;
	left: 50%;
	transform: translateX(-50%);
	background: var(--surface);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-panel);
	padding: 6px 8px;
	display: flex;
	align-items: center;
	gap: 6px;
	box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
	z-index: 900;
}

/* Toast */
.toast {
	position: fixed;
	bottom: 16px;
	right: 16px;
	background: var(--accent);
	color: var(--accent-ink);
	border-radius: var(--radius-control);
	padding: 9px 14px;
	font-size: 13.5px;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
	z-index: 950;
	max-width: 380px;
}

/* Auth screen */
.auth-wrap {
	min-height: 100%;
	display: grid;
	place-items: center;
	padding: 24px;
}

.auth-card {
	width: 100%;
	max-width: 400px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-panel);
	padding: 28px;
}

.auth-brand {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 16px;
}

.auth-brand img {
	width: 34px;
	height: 34px;
	border-radius: 8px;
}

.auth-brand h1 {
	margin: 0;
	font-size: 20px;
	font-weight: var(--weight-bold);
	letter-spacing: -0.02em;
}

.auth-sub {
	margin: 0 0 20px;
	color: var(--ink-muted);
	font-size: 14px;
}

.dev-link-box {
	margin-top: 14px;
	padding: 12px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-control);
	font-size: 13px;
	word-break: break-all;
}

/* Main 3-pane App Shell */
.shell {
	display: grid;
	grid-template-columns: 280px 1fr;
	height: 100%;
	overflow: hidden;
}

.shell.with-comments {
	grid-template-columns: 280px 1fr 330px;
}

.sidebar {
	border-right: 1px solid var(--border);
	background: var(--bg);
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.sidebar-head {
	padding: 12px 14px;
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}

.brand-btn {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: var(--weight-bold);
	font-size: 15px;
	letter-spacing: -0.01em;
}

.brand-btn img {
	width: 24px;
	height: 24px;
	border-radius: 6px;
}

.sidebar-search {
	padding: 10px 12px 8px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.filter-row {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
}

.filter-tab {
	padding: 4px 8px;
	font-size: 12px;
	border: 1px solid transparent;
	background: transparent;
	color: var(--ink-muted);
	border-radius: var(--radius-control);
}

.filter-tab:hover {
	background: var(--surface-2);
	color: var(--ink);
	border-color: transparent;
}

.filter-tab.active {
	background: var(--surface);
	border-color: var(--border);
	color: var(--ink);
}

.note-list {
	flex: 1;
	overflow-y: auto;
	padding: 4px 8px 12px;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.note-item {
	text-align: left;
	width: 100%;
	padding: 9px 10px;
	border: 1px solid transparent;
	background: transparent;
	border-radius: var(--radius-control);
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 3px;
}

.note-item:hover {
	background: var(--surface-2);
	border-color: transparent;
}

.note-item.active {
	background: var(--surface);
	border-color: var(--border);
}

.note-item-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 6px;
}

.note-item-title {
	font-weight: var(--weight-med);
	font-size: 14px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.note-item-excerpt {
	font-size: 12.5px;
	color: var(--ink-muted);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.note-item-meta {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 11.5px;
	color: var(--ink-muted);
	flex-wrap: wrap;
}

.sidebar-foot {
	padding: 10px 12px;
	border-top: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 6px;
}

/* Main Pane */
.main-pane {
	display: flex;
	flex-direction: column;
	min-width: 0;
	min-height: 0;
	background: var(--surface);
}

.doc-topbar {
	padding: 10px 16px;
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	flex-wrap: wrap;
	background: var(--surface);
}

.doc-topbar-left,
.doc-topbar-right {
	display: flex;
	align-items: center;
	gap: 6px;
	flex-wrap: wrap;
}

.mobile-only {
	display: none;
}

.doc-scroll {
	flex: 1;
	overflow-y: auto;
	padding: 24px 32px 64px;
}

.doc-inner {
	max-width: 740px;
	margin: 0 auto;
}

.doc-title-row {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 8px;
}

.doc-title {
	margin: 0;
	font-size: 26px;
	font-weight: var(--weight-bold);
	letter-spacing: -0.02em;
	line-height: 1.25;
	word-break: break-word;
}

.doc-meta-bar {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	font-size: 12.5px;
	color: var(--ink-muted);
	padding-bottom: 14px;
	margin-bottom: 18px;
	border-bottom: 1px solid var(--border);
}

.banner {
	padding: 10px 12px;
	border-radius: var(--radius-control);
	border: 1px solid var(--border);
	background: var(--surface-2);
	margin-bottom: 16px;
	font-size: 13px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	flex-wrap: wrap;
}

.banner.amber {
	background: var(--amber-soft);
	border-color: var(--amber);
}

.banner.ok {
	background: var(--ok-soft);
	border-color: var(--ok);
}

/* Read & Annotate text body */
.doc-body {
	white-space: pre-wrap;
	word-break: break-word;
	font-size: 15.5px;
	line-height: 1.72;
	min-height: 240px;
	user-select: text;
	-webkit-user-select: text;
}

.doc-body.mono-font {
	font-family: var(--font-mono);
	font-size: 14px;
	line-height: 1.65;
}

.doc-highlight {
	background: var(--highlight);
	border-bottom: 2px solid var(--amber);
	border-radius: 2px;
	cursor: pointer;
	padding: 1px 0;
	color: inherit;
}

.doc-highlight.active {
	background: var(--highlight-active);
}

/* Plain-text Editor */
.editor-title-input {
	font-size: 22px;
	font-weight: var(--weight-bold);
	padding: 8px 10px;
	margin-bottom: 12px;
}

.editor-textarea {
	min-height: 380px;
	resize: vertical;
	line-height: 1.68;
	font-size: 15.5px;
	padding: 12px;
}

.editor-textarea.mono-font {
	font-family: var(--font-mono);
	font-size: 14px;
}

.editor-bar {
	display: flex;
	gap: 8px;
	margin-top: 12px;
	align-items: center;
	flex-wrap: wrap;
}

.editor-reason {
	flex: 1;
	min-width: 200px;
}

/* Ledger Timeline */
.ledger-composer {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-panel);
	padding: 14px;
	margin-bottom: 22px;
}

.ledger-composer-head {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 10px;
	flex-wrap: wrap;
}

input.ledger-date-input {
	width: 140px;
	flex: none;
	font-family: var(--font-mono);
	font-size: 13.5px;
}

.ledger-list {
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.ledger-entry {
	border: 1px solid var(--border);
	border-radius: var(--radius-panel);
	background: var(--surface);
	padding: 14px 16px;
}

.ledger-entry-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	flex-wrap: wrap;
	margin-bottom: 8px;
	padding-bottom: 8px;
	border-bottom: 1px solid var(--border);
}

.ledger-entry-date {
	font-family: var(--font-mono);
	font-weight: var(--weight-bold);
	font-size: 14px;
}

.ledger-entry-body {
	white-space: pre-wrap;
	word-break: break-word;
	font-size: 15px;
	line-height: 1.65;
	user-select: text;
}

/* History & Diff view */
.history-controls {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	padding: 12px;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-panel);
	margin-bottom: 16px;
}

.history-controls select {
	width: auto;
	min-width: 160px;
	font-size: 13.5px;
	padding: 5px 24px 5px 8px;
}

.diff-box {
	border: 1px solid var(--border);
	border-radius: var(--radius-panel);
	overflow: hidden;
	font-family: var(--font-mono);
	font-size: 13px;
	line-height: 1.55;
	margin-bottom: 18px;
}

.diff-head {
	padding: 8px 12px;
	background: var(--surface-2);
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	flex-wrap: wrap;
	font-family: var(--font-sans);
	font-size: 12.5px;
}

.diff-table {
	width: 100%;
	border-collapse: collapse;
}

.diff-row td {
	padding: 1px 8px;
	vertical-align: top;
	white-space: pre-wrap;
	word-break: break-word;
}

.diff-row .ln {
	width: 40px;
	text-align: right;
	color: var(--ink-muted);
	user-select: none;
	border-right: 1px solid var(--border);
	font-size: 11.5px;
}

.diff-row .sig {
	width: 18px;
	text-align: center;
	user-select: none;
	font-weight: var(--weight-bold);
}

.diff-row.add {
	background: var(--diff-add-bg);
	color: var(--diff-add-ink);
}

.diff-row.del {
	background: var(--diff-del-bg);
	color: var(--diff-del-ink);
}

.diff-inline-add {
	background: var(--diff-add-hi);
	border-radius: 2px;
}

.diff-inline-del {
	background: var(--diff-del-hi);
	border-radius: 2px;
}

.rev-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.rev-card {
	border: 1px solid var(--border);
	border-radius: var(--radius-panel);
	padding: 11px 14px;
	background: var(--surface);
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.rev-card.selected {
	border-color: var(--accent);
	background: var(--bg);
}

/* Comments Sidebar */
.comments-pane {
	border-left: 1px solid var(--border);
	background: var(--bg);
	display: flex;
	flex-direction: column;
	min-height: 0;
}

@media (min-width: 960px) {
	.comments-pane[data-desktop-hidden='1'] {
		display: none;
	}
}

.comments-head {
	padding: 10px 14px;
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}

.comments-scroll {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.comment-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-panel);
	padding: 11px 12px;
	display: flex;
	flex-direction: column;
	gap: 7px;
}

.comment-card.active {
	border-color: var(--amber);
	box-shadow: 0 0 0 1px var(--amber);
}

.comment-card.resolved {
	opacity: 0.72;
}

.comment-quote {
	border-left: 3px solid var(--amber);
	padding: 3px 8px;
	background: var(--surface-2);
	border-radius: 0 4px 4px 0;
	font-size: 12.5px;
	color: var(--ink-muted);
	white-space: pre-wrap;
	word-break: break-word;
	max-height: 72px;
	overflow: hidden;
}

.comment-meta {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 6px;
	font-size: 12px;
	color: var(--ink-muted);
}

.comment-body {
	white-space: pre-wrap;
	word-break: break-word;
	font-size: 13.5px;
	line-height: 1.5;
}

.comment-actions {
	display: flex;
	align-items: center;
	gap: 4px;
	flex-wrap: wrap;
}

.comment-replies {
	margin-top: 4px;
	padding-top: 8px;
	border-top: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.comment-reply {
	padding-left: 8px;
	border-left: 2px solid var(--border);
	display: flex;
	flex-direction: column;
	gap: 3px;
}

/* Floating selection comment button */
.selection-popup {
	position: fixed;
	z-index: 800;
	background: var(--accent);
	color: var(--accent-ink);
	border: 1px solid var(--accent);
	border-radius: var(--radius-control);
	padding: 6px 11px;
	font-size: 13px;
	font-weight: var(--weight-med);
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.selection-popup:hover {
	opacity: 0.94;
	background: var(--accent);
}

/* Empty state */
.empty-state {
	height: 100%;
	display: grid;
	place-items: center;
	padding: 32px;
	text-align: center;
}

.empty-box {
	max-width: 380px;
}

.empty-box h2 {
	margin: 0 0 8px;
	font-size: 19px;
	font-weight: var(--weight-bold);
}

.empty-box p {
	margin: 0 0 18px;
	color: var(--ink-muted);
	font-size: 14px;
}

/* Native Modal Dialogs */
dialog {
	background: var(--surface);
	color: var(--ink);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-panel);
	padding: 0;
	width: min(520px, calc(100vw - 24px));
	max-height: calc(100vh - 32px);
	box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
}

dialog::backdrop {
	background: rgba(0, 0, 0, 0.45);
}

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

.dialog-head h2 {
	margin: 0;
	font-size: 16px;
	font-weight: var(--weight-bold);
}

.dialog-body {
	padding: 16px 18px;
	overflow-y: auto;
	max-height: calc(100vh - 160px);
}

.dialog-foot {
	padding: 12px 18px;
	border-top: 1px solid var(--border);
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.checkbox-row {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	font-size: 13.5px;
	margin-bottom: 10px;
	cursor: pointer;
}

.checkbox-row input {
	margin-top: 3px;
	width: auto;
}

.share-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 8px 0;
	border-bottom: 1px solid var(--border);
	font-size: 13.5px;
}

/* Responsive mobile layout */
@media (max-width: 959px) {
	.shell,
	.shell.with-comments {
		grid-template-columns: 1fr;
	}

	.mobile-only {
		display: inline-flex;
	}

	.sidebar {
		position: fixed;
		inset: 0;
		z-index: 600;
		width: 100%;
		border-right: none;
	}

	.shell.has-note .sidebar:not(.mobile-open) {
		display: none;
	}

	.shell:not(.has-note) .main-pane {
		display: none;
	}

	.comments-pane {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		width: min(380px, 100vw);
		z-index: 700;
		box-shadow: -8px 0 32px rgba(0, 0, 0, 0.25);
		display: none;
	}

	.comments-pane.mobile-open {
		display: flex;
	}

	.doc-scroll {
		padding: 16px 16px 72px;
	}

	input[type='text'],
	input[type='email'],
	input[type='search'],
	textarea,
	select {
		font-size: 16px;
	}
}
