/* Ownable Content Hub — GitHub-inspired theme (Primer-style neutrals + blue accent) */

:root {
  --surface-1: #ffffff;
  --surface-2: #ffffff;
  --page: #f6f8fa;
  --text-primary: #1f2328;
  --text-secondary: #59636e;
  --muted: #6e7781;
  --gridline: #d8dee4;
  --border: #d0d7de;
  --accent: #0969da;      /* GitHub blue — links, primary actions */
  --accent-2: #1a7f37;    /* GitHub green — secondary/success accents */
  --danger: #d1242f;
  --good: #1a7f37;
  --radius-lg: 6px;
  --radius-md: 6px;
  --radius-sm: 6px;
  --shadow-1: 0 1px 0 rgba(31, 35, 40, 0.04);
  --shadow-popover: 0 8px 24px rgba(140, 149, 159, 0.2);
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #161b22;
    --surface-2: #0d1117;
    --page: #0d1117;
    --text-primary: #e6edf3;
    --text-secondary: #9198a1;
    --muted: #6e7681;
    --gridline: #30363d;
    --border: #3d444d;
    --accent: #4493f8;
    --accent-2: #3fb950;
    --danger: #f85149;
    --good: #3fb950;
    --shadow-1: 0 0 0 rgba(0, 0, 0, 0);
    --shadow-popover: 0 8px 24px rgba(1, 4, 9, 0.6);
  }
}

* { box-sizing: border-box; }
html { font-size: 90%; } /* shrinks every rem-based font size ~10%, without scaling layout/spacing */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  font-size: 0.875rem;
  background: var(--page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }

/* ── Login page ─────────────────────────────────────────────── */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-popover);
  padding: 32px 28px;
}
.login-mark { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-mark span.name { font-weight: 700; letter-spacing: .01em; font-size: 1.05rem; }
.login-card h1 { font-size: 1.2rem; margin: 0 0 4px; }
.login-card .sub { color: var(--text-secondary); font-size: .88rem; margin: 0 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; color: var(--text-secondary); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-2); color: var(--text-primary);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-2); color: var(--text-primary); resize: vertical; min-height: 70px;
}
.checkbox-label {
  display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--text-secondary); cursor: pointer;
}
.checkbox-label input[type="checkbox"] { width: auto; padding: 0; border: none; background: none; }
.err { color: var(--danger); font-size: .85rem; min-height: 1.2em; margin-top: 4px; }

/* ── Buttons ────────────────────────────────────────────────── */
button, .btn {
  font-size: .88rem; font-weight: 500; padding: 6px 16px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  box-shadow: var(--shadow-1);
}
button.primary, .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:hover:not(:disabled) { background: var(--page); border-color: var(--muted); }
button.primary:hover:not(:disabled), .btn.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); filter: brightness(0.92); }
button.block { width: 100%; justify-content: center; }
button.ghost { background: transparent; border-color: transparent; box-shadow: none; }
button.ghost:hover:not(:disabled) { background: var(--page); border-color: transparent; }

