:root {
	color-scheme: dark;
	--bg: #0d1117; --panel: #161b22; --panel2: #1c2128; --hover: #21262d; --line: #30363d;
	--text: #e6edf3; --muted: #8b949e; --blue: #58a6ff; --green: #3fb950; --red: #f85149; --orange: #f78166; --purple: #a371f7;
	--gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	--shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
[hidden] { display: none !important; }

button, select, input, textarea { font: inherit; color: inherit; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; transition: border-color .15s, background .15s; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
button { cursor: pointer; white-space: nowrap; }
button:hover { background: var(--hover); border-color: var(--muted); }
button.primary { background: #238636; border-color: #2ea043; color: #fff; font-weight: 600; }
button.primary:hover { background: #2ea043; }
button.danger { color: var(--red); }
button.danger:hover { background: rgba(248, 81, 73, .15); border-color: var(--red); }
button.ghost { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .3); color: #fff; }
button.ghost:hover { background: rgba(255, 255, 255, .25); }
button.small, select.small { padding: 3px 9px; font-size: 12.5px; }
button.wide { width: 100%; padding: 9px; }

.page-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--gradient); box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand h1 { margin: 0; font-size: 20px; color: #fff; text-shadow: 0 2px 10px rgba(0, 0, 0, .3); }
.brand .host { color: rgba(255, 255, 255, .8); font-size: 13px; }
.page-header nav { display: flex; gap: 6px; flex: 1; }
.page-header nav button { background: transparent; border-color: transparent; color: rgba(255, 255, 255, .85); font-weight: 500; }
.page-header nav button:hover { background: rgba(255, 255, 255, .15); }
.page-header nav button.active { background: rgba(255, 255, 255, .22); color: #fff; border-color: rgba(255, 255, 255, .35); }
.page-header form { margin: 0; }
.count { background: rgba(0, 0, 0, .3); border-radius: 10px; padding: 0 7px; font-size: 12px; }
.count:empty { display: none; }

main { padding: 20px 24px; max-width: 1600px; margin: 0 auto; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }
.hint { color: var(--muted); font-size: 12px; }
.error { color: var(--red); }
#search { min-width: 260px; }

.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.chip:hover { border-color: var(--blue); transform: translateY(-1px); }
.chip.active { border-color: var(--blue); background: rgba(88, 166, 255, .15); box-shadow: 0 0 14px rgba(88, 166, 255, .25); }
.chip b { font-size: 16px; }
.chip span { color: var(--muted); font-size: 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }
.site { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); display: flex; flex-direction: column; gap: 10px; position: relative; }
.site::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; border-radius: 12px 12px 0 0; background: var(--line); }
.site.active::before { background: linear-gradient(90deg, #3fb950, #2ea043); }
.site.failed::before { background: var(--red); }
.site.is-admin { border-color: rgba(163, 113, 247, .5); }
.site-head { display: flex; align-items: center; gap: 8px; }
.site-title { font-size: 16px; font-weight: 600; margin: 0; overflow-wrap: anywhere; flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.active { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.failed, .dot.inactive { background: var(--red); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 6px; background: var(--hover); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.badge.umbraco { background: linear-gradient(135deg, #3544b1, #00bcd4); color: #fff; }
.badge.csharp { background: #512bd4; color: #fff; }
.badge.python { background: #3776ab; color: #fff; }
.badge.html { background: #e34f26; color: #fff; }
.badge.admin { background: var(--purple); color: #fff; }
.badge.state-active { background: rgba(63, 185, 80, .2); color: var(--green); }
.badge.state-failed, .badge.state-inactive { background: rgba(248, 81, 73, .2); color: var(--red); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
a.link { color: var(--blue); cursor: pointer; text-decoration: none; }
a.link:hover { text-decoration: underline; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; border-top: 1px solid var(--line); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
#files td:first-child { white-space: nowrap; }
.list.dragging { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue); }
.drop-hint { display: none; position: absolute; inset: 0; background: rgba(13, 17, 23, .85); align-items: center; justify-content: center; font-size: 18px; color: var(--blue); }
.list.dragging .drop-hint { display: flex; }
.crumbs { font-size: 14px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--hover); }
.num { text-align: right; white-space: nowrap; }
td.tools { white-space: nowrap; text-align: right; }
td.tools a { margin-left: 10px; font-size: 13px; }
.dirty { color: var(--orange); font-size: 12px; }

#tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
#tabs .tab { display: flex; gap: 8px; align-items: center; padding: 5px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
#tabs .tab:hover { border-color: var(--muted); }
#tabs .tab.active { border-color: var(--blue); background: rgba(88, 166, 255, .15); }
#tabs .tab .x { color: var(--muted); padding: 0 2px; }
#tabs .tab .x:hover { color: var(--red); }
#panes .pane { height: calc(100vh - 190px); min-height: 300px; background: #000; padding: 8px; border-radius: 10px; border: 1px solid var(--line); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 22px; min-width: min(440px, 92vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 10px; font-size: 18px; }
dialog p { margin: 0 0 12px; white-space: pre-line; color: var(--muted); }
dialog input, dialog select { width: 100%; }
dialog label, .card label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; color: var(--muted); font-size: 12.5px; }
dialog label input, dialog label select { color: var(--text); font-size: 14px; }
dialog fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; padding: 10px 12px 0; }
dialog legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }
dialog.danger h2 { color: var(--red); }
dialog.danger .primary { background: #da3633; border-color: var(--red); }

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 420px; animation: pop .15s ease-out; }
.toast.error { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

body.login { display: grid; place-items: center; min-height: 100vh; background: var(--bg) radial-gradient(circle at 20% 10%, rgba(102, 126, 234, .25), transparent 40%), radial-gradient(circle at 80% 90%, rgba(118, 75, 162, .25), transparent 40%); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(360px, 92vw); box-shadow: var(--shadow); overflow: hidden; }
.card-head { background: var(--gradient); padding: 22px 24px; }
.card-head h1 { margin: 0; font-size: 22px; color: #fff; }
.card-head p { margin: 4px 0 0; color: rgba(255, 255, 255, .8); }
.card-body { padding: 22px 24px 24px; }
.card-body input { width: 100%; color: var(--text); font-size: 15px; padding: 8px 12px; }

@media (max-width: 800px) {
	main { padding: 12px; }
	.page-header { padding: 12px; gap: 10px; }
	.cards { grid-template-columns: 1fr; }
	#search { min-width: 0; flex: 1; }
	th:nth-child(3), td:nth-child(3) { display: none; }
}

/* ---- v2: header, account menu, environments, dock ---- */
.brand .logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: rgba(255, 255, 255, .2); color: #fff; font-size: 18px; }
.brand h1 { font-size: 17px; line-height: 1.1; }
.brand .host { display: block; font-size: 12px; }
.page-header #search { min-width: 280px; background: rgba(0, 0, 0, .25); border-color: rgba(255, 255, 255, .25); color: #fff; border-radius: 18px; padding-left: 16px; }
.page-header #search::placeholder { color: rgba(255, 255, 255, .65); }
.page-header #search:focus { background: rgba(0, 0, 0, .4); outline-color: #fff; }
.user { position: relative; }
.avatar { width: 36px; height: 36px; padding: 0; border-radius: 50%; background: rgba(255, 255, 255, .22); border-color: rgba(255, 255, 255, .5); color: #fff; font-weight: 700; font-size: 15px; }
.avatar:hover { background: rgba(255, 255, 255, .35); border-color: #fff; }
.menu { position: absolute; right: 0; top: 46px; min-width: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 30; }
.menu form { margin: 0; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; }
.menu button:hover { background: var(--hover); }
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
#btn-dock .count { margin-left: 4px; background: #fff; color: #4b3a8c; font-weight: 700; }
.toolbar .stats { margin: 0; }
.back { text-decoration: none; font-weight: 500; }

.site { cursor: pointer; transition: transform .15s, border-color .15s, box-shadow .15s; }
.site:hover { transform: translateY(-2px); border-color: var(--blue); box-shadow: 0 8px 22px rgba(0, 0, 0, .45); }
.env-rows { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.env-row { display: grid; grid-template-columns: 10px 84px 1fr auto; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.env-label { font-weight: 600; }
.dot.remote { background: var(--purple); }

.detail-title { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.detail-title h2 { margin: 0; font-size: 26px; }
#site-head > .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.envs { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.env { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; border-top: 3px solid var(--blue); }
.env.prod { border-top-color: var(--orange); }
.env-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.env-head h3 { margin: 0; font-size: 18px; }
.env .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }

#dock { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(1, 4, 9, .72); backdrop-filter: blur(3px); }
.dock-window { display: flex; flex-direction: column; width: min(1200px, 94vw); height: min(720px, 86vh); background: #000; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: 0 24px 60px rgba(0, 0, 0, .7); }
#dock.max .dock-window { width: 98vw; height: 96vh; }
.dock-bar { display: flex; align-items: center; gap: 6px; background: var(--panel); padding: 6px 10px; border-bottom: 1px solid var(--line); }
.dock-bar .ghost { color: var(--text); }
#dock #tabs { display: flex; gap: 4px; overflow-x: auto; margin: 0; flex-wrap: nowrap; }
#dock #panes { flex: 1; min-height: 0; position: relative; }
#dock #panes .pane { position: absolute; inset: 0; height: auto; min-height: 0; padding: 6px 10px; border: 0; border-radius: 0; overflow: hidden; }

dialog.editor { width: min(1100px, 94vw); height: min(780px, 90vh); padding: 14px 18px; flex-direction: column; }
dialog.editor[open] { display: flex; }
dialog.editor .toolbar { margin-bottom: 10px; }
dialog.editor textarea { flex: 1; min-height: 0; width: 100%; resize: none; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; tab-size: 4; }
dialog.wide { width: min(1000px, 94vw); }
#logs-text { max-height: 60vh; overflow: auto; background: #000; padding: 10px; border-radius: 6px; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; }
@media (max-width: 800px) { .page-header #search { min-width: 0; flex: 1; } .brand h1, .brand .host { display: none; } .envs { grid-template-columns: 1fr; } }

.list { position: relative; overflow-x: auto; }
.env .actions.quick { margin-top: 12px; }
.env .actions.quick button { background: var(--accent-soft, transparent); }
.badge.version { text-transform: none; color: #fff; background: #57606a; }
.badge.version[data-major="0"] { background: #8250df; }
.badge.version[data-major="1"] { background: #0969da; }
.badge.version[data-major="2"] { background: #1a7f37; }
.badge.version[data-major="3"] { background: #bf8700; }
.badge.version[data-major="4"] { background: #cf222e; }
.badge.version[data-major="5"] { background: #bf3989; }
.badge.version[data-major="6"] { background: #0a7f8f; }
.badge.version[data-major="7"] { background: #953800; }

/* Button icons and tones */
button .ico { width: 1.1em; height: 1.1em; margin: -2px 6px -2px -2px; vertical-align: middle; }
button[data-tone] { --tone: var(--muted); color: var(--tone); border-color: color-mix(in srgb, var(--tone) 35%, var(--line)); background: color-mix(in srgb, var(--tone) 9%, var(--panel2)); }
button[data-tone]:hover { background: color-mix(in srgb, var(--tone) 20%, var(--panel2)); border-color: var(--tone); }
button[data-tone="blue"] { --tone: var(--blue); }
button[data-tone="green"] { --tone: var(--green); }
button[data-tone="red"] { --tone: var(--red); }
button[data-tone="amber"] { --tone: #d29922; }
button[data-tone="teal"] { --tone: #39c5cf; }
button[data-tone="purple"] { --tone: var(--purple); }
button[data-tone="gray"] { --tone: #9da7b3; }
.menu button[data-tone] { background: transparent; border-color: transparent; color: var(--text); }
.menu button[data-tone] .ico { color: var(--tone); }
.menu button[data-tone]:hover { background: var(--hover); border-color: transparent; }
button.primary[data-tone] { background: #238636; border-color: #2ea043; color: #fff; }
/* Delete buttons stand alone at the far right of their row */
.actions > button.danger, #site-head .actions > button.danger { margin-left: auto; }
dialog.editor #editor-box { flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }

/* New site dialog */
dialog.newsite { width: min(640px, 94vw); padding: 0; overflow: hidden; }
dialog.newsite form { padding: 0 24px 20px; }
.ns-head { display: flex; align-items: center; gap: 14px; margin: 0 -24px 18px; padding: 20px 24px; background: linear-gradient(135deg, rgba(88,101,242,.35), rgba(139,92,246,.22)); border-bottom: 1px solid var(--line); }
.ns-head h2 { margin: 0; font-size: 20px; }
.ns-head p { margin: 2px 0 0; font-size: 13px; }
.ns-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; color: #fff; background: linear-gradient(135deg, #6c7bff, #8b5cf6); box-shadow: 0 4px 14px rgba(108,123,255,.4); }
.ns-section { margin: 4px 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.type-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
dialog .type-card { position: relative; display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: rgba(255,255,255,.02); transition: border-color .15s, background .15s, transform .15s; }
.type-card:hover { border-color: var(--blue); transform: translateY(-1px); }
.type-card input { position: absolute; opacity: 0; pointer-events: none; width: auto; }
.type-card .tc-title { color: var(--text); font-size: 14px; font-weight: 600; }
.type-card .tc-sub { font-size: 12px; color: var(--muted); }
.type-card:has(input:checked) { border-color: var(--blue); background: rgba(88,166,255,.12); box-shadow: 0 0 0 1px var(--blue) inset; }
.type-card:has(input:focus-visible) { outline: 2px solid var(--blue); }
.ns-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
dialog.newsite .hint { margin: 2px 0 0; font-size: 12px; }
dialog.newsite menu { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
@media (max-width: 560px) { .type-cards, .ns-grid { grid-template-columns: 1fr; } }
dialog.newsite input:not([type=radio]), dialog.newsite select { height: 38px; padding: 0 12px; font-size: 14px; line-height: 1.2; }
dialog.newsite select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
dialog.newsite select option { background: var(--panel2); color: var(--text); }
