:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #0d1b2a;
  --ink-2: #3f4a56;
  --muted: #7d776e;
  --line: #e6e1d8;
  --line-2: #d6cfc3;
  --accent: #05253f;
  --accent-ink: #ffffff;
  --accent-soft: #e4e9ef;
  --gold: #8a7d6e;
  --danger: #b4372f;
  --shadow: 0 1px 2px rgba(20, 22, 26, .04), 0 6px 20px -8px rgba(20, 22, 26, .12);
  --shadow-lg: 0 24px 60px -20px rgba(20, 22, 26, .35);
  --radius: 14px;
  --serif: "Libre Caslon Text", "Times New Roman", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121315; --surface: #1b1d20; --surface-2: #17191b; --ink: #ecebe7; --ink-2: #c3c2bd;
    --muted: #8d8f94; --line: #2a2d31; --line-2: #383b40; --accent: #9fb7d3; --accent-ink: #05253f;
    --accent-soft: #1a2633; --gold: #b9ab97; --danger: #e0766d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -10px rgba(0,0,0,.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121315; --surface: #1b1d20; --surface-2: #17191b; --ink: #ecebe7; --ink-2: #c3c2bd;
  --muted: #8d8f94; --line: #2a2d31; --line-2: #383b40; --accent: #9fb7d3; --accent-ink: #05253f;
  --accent-soft: #1a2633; --gold: #b9ab97; --danger: #e0766d; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--accent); }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); text-decoration: none; white-space: nowrap; font: 400 21px/1 var(--serif); }