/* ── App shell ──────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px; flex-shrink: 0; background: var(--surface-1);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 18px 12px;
}
.sidebar .brand { display: flex; align-items: center; gap: 9px; padding: 6px 8px 18px; }
.sidebar .brand .name { font-weight: 700; font-size: 1rem; letter-spacing: .01em; }

.logo {
  width: 60px; height: 60px; border-radius: 14px; background: #fff; object-fit: contain;
  padding: 1px; flex-shrink: 0; border: 1px solid var(--border);
}

.nav-group { margin-bottom: 18px; }
.nav-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 4px 8px; margin-bottom: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-md);
  color: var(--text-secondary); cursor: pointer; font-size: .9rem; border: none; background: transparent;
  box-shadow: none; font-weight: 400;
  width: 100%; text-align: left;
}
.nav-item:hover { background: var(--page); color: var(--text-primary); }
.nav-item.active { background: var(--page); color: var(--text-primary); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item.external { color: var(--accent-2); }

.sidebar-secondary-logo { margin-top: auto; padding: 10px 0 14px; }
.sidebar-secondary-logo img { display: block; width: 100%; height: auto; object-fit: contain; }
.sidebar-foot { padding-top: 14px; border-top: 1px solid var(--gridline); }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 6px 8px; font-size: .82rem; }
.user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .78rem; flex-shrink: 0;
}
.user-chip .who { overflow: hidden; }
.user-chip .email { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 150px; }
.user-chip .role { color: var(--muted); font-size: .74rem; text-transform: capitalize; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  padding: 18px 28px; border-bottom: 1px solid var(--border); background: var(--page);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex-shrink: 0; }
.topbar .desc { color: var(--text-secondary); font-size: .85rem; margin: 0; }
.search-box {
  flex: 1; min-width: 180px; max-width: 360px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-md); background: var(--surface-1);
}
.spacer { flex: 1; }

.content { padding: 22px 28px 60px; }

.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 28px 18px; }
.tag-chip {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-secondary); font-size: .8rem; cursor: pointer; box-shadow: none; font-weight: 400;
}
.tag-chip:hover { border-color: var(--accent); }
.tag-chip.active { background: var(--accent); color: #fff; border-color: transparent; }

/* ── Item grid ──────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.item-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; cursor: pointer; display: flex; flex-direction: column; gap: 8px;
}
.item-card:hover { box-shadow: var(--shadow-1); border-color: var(--muted); }
.item-card.open { border-color: var(--accent); }
.card-thumb {
  width: 100%; height: 150px; object-fit: contain; background: var(--page);
  border: 1px solid var(--gridline); border-radius: var(--radius-md); cursor: pointer;
}
.detail-thumb {
  display: block; max-width: 100%; max-height: 420px; margin: 0 auto 14px; background: var(--page);
  border: 1px solid var(--gridline); border-radius: var(--radius-md); cursor: pointer;
}
.thumb-caption { font-size: .72rem; color: var(--muted); text-align: center; margin-top: -2px; }
.item-card .top-row { display: flex; justify-content: flex-end; }
.item-card .copy-btn { padding: 3px 10px; font-size: .76rem; }
.item-card h3 { font-size: .9rem; margin: 0; word-break: break-word; display: flex; align-items: baseline; gap: 6px; }
.item-card .desc { color: var(--text-secondary); font-size: .78rem; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-card .tags, .detail-body .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-block; background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 999px; padding: 0 9px; line-height: 20px; font-size: .74rem; color: var(--accent);
}
.item-card .meta { font-size: .7rem; color: var(--muted); margin-top: auto; padding-top: 4px; }

/* Grid view: cards opened from the grid stack here, below it — several can be open at once. */
.open-details { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.open-detail-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px 22px;
}

.empty-state { color: var(--muted); text-align: center; padding: 60px 20px; font-size: .87rem; }

/* ── View toggle ────────────────────────────────────────────── */
.view-toggle { display: flex; gap: 2px; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 2px; }
.view-toggle .view-btn { border: none; padding: 6px 10px; border-radius: calc(var(--radius-md) - 2px); background: transparent; }
.view-toggle .view-btn.active { background: var(--page); color: var(--text-primary); }

