/* ==========================================================================
   Shelter save editor - app styles (no framework)
   Light/dark themes: follows the OS setting unless the user picked one with
   the toggle (stored in localStorage, applied as <html data-theme="...">).
   ========================================================================== */

/* ---- theme tokens ------------------------------------------------------- */
:root {
	color-scheme: light;

	--bg:            #eceff1;
	--surface:       #ffffff;
	--surface-2:     #f5f7f8;
	--surface-hover: #e8eef1;
	--border:        #d5dde1;
	--text:          #1d2529;
	--text-muted:    #5d6b73;

	--primary:       #546e7a;
	--primary-hover: #455a64;
	--on-primary:    #ffffff;
	--accent:        #e53935;
	--accent-hover:  #c62828;
	--on-accent:     #ffffff;

	--nav-active-bg: #d9e2e6;
	--focus:         #1e88e5;
	--shadow:        0 1px 3px rgba(0, 0, 0, .14), 0 2px 8px rgba(0, 0, 0, .08);
	--shadow-lg:     0 4px 12px rgba(0, 0, 0, .18), 0 10px 28px rgba(0, 0, 0, .12);

	--rarity-legendary: #a06a00;
	--rarity-rare:      #1a5fd0;
	--rarity-normal:    #2a7a31;

	--json-key:  #1a5fd0;
	--json-str:  #2a7a31;
	--json-num:  #b4531a;
	--json-bool: #8a3fb5;

	--logo-filter: none;
	--drawer-w: 240px;
	--radius: 8px;
}

/* dark values: applied by the manual toggle here, and by the OS setting in the media query below */
:root[data-theme="dark"] {
	color-scheme: dark;

	--bg:            #14181b;
	--surface:       #1d2327;
	--surface-2:     #252c31;
	--surface-hover: #2d363c;
	--border:        #37424a;
	--text:          #e6ebee;
	--text-muted:    #9aa8b0;

	--primary:       #78909c;
	--primary-hover: #90a4ae;
	--on-primary:    #10171a;
	--accent:        #ff6659;
	--accent-hover:  #ff8a80;
	--on-accent:     #1a0b0a;

	--nav-active-bg: #2d3a42;
	--focus:         #64b5f6;
	--shadow:        0 1px 3px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .35);
	--shadow-lg:     0 4px 12px rgba(0, 0, 0, .6), 0 10px 28px rgba(0, 0, 0, .45);

	--rarity-legendary: #f0b429;
	--rarity-rare:      #6da8ff;
	--rarity-normal:    #6fcf76;

	--json-key:  #7fb2ff;
	--json-str:  #8fd694;
	--json-num:  #f0a36b;
	--json-bool: #c79bf0;

	--logo-filter: invert(1);
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;

		--bg:           #14181b;
		--surface:       #1d2327;
		--surface-2:     #252c31;
		--surface-hover: #2d363c;
		--border:        #37424a;
		--text:          #e6ebee;
		--text-muted:    #9aa8b0;

		--primary:       #78909c;
		--primary-hover: #90a4ae;
		--on-primary:    #10171a;
		--accent:        #ff6659;
		--accent-hover:  #ff8a80;
		--on-accent:     #1a0b0a;

		--nav-active-bg: #2d3a42;
		--focus:         #64b5f6;
		--shadow:        0 1px 3px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .35);
		--shadow-lg:     0 4px 12px rgba(0, 0, 0, .6), 0 10px 28px rgba(0, 0, 0, .45);

		--rarity-legendary: #f0b429;
		--rarity-rare:      #6da8ff;
		--rarity-normal:    #6fcf76;

		--json-key:  #7fb2ff;
		--json-str:  #8fd694;
		--json-num:  #f0a36b;
		--json-bool: #c79bf0;

		--logo-filter: invert(1);
	}
}

