/* Design tokens lifted from Symphony's uikit (shadcn/ui). This app is dark-only,
   so :root carries Symphony's .dark theme values verbatim (OKLCH). */
:root {
	color-scheme: dark;

	--radius: 0.625rem;
	--radius-sm: calc(var(--radius) - 4px);
	--radius-md: calc(var(--radius) - 2px);
	--radius-lg: var(--radius);

	--background: oklch(0.145 0 0);
	--foreground: oklch(0.985 0 0);
	--card: oklch(0.205 0 0);
	--card-foreground: oklch(0.985 0 0);
	--primary: oklch(0.922 0 0);
	--primary-foreground: oklch(0.205 0 0);
	--secondary: oklch(0.269 0 0);
	--secondary-foreground: oklch(0.985 0 0);
	--muted: oklch(0.269 0 0);
	--muted-foreground: oklch(0.708 0 0);
	--accent: oklch(0.269 0 0);
	--accent-foreground: oklch(0.985 0 0);
	--destructive: oklch(0.704 0.191 22.216);
	--success: oklch(0.696 0.17 162.48);
	--border: oklch(1 0 0 / 10%);
	--input: oklch(1 0 0 / 15%);
	--ring: oklch(0.556 0 0);

	--sidebar: oklch(0.205 0 0);
	--sidebar-foreground: oklch(0.985 0 0);
	--sidebar-accent: oklch(0.269 0 0);
	--sidebar-accent-foreground: oklch(0.985 0 0);
	--sidebar-border: oklch(1 0 0 / 10%);

	--font-sans: "Geist", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
	--font-mono: "Geist Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
	font: 14px/1.5 var(--font-sans);
	margin: 0;
	background: var(--background);
	color: var(--foreground);
	-webkit-font-smoothing: antialiased;
}

/* ── app shell: floating, icon-collapsible sidebar (ported from Symphony) ───── */
.app { display: flex; min-height: 100vh; }

.sidebar { flex: 0 0 16rem; width: 16rem; padding: 8px; transition: flex-basis .2s ease, width .2s ease; }
.sidebar.collapsed { flex-basis: 4rem; width: 4rem; }

.sidebar-inner {
	position: sticky; top: 8px;
	height: calc(100vh - 16px);
	display: flex; flex-direction: column;
	background: var(--sidebar);
	color: var(--sidebar-foreground);
	border: 1px solid var(--sidebar-border);
	border-radius: var(--radius-lg);
	box-shadow: 0 1px 2px rgba(0,0,0,.3);
	overflow: hidden;
}

.sidebar-header { display: flex; align-items: center; gap: 8px; padding: 8px; }
.sidebar-content { flex: 1 1 auto; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer { margin-top: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--sidebar-border); }

.sidebar-group { display: flex; flex-direction: column; gap: 4px; padding: 8px; }
.group-label { display: flex; align-items: center; height: 32px; padding: 0 8px; font-size: 12px; font-weight: 500; color: var(--muted-foreground); }
.menu { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; width: 100%; min-width: 0; }
.menu-item { position: relative; }

.nav-item {
	display: flex; align-items: center; gap: 8px;
	height: 32px; padding: 8px;
	border-radius: var(--radius-md);
	color: var(--sidebar-foreground);
	text-decoration: none; font-size: 14px;
	white-space: nowrap; overflow: hidden;
	transition: background-color .15s ease, color .15s ease;
}
.nav-item:hover { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); }
.nav-item.active { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); font-weight: 500; }
.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; }

.brand { font-weight: 600; font-size: 15px; }
.brand svg { width: 18px; height: 18px; flex: 0 0 18px; }

.sidebar-toggle {
	margin-left: auto;
	display: inline-flex; align-items: center; justify-content: center;
	width: 28px; height: 28px; padding: 0;
	background: transparent; border: 0; border-radius: var(--radius-sm);
	color: var(--sidebar-foreground); cursor: pointer;
	transition: background-color .15s ease;
}
.sidebar-toggle:hover { background: var(--sidebar-accent); }
.sidebar-toggle svg { width: 16px; height: 16px; }