/* ── List view (sortable table) ────────────────────────────────── */
.list-controls { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.list-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.list-table th, .list-table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--gridline); }
.list-table th {
  color: var(--text-secondary); font-weight: 600; white-space: nowrap; cursor: pointer;
  user-select: none;
}
.list-table th:hover { color: var(--text-primary); }
.list-table tbody tr { cursor: pointer; }
.list-table tbody tr:hover td { background: var(--page); }
.list-table tbody tr.selected td { background: var(--gridline); }
.list-table tbody tr:last-child td { border-bottom: none; }
.list-table td.list-title-cell { font-weight: 600; white-space: nowrap; }
.star-btn {
  border: none; background: none; padding: 0; font-size: 1.05rem; line-height: 1; color: var(--muted);
  cursor: pointer; flex-shrink: 0; box-shadow: none;
}
.star-btn.active { color: #d99a1a; }
.star-btn:hover { color: #d99a1a; }
.attachment-mark { font-size: .9rem; flex-shrink: 0; }
.list-table td.attachment-cell { text-align: center; color: var(--muted); }
.list-table td.list-text-cell { color: var(--text-secondary); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-table .list-subtext { font-weight: 400; font-size: .74rem; color: var(--muted); }

/* ── Split view — text browser: every text stacked in its own box ───── */
.split-view { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.split-text-card {
  width: 66.6667%; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.split-text-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.split-text-head h3 { font-size: .95rem; margin: 0; display: flex; align-items: baseline; gap: 6px; }
.split-sent-to { font-size: .76rem; color: var(--muted); margin-top: 8px; }
@media (max-width: 900px) {
  .split-text-card { width: 100%; }
}

/* ── Quick add (bottom of a section) ───────────────────────────── */
.quick-add {
  margin-top: 18px; border: 1px dashed var(--border); border-radius: var(--radius-lg);
  padding: 14px 16px; background: var(--surface-1);
}
.quick-add-row { display: flex; gap: 8px; margin-bottom: 8px; }
.quick-add-row select, .quick-add-row input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-2); color: var(--text-primary);
}
.quick-add-row input { flex: 1; }
.quick-add-row input#qa-tags { flex: 0 1 200px; }
.quick-add textarea {
  width: 100%; min-height: 100px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-2); color: var(--text-primary); resize: none; overflow-y: hidden;
}
.quick-add-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.quick-add-hint { font-size: .74rem; color: var(--muted); }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,11,11,0.45); display: flex;
  align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal {
  width: 100%; max-width: 560px; background: var(--surface-1); border-radius: var(--radius-lg);
  border: 1px solid var(--border); box-shadow: var(--shadow-popover); padding: 26px 26px 22px;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; gap: 10px; }
.modal-head h2 { font-size: 1.1rem; margin: 0; }

/* ── Page-through preview lightbox ──────────────────────────── */
.preview-overlay { align-items: center; }
.preview-modal {
  width: 100%; max-width: 900px; background: var(--surface-1); border-radius: var(--radius-lg);
  border: 1px solid var(--border); box-shadow: var(--shadow-popover); padding: 16px 20px 20px;
}
.preview-topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.preview-title { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.preview-body { display: flex; align-items: center; gap: 10px; }
.preview-nav { font-size: 1.4rem; padding: 8px 14px; line-height: 1; flex-shrink: 0; }
.preview-image { flex: 1; min-width: 0; max-height: 75vh; width: 100%; object-fit: contain; background: var(--page); border-radius: var(--radius-md); border: 1px solid var(--gridline); }
.preview-footer { text-align: center; font-size: .82rem; color: var(--muted); margin-top: 10px; }
.modal .field textarea#f-body { min-height: 140px; resize: none; overflow-y: hidden; }
.field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-2); color: var(--text-primary);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.file-drop {
  border: 1.5px dashed var(--border); border-radius: var(--radius-md); padding: 18px; text-align: center;
  color: var(--text-secondary); font-size: .85rem; cursor: pointer; background: var(--page);
}
.file-drop.has-file { color: var(--text-primary); border-style: solid; border-color: var(--accent); }
.file-drop input { display: none; }

.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }

.detail-body { font-size: .85rem; }
.detail-body .row { display: flex; gap: 8px; margin-bottom: 10px; }
.detail-body .k { color: var(--text-secondary); width: 90px; flex-shrink: 0; }
.preview-frame { width: 100%; height: 420px; border: 1px solid var(--border); border-radius: var(--radius-md); margin-top: 10px; background: var(--page); }
.text-block {
  white-space: pre-wrap; background: var(--page); border: 1px solid var(--gridline); border-radius: var(--radius-md);
  padding: 12px 14px; font-size: .87rem; line-height: 1.5; max-height: 320px; overflow-y: auto;
}

/* ── Toast ──────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--page); padding: 10px 18px; border-radius: var(--radius-md);
  font-size: .85rem; box-shadow: var(--shadow-popover); z-index: 100; display: none;
}
#toast.error { background: var(--danger); color: #fff; }

/* ── Analytics card ─────────────────────────────────────────── */
.analytics-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 26px; max-width: 480px;
}
.analytics-card .badge { display: inline-block; background: var(--page); border: 1px solid var(--gridline); color: var(--text-secondary); font-size: .74rem; padding: 3px 10px; border-radius: 999px; margin-bottom: 12px; }

/* ── Admin users table ──────────────────────────────────────── */
table.users-table { width: 100%; border-collapse: collapse; font-size: .87rem; max-width: 720px; }
table.users-table th, table.users-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--gridline); }
table.users-table th { color: var(--text-secondary); font-weight: 600; }
table.users-table select { padding: 5px 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); }

/* ── Knowledge Base ─────────────────────────────────────────── */
.kb-page { max-width: 900px; }
.kb-sub { color: var(--text-secondary); font-size: .88rem; margin: 0 0 22px; }
.kb-heading { font-size: .95rem; margin: 26px 0 10px; }
.kb-heading:first-of-type { margin-top: 0; }
.kb-table td { vertical-align: top; }

@media (max-width: 760px) {
  .sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; }
  .topbar h1 { font-size: 1rem; }
}