.brand small { display: block; font: 700 11px/1 var(--serif); letter-spacing: .22em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.brand span { color: var(--ink); }
.mark { width: 40px; height: 40px; border-radius: 8px; mix-blend-mode: multiply; }
.login-logo { display: block; width: min(220px, 60%); height: auto; margin: 0 auto 4px; mix-blend-mode: multiply; }
.login-title { font: 400 30px/1.1 var(--serif); margin: 8px 0 4px; color: var(--ink); display: flex; align-items: center; justify-content: center; gap: 12px; }
.login-title::before, .login-title::after { content: ""; height: 1px; width: 44px; background: var(--gold); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mark, :root:not([data-theme="light"]) .login-logo { mix-blend-mode: normal; background: #fefefe; }
  :root:not([data-theme="light"]) .login-logo { border-radius: 12px; padding: 10px; }
}
:root[data-theme="dark"] .mark, :root[data-theme="dark"] .login-logo { mix-blend-mode: normal; background: #fefefe; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: inherit; transition: transform .08s, background .15s, border-color .15s; }
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Inputs */
label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 14px 0 6px; }
.opt { color: var(--muted); font-weight: 400; }
input[type=text], input[type=url], input[type=email], input[type=tel], input:not([type]), textarea, select {
  width: 100%; border: 1px solid var(--line-2); background: var(--surface); border-radius: 10px; padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237b7f88' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; cursor: pointer; }
.err { color: var(--danger); font-size: 13px; min-height: 1em; margin: 10px 0 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 36px 28px; box-shadow: var(--shadow); text-align: center; }
.login-card form { text-align: left; margin-top: 20px; }
.login-card .btn { margin-top: 14px; height: 44px; }
.login-msg { font-size: 14px; margin: 16px 0 0; color: var(--ink-2); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 12px max(16px, calc((100vw - 1240px) / 2)); background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line); }
.search { flex: 1; max-width: 520px; margin-left: auto; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border: 1px solid var(--line-2); background: var(--surface); border-radius: 10px; color: var(--muted); }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: 0; outline: 0; padding: 0; background: transparent; flex: 1; min-width: 0; color: var(--ink); box-shadow: none !important; }
.search kbd { font: 500 11px var(--sans); border: 1px solid var(--line-2); border-radius: 5px; padding: 1px 6px; }
.menu { position: relative; }
.avatar-btn { width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer; font-weight: 600; font-size: 13px; color: #fff; }
.menu-pop { position: absolute; right: 0; top: 46px; min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; }
.menu-pop button { display: block; width: 100%; text-align: left; padding: 9px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.menu-pop button:hover { background: var(--surface-2); }
.menu-head { padding: 8px 10px 10px; font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* Layout */
.wrap { max-width: 1240px; margin: 0 auto; padding: 28px 16px 80px; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 24px; }
.intro h1 { font: 400 clamp(28px, 3.6vw, 40px)/1.12 var(--serif); margin: 0 0 10px; color: var(--accent); }
.intro p { margin: 0; max-width: 520px; }
.channels { display: flex; gap: 10px; flex-wrap: wrap; }
.channel { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.channel small { display: block; font-size: 11px; color: var(--muted); line-height: 1.2; }
.channel strong { font-weight: 600; font-size: 14px; }
.ch-ico { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

.filters { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.filter-right { display: flex; gap: 8px; }
.filter-right select { width: auto; height: 38px; padding-top: 0; padding-bottom: 0; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.seg::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.seg button { border: 0; background: transparent; padding: 7px 13px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-weight: 500; font-size: 14px; white-space: nowrap; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button:not(.on):hover { background: var(--surface-2); }
.seg-full { display: flex; width: 100%; }
.seg-full button { flex: 1; }

.chips { display: flex; gap: 6px; margin: 14px 0 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { border: 1px solid var(--line-2); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; color: var(--ink-2); }
.chip .n { color: var(--muted); margin-left: 4px; font-size: 12px; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.on .n { color: inherit; opacity: .7; }
.count { font-size: 13px; margin: 6px 0 14px; }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 18px; }
.card { position: relative; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; text-align: left; padding: 0; overflow: hidden; transition: transform .18s ease, box-shadow .18s ease, border-color .18s; animation: rise .35s ease both; }
.card:hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(20,22,26,.05), 0 18px 36px -14px rgba(20,22,26,.25); border-color: var(--line-2); }
.card:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.card.fresh { box-shadow: 0 0 0 2px var(--gold), var(--shadow); }

.thumb { position: relative; aspect-ratio: 16 / 10; background: var(--surface-2); border-bottom: 1px solid var(--line); overflow: hidden; display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .type { position: absolute; top: 10px; left: 10px; display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 7px; font-size: 11px; font-weight: 600; letter-spacing: .02em; background: rgba(255,255,255,.92); color: #1a1c20; backdrop-filter: blur(6px); }
.thumb .type svg { width: 13px; height: 13px; }
.tile { width: 100%; height: 100%; display: grid; place-items: center; padding: 20px; text-align: center; }
.tile-link { background: linear-gradient(135deg, #05253f, #2b4a68); color: #fff; }
.tile-link .dom { color: #d9cfc1; }
.tile-link .mono { font: 700 40px/1 var(--serif); }
.tile-link .dom { font-size: 12px; opacity: .85; margin-top: 6px; }
.tile-doc .page { width: 86px; height: 108px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 6px; position: relative; box-shadow: 0 8px 20px -10px rgba(0,0,0,.3); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 12px; }
.tile-doc .page::before { content: ""; position: absolute; top: 16px; left: 14px; right: 14px; height: 40px; background: repeating-linear-gradient(var(--line-2) 0 2px, transparent 2px 9px); }
.tile-doc .ext { font: 700 11px var(--sans); letter-spacing: .06em; color: #fff; background: var(--extc, #b4372f); padding: 3px 7px; border-radius: 4px; }
.tile-note { background: var(--surface-2); font: italic 400 18px/1.4 var(--serif); color: var(--ink); padding: 22px 24px; text-align: left; display: flex; align-items: center; }
.tile-note::before { content: "\201C"; font-size: 54px; color: var(--gold); line-height: 0; margin-right: 6px; transform: translateY(14px); }
.tile-tip { background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--gold) 22%, var(--surface-2)), var(--surface-2) 70%); color: var(--ink-2); display: flex; flex-direction: column; gap: 10px; font: italic 400 18px var(--serif); }
.tile-tip svg { width: 44px; height: 44px; color: var(--gold); stroke-width: 1.4; }
.tile-note span { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

.body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.cat { align-self: flex-start; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--catc, var(--accent)); }
.title { font-weight: 600; font-size: 15.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.note { color: var(--ink-2); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.meta { margin-top: auto; padding-top: 10px; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.av { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 600; color: #fff; flex: none; }
.meta .who { color: var(--ink-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta .src { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; }
.meta .src svg { width: 14px; height: 14px; }

/* Skeleton */
.skel { height: 300px; border-radius: var(--radius); background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%) 0 0 / 300% 100%; border: 1px solid var(--line); animation: shimmer 1.4s infinite linear; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* Empty */
.empty { text-align: center; padding: 60px 16px; }
.empty h2 { font: 400 26px var(--serif); color: var(--accent); margin: 18px 0 6px; }
.empty .btn { margin-top: 14px; }
.empty-art { position: relative; width: 120px; height: 70px; margin: 0 auto; }
.empty-art span { position: absolute; width: 90px; height: 56px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); box-shadow: var(--shadow); }
.empty-art span:nth-child(1) { left: 0; top: 14px; transform: rotate(-8deg); }
.empty-art span:nth-child(2) { left: 30px; top: 4px; transform: rotate(6deg); }
.empty-art span:nth-child(3) { left: 15px; top: 10px; background: var(--accent-soft); }

/* Dialogs */
.dlg { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); border: 1px solid var(--line); border-radius: 18px; padding: 22px 24px 24px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
.dlg-wide { width: min(880px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(14, 16, 20, .45); backdrop-filter: blur(3px); }
.dlg[open] { animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dlg-head h2 { font: 400 24px/1.15 var(--serif); margin: 0; color: var(--accent); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.unfurl { margin-top: 10px; display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.unfurl img { width: 84px; height: 56px; object-fit: cover; border-radius: 6px; flex: none; }
.unfurl b { display: block; font-size: 14px; }

.drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 16px; border: 1.5px dashed var(--line-2); border-radius: 12px; cursor: pointer; text-align: center; color: var(--ink-2); font-weight: 400; margin-top: 16px; transition: border-color .15s, background .15s; }
.drop svg { width: 26px; height: 26px; color: var(--accent); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.file-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px; }
.file-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Detail view */
.view { display: grid; grid-template-columns: 1.25fr 1fr; gap: 24px; }
.view-media { border-radius: 12px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); min-height: 260px; display: grid; place-items: center; }
.view-media img { width: 100%; max-height: 70vh; object-fit: contain; display: block; }
.view-media iframe { width: 100%; height: 70vh; border: 0; background: #fff; }
.view-media .tile { min-height: 300px; }
.view-info h2 { font: 400 25px/1.2 var(--serif); margin: 6px 0 10px; word-break: break-word; }
.view-info .note-full { white-space: pre-wrap; color: var(--ink-2); margin: 0 0 16px; }
.view-info .meta { padding-top: 0; margin-bottom: 18px; }
.view-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.view-close { position: absolute; top: 12px; right: 12px; }
.view-host { font-size: 13px; color: var(--muted); word-break: break-all; margin-bottom: 14px; }
.edit-row { display: flex; gap: 8px; margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }

/* Members */
.table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--line); border-radius: 12px; }
table.members { width: 100%; border-collapse: collapse; font-size: 14px; }
.members th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.members td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.members tr:last-child td { border-bottom: 0; }
.members td input { padding: 7px 9px; border-color: transparent; background: transparent; }
.members td input:hover { border-color: var(--line-2); }
.member-form { display: grid; grid-template-columns: 1fr 1.3fr 1fr auto; gap: 8px; }

/* Toast + drop overlay */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 11px; font-size: 14px; box-shadow: var(--shadow-lg); z-index: 50; animation: pop .2s ease; max-width: calc(100vw - 32px); }
.drop-overlay { position: fixed; inset: 0; z-index: 40; background: color-mix(in srgb, var(--accent) 22%, transparent); display: grid; place-items: center; backdrop-filter: blur(2px); }
.drop-overlay div { background: var(--surface); padding: 18px 26px; border-radius: 14px; font: 400 22px var(--serif); color: var(--accent); border: 2px dashed var(--accent); }

/* Phones */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .search { order: 3; max-width: none; flex-basis: 100%; margin-left: 0; }
  .search kbd { display: none; }
  #add-btn { margin-left: auto; padding: 0 12px; }
  .channels { width: 100%; }
  .channel { flex: 1 1 100%; }
  .channel div { flex: 1; min-width: 0; }
  .filters { flex-direction: column; align-items: stretch; }
  .filter-right select { flex: 1; }
  .grid { grid-template-columns: 1fr; }
  .view { grid-template-columns: 1fr; }
  .view-media iframe { height: 55vh; }
  .member-form { grid-template-columns: 1fr; }
  .dlg { padding: 18px 16px 20px; }
}
