:root {
  --bg: #080a08;
  --panel: #0d100d;
  --panel-alt: #131713;
  --line: #354035;
  --text: #d7ddd2;
  --dim: #7d897a;
  --accent: #91c787;
  --warn: #d8b268;
  --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: 154px 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; }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; padding: 0 7px 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); }

.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 { 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); padding: 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); grid-auto-rows: 104px; gap: 6px; align-content: start; overflow: auto; }
.file-grid.drop-target { outline: 1px solid var(--accent); outline-offset: -5px; background: #101610; }
.file-item { min-width: 0; padding: 8px; display: grid; grid-template-rows: 34px minmax(0, 1fr) auto; gap: 4px; border: 1px solid var(--line); background: var(--panel); color: var(--text); text-align: left; }
.file-item:hover, .file-item:focus-visible { border-color: var(--accent); background: var(--panel-alt); color: var(--text); outline: 0; }
.file-item.selected { border-color: var(--accent); background: #182018; }
.file-item .file-icon { color: var(--dim); font-size: 21px; line-height: 1; }
.file-item.directory .file-icon, .file-item.directory .file-name { color: var(--accent); }
.file-item .file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; overflow-wrap: anywhere; }
.file-item small { display: flex; justify-content: space-between; gap: 4px; font-size: 9px; }
.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 { overflow: hidden; background: #000; }
.terminal-panel .panel-head { background: var(--panel); }
#terminal { width: 100%; height: calc(100% - 38px); padding: 6px; background: #000; }
.xterm { height: 100%; }
.xterm-viewport { overflow-y: auto !important; }

#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); }
  .card-grid { grid-template-columns: 1fr; gap: 4px; padding: 0 4px 4px; }
  .card-grid article { padding: 8px; }
  .log-row { grid-template-columns: 120px 95px minmax(0, 1fr); }
  .log-row span:nth-child(3) { display: none; }
  #session-note { display: none; }
}