/* ---- base --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 500; line-height: 1.25; }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.1rem; margin-top: 1rem; }

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

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

.material-icons { user-select: none; }

/* ---- buttons ------------------------------------------------------------ */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: .4rem;
	min-height: 36px;
	padding: 0 16px;
	border: 1px solid transparent;
	border-radius: 6px;
	background: transparent;
	color: var(--primary);
	font-family: inherit;
	font-size: .875rem;
	font-weight: 500;
	line-height: 1;
	letter-spacing: .04em;
	text-transform: uppercase;
	text-decoration: none;
	cursor: pointer;
	transition: background-color .15s, box-shadow .15s, border-color .15s;
}
.btn:hover { background: var(--surface-hover); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: default; }

.btn-primary {
	background: var(--primary);
	color: var(--on-primary);
	box-shadow: var(--shadow);
}
.btn-primary:hover { background: var(--primary-hover); color: var(--on-primary); }

.btn-outline { border-color: var(--border); }

.btn-icon {
	width: 36px;
	min-height: 36px;
	padding: 0;
	border-radius: 50%;
}

.btn-fab {
	width: 56px;
	height: 56px;
	min-height: 56px;
	padding: 0;
	border-radius: 50%;
	background: var(--accent);
	color: var(--on-accent);
	box-shadow: var(--shadow-lg);
}
.btn-fab:hover { background: var(--accent-hover); color: var(--on-accent); }

/* ---- form controls ------------------------------------------------------ */
input[type="text"], input[type="number"], select {
	width: 100%;
	min-height: 38px;
	padding: 6px 10px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--surface);
	color: var(--text);
	font: inherit;
}
input[type="text"]:disabled, input[type="number"]:disabled, select:disabled {
	background: var(--surface-2);
	color: var(--text-muted);
	opacity: .75;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
	border-color: var(--focus);
	outline: 1px solid var(--focus);
}

input[type="range"] {
	width: 100%;
	accent-color: var(--accent);
	cursor: pointer;
}
input[type="range"]:disabled { cursor: default; }

input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

input[type="color"] {
	width: 44px;
	height: 32px;
	padding: 2px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--surface);
	cursor: pointer;
}
input[type="color"]:disabled { opacity: .5; cursor: default; }

input[type="file"] {
	width: 100%;
	padding: 18px;
	border: 2px dashed var(--border);
	border-radius: var(--radius);
	background: var(--surface-2);
	color: var(--text);
	font: inherit;
	cursor: pointer;
}
input[type="file"]::file-selector-button {
	margin-right: 14px;
	padding: 8px 14px;
	border: 0;
	border-radius: 6px;
	background: var(--primary);
	color: var(--on-primary);
	font: inherit;
	font-weight: 500;
	cursor: pointer;
}
input[type="file"]:hover { border-color: var(--primary); }

option { background: var(--surface); color: var(--text); }
option.legendary, .legendary { color: var(--rarity-legendary); }
option.rare, .rare           { color: var(--rarity-rare); }
option.normal, .normal       { color: var(--rarity-normal); }

label { font-weight: 500; }

/* ---- cards -------------------------------------------------------------- */
.card {
	background: var(--surface);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	overflow: hidden;
}
.card-body    { padding: 16px; }
.card-actions { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }

/* ---- landing page ------------------------------------------------------- */
.landing { padding: 16px; }
.landing .card { width: min(500px, 100%); margin: 48px auto; }
.landing .card-help { margin-top: 0; }
.landing .card-banner { display: block; width: 100%; height: auto; }
.landing .card-help .card-body { color: var(--text); }
.landing .card-help h3 { margin: 4px 0 12px; }
.landing .legal { color: var(--text-muted); font-size: .9rem; }

.theme-fab {
	position: fixed;
	top: 12px;
	right: 12px;
	z-index: 20;
	background: var(--surface);
	color: var(--text);
	box-shadow: var(--shadow);
}
.theme-fab:hover { background: var(--surface-hover); color: var(--text); }

/* ---- app shell ---------------------------------------------------------- */
.app {
	display: grid;
	grid-template-columns: var(--drawer-w) minmax(0, 1fr);
	grid-template-rows: auto 1fr;
	grid-template-areas: "drawer header" "drawer main";
	min-height: 100vh;
}