.user-btn { height: auto; }
.avatar {
	flex: 0 0 28px; width: 28px; height: 28px;
	display: flex; align-items: center; justify-content: center;
	border-radius: var(--radius-md);
	background: var(--sidebar-accent); color: var(--sidebar-accent-foreground);
	font-size: 12px; font-weight: 600;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.user-meta .user-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.user-meta .user-email { font-size: 12px; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; }

/* collapsed → icon rail: hide every text label, center the icons */
.sidebar.collapsed .label { display: none; }
.sidebar.collapsed .brand { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; }
.sidebar.collapsed .sidebar-toggle { margin-left: 0; }
.sidebar.collapsed .nav-item { width: 32px; margin: 0 auto; justify-content: center; }
.sidebar.collapsed .group-label { height: 0; padding: 0; opacity: 0; }
.sidebar.collapsed .avatar { margin: 0 auto; }

.content { flex: 1; min-width: 0; }

main { padding: 24px; max-width: 980px; margin: 0 auto; display: grid; gap: 24px; }

.page-head h1 { margin: 0 0 4px; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.page-head p { margin: 0; }

/* ── cards / sections ──────────────────────────────────────────────────────── */
section {
	background: var(--card);
	color: var(--card-foreground);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	padding: 24px;
	box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
section h2 { margin: 0 0 16px; font-size: 18px; font-weight: 600; line-height: 1; letter-spacing: -0.01em; }

/* A task entry inside the Tasks list — an inset card on the section background. */
.task-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px; margin-bottom: 12px; }
.task-card:last-child { margin-bottom: 0; }
.task-card details { margin-top: 8px; }
.task-card summary { cursor: pointer; color: var(--muted-foreground); font-size: 13px; }

/* ── tables ────────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted-foreground); font-weight: 500; height: 40px; }
tbody tr { transition: background-color .15s ease; }
tbody tr:hover { background: oklch(1 0 0 / 3%); }
tbody tr:last-child td { border-bottom: 0; }

/* ── usage meter ───────────────────────────────────────────────────────────── */
.bar { background: var(--secondary); border-radius: 999px; height: 8px; overflow: hidden; min-width: 80px; display: inline-block; vertical-align: middle; }
.bar > span { display: block; height: 100%; background: var(--success); }
.bar.over > span { background: var(--destructive); }

/* ── badges / pills ────────────────────────────────────────────────────────── */
.pill { display: inline-block; padding: 2px 8px; border-radius: var(--radius-md); font-size: 12px; font-weight: 500; border: 1px solid transparent; }
.ok { background: oklch(0.696 0.17 162.48 / 18%); color: oklch(0.85 0.14 162); }
.no { background: oklch(0.704 0.191 22.216 / 15%); color: oklch(0.82 0.12 22); }

/* ── buttons ───────────────────────────────────────────────────────────────── */
button, a.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 6px;
	background: oklch(1 0 0 / 4%);
	color: var(--foreground);
	border: 1px solid var(--input);
	border-radius: var(--radius-md);
	padding: 6px 12px;
	font: 500 14px/1 var(--font-sans);
	cursor: pointer;
	text-decoration: none;
	transition: background-color .15s ease, border-color .15s ease;
}
button:hover, a.btn:hover { background: oklch(1 0 0 / 8%); }
button.primary, a.btn.primary { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }
button.primary:hover, a.btn.primary:hover { background: oklch(0.922 0 0 / 90%); }
a.btn-link { text-decoration: none; }

/* ── inputs ────────────────────────────────────────────────────────────────── */
input, select, textarea {
	background: oklch(1 0 0 / 4%);
	color: var(--foreground);
	border: 1px solid var(--input);
	border-radius: var(--radius-md);
	padding: 6px 12px;
	font: inherit;
	transition: border-color .15s ease, box-shadow .15s ease;
	/* Render the native dropdown popup in dark mode so its options aren't
	   light-text-on-light-background (otherwise the items are invisible). */
	color-scheme: dark;
}
/* Solid option colors for browsers that honor option styling, so the popup
   list is legible regardless of the select's translucent background. */
select option {
	background: var(--card);
	color: var(--card-foreground);
}
input::placeholder, textarea::placeholder { color: var(--muted-foreground); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
	outline: none;
	border-color: var(--ring);
	box-shadow: 0 0 0 3px oklch(0.556 0 0 / 40%);
}
textarea { width: 100%; box-sizing: border-box; min-height: 80px; resize: vertical; }
label { display: inline-flex; align-items: center; gap: 6px; }

/* ── misc ──────────────────────────────────────────────────────────────────── */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted-foreground); }
pre { background: var(--background); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; overflow: auto; max-height: 280px; white-space: pre-wrap; font-family: var(--font-mono); font-size: 13px; }
code { background: var(--background); padding: 1px 4px; border-radius: 4px; font-family: var(--font-mono); }
.log { font-family: var(--font-mono); font-size: 12px; color: var(--muted-foreground); }
a { color: inherit; }

