/* ==========================================================
   ChangeLog.Ninja - styles
   Theme: dark, dense, monospace where it counts
   ========================================================== */

:root {
    --bg:           #0f1419;
    --bg-soft:      #161b22;
    --bg-card:      #1c232c;
    --bg-hover:     #232b35;
    --border:       #2a323d;
    --border-soft:  #222a33;
    --text:         #e6edf3;
    --text-muted:   #8b949e;
    --text-dim:     #6e7681;
    --accent:       #58a6ff;
    --accent-soft:  #1f6feb33;
    --good:         #3fb950;
    --warn:         #d29922;
    --bad:          #f85149;
    --code-bg:      #0d1117;
    --tag-bg:       #1f6feb33;
    --tag-text:     #79c0ff;
    --shadow:       0 8px 24px rgba(0,0,0,.4);
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", "Consolas", monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

/* ---------- Top bar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .5rem 1rem;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: .75rem;
}
.brand {
    font-size: 1rem;
    color: var(--text);
    margin-right: .5rem;
    white-space: nowrap;
}
.tabs {
    display: flex;
    gap: .25rem;
}
.tab {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: .35rem .75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: .9rem;
}
.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent-soft);
}
#globalSearch {
    width: 320px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .4rem .65rem;
    border-radius: 6px;
    font-size: .9rem;
}
#globalSearch:focus { outline: none; border-color: var(--accent); }

.user-chip {
    color: var(--text-muted);
    font-size: .85rem;
    padding: .25rem .5rem;
}

.role-badge {
    display: inline-block;
    background: var(--bg-hover);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: .05rem .45rem;
    border-radius: 999px;
    font-size: .7rem;
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: .03em;
    vertical-align: middle;
}
.role-badge.role-admin {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: transparent;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .4rem .85rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: .88rem;
    text-decoration: none;
    transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg-hover); border-color: #3a4452; }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #0d1117;
    font-weight: 600;
}
.btn-primary:hover { background: #79b6ff; border-color: #79b6ff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: #5a2228; }
.btn-danger:hover { background: #2a181a; }
.btn-sm { padding: .25rem .55rem; font-size: .8rem; }
.btn-icon { padding: .3rem .5rem; }

/* ---------- Main area ---------- */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.25rem;
}

.view-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.view-head h2 { margin: 0; font-size: 1.1rem; }
.toolbar {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
}
.toolbar input, .toolbar select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .4rem .6rem;
    border-radius: 6px;
    font-size: .88rem;
}
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--accent); }

/* ---------- Tables ---------- */
.table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}
thead th {
    text-align: left;
    padding: .6rem .75rem;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    position: sticky;
    top: 0;
}
tbody td {
    padding: .55rem .75rem;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
tbody td.actions { text-align: right; white-space: nowrap; }
tbody td.actions .btn { margin-left: .25rem; }
tbody .mono, .mono { font-family: var(--mono); }
tbody .num { text-align: right; }

.empty {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

/* ---------- Tags ---------- */
.tag {
    display: inline-block;
    background: var(--tag-bg);
    color: var(--tag-text);
    padding: .12rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-family: var(--mono);
    margin-right: .25rem;
    cursor: pointer;
}
.tag:hover { filter: brightness(1.2); }
.tag-row { display: flex; gap: .25rem; flex-wrap: wrap; }

/* ---------- Feed view ---------- */
.feed-filters {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-bottom: .75rem;
    flex-wrap: wrap;
}
.entry {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .85rem 1rem;
    margin-bottom: .65rem;
}
.entry-head {
    display: flex;
    align-items: baseline;
    gap: .65rem;
    flex-wrap: wrap;
    margin-bottom: .35rem;
}
.entry-server {
    font-family: var(--mono);
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}
.entry-server:hover { text-decoration: underline; }
.entry-time {
    color: var(--text-dim);
    font-size: .8rem;
    font-family: var(--mono);
}
.entry-author {
    color: var(--text-muted);
    font-size: .8rem;
}
.entry-summary {
    color: var(--text);
    font-weight: 500;
    margin: .15rem 0 .35rem;
    font-size: .95rem;
}
.entry-body {
    color: var(--text-muted);
    font-size: .88rem;
    margin: .35rem 0 .5rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.entry-body code,
.entry-body pre {
    font-family: var(--mono);
    font-size: .82rem;
}
.entry-body pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .65rem .8rem;
    overflow-x: auto;
    color: #e6edf3;
    white-space: pre;
}
.entry-body code {
    background: var(--code-bg);
    padding: .1rem .35rem;
    border-radius: 4px;
}
.entry-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    margin-top: .35rem;
    font-size: .78rem;
    color: var(--text-dim);
}
.entry-actions { display: flex; gap: .25rem; }
.entry-actions .btn-sm { font-size: .75rem; padding: .15rem .5rem; }

mark.hl {
    background: #d2992233;
    color: var(--warn);
    padding: 0 2px;
    border-radius: 2px;
}

/* ---------- Server detail (drawer-ish inline expand) ---------- */
.server-detail {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}
.server-detail h3 {
    margin: 0 0 .5rem 0;
    font-family: var(--mono);
    color: var(--accent);
}
.kv {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: .35rem .75rem;
    font-size: .88rem;
    margin-bottom: .75rem;
}
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-family: var(--mono); }

.subgrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: .75rem;
    margin-top: .75rem;
}
.subcard {
    background: var(--bg-soft);
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    padding: .65rem .8rem;
}
.subcard h4 {
    margin: 0 0 .4rem 0;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}
.subcard ul { list-style: none; padding: 0; margin: 0; }
.subcard li { padding: .15rem 0; font-family: var(--mono); font-size: .85rem; }
.subcard li.empty-li { font-family: var(--sans); color: var(--text-dim); font-style: italic; }

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 4rem 1rem 1rem;
    z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 100%;
    max-width: 720px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 5rem);
}
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-soft);
}
.modal-head h2 { margin: 0; font-size: 1rem; }
.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 .35rem;
}
.modal-close:hover { color: var(--text); }
.modal-card form {
    padding: 1rem;
    overflow-y: auto;
}
.modal-foot {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: .5rem;
    padding-top: .75rem;
    border-top: 1px solid var(--border-soft);
    margin-top: .75rem;
}
.modal-foot .spacer { flex: 1; }
.modal-foot .hint { margin-right: auto; font-size: .75rem; color: var(--text-dim); }

/* ---------- Forms ---------- */
form label {
    display: block;
    margin-bottom: .75rem;
    font-size: .82rem;
    color: var(--text-muted);
    font-weight: 500;
}
form input[type="text"],
form input[type="search"],
form input[type="password"],
form input:not([type]),
form select,
form textarea {
    display: block;
    width: 100%;
    margin-top: .25rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .5rem .65rem;
    border-radius: 6px;
    font-size: .9rem;
    font-family: inherit;
}
form textarea {
    font-family: var(--mono);
    font-size: .85rem;
    resize: vertical;
    min-height: 8rem;
}
form input:focus, form select:focus, form textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.hint { color: var(--text-dim); font-size: .75rem; font-weight: normal; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
}

/* ---------- Floating action button ---------- */
.fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 50%;
    background: var(--accent);
    color: #0d1117;
    border: none;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    z-index: 40;
}
.fab:hover { transform: scale(1.05); }

/* ---------- Toasts ---------- */
.toasts {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    align-items: center;
}
.toast {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    padding: .55rem 1rem;
    border-radius: 6px;
    box-shadow: var(--shadow);
    font-size: .85rem;
    animation: pop .15s ease-out;
}
.toast.error { border-color: #5a2228; color: #ff8088; }
.toast.ok    { border-color: #2c6e3a; color: var(--good); }
@keyframes pop {
    from { transform: translateY(8px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

/* ---------- Alerts ---------- */
.alert {
    padding: .65rem .85rem;
    border-radius: 6px;
    margin-bottom: .75rem;
    border: 1px solid var(--border);
}
.alert-error { background: #2a181a; border-color: #5a2228; color: #ff8088; }
.alert-ok    { background: #102d18; border-color: #2c6e3a; color: var(--good); }

/* ---------- Login / install ---------- */
.login-page, .install-page {
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card, .install-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow);
}
.install-card { max-width: 560px; }
.login-card h1, .install-card h1 {
    margin: 0 0 1rem 0;
    font-size: 1.15rem;
}

/* ---------- Revisions ---------- */
.revisions {
    margin-top: 1rem;
    border-top: 1px solid var(--border);
    padding-top: .75rem;
}
.revisions h4 {
    margin: 0 0 .5rem 0;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}
.revision {
    background: var(--bg-soft);
    border-left: 2px solid var(--warn);
    padding: .5rem .75rem;
    margin-bottom: .35rem;
    font-size: .8rem;
}
.revision-meta { color: var(--text-dim); font-family: var(--mono); }

.utility-bar {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: .5rem;
}

/* ---------- Multi-select / bulk log ---------- */
.hidden { display: none !important; }

.sel-col {
    width: 28px;
    text-align: center;
    padding-left: .25rem;
    padding-right: .25rem;
}
.sel-col input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

.bulk-bar {
    display: flex;
    align-items: center;
    gap: .65rem;
    margin: 0 0 .65rem;
    padding: .5rem .75rem;
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: 6px;
    color: var(--text);
    font-size: .88rem;
}
.bulk-bar .bulk-count   { color: var(--text); white-space: nowrap; }
.bulk-bar .bulk-preview { color: var(--text-muted); font-family: var(--mono); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 50vw; }
.bulk-bar .spacer       { flex: 1; }

.bulk-info {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .55rem .65rem;
    margin-bottom: .65rem;
}
.bulk-server-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    margin-top: .35rem;
    max-height: 7.5rem;
    overflow-y: auto;
}

/* small-screen tweaks */
@media (max-width: 720px) {
    .topbar { flex-direction: column; align-items: stretch; }
    .topbar-left, .topbar-right { justify-content: space-between; }
    #globalSearch { width: 100%; }
    .form-row { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 100px 1fr; }
}
