* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
	background: #0f1115; color: #e8e8e8;
	display: flex; flex-direction: column;
}
header {
	padding: 12px 20px; border-bottom: 1px solid #1f2330;
	display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { width: 28px; height: 28px; }
.header-right { display: flex; align-items: center; gap: 10px; }
header h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.brand-prefix { color: #7ea6ff; }
.brand-suffix { color: #fff; }
header small { color: #8a92a3; }
.active-org {
	font-size: 12px;
	font-weight: 600;
	color: #7ea6ff;
	background: #1a2540;
	border: 1px solid #2a4a87;
	padding: 4px 10px;
	border-radius: 12px;
	text-transform: none;
	letter-spacing: 0.01em;
}
.active-org:empty { display: none; }
.user-name {
	font-size: 13px; color: #cbd3e3;
}

/* --- Company welcome card (injected after selection) --- */
.msg.assistant.company-welcome .body {
	background: #12161f;
	border: 1px solid #2a334d;
	border-left: 3px solid #7ea6ff;
	border-radius: 8px;
	padding: 12px 16px;
	margin-top: 2px;
}
.msg.assistant.company-welcome h2 {
	margin-top: 2px;
}

/* --- Company selector modal --- */
/* The [hidden] attribute's user-agent default is `display: none`, but a more
   specific .modal rule below would override it. Force it to stay hidden. */
.modal[hidden] { display: none; }
.modal {
	position: fixed;
	inset: 0;
	background: rgba(15, 17, 21, 0.85);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100;
	padding: 20px;
}
.modal-card {
	background: #12161f;
	border: 1px solid #2a334d;
	border-radius: 12px;
	padding: 28px 28px 24px;
	max-width: 480px;
	width: 100%;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.modal-card h2 {
	margin: 0 0 6px;
	color: #fff;
	font-size: 20px;
}
.modal-card .modal-sub {
	margin: 0 0 20px;
	color: #8a92a3;
	font-size: 13px;
	line-height: 1.5;
}
.modal-card .modal-sub code {
	background: #1a1f2a;
	padding: 1px 6px;
	border-radius: 3px;
	font-size: 12px;
	color: #7ea6ff;
}
.company-list { display: flex; flex-direction: column; gap: 8px; }
.company-btn {
	display: block;
	width: 100%;
	text-align: left;
	padding: 12px 16px;
	background: #161a24;
	border: 1px solid #2a334d;
	border-radius: 10px;
	color: #e8e8e8;
	font-size: 15px;
	font-weight: 500;
	cursor: pointer;
	transition: background 120ms ease, border-color 120ms ease;
}
.company-btn:hover {
	background: #1a2540;
	border-color: #4a5a87;
}
.company-btn .company-desc {
	display: block;
	margin-top: 4px;
	font-size: 12px;
	font-weight: 400;
	color: #6f7891;
}
.modal-card .error {
	background: #2a1418;
	border: 1px solid #5a2028;
	color: #f2b4c0;
	padding: 10px 12px;
	border-radius: 8px;
	font-size: 13px;
	margin-top: 12px;
}
.logout-btn {
	padding: 6px 12px; border-radius: 6px; border: 1px solid #2a334d;
	background: transparent; color: #cbd3e3; font-size: 12px; cursor: pointer;
	transition: background 120ms ease, color 120ms ease;
}
.logout-btn:hover { background: #2a334d; color: #fff; }
main {
	flex: 1; overflow-y: auto;
	padding: 20px; max-width: 880px; margin: 0 auto; width: 100%;
}
.msg { margin-bottom: 16px; line-height: 1.55; }
.msg.user .body { color: #cfe1ff; white-space: pre-wrap; }
.msg.assistant .body { color: #e8e8e8; }
.msg.tool {
	color: #6f7891; font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
	background: #161a24; border-left: 2px solid #2a334d; padding: 6px 10px; margin-left: 12px;
	border-radius: 0 4px 4px 0; white-space: pre-wrap;
}
.msg .role { font-size: 11px; text-transform: uppercase; color: #6f7891; margin-bottom: 2px; }

/* --- Markdown rendering inside assistant bubbles --- */
.msg .markdown h1,
.msg .markdown h2,
.msg .markdown h3,
.msg .markdown h4 {
	margin: 14px 0 6px;
	color: #fff;
	font-weight: 600;
	line-height: 1.3;
}
.msg .markdown h1 { font-size: 20px; }
.msg .markdown h2 { font-size: 17px; }
.msg .markdown h3 { font-size: 15px; }
.msg .markdown h4 { font-size: 14px; color: #cbd3e3; }
.msg .markdown p { margin: 6px 0; }
.msg .markdown ul,
.msg .markdown ol { margin: 6px 0; padding-left: 22px; }
.msg .markdown li { margin: 2px 0; }
.msg .markdown strong { color: #fff; font-weight: 600; }
.msg .markdown em { color: #cfe1ff; }
.msg .markdown code {
	background: #1a1f2a; padding: 1px 5px; border-radius: 3px;
	font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px;
	color: #e6c98a;
}
.msg .markdown pre {
	background: #1a1f2a; padding: 10px 12px; border-radius: 6px;
	overflow-x: auto; margin: 8px 0;
}
.msg .markdown pre code {
	background: none; padding: 0; color: #e8e8e8;
}
.msg .markdown blockquote {
	margin: 6px 0; padding-left: 12px; border-left: 3px solid #2a334d; color: #a9b1c6;
}
.msg .markdown a { color: #7ea6ff; text-decoration: underline; }
.msg .markdown hr { border: 0; border-top: 1px solid #1f2330; margin: 10px 0; }
.msg .markdown table {
	border-collapse: collapse; margin: 8px 0; font-size: 13px;
	width: auto; overflow-x: auto;
}
.msg .markdown th,
.msg .markdown td {
	border: 1px solid #2a334d; padding: 6px 10px; text-align: left;
}
.msg .markdown th { background: #161a24; color: #fff; font-weight: 600; }
.msg .markdown tr:nth-child(even) td { background: #12161f; }

/* --- Staff list (interactive multi-select) --- */
.msg.staff-list {
	background: #12161f;
	border: 1px solid #2a334d;
	border-radius: 8px;
	padding: 12px 14px;
	max-width: 860px;
}
.staff-list-title {
	color: #fff;
	font-weight: 600;
	font-size: 14px;
	margin-bottom: 10px;
}
.staff-list-table-wrap {
	max-height: 360px;
	overflow-y: auto;
	border-radius: 6px;
	border: 1px solid #1f2330;
}
.staff-list-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
}
.staff-list-table thead th {
	position: sticky; top: 0;
	background: #161a24;
	color: #cbd3e3;
	font-weight: 600;
	padding: 8px 10px;
	text-align: left;
	border-bottom: 1px solid #2a334d;
}
.staff-list-table tbody td {
	padding: 7px 10px;
	border-bottom: 1px solid #1a1f2a;
	color: #e8e8e8;
}
.staff-list-table tbody tr:hover { background: #161a24; }
.staff-list-table .checkbox-col { width: 36px; text-align: center; }
.staff-list-table input[type="checkbox"] {
	width: 15px; height: 15px;
	cursor: pointer;
	accent-color: #4a5a87;
}
.staff-list-table input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.3; }

.staff-list-actions {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-top: 12px;
}
.staff-list-counter {
	font-size: 12px;
	color: #8a92a3;
}
.staff-list-btn {
	padding: 8px 16px;
	border-radius: 6px;
	border: 0;
	background: #4a5a87;
	color: #fff;
	font-weight: 600;
	font-size: 13px;
	cursor: pointer;
	transition: background 120ms ease, opacity 120ms ease;
}
.staff-list-btn:hover:not(:disabled) { background: #5a6a97; }
.staff-list-btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

/* --- Tree / org chart (coloured department cards) --- */
.msg.tree {
	background: #12161f;
	border: 1px solid #2a334d;
	border-radius: 8px;
	padding: 14px 16px;
	max-width: 1040px;
}
.tree-title {
	color: #fff;
	font-weight: 700;
	font-size: 15px;
	margin-bottom: 2px;
}
.tree-subtitle {
	color: #8a92a3;
	font-size: 12px;
	font-style: italic;
	margin-bottom: 12px;
}
.tree-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
	gap: 12px;
}
.tree-dept {
	/* background-color + border-left-color are set inline per department
	   so each card picks up its own hue from the JS colour generator */
	background-color: #1a2030;
	border: 1px solid #2a334d;
	border-left: 4px solid #4a5a87;
	border-radius: 6px;
	padding: 10px 12px 12px 12px;
	min-width: 0;
}
.tree-dept-header {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 8px;
	padding-bottom: 6px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.tree-dept-name {
	color: #fff;
	font-weight: 700;
	font-size: 13px;
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.tree-dept-count {
	/* background-color is set inline to the card's accent hue */
	color: #0b0e14;
	font-size: 11px;
	font-weight: 700;
	padding: 2px 8px;
	border-radius: 999px;
	flex-shrink: 0;
}
.tree-dept-roles {
	display: flex;
	flex-direction: column;
	gap: 6px;
	font-size: 12px;
	color: #cbd3e3;
}
.tree-role {
	line-height: 1.4;
}
.tree-role-name {
	color: #e8e8e8;
	font-weight: 600;
}
.tree-role-count {
	color: #8a92a3;
	font-weight: 400;
}
.tree-person {
	color: #cbd3e3;
}
.tree-people {
	list-style: none;
	margin: 2px 0 0 10px;
	padding: 0;
}
.tree-people li {
	color: #cbd3e3;
	padding: 1px 0 1px 10px;
	position: relative;
}
.tree-people li::before {
	content: "·";
	position: absolute;
	left: 0;
	color: #6f7891;
	font-weight: 700;
}

/* Small colour-coded pill for a preferred Belbin role, rendered next to a
   staff name in the /tree org chart. Background + text colour are set
   inline per-pill from BELBIN_COLORS (JS) so each role keeps its canonical
   hue and the text stays legible on both light and dark pills. */
.belbin-tag {
	display: inline-block;
	margin-left: 5px;
	padding: 1px 6px;
	font-size: 9px;
	font-weight: 700;
	font-family: 'SF Mono', Menlo, Consolas, monospace;
	letter-spacing: 0.4px;
	border-radius: 3px;
	vertical-align: 1px;
	line-height: 1.4;
}

/* --- Chart bubble (radar chart message) --- */
.msg.chart {
	background: #12161f;
	border: 1px solid #2a334d;
	border-radius: 8px;
	padding: 12px 14px;
	max-width: 560px;
}
.msg.chart .chart-title {
	color: #fff;
	font-weight: 600;
	font-size: 14px;
	margin-bottom: 8px;
}
.msg.chart .chart-canvas-wrap {
	position: relative;
	height: 704px;
	width: 100%;
}
.msg.chart .chart-canvas-wrap.spread {
	height: auto;
	aspect-ratio: 16 / 9;
}
.msg.chart .chart-canvas-wrap.bars {
	height: auto;
	aspect-ratio: 16 / 7;
}

/* Help menu */
.msg.help-menu {
	max-width: 700px;
}
.help-org-card {
	background: #1a1f2e;
	border: 1px solid #2a334d;
	border-radius: 8px;
	padding: 16px 20px;
	margin-bottom: 16px;
}
.help-org-name {
	color: #fff;
	font-size: 20px;
	font-weight: 700;
	margin: 0 0 10px 0;
}
.help-org-desc {
	color: #cbd3e3;
	font-size: 14px;
	line-height: 1.5;
	margin: 0 0 12px 0;
}
.help-org-detail {
	color: #9aa3b8;
	font-size: 13px;
	line-height: 1.5;
	margin-bottom: 6px;
}
.help-org-detail strong {
	color: #cbd3e3;
}
.help-menu-title {
	color: #cbd3e3;
	font-size: 14px;
	font-weight: 600;
	margin-bottom: 10px;
}
.help-menu-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 8px;
}
.help-menu-btn {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	padding: 12px 14px;
	background: #1a1f2e;
	border: 1px solid #2a334d;
	border-radius: 8px;
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s;
}
.help-menu-btn:hover {
	background: #232a3c;
	border-color: #3a7bd5;
}
.help-menu-btn-label {
	color: #fff;
	font-size: 14px;
	font-weight: 600;
	margin-bottom: 4px;
}
.help-menu-btn-desc {
	color: #9aa3b8;
	font-size: 12px;
	line-height: 1.4;
}

form#composer {
	display: flex; gap: 8px;
	padding: 12px 20px; border-top: 1px solid #1f2330; background: #0f1115;
}
input#input {
	flex: 1; padding: 10px 14px; border-radius: 6px; border: 1px solid #2a334d;
	background: #161a24; color: #e8e8e8; font-size: 15px;
}
input#input:focus { outline: none; border-color: #4a5a87; }
button {
	padding: 10px 18px; border-radius: 6px; border: 0;
	background: #4a5a87; color: #fff; font-weight: 600; cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===================================================================
   Responsive breakpoints
   =================================================================== */

@media (max-width: 768px) {
	.help-menu-grid {
		grid-template-columns: repeat(2, 1fr);
	}
	.msg.tree { max-width: 100%; }
}

@media (max-width: 640px) {
	header { padding: 10px 14px; }
	header h1 { font-size: 17px; }
	.active-org { font-size: 11px; padding: 3px 8px; }

	main { max-width: 100%; padding: 14px 10px; }

	.msg { margin-bottom: 12px; }
	.msg.chart { max-width: 100%; padding: 10px; }
	.msg.chart .chart-canvas-wrap { height: 500px; }
	.msg.chart .chart-canvas-wrap.spread { height: auto; aspect-ratio: 16 / 9; }
	.msg.chart .chart-canvas-wrap.bars { height: auto; aspect-ratio: 16 / 7; }
	.msg.staff-list { max-width: 100%; padding: 10px; }
	.msg.help-menu { max-width: 100%; }
	.msg.tree { padding: 10px; }

	.staff-list-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
	.staff-list-table { font-size: 12px; min-width: 520px; }
	.staff-list-table thead th { padding: 6px 8px; }
	.staff-list-table tbody td { padding: 6px 8px; }

	.tree-grid { grid-template-columns: 1fr; }

	.help-menu-grid { grid-template-columns: 1fr; }
	.help-org-card { padding: 12px 14px; }
	.help-org-name { font-size: 17px; }

	form#composer { padding: 10px 10px; gap: 6px; }
	input#input { padding: 10px 12px; font-size: 14px; }
	button { padding: 10px 14px; font-size: 14px; }
}

@media (max-width: 480px) {
	header h1 { font-size: 16px; }
	.header-right { gap: 6px; }
	.user-name { font-size: 11px; }
	.logout-btn { padding: 4px 8px; font-size: 11px; }

	.msg .role { font-size: 10px; }
	.msg.staff-list { padding: 8px; }
	.staff-list-table { min-width: 460px; font-size: 11px; }

	.help-menu-btn { padding: 10px 12px; }
	.help-menu-btn-label { font-size: 13px; }

	.modal-card { padding: 20px 18px; }
}