.app-header {
	grid-area: header;
	position: sticky;
	top: 0;
	z-index: 10;
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	min-height: 116px;
	padding: 12px 16px;
	background: url("../images/fs-wide.png") center / cover #3b4a40;
	color: #fff;
}
.header-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.app-header .btn-icon {
	background: rgba(0, 0, 0, .45);
	color: #fff;
}
.app-header .btn-icon:hover { background: rgba(0, 0, 0, .65); color: #fff; }

.menu-toggle { display: none; }

.app-drawer {
	grid-area: drawer;
	position: sticky;
	top: 0;
	align-self: start;
	height: 100vh;
	overflow-y: auto;
	background: var(--surface);
	border-right: 1px solid var(--border);
	z-index: 15;
}
.drawer-logo {
	height: 100px;
	background: url("../images/vaulttec.png") center / 140px no-repeat;
	filter: var(--logo-filter);
	border-bottom: 1px solid var(--border);
}
.drawer-nav { display: flex; flex-direction: column; padding: 8px 0; }
.drawer-nav a {
	display: block;
	padding: 12px 24px;
	color: var(--text);
	text-decoration: none;
	font-weight: 500;
	border-left: 4px solid transparent;
}
.drawer-nav a:hover { background: var(--surface-hover); color: var(--text); }
.drawer-nav a.is-active {
	background: var(--nav-active-bg);
	border-left-color: var(--accent);
}

.app-main { grid-area: main; padding: 8px 20px 40px; min-width: 0; }

.drawer-scrim { display: none; }

@media (max-width: 860px) {
	.app {
		grid-template-columns: minmax(0, 1fr);
		grid-template-areas: "header" "main";
	}
	.menu-toggle { display: inline-flex; }
	.app-drawer {
		position: fixed;
		inset: 0 auto 0 0;
		width: var(--drawer-w);
		transform: translateX(-100%);
		transition: transform .2s ease;
		box-shadow: var(--shadow-lg);
	}
	.app.drawer-open .app-drawer { transform: none; }
	.app.drawer-open .drawer-scrim {
		display: block;
		position: fixed;
		inset: 0;
		z-index: 12;
		background: rgba(0, 0, 0, .5);
	}
	.app-main { padding: 8px 12px 32px; }
}
@media (max-width: 600px) {
	/* show the whole banner instead of cropping its centre */
	.app-header {
		min-height: 84px;
		align-items: center;
		background: url("../images/fs-wide.png") center / contain no-repeat #1c211e;
	}
	.landing .card { margin: 64px auto 24px; }
}

/* ---- layout helpers ----------------------------------------------------- */
.grid { display: grid; gap: 24px; grid-template-columns: repeat(12, minmax(0, 1fr)); margin-bottom: 8px; }
.col-3  { grid-column: span 3; }
.col-4  { grid-column: span 4; }
.col-6  { grid-column: span 6; }
.col-7  { grid-column: span 7; }
.col-12 { grid-column: span 12; }
@media (max-width: 1100px) {
	.col-3 { grid-column: span 6; }
	.col-4, .col-7 { grid-column: span 12; }
}
@media (max-width: 860px) {
	.col-3, .col-4, .col-6, .col-7 { grid-column: span 12; }
}

/* ---- tables ------------------------------------------------------------- */
.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
.table-wrap.scroll { max-height: 600px; }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td {
	padding: 10px 14px;
	text-align: left;
	border-bottom: 1px solid var(--border);
	white-space: nowrap;
}
table.data thead th {
	position: sticky;
	top: 0;
	z-index: 1;
	background: var(--surface-2);
	color: var(--text-muted);
	font-size: .78rem;
	font-weight: 600;
	letter-spacing: .05em;
	text-transform: uppercase;
}
table.data td.num, table.data th.num { text-align: right; }
table.data tr.group-row th {
	background: var(--surface-2);
	color: var(--text-muted);
	font-size: .75rem;
	font-weight: 600;
	letter-spacing: .05em;
	text-transform: uppercase;
	text-align: left;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-hover); }
table.data tr.clickable { cursor: pointer; }
table.data tr.is-selected { background: var(--nav-active-bg); }
table.data td select { min-width: 160px; }

