:root {
  --bg: #080a08;
  --panel: #100e0a;
  --panel-alt: #18140d;
  --line: #493f2d;
  --text: #ded8ca;
  --dim: #938873;
  --accent: #d8b268;
  --warn: #91c787;
  --danger: #d47777;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font: 12px/1.35 ui-monospace, "Cascadia Mono", "Courier New", monospace; }
button, input { font: inherit; }
button, a { color: var(--accent); }
button { border: 0; background: none; cursor: pointer; }
a { text-decoration: none; }
button:hover, button:focus-visible, a:hover, a:focus-visible { color: var(--bg); background: var(--accent); outline: 0; }

.login-shell { height: 100%; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(460px, 100%); border: 1px solid var(--line); background: var(--panel); padding: 28px; }
.eyebrow { color: var(--accent); font-size: 10px; letter-spacing: .09em; }
.login-box h1 { margin: 22px 0 8px; color: var(--accent); font-size: 25px; letter-spacing: -.04em; }
.login-box p { margin: 0 0 28px; color: var(--dim); }
.login-box form { display: grid; gap: 9px; margin-bottom: 20px; }
.login-box label { color: var(--dim); }
.login-box input { width: 100%; height: 44px; padding: 0 11px; border: 1px solid var(--line); border-radius: 0; background: var(--bg); color: var(--text); outline: 0; }
.login-box input:focus { border-color: var(--accent); outline: 1px solid var(--accent); outline-offset: 1px; }
.login-box form button { height: 42px; margin-top: 5px; border: 1px solid var(--accent); background: var(--accent); color: var(--bg); font-weight: 700; }
.login-box form button:hover { background: #b1d9a9; }
#login-error { min-height: 1.4em; color: var(--danger); }

.control { height: 100dvh; padding: 7px; display: grid; grid-template-rows: 32px minmax(0, 1fr) 26px; gap: 7px; }
header, footer { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); padding: 0 9px; white-space: nowrap; }
header b, footer b { color: var(--accent); }
header span, footer { color: var(--dim); }
.header-right { display: flex; align-items: center; gap: 16px; }
.workspace { min-height: 0; display: grid; grid-template-columns: 205px minmax(0, 1fr); gap: 7px; }
nav { min-height: 0; display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--line); background: var(--panel); padding: 7px; overflow: hidden; }
nav button, nav a { display: block; width: 100%; padding: 8px 7px; text-align: left; color: var(--dim); white-space: nowrap; }
nav button.active { color: var(--bg); background: var(--accent); }
nav a { margin-top: auto; border-top: 1px solid var(--line); color: var(--accent); }
.panels { min-width: 0; min-height: 0; position: relative; }
.panel { display: none; width: 100%; height: 100%; min-height: 0; border: 1px solid var(--line); background: var(--bg); overflow: auto; }
.panel.active { display: block; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; padding: 7px; }
.metrics article { min-width: 0; min-height: 130px; padding: 12px; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--line); background: var(--panel); }
.metrics label, small { color: var(--dim); }
.metrics output { color: var(--accent); font-size: clamp(24px, 3vw, 42px); font-weight: 700; letter-spacing: -.07em; white-space: nowrap; }
.bar { height: 5px; border: 1px solid var(--line); }
.bar i { display: block; width: 0; height: 100%; background: var(--accent); transition: width .25s linear; }

