:root {
    --bg: #0f1115;
    --bg2: #161920;
    --card: #1b1f27;
    --border: #2a2f3a;
    --text: #e3e6ec;
    --muted: #8b93a3;
    --accent: #5865f2;
    --accent-h: #4752c4;
    --danger: #e5484d;
    --ok: #3fb950;
    --radius: 8px;
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: #8ab4ff; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { background: #0b0d11; border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font: 12.5px/1.4 ui-monospace, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.ok { color: var(--ok); } .bad { color: var(--danger); }
.inline { display: inline; }

/* nawigacja */
.topbar { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 54px; background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-links a, .nav-user a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.nav-links a:hover, .nav-user a:hover { color: var(--text); background: var(--card); text-decoration: none; }
.nav-links a.active, .nav-user a.active { color: var(--text); background: var(--card); }
.nav-user { display: flex; align-items: center; gap: 8px; }

.container { max-width: 1400px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.narrow { max-width: 420px; }

/* formularze */
input, select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; font: inherit; width: 100%; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: 2px; height: 36px; width: 60px; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12.5px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13.5px; cursor: pointer; }
label.check.disabled { opacity: .45; cursor: not-allowed; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { min-width: 180px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #222733; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.alert-error { background: #3a1416; border-color: #6b2226; color: #ffb3b5; }
.alert-success { background: #12301b; border-color: #22603a; color: #a6f0b8; }

.badge { --c: var(--accent); display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); }
a.badge:hover { text-decoration: none; filter: brightness(1.2); }

/* tabela */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.row-edit { display: inline-block; text-align: left; }
.row-edit summary { list-style: none; }
.row-edit summary::-webkit-details-marker { display: none; }
.row-edit[open] .row-edit-body { position: absolute; right: 40px; z-index: 5; width: 300px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }

/* logowanie */
.login-box { max-width: 360px; margin: 10vh auto; }
.login-box h1 { margin-bottom: 16px; }

/* filtry */
.filters { position: relative; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.filter-grid .span2 { grid-column: span 2; }
.filter-actions { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.auto-refresh { margin-left: auto; }
/* układ strony logów: sidebar z kanałami + treść */
.logs-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.sidebar { position: sticky; top: 74px; max-height: calc(100vh - 94px); display: flex; flex-direction: column; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 8px; }
.sb-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 6px; font-weight: 600; text-transform: uppercase; font-size: 12px; letter-spacing: .04em; color: var(--muted); }
.sidebar .channel-search { margin: 0 2px; }
.ch-list { overflow-y: auto; display: flex; flex-direction: column; gap: 1px; padding-right: 2px; }
.ch-item { display: flex; align-items: center; gap: 8px; padding: 0 8px; border-radius: 6px; color: var(--muted); min-height: 32px; }
.ch-item:hover { background: var(--bg2); color: var(--text); }
.ch-item.active { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); }
.ch-item a, a.ch-item { color: inherit; flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 6px 0; text-decoration: none; }
.ch-item input { flex: none; margin: 0; opacity: .55; }
.ch-item input:checked, .ch-item:hover input { opacity: 1; }
.ch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-hash { width: 13px; text-align: center; font-weight: 700; }
.ch-all { font-weight: 600; }
.ch-group { margin-top: 10px; }
.ch-cat { display: flex; align-items: center; gap: 4px; padding: 0 4px 0 2px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-radius: 6px; }
.ch-cat:hover, .ch-cat.active { color: var(--text); }
.ch-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; background: none; border: 0; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; padding: 5px 0; text-align: left; }
.ch-caret { width: 14px; flex: none; font-size: 10px; transition: transform .15s; }
.ch-cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-count { font-weight: 500; font-size: 10.5px; opacity: .6; }
.ch-cat-filter { color: inherit; opacity: 0; padding: 3px; border-radius: 4px; display: inline-flex; }
.ch-cat:hover .ch-cat-filter, .ch-cat.active .ch-cat-filter { opacity: .8; }
.ch-cat-filter:hover { opacity: 1 !important; background: var(--bg2); }
.ch-group.collapsed:not(.searching) .ch-caret { transform: rotate(-90deg); }
.ch-group.collapsed:not(.searching) .ch-items { display: none; }
.sb-actions { display: inline-flex; gap: 2px; }
.sb-actions button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0 3px; line-height: 1; }
.sb-actions button:hover { color: var(--text); }
@media (hover: none) { .ch-cat-filter { opacity: .8; } }
.ch-admin { font-size: 10px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent); border-radius: 4px; padding: 0 5px; }

/* discord */
.btn-discord { background: #5865f2; border-color: #5865f2; color: #fff; width: 100%; padding: 10px 14px; font-weight: 600; }
.btn-discord:hover { background: #4752c4; }
.avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex: none; background: var(--bg); }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell .avatar { width: 34px; height: 34px; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
/* kategorie i kanały - grupy zwijane */
.ch-grp .grp-head td { background: var(--bg2); padding-top: 6px; padding-bottom: 6px; }
.grp-toggle { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; text-align: left; padding: 2px 0; }
.grp-caret { width: 14px; font-size: 11px; color: var(--muted); transition: transform .15s; }
.ch-grp.collapsed:not(.searching) .grp-caret { transform: rotate(-90deg); }
.ch-grp.collapsed:not(.searching) tr.ch-row { display: none; }
.ch-grp.unassigned-grp .grp-head td { background: color-mix(in srgb, var(--danger) 10%, var(--bg2)); }
tr.unassigned td:nth-child(2) code { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.logs-main { min-width: 0; }

/* logi */
.log-list { display: flex; flex-direction: column; gap: 8px; }
.log { --c: #3498db; background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--c); border-radius: var(--radius); padding: 10px 14px; }
.log header { display: flex; align-items: center; gap: 10px; font-size: 12.5px; margin-bottom: 6px; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log-id { margin-left: auto; color: #555d6e; font-size: 11.5px; }
.msg { white-space: pre-wrap; word-break: break-word; }
.msg-link { word-break: break-all; }

/* zdjęcia w logach */
.log-gallery { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.log-thumb { display: block; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); background: var(--bg); cursor: zoom-in; line-height: 0; }
.log-thumb img { max-width: 320px; max-height: 200px; display: block; transition: transform .15s; }
.log-thumb:hover img { transform: scale(1.03); }
.log-thumb.broken { line-height: 1.5; padding: 8px 12px; cursor: pointer; }
.log-thumb.broken img { display: none; }
.log-thumb.broken::after { content: "Zdjęcie niedostępne – otwórz link"; color: var(--muted); font-size: 12.5px; }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(5, 6, 9, .92); display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px; grid-template-rows: auto minmax(0, 1fr); }
.lightbox[hidden] { display: none; }
.lb-bar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 14px; }
.lb-count { margin-right: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-stage { overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 0 0 20px; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; border-radius: 4px; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.lb-stage.zoomed { overflow: auto; display: block; }
.lb-stage.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.lb-nav { background: none; border: 0; color: #fff; font-size: 48px; cursor: pointer; opacity: .6; }
.lb-nav:hover { opacity: 1; }
.lightbox.single .lb-nav { visibility: hidden; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-flex; gap: 6px; align-items: center; font: 12px/1.4 ui-monospace, Consolas, monospace; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 2px 7px; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip-k { color: var(--muted); font-family: system-ui, sans-serif; }
.chip-wrap { display: inline-flex; max-width: 100%; }
.chip-wrap .chip { border-top-right-radius: 0; border-bottom-right-radius: 0; min-width: 0; }
.chip-add { font-size: 11px; padding: 2px 6px; border: 1px solid var(--border); border-left: 0; border-radius: 0 4px 4px 0; background: var(--bg); color: var(--muted); display: inline-flex; align-items: center; }
.chip-add:hover { color: var(--p2); border-color: var(--p2); text-decoration: none; }

/* oznaczenia dwóch graczy */
:root { --p1: #f0b232; --p2: #23a5d5; }
.pdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.pdot.p1, .ptag.p1 { --pc: var(--p1); } .pdot.p2, .ptag.p2 { --pc: var(--p2); }
.pdot { background: var(--pc); }
.ptag { font-size: 11.5px; font-weight: 600; padding: 0 7px; border-radius: 4px; color: var(--pc); border: 1px solid color-mix(in srgb, var(--pc) 50%, transparent); background: color-mix(in srgb, var(--pc) 14%, transparent); }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 20px 0; flex-wrap: wrap; }
.pager-info { width: 100%; text-align: center; }

/* rangi */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.perm { align-items: flex-start !important; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; }
.perm span { display: flex; flex-direction: column; }
.perm small { color: var(--muted); }
.channel-tools { display: flex; gap: 8px; align-items: center; }
.channel-tools input { max-width: 280px; }
.channel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 14px; max-height: 420px; overflow: auto; padding: 4px; }

@media (max-width: 900px) {
    .logs-layout { grid-template-columns: 1fr; }
    .sidebar { position: static; max-height: 260px; }
    .log-thumb img { max-width: 100%; }
    .lightbox { grid-template-columns: 40px minmax(0, 1fr) 40px; }
}
@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px; }
    .container { padding: 16px; }
    .filter-grid .span2 { grid-column: auto; }
    .table { display: block; overflow-x: auto; }
}
