:root {
	--bg: #0b0f17;
	--panel: #131a26;
	--panel-2: #1b2433;
	--border: #243044;
	--text: #e6edf6;
	--muted: #8a99ad;
	--accent: #2f81f7;
	--accent-hover: #4a93ff;
	--radius: 10px;
}

* { box-sizing: border-box; }

/* [hidden] must beat layout rules like .room-layout { display: grid }. */
[hidden] { display: none !important; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
	display: flex;
	align-items: baseline;
	gap: 0.75rem;
	padding: 0.9rem 1.25rem;
	border-bottom: 1px solid var(--border);
	background: var(--panel);
}

.brand {
	font-weight: 700;
	letter-spacing: 0.08em;
	color: var(--accent);
	text-decoration: none;
}

.tagline { color: var(--muted); font-size: 0.85rem; }

.container {
	max-width: 1180px;
	margin: 2rem auto;
	padding: 0 1.25rem;
	display: flex;
	flex-direction: column;
	gap: 1.25rem;
}

/* Single-card pages (home/join) stay compact within the wide container. */
.card.narrow {
	max-width: 460px;
	margin-left: auto;
	margin-right: auto;
	width: 100%;
}

/* Room: two columns. Left = identity + grid (grid stays put); right = crew +
   contracts (grows downward). align-items:stretch keeps the left column as tall
   as the right, giving the sticky grid room to travel. */
.room-layout {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
	gap: 1.25rem;
}

.col {
	display: flex;
	flex-direction: column;
	gap: 1.25rem;
	min-width: 0;
}

.col-left #grid {
	position: sticky;
	top: 1.25rem;
}

@media (max-width: 820px) {
	.room-layout { grid-template-columns: 1fr; }
	.col-left #grid { position: static; }
}

.card {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 1.25rem 1.5rem;
}

h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
h2 { margin: 0 0 0.75rem; font-size: 1.05rem; color: var(--muted); font-weight: 600; }

.muted { color: var(--muted); margin: 0.25rem 0; }

.stack { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }

label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }

input[type="text"] {
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0.6rem 0.75rem;
	color: var(--text);
	font-size: 1rem;
}

input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }

button {
	align-self: flex-start;
	background: var(--accent);
	color: white;
	border: none;
	border-radius: 8px;
	padding: 0.6rem 1.1rem;
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
}

button:hover { background: var(--accent-hover); }

.room-head .share input { width: 100%; margin-top: 0.25rem; font-family: ui-monospace, monospace; }

.crew { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }

.crew li {
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 0.3rem 0.8rem;
	font-size: 0.9rem;
}

input[type="number"] {
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0.6rem 0.75rem;
	color: var(--text);
	font-size: 1rem;
	width: 8rem;
}

input[type="number"]:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* Inline add/edit forms */
.row {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: center;
}

.row input[type="text"] { flex: 1 1 12rem; min-width: 8rem; }

button.secondary {
	background: var(--panel-2);
	border: 1px solid var(--border);
	color: var(--text);
	font-weight: 500;
	padding: 0.45rem 0.8rem;
}

button.secondary:hover { background: var(--border); }

button.link {
	background: none;
	border: none;
	color: var(--accent);
	padding: 0.2rem 0.4rem;
	font-size: 0.85rem;
	font-weight: 500;
	cursor: pointer;
}

button.link:hover { color: var(--accent-hover); background: none; text-decoration: underline; }
button.link.danger { color: #e5687a; }
button.link.danger:hover { color: #ff8497; }

/* Contracts */
.add-contract { margin: 0.75rem 0 1rem; }

.contract-list { display: flex; flex-direction: column; gap: 1rem; }

.contract {
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 0.9rem 1rem;
}

.contract-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.5rem;
	margin-bottom: 0.6rem;
}

.contract-title { display: flex; align-items: baseline; gap: 0.6rem; }
.contract-title > span:first-child { font-weight: 600; font-size: 1.05rem; }

.reward {
	color: #6fcf8e;
	font-size: 0.85rem;
	font-variant-numeric: tabular-nums;
}

.contract .actions { display: flex; gap: 0.25rem; }

.pickups { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.6rem; }

.pickup {
	border-left: 2px solid var(--border);
	padding-left: 0.75rem;
}

.pickup-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.5rem;
}

.pickup-route { font-size: 0.95rem; }
.pickup-route strong { color: var(--text); }

.deliveries { list-style: none; padding: 0; margin: 0.4rem 0; display: flex; flex-direction: column; gap: 0.3rem; }

.delivery {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0.35rem 0.6rem;
	font-size: 0.9rem;
}

.delivery .dest { flex: 1; }
.delivery .scu { color: var(--muted); font-variant-numeric: tabular-nums; }
.delivery .actions { display: flex; gap: 0.1rem; }
.delivery.editing, .contract.editing { outline: 1px dashed var(--accent); }

.add-pickup, .add-delivery { margin-top: 0.4rem; }
.add-delivery { padding-left: 0; }