/* ---- resources ---------------------------------------------------------- */
.resource {
	padding: 12px 16px 14px;
	border-bottom: 1px solid var(--border);
}
.resource:last-child { border-bottom: 0; }
.resource-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 6px;
}
.resource-head label { font-size: 1rem; }
.resource-head input[type="number"] { width: 110px; text-align: right; }

/* ---- dweller editor ----------------------------------------------------- */
.dweller-form { padding: 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 700px) { .dweller-form { grid-template-columns: minmax(0, 1fr); } }
.field { margin-bottom: 12px; }
.field > label { display: block; margin-bottom: 4px; font-size: .8rem; color: var(--text-muted); }
.field-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.field-row label { font-size: .9rem; }
.field-row input[type="number"] { width: 80px; }
.special-row { display: grid; grid-template-columns: 20px minmax(0, 1fr) 24px; align-items: center; gap: 8px; margin-bottom: 6px; }
.special-row b { font-weight: 700; }
.special-row output { text-align: right; font-variant-numeric: tabular-nums; }
.hint { color: var(--text-muted); font-size: .85rem; }
/* hair and face accessory pickers: a button showing the current choice, which opens a modal with the grid */
.picker-row {
	grid-column: 1 / -1;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
	gap: 12px;
}
.picker-row .field { margin-bottom: 0; min-width: 0; }
.picker-button {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	width: 100%;
	padding: 8px 6px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--surface-2);
	color: var(--text);
	font: inherit;
	cursor: pointer;
}
.picker-button:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--primary); }
.picker-button:disabled { opacity: .6; cursor: default; }
.picker-button canvas { width: 72px; height: 64px; }
.picker-name {
	max-width: 100%;
	overflow: hidden;
	font-size: .82rem;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.picker-dialog {
	width: min(680px, 94vw);
	max-height: 86vh;
	padding: 0;
	border: 1px solid var(--border);
	border-radius: 10px;
	background: var(--surface);
	color: var(--text);
	box-shadow: var(--shadow-lg);
	overflow: hidden;
}
.picker-dialog[open] { display: flex; flex-direction: column; }
.picker-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 12px 10px 18px;
	border-bottom: 1px solid var(--border);
}
.dialog-head h3 { margin: 0; font-size: 1.05rem; }

.hair-picker {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
	gap: 8px;
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;      /* the modal's own scroll area */
	padding: 14px 16px 18px;
}
.hair-picker > .hint { grid-column: 1 / -1; margin: 0; }
.hair-group {
	grid-column: 1 / -1;
	margin-top: 4px;
	color: var(--text-muted);
	font-size: .72rem;
	font-weight: 600;
	letter-spacing: .05em;
	text-transform: uppercase;
}
.hair-tile {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	gap: 2px;
	min-width: 0;
	padding: 4px 2px 3px;
	border: 2px solid transparent;
	border-radius: 6px;
	background: var(--surface);
	color: var(--text);
	font: inherit;
	cursor: pointer;
}
.hair-tile:hover { background: var(--surface-hover); }
.hair-tile.is-selected { border-color: var(--accent); background: var(--surface-hover); }
.hair-tile canvas { display: block; width: 100%; height: auto; aspect-ratio: 72 / 64; }
.hair-none {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	aspect-ratio: 72 / 64;
	color: var(--text-muted);
	font-size: .8rem;
}
.hair-caption {
	max-width: 100%;
	overflow: hidden;
	color: var(--text-muted);
	font-size: .68rem;
	line-height: 1.2;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* ---- other / misc ------------------------------------------------------- */
.action-list { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding-top: 12px; }

.warning {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 16px auto;
	max-width: 910px;
	padding: 10px 14px;
	border: 1px solid var(--accent);
	border-radius: var(--radius);
	color: var(--accent);
	font-weight: 500;
}

/* ---- raw JSON tree ------------------------------------------------------ */
.tree-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }

