/* aveloris Knowledge Base — PoC admin UI */

:root {
    --bg: #0d0f13;
    --panel: #161a21;
    --panel-2: #1d222b;
    --border: #262d38;
    --text: #e6e9ef;
    --muted: #8b93a3;
    --accent: #6aa3ff;
    --danger: #ff6b6b;
    --ok: #4ade80;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.view { display: none; }
.view.active { display: block; }

/* --- Login --- */
#login-view.active {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card h1 { margin: 0; font-size: 30px; letter-spacing: -0.5px; }
.login-card .sub { margin: 4px 0 22px; color: var(--muted); font-size: 13px; }
.dot { color: var(--accent); }

/* --- Layout --- */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 5;
}

.brand { font-size: 17px; font-weight: 600; }
.brand-sub { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }

main {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* --- Cards --- */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.card h2 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.desc { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.count { color: var(--muted); font-weight: 400; }

code {
    background: var(--panel-2);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    word-break: break-all;
}

/* --- Forms --- */
label {
    display: block;
    margin: 14px 0 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.hint { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.7; }

input[type="text"], input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
}

input:focus { outline: none; border-color: var(--accent); }

/* --- Dropzone --- */
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 26px 16px;
    background: var(--panel-2);
    border: 1.5px dashed var(--border);
    border-radius: 10px;
    color: var(--muted);
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s, color .15s;
}

.dropzone:hover,
.dropzone:focus-visible {
    outline: none;
    border-color: var(--accent);
    color: var(--text);
}

/* Applied while a file is dragged over the zone */
.dropzone.dragover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--panel-2));
    color: var(--text);
}

.dz-icon { opacity: 0.8; }
.dz-text { font-size: 13px; }
.dz-text strong { color: var(--text); font-weight: 600; }
.dz-browse { color: var(--accent); text-decoration: underline; }
.dz-sub { font-size: 12px; opacity: 0.65; }

/* Selected-file pill, shown in place of the dropzone */
.dz-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.dz-file.hidden, .dropzone.hidden { display: none; }
.dz-file-icon { font-size: 18px; }
.dz-file-name { flex: 1; min-width: 0; font-size: 13px; word-break: break-all; }
.dz-file-size { font-size: 12px; color: var(--muted); flex-shrink: 0; }

.dz-clear {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
    padding: 0 4px;
    flex-shrink: 0;
}
.dz-clear:hover { color: var(--danger); }

button {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    padding: 10px 16px;
}

button:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); color: #08101f; width: 100%; margin-top: 18px; }
.btn-secondary { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.btn-ghost { background: none; color: var(--muted); border-color: var(--border); padding: 7px 12px; }
.btn-ghost:hover { color: var(--text); }

#test-form { display: flex; gap: 8px; }
#test-form input { flex: 1; }

.err { color: var(--danger); font-size: 12px; min-height: 16px; margin: 10px 0 0; }

/* --- Checkbox row --- */
.check-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 18px 0 0;
    padding: 12px 14px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    color: var(--text);
}

.check-row:hover { border-color: var(--accent); }

