:root {
  --bg: #0b0c0f;
  --panel: #13151a;
  --panel-2: #1a1d24;
  --line: #262a33;
  --text: #ece8de;
  --muted: #8b8f99;
  --gold: #d6b25e;
  --gold-2: #f2c14e;
  --gold-soft: rgba(214, 178, 94, 0.14);
  --red: #e5675b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(214, 178, 94, 0.08), transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border: 1px solid transparent; border-radius: 8px;
  font-weight: 700; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-gold { background: linear-gradient(180deg, var(--gold-2), #c9962e); color: #1a1204; }
.btn-gold:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--gold); color: var(--gold-2); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }

/* ---------------------------------------------------------- sign in */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-card {
  width: min(420px, 100%); padding: 36px 28px; text-align: center;
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line);
  border-top: 2px solid var(--gold); border-radius: 14px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.gate-logo { width: 72px; height: 72px; }
.gate h1 { margin: 12px 0 6px; font-size: 22px; letter-spacing: 0.02em; }
.gate p { margin: 0 0 22px; color: var(--muted); }
.gate .btn + .btn { margin-top: 10px; }

/* ---------------------------------------------------------- layout */
.app {
  display: grid; grid-template-columns: 240px minmax(0, 1fr); grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "side main"; min-height: 100vh;
}
.top {
  grid-area: top; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: rgba(11, 12, 15, 0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; font-size: 16px; letter-spacing: 0.02em; }
.brand small { color: var(--muted); font-size: 12px; }
.me { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.me img { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--gold); }
.me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.menu-btn { display: none; }

.side {
  grid-area: side; position: sticky; top: 59px; align-self: start; height: calc(100vh - 59px); overflow-y: auto;
  padding: 18px 12px; border-right: 1px solid var(--line);
}
.side-label { margin: 0 8px 8px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.cat {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; margin-bottom: 2px; background: none; border: 0; border-radius: 8px; text-align: left; cursor: pointer;
}
.cat:hover { background: var(--panel-2); }
.cat.active { background: var(--gold-soft); color: var(--gold-2); }
.cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.cat.private .cat-name::before { content: "🔒 "; }
.cat.private { border: 1px dashed rgba(229, 103, 91, 0.45); }
.side-note { margin: 16px 8px 0; color: var(--muted); font-size: 12px; }

.main { grid-area: main; min-width: 0; padding: 18px 20px 40px; }

/* ---------------------------------------------------------- filters */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.search { position: relative; flex: 1 1 320px; min-width: 0; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gold); font-size: 18px; }
.search input {
  width: 100%; padding: 10px 12px 10px 36px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.filters input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.field { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.field input { padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); }
.quick { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.quick button { padding: 8px 10px; background: var(--bg); border: 0; border-right: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.quick button:last-child { border-right: 0; }
.quick button:hover { color: var(--gold-2); }
.live { display: flex; align-items: center; gap: 6px; padding: 8px 4px; color: var(--muted); cursor: pointer; }
.live input { accent-color: var(--gold); }

.summary { margin: 14px 2px 10px; color: var(--muted); font-size: 13px; }
.summary #summary { color: var(--text); font-weight: 700; }

/* ---------------------------------------------------------- table */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.logs { width: 100%; border-collapse: collapse; table-layout: fixed; }
.logs th {
  padding: 10px 12px; background: var(--panel-2); color: var(--muted); text-align: left;
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
}
.logs th:nth-child(1) { width: 112px; }
.logs th:nth-child(2) { width: 130px; }
.logs th:nth-child(3) { width: 18%; }
.logs th:nth-child(4), .logs th:nth-child(5) { width: 19%; }
.logs td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.logs tbody tr { cursor: pointer; }
.logs tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.logs tr.fresh { animation: fresh 2.5s ease-out; }
@keyframes fresh { from { background: var(--gold-soft); } to { background: transparent; } }

.time b { display: block; font-variant-numeric: tabular-nums; }
.time small { display: block; color: var(--muted); font-size: 11px; }
.time .ago { color: var(--gold); }
.cat-chip {
  display: inline-block; padding: 3px 8px; border-radius: 999px; background: var(--gold-soft); color: var(--gold-2);
  font-size: 11px; font-weight: 700; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.cat-chip.private { background: rgba(229, 103, 91, 0.15); color: #ff9a8f; }
.what { font-weight: 700; }
.person-name { padding: 0; background: none; border: 0; font-weight: 600; text-align: left; cursor: pointer; }
.person-name:hover { color: var(--gold-2); text-decoration: underline; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.chip {
  padding: 1px 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; color: var(--muted);
  font: 11px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover { border-color: var(--gold); color: var(--gold-2); }
.muted { color: var(--muted); }
.details-text { white-space: pre-wrap; color: #cfcabe; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
tr.open .details-text { display: block; -webkit-line-clamp: unset; }
.thumb { display: inline-block; margin-top: 6px; }
.thumb img { max-width: 160px; max-height: 100px; border-radius: 6px; border: 1px solid var(--line); }
.empty { margin: 0; padding: 40px; text-align: center; color: var(--muted); }
.more { display: flex; justify-content: center; margin-top: 16px; }

/* ---------------------------------------------------------- site access (owner only) */
.main.show-access > :not(#access) { display: none !important; }
.access h2 { margin: 0 0 4px; font-size: 20px; }
.access h3 { margin: 26px 2px 10px; font-size: 14px; letter-spacing: 0.04em; }
.access .count { color: var(--muted); font-weight: 400; }
.access-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.access-head p { margin: 0; color: var(--muted); max-width: 640px; }
.block-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.block-form .grow { flex: 1 1 220px; min-width: 0; }
.block-form .grow2 { flex: 2 1 260px; min-width: 0; }
.block-form .field input { width: 100%; min-width: 0; }
.btn-danger { background: #8f2a22; border-color: #b83a30; color: #fff; }
.btn-danger:hover { background: #a8332a; }
.access-msg { margin: 10px 2px 0; color: #ff9a8f; }
.access-msg.ok { color: #8fd69a; }
.access-table tbody tr { cursor: default; }
.access-table th { width: auto !important; }
.access-table th:last-child { width: 120px !important; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who img { width: 30px; height: 30px; border-radius: 50%; flex: none; }
.who .who-text { min-width: 0; }
.who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: var(--muted); font: 11px ui-monospace, Consolas, monospace; }
.tag { display: inline-block; margin: 0 4px 4px 0; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.tag.ok { background: rgba(143, 214, 154, 0.14); color: #8fd69a; }
.tag.no { background: rgba(255, 255, 255, 0.06); color: var(--muted); }
.tag.bad { background: rgba(229, 103, 91, 0.15); color: #ff9a8f; }
.tag.live { background: var(--gold-soft); color: var(--gold-2); }
.access-table td:last-child { text-align: right; width: 120px; }
.side-owner { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------------------------------------------------------- phones and small screens */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .top { padding: 10px 16px; gap: 10px; }
  .brand b { font-size: 15px; }
  .menu-btn { display: inline-block; }
  .brand small { display: none; }
  .me span { display: none; }
  .side {
    position: fixed; top: 59px; left: 0; bottom: 0; z-index: 30; width: 260px; height: auto;
    background: var(--panel); transform: translateX(-100%); transition: transform 0.2s;
  }
  body.side-open .side { transform: none; box-shadow: 20px 0 60px rgba(0, 0, 0, 0.6); }
  .main { padding: 12px 16px 40px; }
  .field { flex: 1 1 140px; min-width: 0; }
  .field input { width: 100%; min-width: 0; }
  .filters > * { min-width: 0; max-width: 100%; }
  .search { flex-basis: 100%; }

  .logs thead { display: none; }
  .logs, .logs tbody, .logs tr, .logs td { display: block; width: 100%; }
  .logs tr { padding: 10px 12px; border-top: 1px solid var(--line); }
  .logs td { padding: 3px 0; border: 0; }
  .logs td.time { display: flex; gap: 8px; align-items: baseline; }
  .logs td.time small { display: inline; }
  .logs td.person:has(.muted) { display: none; }
  .logs td.person::before { content: attr(data-label); display: block; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
}