.json-tree {
	padding: 12px 14px;
	background: var(--surface);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	font: .82rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
	overflow-x: auto;
}
.json-tree details > summary {
	padding: 1px 4px;
	border-radius: 4px;
	cursor: pointer;
	white-space: nowrap;
}
.json-tree details > summary:hover { background: var(--surface-hover); }
.json-tree .children {
	margin-left: 7px;
	padding-left: 14px;
	border-left: 1px solid var(--border);
}
.json-tree .leaf { padding: 1px 4px 1px 18px; white-space: pre-wrap; word-break: break-word; }

.json-tree .k { color: var(--json-key); }
.json-tree .k-index { color: var(--text-muted); }
.json-tree .colon { color: var(--text-muted); }
.json-tree .meta { margin-left: 8px; color: var(--text-muted); font-size: .9em; }
.json-tree .v-str { color: var(--json-str); }
.json-tree .v-num { color: var(--json-num); }
.json-tree .v-bool { color: var(--json-bool); }
.json-tree .v-null, .json-tree .v-empty { color: var(--text-muted); }

/* ---- vault room builder ------------------------------------------------- */
.room-controls {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: center;
	gap: 16px;
	margin: 0 auto 20px;
	max-width: 910px;
}
.room-controls .field { margin: 0; }
.room-controls .field-type { flex: 1 1 240px; max-width: 320px; }
.room-controls .field-small { width: 90px; }

.vault-scroll { overflow-x: auto; padding-bottom: 8px; }
#vault {
	--cell: 35px;
	width: calc(var(--cell) * 26);
	margin: 0 auto;
	background: var(--surface);
	box-shadow: var(--shadow);
	border-radius: 4px;
	overflow: hidden;
}
.vault-row { display: flex; height: 50px; }
.vault-row > div { display: flex; height: 50px; }   /* wrapper div returned by rooms.ajax.php */

.roomDiv {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	height: 50px;
	overflow: hidden;
	background-color: #9e9a8e;
	color: #1b1b1b;
	font-size: 11px;
	line-height: 1;
	white-space: nowrap;
	text-overflow: ellipsis;
	cursor: pointer;
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
	transition: filter .1s;
}
.roomDiv:hover { filter: brightness(1.25); }

.room0 { width: calc(var(--cell) * 1); }
.room1 { width: calc(var(--cell) * 3); }
.room2 { width: calc(var(--cell) * 6); }
.room3 { width: calc(var(--cell) * 9); }

.Entrance { background-color: #777777; color: #fff; }
.FakeWasteland { background-color: #ffffff; }
.Elevator { background-color: #996666; }
.Overseer { background-color: #ffa500; }
.LivingQuarters { background-color: #777799; color: #fff; }
.Radio { background-color: #999977; }
.WeaponFactory, .OutfitFactory, .DesignFactory, .DecorationFactory, .UltraciteWeaponFactory { background-color: #dddd77; }
.Cafeteria, .Hydroponic, .NukaCola, .Geothermal, .Energy2, .WaterPlant, .Water2, .UltraciteMining { background-color: #77dd77; }
.MedBay, .ScienceLab { background-color: #7777dd; color: #fff; }
.Storage { background-color: #4e413e; color: #fff; }
.Gym, .Dojo, .Classroom, .Armory, .SuperRoom2, .Casino, .Bar, .BarberShop { background-color: #aaaaaa; }
.rock { background-color: #333333; color: #bbb; width: calc(var(--cell) * 2); }

/* ---- toast -------------------------------------------------------------- */
.toast-host {
	position: fixed;
	left: 50%;
	bottom: 24px;
	z-index: 100;
	display: flex;
	flex-direction: column;
	gap: 8px;
	align-items: center;
	transform: translateX(-50%);
	pointer-events: none;
}
.toast {
	max-width: min(90vw, 480px);
	padding: 12px 18px;
	border-radius: 6px;
	background: #2b3338;
	color: #f1f5f7;
	box-shadow: var(--shadow-lg);
	font-size: .9rem;
	animation: toast-in .2s ease;
}
.toast.error { background: #b71c1c; color: #fff; }
:root[data-theme="dark"] .toast:not(.error) { background: #e6ebee; color: #14181b; }
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .toast:not(.error) { background: #e6ebee; color: #14181b; }
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { transition: none !important; animation: none !important; }
}