.metric-history { height: 210px; margin: 0 7px 7px; border: 1px solid var(--line); background: var(--panel); overflow: hidden; }
.metric-history > header { height: 32px; padding: 0 10px; border: 0; border-bottom: 1px solid var(--line); background: var(--panel-alt); }
.metric-history h2 { margin: 0; color: var(--accent); font-size: 10px; letter-spacing: .08em; }
.chart-legend { display: flex; align-items: center; gap: 14px; color: var(--dim); font-size: 10px; }
.chart-legend span::before { content: ""; display: inline-block; width: 12px; height: 2px; margin: 0 5px 3px 0; background: var(--accent); }
.chart-legend [data-series="memory"]::before { background: var(--warn); }
.chart-legend [data-series="temperature"]::before { background: var(--danger); }
.metric-chart-wrap { height: calc(100% - 32px); position: relative; overflow: hidden; }
#metric-chart { display: block; width: 100%; height: 100%; touch-action: none; }
.metric-chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-size: 10px; pointer-events: none; }
.metric-chart-tooltip { position: absolute; z-index: 2; min-width: 156px; padding: 7px 9px; border: 1px solid var(--accent); background: rgb(8 10 8 / 94%); color: var(--text); font: inherit; line-height: 1.55; white-space: pre; pointer-events: none; box-shadow: 4px 4px 0 #000; }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; padding: 0 7px 7px; }
.standalone-card-grid { padding: 7px; }
.card-grid article { min-width: 0; border: 1px solid var(--line); background: var(--panel); padding: 11px; overflow: hidden; }
.card-grid h2, .panel-head h2 { margin: 0 0 9px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .08em; }
dl { margin: 0; }
dl div { display: grid; grid-template-columns: minmax(90px, .7fr) minmax(0, 1.3fr); gap: 8px; padding: 2px 0; border-bottom: 1px dotted #222a22; }
dt { color: var(--dim); white-space: nowrap; }
dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
pre { margin: 0; color: var(--text); font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }

.table-panel { overflow: hidden; }
.panel-head { height: 38px; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.panel-head h2 { margin: 0; }
.table-wrap { height: calc(100% - 38px); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th { position: sticky; top: 0; z-index: 1; background: var(--panel-alt); color: var(--dim); text-align: left; font-weight: 400; }
th, td { padding: 6px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:hover { background: var(--panel-alt); }
.state-active { color: var(--accent); }
.state-failed { color: var(--danger); }

.devices-panel { overflow: hidden; }
.device-grid { height: calc(100% - 62px); padding: 7px; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); grid-auto-rows: minmax(280px, 1fr); gap: 7px; overflow: auto; }
.device-card { min-width: 0; padding: 12px; display: flex; flex-direction: column; border: 1px solid var(--line); background: var(--panel); overflow: hidden; }
.device-card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 10px; color: var(--accent); font-size: 12px; letter-spacing: .08em; }
.device-card dl { flex: 1; min-height: 0; overflow: auto; }
.device-card dl div { grid-template-columns: minmax(110px, .75fr) minmax(0, 1.25fr); }
.device-state { padding: 2px 5px; border: 1px solid var(--accent); color: var(--accent); font-size: 9px; font-weight: 400; white-space: nowrap; }
.device-card:not(.device-device) { border-color: var(--warn); }
.device-card:not(.device-device) .device-state { border-color: var(--warn); color: var(--warn); }
.device-screen-button { width: 100%; margin-top: 10px; padding: 7px 9px; border: 1px solid var(--line); color: var(--dim); text-align: left; }
.device-screen-button:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.device-screen-button:not(:disabled):hover, .device-screen-button:not(:disabled):focus-visible { color: var(--bg); background: var(--accent); }
.device-screen-button:disabled { cursor: not-allowed; opacity: .58; }
.device-empty { min-height: 180px; padding: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--dim); }
.device-summary { height: 24px; border-width: 1px 0 0; padding: 0 9px; color: var(--dim); font-size: 10px; }
.device-summary button { padding: 2px 5px; color: var(--accent); font-size: inherit; }
.screen-helper-info p { margin: 0 0 12px; }
.screen-helper-info p:last-child { margin-bottom: 0; }
.screen-helper-path { padding: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--accent); overflow-wrap: anywhere; }

.server-device { border-color: var(--warn); }
.server-device h2 { color: var(--warn); }
.server-device .device-state { border-color: var(--warn); color: var(--warn); }
.server-device .device-screen-button { border-color: var(--warn); color: var(--warn); }
.server-device .device-screen-button:hover, .server-device .device-screen-button:focus-visible { color: var(--bg); background: var(--warn); }

.minecraft-panel { overflow: hidden; }
.minecraft-grid { align-content: stretch; }

.log-list { height: calc(100% - 38px); overflow: auto; }
.log-row { display: grid; grid-template-columns: 178px 160px 26px minmax(0, 1fr); gap: 8px; padding: 5px 9px; border-bottom: 1px solid #202720; font-size: 11px; }
.log-row span:nth-child(-n+3) { color: var(--dim); }
.log-row[data-priority="0"], .log-row[data-priority="1"], .log-row[data-priority="2"], .log-row[data-priority="3"] { color: var(--danger); }

.files-panel { position: relative; overflow: hidden; }
.file-head > div { display: flex; gap: 8px; }
#root-mode { padding: 5px 8px; border: 1px solid var(--line); }
#root-mode.active { border-color: var(--danger); background: var(--danger); color: var(--bg); }
.file-path { height: 34px; display: flex; align-items: center; gap: 9px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel-alt); }
.file-path span { color: var(--accent); }
.file-path code { color: var(--text); font: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-grid { height: calc(100% - 96px); position: relative; padding: 7px; display: grid; grid-template-columns: repeat(auto-fill, 94px); grid-auto-rows: 82px; gap: 2px; align-content: start; overflow: auto; user-select: none; touch-action: pan-x pan-y; }
.file-grid.drop-target { outline: 1px solid var(--accent); outline-offset: -4px; background: #101610; }
.file-item { min-width: 0; height: 82px; padding: 5px 4px 4px; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; border: 1px solid transparent; background: transparent; color: var(--text); text-align: center; border-radius: 2px; }
.file-item:hover, .file-item:focus-visible { border-color: #526252; background: #121712; color: var(--text); outline: 0; }
.file-item.selected { border-color: var(--accent); background: #1b281b; box-shadow: inset 0 0 0 1px #2d462d; }
.file-item.dragging { opacity: .45; }
.file-item.drop-folder { border-color: var(--accent); background: #243324; box-shadow: inset 0 0 0 1px var(--accent); }
.file-item .file-icon { width: 38px; height: 38px; position: relative; display: grid; place-items: center; flex: 0 0 38px; }
.file-item .file-icon img { display: block; width: 36px; height: 36px; object-fit: contain; filter: saturate(.68) brightness(.94); }
.file-item.directory .file-icon img { filter: sepia(.25) saturate(.85) hue-rotate(55deg) brightness(.9); }
.file-item .file-badge { position: absolute; right: -1px; bottom: 0; width: 13px; height: 13px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--panel); color: var(--accent); font-size: 9px; line-height: 1; }
.file-item .file-name { width: 100%; min-width: 0; max-height: 28px; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; line-height: 12px; }
.file-item.hidden-entry .file-icon, .file-item.hidden-entry .file-name { opacity: .58; }
.file-item.access-denied .file-name { color: var(--danger); }
.file-item.access-denied .file-icon img { filter: grayscale(1) sepia(1) saturate(5) hue-rotate(305deg) brightness(.86); opacity: .82; }
.file-item.access-denied .file-badge { border-color: var(--danger); color: var(--danger); }
.file-item.access-denied:hover, .file-item.access-denied:focus-visible { border-color: var(--danger); background: #211313; }
.file-item.access-denied.selected { border-color: var(--danger); background: #2a1515; box-shadow: inset 0 0 0 1px #4b2525; }
.file-item small { display: none; }
.selection-marquee { position: absolute; z-index: 25; border: 1px solid var(--accent); background: rgb(145 199 135 / 13%); pointer-events: none; }
.drag-ghost { position: fixed; left: -9999px; top: -9999px; padding: 5px 9px; border: 1px solid var(--accent); background: var(--panel); color: var(--accent); font: inherit; }
.file-status { height: 24px; border-width: 1px 0 0; padding: 0 9px; font-size: 10px; }

.context-menu { position: fixed; z-index: 30; width: 164px; margin: 0; padding: 4px; border: 1px solid var(--line); background: var(--panel); box-shadow: 5px 5px 0 #000; }
.context-menu button { width: 100%; padding: 7px 8px; display: block; color: var(--text); text-align: left; }
.context-menu button:hover, .context-menu button:focus-visible { color: var(--bg); background: var(--accent); }
.context-menu button[data-file-action="trash"] { color: var(--danger); }

.dialog-backdrop { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 14px; background: rgb(0 0 0 / 72%); }
.dialog { width: min(650px, 100%); max-height: min(650px, calc(100dvh - 28px)); display: grid; grid-template-rows: 38px minmax(0, 1fr) auto; border: 1px solid var(--line); background: var(--panel); box-shadow: 8px 8px 0 #000; overflow: hidden; }
.dialog > header { border-width: 0 0 1px; }
.dialog > header h2 { margin: 0; color: var(--accent); font-size: 11px; }
.dialog-body { min-height: 80px; padding: 12px; overflow: auto; }
.dialog-body input { width: 100%; height: 40px; padding: 0 9px; border: 1px solid var(--line); border-radius: 0; background: var(--bg); color: var(--text); outline: 0; }
.dialog-body input:focus { border-color: var(--accent); outline: 1px solid var(--accent); }
.dialog-body img { display: block; max-width: 100%; max-height: 65dvh; margin: auto; object-fit: contain; image-rendering: auto; }
.dialog-body pre { max-height: 60dvh; padding: 10px; border: 1px solid var(--line); background: #000; overflow: auto; white-space: pre; }
.dialog-actions { min-height: 38px; justify-content: flex-end; gap: 8px; border-width: 1px 0 0; }
.dialog-actions button { padding: 6px 10px; border: 1px solid var(--line); }
.dialog-actions button.primary { border-color: var(--accent); background: var(--accent); color: var(--bg); }
.dialog-actions button.danger { border-color: var(--danger); color: var(--danger); }
.dialog-actions button.danger:hover { background: var(--danger); color: var(--bg); }
.dialog-note { color: var(--dim); }
.dialog-error { min-height: 1.4em; color: var(--danger); }

.terminal-panel { position: relative; overflow: hidden; background: #000; }
.terminal-panel .panel-head { background: var(--panel); }
#terminal { width: 100%; height: calc(100% - 38px); padding: 6px; overflow: hidden; background: #000; }
.xterm { height: 100%; }
.xterm-viewport { overflow-x: hidden !important; overflow-y: auto !important; }
#terminal .xterm-selection { display: none !important; }
.mnut-terminal-selection { position: absolute; inset: 0; z-index: 50; overflow: hidden; pointer-events: none; }
.mnut-terminal-selection span { position: absolute; display: block; background: rgb(145 199 135 / 72%); }
.terminal-panel.root-mode-visual .mnut-terminal-selection span { background: rgb(212 119 119 / 72%); }
/* The DOM renderer owns cursor placement. Draw only the bar as a pseudo-element
   so blinking never hides the character contained by the cursor cell. */
#terminal .xterm-rows .xterm-cursor { position: relative !important; }
#terminal .xterm-rows .xterm-cursor.xterm-cursor-bar { box-shadow: none !important; animation: none !important; }
#terminal .xterm-rows .xterm-cursor.xterm-cursor-bar::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  background: #91c787;
  pointer-events: none;
}
#terminal .xterm-rows .xterm-cursor.xterm-cursor-outline { outline-color: #91c787 !important; }
.terminal-panel.root-mode-visual #terminal .xterm-rows .xterm-cursor.xterm-cursor-bar::after { background: #d47777; }
.terminal-panel.root-mode-visual #terminal .xterm-rows .xterm-cursor.xterm-cursor-outline { outline-color: #d47777 !important; }
#terminal .xterm-rows.xterm-focus .xterm-cursor.xterm-cursor-blink::after { animation: mnut-cursor-bar-blink 1s steps(1, end) infinite; }
@keyframes mnut-cursor-bar-blink { 0%, 48% { visibility: visible; } 49%, 100% { visibility: hidden; } }

.files-panel.root-mode-visual, .terminal-panel.root-mode-visual { border-color: #9b5151; box-shadow: inset 0 0 80px rgb(212 119 119 / 7%); }
.files-panel.root-mode-visual .panel-head, .terminal-panel.root-mode-visual .panel-head { border-color: #884848; background: #281313; }
.files-panel.root-mode-visual .panel-head h2, .terminal-panel.root-mode-visual .panel-head h2 { color: #e38a8a; }
.files-panel.root-mode-visual .file-path { border-color: #773f3f; background: #211010; }
.files-panel.root-mode-visual .file-path span { color: #e38a8a; }
.files-panel.root-mode-visual .file-grid { background: linear-gradient(rgb(110 36 36 / 8%), rgb(40 12 12 / 5%)); }
.terminal-panel.root-mode-visual #terminal { background: #0b0606; }
.files-panel.root-mode-visual::after, .terminal-panel.root-mode-visual::after {
  content: "ROOT MODE";
  position: absolute;
  z-index: 20;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%) rotate(-12deg);
  color: rgb(232 126 126 / 12%);
  font-size: clamp(54px, 11vw, 170px);
  font-weight: 900;
  letter-spacing: .12em;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

#status-lamp { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border: 1px solid var(--accent); background: var(--accent); }
::selection { color: var(--bg); background: var(--accent); }

@media (max-width: 760px) {
  .control { padding: 4px; gap: 4px; grid-template-rows: 28px minmax(0, 1fr) 23px; font-size: 10px; }
  header, footer { padding: 0 6px; }
  .header-right { gap: 8px; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: 34px minmax(0, 1fr); gap: 4px; }
  nav { flex-direction: row; gap: 2px; padding: 3px; overflow-x: auto; overflow-y: hidden; }
  nav button, nav a { width: auto; padding: 5px 8px; }
  nav a { margin: 0 0 0 auto; border: 0; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; }
  .metrics article { min-height: 102px; padding: 8px; }
  .metrics output { font-size: clamp(23px, 9vw, 36px); }
  .metric-history { height: 180px; margin: 0 4px 4px; }
  .metric-history > header { padding: 0 6px; }
  .chart-legend { gap: 7px; font-size: 9px; }
  .chart-legend span::before { width: 8px; margin-right: 3px; }
  .card-grid { grid-template-columns: 1fr; gap: 4px; padding: 0 4px 4px; }
  .standalone-card-grid { padding: 4px; }
  .card-grid article { padding: 8px; }
  .device-grid { padding: 4px; grid-template-columns: 1fr; grid-auto-rows: minmax(280px, auto); gap: 4px; }
  .log-row { grid-template-columns: 120px 95px minmax(0, 1fr); }
  .log-row span:nth-child(3) { display: none; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); grid-auto-rows: 78px; gap: 1px; padding: 4px; }
  .file-item { height: 78px; }
  .file-item .file-icon { width: 35px; height: 35px; flex-basis: 35px; }
  .file-item .file-icon img { width: 33px; height: 33px; }
  #file-selection { max-width: 52vw; overflow: hidden; text-overflow: ellipsis; }
  #session-note { display: none; }
}