.check-row input[type="checkbox"] {
    width: auto;
    margin: 2px 0 0;
    flex-shrink: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.check-text { font-size: 13px; }

.check-hint {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.45;
}

/* Per-entry sub-pages toggle in the list */
.entry-sub {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin: 0;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}

.entry-sub:hover { border-color: var(--accent); color: var(--text); }
.entry-sub:has(input:checked) {
    border-color: var(--accent);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.entry-sub input { width: auto; margin: 0; accent-color: var(--accent); cursor: pointer; }

/* --- Entry list --- */
.entry-list { display: flex; flex-direction: column; gap: 8px; }

.entry {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.entry-icon { font-size: 18px; flex-shrink: 0; }
.entry-body { flex: 1; min-width: 0; }
.entry-url { font-size: 13px; word-break: break-all; }
.entry-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.entry a { color: var(--accent); text-decoration: none; }
.entry a:hover { text-decoration: underline; }

.btn-del {
    background: none;
    border-color: var(--border);
    color: var(--muted);
    padding: 6px 10px;
    flex-shrink: 0;
}
.btn-del:hover { color: var(--danger); border-color: var(--danger); }

.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }

/* --- Lookup result --- */
#test-result:not(:empty) { margin-top: 16px; }

.chain {
    font-size: 12px;
    color: var(--muted);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.chain-step { padding: 2px 0; word-break: break-all; }
.chain-step.hit { color: var(--ok); }
.chain-step.hit::after { content: "  ← match"; opacity: 0.8; }
.chain-step.miss { opacity: 0.55; }

/* --- Edit button in entry rows --- */
.btn-edit {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 6px 12px;
    flex-shrink: 0;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-edit:hover { color: var(--accent); border-color: var(--accent); }

/* --- Modal / editor --- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 50;
}
.modal.hidden { display: none; }

/* --- Table view --- */
.modal-box.modal-wide { max-width: 1200px; }
.table-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.table-tools input[type="search"] { flex: 1 1 260px; margin: 0; }
.table-wrap { overflow: auto; max-height: 58vh; border: 1px solid var(--border); border-radius: 8px; }
.kb-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.kb-table th, .kb-table td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; white-space: nowrap; }
.kb-table th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-weight: 600; z-index: 1; }
.kb-table td[contenteditable="true"] { cursor: text; }
.kb-table td[contenteditable="true"]:focus { outline: 1px solid var(--accent); background: var(--panel-2); }
.kb-table td.saving { opacity: 0.5; }
.kb-table td.saved { box-shadow: inset 0 0 0 1px var(--ok); }
.kb-table td.row-actions { width: 1%; }
.kb-table td.row-actions button { padding: 2px 8px; font-size: 12px; }
.table-pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 8px; color: var(--muted); font-size: 13px; }

.modal-box {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 100%;
    max-width: 760px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 15px; }

.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

.editor-file-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 14px 0 6px;
}
.editor-file-actions { display: flex; gap: 8px; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-inline { width: auto; margin: 0; }

.editor-text {
    width: 100%;
    min-height: 320px;
    resize: vertical;
    background: var(--bg, #0d0f13);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--text);
    font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
    font-size: 13px;
    line-height: 1.55;
    tab-size: 4;
}
.editor-text:focus { outline: none; border-color: var(--accent); }

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    opacity: 0;
    transition: transform .2s, opacity .2s;
    pointer-events: none;
}

.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* Who a document is for. Sized and weighted to match .entry-sub beside it —
   a full-height boxed <select> next to a small pill made the row look like two
   unrelated controls stapled together. The scope is no longer repeated in the
   meta line either; the control is the one place it is stated. */
.sel-scope {
    flex-shrink: 0;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.2;
    cursor: pointer;
    max-width: 150px;
}
.sel-scope:hover { border-color: var(--accent); color: var(--text); }
.sel-scope:focus { outline: none; border-color: var(--accent); }
/* Published to the whole company is the state worth spotting at a glance. */
.sel-scope:has(option[value="global"]:checked) {
    border-color: var(--accent);
    color: var(--text);
}

/* --- Form fields of a guide (editor) --- */
.field-map { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 10px 0 12px; background: var(--panel-2); }
.field-map.hidden { display: none; }
.fm-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.fm-title { font-weight: 600; }
.fm-tools { margin-left: auto; display: flex; gap: 6px; }
.fm-wrap { max-height: 34vh; overflow: auto; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); }
.fm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fm-table th, .fm-table td { border-bottom: 1px solid var(--border); padding: 4px 6px; text-align: left; vertical-align: middle; }
.fm-table th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-weight: 600; z-index: 1; }
.fm-table .fm-num { color: var(--muted); width: 28px; }
.fm-table .fm-req { width: 48px; text-align: center; }
.fm-table .fm-act { white-space: nowrap; width: 1%; }
.fm-table .fm-act button { padding: 2px 7px; font-size: 12px; }
.fm-table .fm-input { width: 100%; margin: 0; padding: 4px 6px; font-size: 13px; }
.fm-table .fm-input.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.fm-table .fm-type { width: 110px; }
.fm-table input[type="checkbox"] { margin: 0; }
.fm-tag { display: inline-block; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.fm-table tr.fm-bad .fm-ref { border-color: var(--danger); }