/* Drag handles */
.drag {
	cursor: grab;
	color: var(--muted);
	user-select: none;
	padding: 0 0.4rem 0 0;
	font-size: 1rem;
	line-height: 1;
}
.drag:active { cursor: grabbing; }
.contract-head .drag { align-self: center; }
.sortable-ghost { opacity: 0.4; }
.sortable-chosen { outline: 1px solid var(--accent); }

/* Cargo grid */
.grid-size { margin: 0.5rem 0 1rem; }
.grid-size label { flex-direction: row; align-items: center; gap: 0.4rem; color: var(--muted); }
.grid-size input[type="number"] { width: 4.5rem; }

.grid { display: grid; gap: 0.5rem; }
.cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.cols-7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cols-8 { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.cols-9 { grid-template-columns: repeat(9, minmax(0, 1fr)); }
.cols-10 { grid-template-columns: repeat(10, minmax(0, 1fr)); }

.grid-cell {
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0.5rem;
	min-height: 68px;
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
}
.grid-cell.empty { opacity: 0.45; border-style: dashed; }
.grid-cell[draggable="true"] { cursor: grab; }
.grid-cell[draggable="true"]:active { cursor: grabbing; }
.grid-cell.drop-target { border-color: var(--accent); background: var(--panel); outline: 1px solid var(--accent); }
.grid-cell .coord { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.grid-cell .cell-dest { font-weight: 600; font-size: 0.95rem; }
.grid-cell .cell-meta { font-size: 0.75rem; color: var(--muted); margin-top: auto; }

.culled { margin-top: 1rem; }
.culled h3 { font-size: 0.9rem; color: #e5687a; font-weight: 600; margin: 0 0 0.5rem; }
.culled ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.culled li { display: flex; gap: 0.6rem; align-items: baseline; font-size: 0.9rem; color: var(--muted); }

/* Plan/Run view toggle */
.view-toggle {
	display: inline-flex;
	gap: 0;
	border: 1px solid var(--border);
	border-radius: 999px;
	overflow: hidden;
	margin-bottom: 0.25rem;
	align-self: flex-start;
}
.view-toggle button {
	background: var(--panel);
	color: var(--muted);
	border: none;
	border-radius: 0;
	padding: 0.4rem 1.1rem;
	font-size: 0.9rem;
	font-weight: 600;
}
.view-toggle button.active { background: var(--accent); color: #fff; }
.view-toggle button:not(.active):hover { background: var(--panel-2); color: var(--text); }

/* Delivery done state (plan view) */
.delivery .done-check { accent-color: var(--accent); width: 1rem; height: 1rem; cursor: pointer; }
.delivery.done .dest, .delivery.done .scu { text-decoration: line-through; color: var(--muted); }

/* Run view */
.run-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
.run-badge {
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--muted);
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 0.1rem 0.55rem;
	margin-left: 0.4rem;
	vertical-align: middle;
}
.run-actions {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-top: 1rem;
	padding-top: 0.9rem;
	border-top: 1px solid var(--border);
}
.run-actions .row { flex: 0 1 auto; }
.run-actions label { flex-direction: row; align-items: center; gap: 0.4rem; }
.run-actions input[type="number"] { width: 8rem; }

/* Session view */
.session-stats { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 0.5rem 0 1.25rem; }
.stat {
	flex: 1 1 8rem;
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0.7rem 0.9rem;
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}
.stat-val { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.75rem; color: var(--muted); }

.session-tops { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1rem; }
.session-tops h3 { font-size: 0.9rem; color: var(--muted); margin: 0 0 0.5rem; }
.named-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.named-list li { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.9rem; }
.named-list .muted { font-variant-numeric: tabular-nums; }

.run-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.run-table th, .run-table td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }
.run-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
.run-table td { font-variant-numeric: tabular-nums; }
.run-table td:first-child, .run-table th:first-child { width: 4rem; }

@media (max-width: 560px) {
	.session-tops { grid-template-columns: 1fr; }
}
.run-progress { color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

.bar { height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin: 0.5rem 0 1rem; }
.bar-fill { height: 100%; background: #6fcf8e; transition: width 0.2s ease; }

.run-cell {
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0.6rem;
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
}
.run-cell.cleared { border-color: #2f6f44; background: #14241a; }
.run-cell-head { display: flex; align-items: baseline; gap: 0.5rem; }
.run-cell-head .coord { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.run-cell-head .run-dest { font-weight: 600; flex: 1; }
.run-cell-head .run-count { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Commodity tiles wrap within a destination card. */
.run-items { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.run-item { margin: 0; }
.run-item label {
	display: inline-flex;
	flex-direction: row;
	align-items: center;
	gap: 0.4rem;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 0.25rem 0.5rem;
	cursor: pointer;
	font-size: 0.82rem;
	white-space: nowrap;
}
.run-item label:hover { border-color: var(--accent); }
.run-item input[type="checkbox"] { accent-color: #6fcf8e; width: 0.95rem; height: 0.95rem; margin: 0; flex: none; }
.run-item .ri-mat { font-weight: 500; }
.run-item .ri-scu { color: var(--muted); font-variant-numeric: tabular-nums; }
.run-item.done label { opacity: 0.55; }
.run-item.done .ri-mat { text-decoration: line-through; }
