/* Keicy AI Admin: light theme modelled on the cPanel File Manager. */
:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #fff;
  --text: #293a4a;
  --muted: #6b7a89;
  --border: #d9dee5;
  --border-soft: #e9edf2;
  --accent: #179bd7;
  --accent-dark: #0f7fb3;
  --accent-ink: #fff;
  --accent-soft: #eaf5fb;
  --accent-line: #c4e2f2;
  --header: #293a4a;
  --row-hover: #f3f8fc;
  --row-sel: #d8ecf8;
  --danger: #d9534f;
  --good: #2f8a4c;
  --warn: #b8740a;
  --mono: "SFMono-Regular", Consolas, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.45 "Open Sans", "Segoe UI", Roboto, Arial, sans-serif; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.defs { position: absolute; width: 0; height: 0; }

/* ---------- Top bar ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 0 16px; min-height: 48px; background: var(--header); color: #fff; flex: none; }
.top nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.top nav a { color: #c9d5e0; padding: 6px 10px; border-radius: 3px; }
.top nav a:hover { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.top nav a.on { color: #fff; background: rgba(255,255,255,.12); }
.top nav form { margin: 0 0 0 8px; }
.top .linkbtn { color: #c9d5e0; }
.top .linkbtn:hover { color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand em { font-style: normal; color: #6fd0ff; }
.brand.big { font-size: 18px; margin-bottom: 18px; color: var(--text); }
.brand.big em { color: var(--accent); }
.mark { width: 26px; height: 26px; border-radius: 4px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; }
.linkbtn { background: none; border: 0; color: var(--muted); padding: 0; }
.linkbtn:hover { color: var(--text); }

/* ---------- Generic page pieces (login, audit, editor) ---------- */
.page { width: 100%; max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.auth { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; }
.auth-card { width: 100%; max-width: 380px; padding: 32px; box-shadow: 0 2px 10px rgba(41,58,74,.08); }
.auth-card h1 { font-size: 20px; margin-bottom: 6px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
input, select, textarea { font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 3px; padding: 7px 9px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23,155,215,.18); }
input.code { font-size: 24px; letter-spacing: .35em; text-align: center; font-family: var(--mono); }
.err { color: var(--danger); background: #fbeceb; border: 1px solid #f1c7c5; padding: 8px 12px; border-radius: 3px; margin: 12px 0 0; }
.note { color: var(--warn); margin: 8px 0 0; }
.fine { font-size: 12px; color: var(--muted); margin: 18px 0 0; text-align: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 3px;
  border: 1px solid var(--border); background: #fff; color: var(--text); font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f5f7f9; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--danger); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover { background: #c64440; }
.btn.sm { padding: 4px 10px; font-size: 12px; font-weight: 500; }
.btn.wide { width: 100%; padding: 10px; }

.flash { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.flash li { padding: 9px 14px; border-radius: 3px; border: 1px solid var(--border); background: var(--surface); }
.flash .success { border-color: #b9dfc5; background: #eef8f1; color: var(--good); }
.flash .warning { border-color: #f0dc9a; background: #fff8e1; color: #7a5a10; }
.flash .error { border-color: #f1c7c5; background: #fbeceb; color: var(--danger); }

.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-family: var(--mono); font-size: 12px; }
.crumbs span { color: var(--muted); }
.h { font-size: 18px; margin-bottom: 14px; }
.chk { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; flex-wrap: wrap; }
.chk select { padding: 3px 6px; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 3px; background: var(--accent-soft); color: var(--accent-dark); border: 1px solid var(--accent-line); margin-left: 6px; }

/* Audit log table */
.table-card { overflow-x: auto; }
table.files { width: 100%; border-collapse: collapse; }
.files th { text-align: left; font-weight: 600; padding: 7px 10px; background: #f1f4f7; border-bottom: 1px solid var(--border); white-space: nowrap; }
.files td { padding: 6px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.files tbody tr:nth-child(even) td { background: #fafbfc; }
.files tr:hover td { background: var(--row-hover); }
.files tr.bad td { background: #fdf1f0; }
.empty { text-align: center; padding: 32px; color: var(--muted); }

/* ---------- File manager ---------- */
.fm-page { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 16px 16px; }
.fm-page > .flash { flex: none; }
.fm { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; background: var(--surface); border: 1px solid var(--border); padding: 6px 8px; }
.toolbar .spacer { flex: 1; }
.tool, .nav { background: none; border: 1px solid transparent; border-radius: 3px; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 9px; color: var(--text); white-space: nowrap; }
.tool svg, .nav svg { width: 15px; height: 15px; stroke: var(--accent); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tool:hover:not(:disabled), .nav:hover:not(.off) { background: var(--accent-soft); border-color: var(--accent-line); text-decoration: none; }
.tool:disabled, .nav.off { color: #aab4be; cursor: default; }
.tool:disabled svg, .nav.off svg { stroke: #c2cad2; }
.search input { width: 220px; height: 30px; padding: 0 9px; }

.fm-main { flex: 1; min-height: 0; display: flex; gap: 12px; }
.fm-side { width: 260px; flex: none; background: var(--surface); border: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.path-go { display: flex; gap: 4px; padding: 10px; border-bottom: 1px solid var(--border-soft); }
.path-go input { flex: 1; min-width: 0; height: 28px; padding: 0 8px; }
.btn-go { height: 28px; border: 0; border-radius: 3px; background: var(--accent); color: #fff; padding: 0 12px; font-weight: 600; }
.btn-go:hover { background: var(--accent-dark); }
.tree { overflow: auto; flex: 1; padding: 8px 6px; }
.tree ul { list-style: none; margin: 0; padding-left: 16px; }
.tree > ul { padding-left: 0; }
.node { display: flex; align-items: center; gap: 6px; padding: 2px 6px; border-radius: 3px; color: var(--text); white-space: nowrap; }
.node:hover { background: var(--row-hover); text-decoration: none; }
.node.active { background: var(--row-sel); font-weight: 600; }
.fi { width: 20px; height: 17px; flex: none; }
.fi.file { width: 16px; height: 18px; margin: 0 2px; }

.fm-content { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.navbar { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--border); background: #f8fafc; }
.navbar .crumbs { margin-left: auto; padding: 0 6px; }

.table-wrap { flex: 1; overflow: auto; }
.fm-table { width: 100%; border-collapse: collapse; min-width: 680px; }
.fm-table th { position: sticky; top: 0; z-index: 1; background: #f1f4f7; border-bottom: 1px solid var(--border); text-align: left;
  font-weight: 600; padding: 7px 10px; white-space: nowrap; cursor: pointer; user-select: none; }
.fm-table th:hover { background: #e7edf3; }
.fm-table .arrow { color: var(--accent); font-size: 10px; margin-left: 4px; }
.fm-table tbody tr { border-bottom: 1px solid var(--border-soft); }
.fm-table tbody tr:nth-child(even) { background: #fafbfc; }
.fm-table tbody tr:hover { background: var(--row-hover); }
.fm-table tbody tr.sel { background: var(--row-sel); }
.fm-table td { padding: 5px 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.fm-table td.name a, .fm-table td.name .plain { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.fm-table td.name a:hover { text-decoration: none; }
.fm-table td.perm { font-family: var(--mono); font-size: 12px; }
.fm-table .ck { width: 30px; padding-right: 0; cursor: default; }
.fm-table .ck input { margin: 0; vertical-align: middle; cursor: pointer; }
.sel-list { margin: 0; padding: 6px 10px 6px 26px; max-height: 140px; overflow: auto; background: #f5f7f9; border: 1px solid var(--border-soft);
  border-radius: 3px; font-family: var(--mono); font-size: 12px; word-break: break-all; }
.statusbar { border-top: 1px solid var(--border); padding: 6px 12px; color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: #f8fafc; }

/* Dialogs */
dialog.modal { border: 0; padding: 0; border-radius: 4px; width: calc(100% - 32px); max-width: 440px; box-shadow: 0 10px 30px rgba(0,0,0,.25); color: var(--text); }
dialog.modal::backdrop { background: rgba(30,45,60,.45); }
dialog.modal form { display: flex; flex-direction: column; margin: 0; }
dialog.modal header { background: var(--header); color: #fff; padding: 10px 14px; font-weight: 600; }
dialog.modal .mbody { padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; }
dialog.modal .mbody p { margin: 0; word-break: break-all; }
dialog.modal .hint { font-size: 12px; color: var(--muted); }
dialog.modal footer { padding: 10px 14px; background: #f5f7f9; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Editor ---------- */
.editor { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); }
.editor-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 12px; background: #f8fafc; border-bottom: 1px solid var(--border); }
.editor-bar span:last-child { display: flex; gap: 8px; }
.editor textarea { width: 100%; height: calc(100vh - 220px); min-height: 360px; resize: vertical; border: 0; border-radius: 0;
  font: 13px/1.55 var(--mono); tab-size: 2; padding: 14px; white-space: pre; overflow: auto; }
.editor textarea:focus { box-shadow: none; }
.page > .crumbs { margin-bottom: 12px; font-size: 13px; }

@media (max-width: 820px) {
  .fm-side { display: none; }
  .tool span, .nav span { display: none; }
  .toolbar .spacer { display: none; }
  .search, .search input { width: 100%; }
  .navbar .crumbs { margin-left: 0; width: 100%; padding: 4px 6px 0; }
}

/* ---------- Python apps ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .h { margin-bottom: 4px; display: flex; align-items: center; gap: 10px; }
.sub { margin: 0; }
.page-crumbs { margin-bottom: 12px; font-family: inherit; font-size: 13px; }
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: #e7ecf1; color: var(--muted); }
.pill.ok { background: #e3f4e8; color: var(--good); }
.pill.bad { background: #fbeceb; color: var(--danger); }
.files .actions { text-align: right; white-space: nowrap; }
.inline-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; margin: 0; }
.err.block { white-space: pre-wrap; margin: 0 0 12px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel h2 { font-size: 15px; padding-bottom: 8px; border-bottom: 1px solid var(--border-soft); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin: 0; }
.prefix-input { display: flex; }
.prefix-input > span { display: flex; align-items: center; padding: 0 8px; background: #f1f4f7; border: 1px solid var(--border); border-right: 0; border-radius: 3px 0 0 3px; color: var(--muted); font-weight: 400; font-family: var(--mono); font-size: 12px; }
.prefix-input input { flex: 1; min-width: 0; border-radius: 0 3px 3px 0; }
input[readonly] { background: #f5f7f9; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; margin: 0; }
.inline-form input { flex: 1; min-width: 160px; }
.copy-row { display: flex; gap: 8px; align-items: flex-start; }
.copy-row code { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; background: #f5f7f9; border: 1px solid var(--border); border-radius: 3px; padding: 7px 9px; word-break: break-all; }
.out-title { font-size: 13px; margin: 4px 0 0; }
pre.out { margin: 0; max-height: 360px; overflow: auto; background: #1e2a36; color: #e6edf3; font: 12px/1.5 var(--mono); padding: 10px 12px; border-radius: 3px; white-space: pre-wrap; word-break: break-word; }
details.pkgs summary { cursor: pointer; color: var(--accent); }
details.pkgs table { margin-top: 8px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Terminal ---------- */
.term-card { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); }
.term-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: #f8fafc; }
.term-head h1 { font-size: 15px; }
.term-head .spacer { flex: 1; }
.term-note { margin: 0; padding: 8px 12px; font-size: 12px; color: #6d5a1c; background: #fff8e1; border-bottom: 1px solid #f0dc9a; }
.term { flex: 1; min-height: 320px; background: #1e2a36; padding: 6px 0 0 8px; }