/* ── modal dialog (Account usage caps) — Datastar data-show overlay ────────── */
.modal-overlay {
	position: fixed; inset: 0; z-index: 50;
	background: rgba(0,0,0,.55);
	display: flex; align-items: center; justify-content: center;
	padding: 24px;
}
.modal {
	width: min(640px, calc(100vw - 48px));
	max-height: calc(100vh - 48px);
	display: flex; flex-direction: column; overflow: hidden;
	background: var(--card);
	color: var(--foreground);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	box-shadow: 0 16px 48px rgba(0,0,0,.5);
}
.modal-header {
	display: flex; align-items: center; justify-content: space-between;
	padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; overflow: auto; }
.modal-section { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
/* plan text inside the task plan modal: scrollable, wraps long lines */
.plan-text {
	max-height: 48vh; overflow: auto; white-space: pre-wrap; word-break: break-word;
	margin: 0; padding: 12px;
	background: oklch(1 0 0 / 3%); border: 1px solid var(--border); border-radius: var(--radius-md);
	font-size: 13px; line-height: 1.5;
}

/* small square icon button (modal close, remove-tier) */
.icon-btn {
	display: inline-flex; align-items: center; justify-content: center;
	width: 32px; height: 32px; padding: 0;
	font-size: 18px; line-height: 1;
	background: oklch(1 0 0 / 4%); color: var(--foreground);
	border: 1px solid var(--input); border-radius: var(--radius-md);
	cursor: pointer; transition: background-color .15s ease;
}
.icon-btn:hover { background: oklch(1 0 0 / 8%); }

/* cap-tier table */
.caps-table { margin: 16px 0 12px; }
.caps-table th { font-size: 13px; }
.caps-table td { vertical-align: middle; }
.caps-table .cmp { color: var(--muted-foreground); margin-right: 4px; }
.input-sm { width: 72px; }

/* HTMX loading indicator (shown only while a request is in flight) */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
.run-result pre { margin-top: 12px; }

/* ── "busy" feedback for any control issuing an HTMX request ──────────────────
   A button is busy from when it fires a request until the resulting state is
   rendered: HTMX adds .htmx-request for the request itself, and the layout script
   adds .is-busy (+ disabled) for the whole window, including the wait for the SSE
   morph that swaps the button out. We grey it, show a spinner, and ignore clicks
   so a request can't be double-submitted. */
button.htmx-request, a.btn.htmx-request, button.is-busy, a.btn.is-busy, button:disabled {
	opacity: .6; cursor: progress; pointer-events: none;
}
/* spinner appended after the label (flex `gap` spaces it). Skipped for the small
   square icon buttons, where there's no room. */
button.htmx-request:not(.icon-btn)::after, a.btn.htmx-request::after,
button.is-busy:not(.icon-btn)::after, a.btn.is-busy::after {
	content: ""; display: inline-block;
	width: .85em; height: .85em;
	border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
	animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── login page — same dark tokens, centered card ──────────────────────────── */
body.login-body { background: var(--background); color: var(--foreground); }
.login-wrap { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-wrap .card { width: 100%; max-width: 28rem; padding: 2rem; background: transparent; border: 0; text-align: center; }
.login-wrap h1 { font-size: 1.875rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 .5rem; }
.login-wrap > .card > p { color: var(--muted-foreground); margin: 0 0 2rem; }
a.gbtn {
	display: flex; gap: .75rem; align-items: center; justify-content: center;
	width: 100%; box-sizing: border-box; text-decoration: none;
	padding: .75rem 1rem;
	border: 1px solid var(--input); border-radius: var(--radius-md);
	background: oklch(1 0 0 / 4%); color: var(--foreground);
	font-weight: 500; transition: background-color .15s ease;
}
a.gbtn:hover { background: oklch(1 0 0 / 8%); }
.gbtn svg { width: 1.25rem; height: 1.25rem; }
