:root {
  color-scheme: dark;
  --canvas: #191a20;
  --rail: #202128;
  --panel: #23252e;
  --surface: #292b35;
  --hover: #313440;
  --active: #353953;
  --line: #393b49;
  --ink: #f0f0f6;
  --muted: #aeb0c2;
  --accent: #aeb5ff;
  --primary: #6269e9;
  --primary-hover: #535ad7;
  --green: #8cdbb3;
  --green-bg: #233e35;
  --blue: #b5caff;
  --blue-bg: #2d3958;
  --amber: #f2cc94;
  --amber-bg: #40342c;
  --danger: #ffadba;
  --shadow: #0f101599;
  --topbar: 58px;
  font-family: Inter, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --canvas: #f1f2f8;
  --rail: #e9ebf4;
  --panel: #fff;
  --surface: #f7f8fc;
  --hover: #eef0f9;
  --active: #e5e8ff;
  --line: #d8dbe8;
  --ink: #212334;
  --muted: #545970;
  --accent: #4146ae;
  --primary: #4c51c8;
  --primary-hover: #3d43b5;
  --green: #196247;
  --green-bg: #dbf2e7;
  --blue: #314e99;
  --blue-bg: #e4ebff;
  --amber: #794b1c;
  --amber-bg: #faeddb;
  --danger: #a1203f;
  --shadow: #30395933;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 14px; line-height: 1.5; }
button, textarea, input, select { font: inherit; color: inherit; }
button, select, label:has(input[type="radio"]) { cursor: pointer; }
button:disabled { opacity: .65; cursor: wait; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.skip-link:focus { position: fixed; z-index: 5; left: 16px; top: 12px; padding: 10px; background: var(--panel); }

.workspace { display: grid; grid-template-columns: 216px minmax(0, 1fr); height: 100dvh; }
.workspace.show-detail { grid-template-columns: 216px minmax(320px, 1fr) minmax(360px, .95fr); }
.mobile-bar { display: none; }
.sidebar, .feed, .detail { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.sidebar { background: var(--rail); border-right: 1px solid var(--line); }
.brand { min-height: 70px; display: flex; align-items: center; gap: 10px; padding: 12px 16px; font-weight: 700; }
.brand img { display: block; padding: 4px; border-radius: 9px; background: #252738; object-fit: contain; }
.brand small { display: block; color: var(--muted); font-size: 11px; font-weight: 500; }
.channel-nav { padding: 12px 10px; display: grid; gap: 4px; }
.channel-nav a { display: flex; align-items: center; gap: 9px; border-radius: 7px; min-height: 42px; padding: 0 11px; color: var(--muted); font-weight: 550; }
.channel-nav a:last-child { margin-top: 14px; }
.channel-nav a:hover { background: var(--hover); color: var(--ink); }
.channel-nav a[aria-current="page"] { color: var(--accent); background: var(--active); }
.channel-icon { font-size: 18px; width: 19px; text-align: center; line-height: 1; }
.sidebar-footer { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); display: grid; gap: 12px; }
.theme-switch { display: flex; gap: 3px; border: 1px solid var(--line); border-radius: 8px; padding: 3px; margin: 0; min-width: 0; }
.theme-switch label { flex: 1; position: relative; text-align: center; }
.theme-switch input { position: absolute; opacity: 0; width: 1px; }
.theme-switch span { display: block; border-radius: 5px; padding: 6px 4px; color: var(--muted); }
.theme-switch input:checked + span { background: var(--active); color: var(--accent); font-weight: 650; }
.theme-switch input:focus-visible + span { outline: 2px solid var(--accent); }
.account { min-height: 42px; min-width: 0; display: flex; align-items: center; gap: 8px; }
.account-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#userButtonContainer .user-dropdown { left: 0; right: auto; top: auto; bottom: calc(100% + 8px); background: var(--panel); border-color: var(--line); color: var(--ink); }
#userButtonContainer .user-name, #userButtonContainer .user-dropdown-item { color: var(--ink); }
#userButtonContainer .user-email { color: var(--muted); }
#userButtonContainer .user-dropdown-item:hover { background: var(--hover); color: var(--ink); }
#userButtonContainer .login-register-btn { color: var(--accent); border-color: var(--line); }

.feed { background: var(--canvas); }
.feed-header { background: var(--panel); padding: 18px 24px 16px; border-bottom: 1px solid var(--line); }
.feed-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.feed-title-row h1 { font-size: 22px; letter-spacing: -.025em; }
.filters { display: flex; gap: 8px; }
.filters input, .filters select, textarea { min-width: 0; border: 1px solid var(--line); border-radius: 7px; background: var(--canvas); }
.filters input, .filters select { min-height: 38px; padding: 6px 10px; }
.filters input { flex: 1; width: 100%; }
.filters select { max-width: 46%; }
::placeholder { color: var(--muted); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 7px 11px; min-height: 36px; border: 1px solid transparent; border-radius: 7px; background: transparent; font-weight: 650; white-space: nowrap; }
.primary { color: #fff; background: var(--primary); }
.primary:hover { background: var(--primary-hover); }
.secondary { border-color: var(--line); color: var(--ink); }
.secondary:hover, .text-button:hover { background: var(--hover); }
.text-button { color: var(--muted); }

.feed-scroll, .detail-scroll { flex: 1; overflow: auto; min-height: 0; overscroll-behavior: contain; scrollbar-color: var(--line) transparent; }
.feed-scroll { padding: 16px 24px 24px; }
.posts { list-style: none; padding: 0; margin: 0 auto; max-width: 960px; display: grid; gap: 8px; }
.post-link { display: grid; grid-template-columns: 36px minmax(0, 1fr); column-gap: 11px; align-items: start; min-height: 76px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.post-link:hover { background: var(--hover); }
.post-link[aria-current="true"] { background: var(--active); border-color: var(--accent); }
.post-preview { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 650; }
.post-meta { color: var(--muted); display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; margin-top: 5px; font-size: 12px; }
.post-author { max-width: min(40%, 160px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { border-radius: 50%; width: 36px; height: 36px; display: grid; place-items: center; background: var(--blue-bg); color: var(--blue); font-size: 14px; font-weight: 700; }
.avatar.official { background: var(--active); color: var(--accent); }
.badge { display: inline-flex; align-items: center; border-radius: 5px; padding: 2px 6px; font-size: 11px; font-weight: 650; color: var(--muted); background: var(--hover); line-height: 1.4; }
.badge-suggestion, .badge-replied, .badge-official { background: var(--blue-bg); color: var(--blue); }
.badge-problem { background: var(--amber-bg); color: var(--amber); }
.badge-resolved { background: var(--green-bg); color: var(--green); }
.list-footer { max-width: 960px; margin-inline: auto; padding: 16px 0; text-align: center; }
.state { display: grid; justify-items: center; gap: 10px; padding: 18px 10px; text-align: center; color: var(--muted); overflow-wrap: anywhere; }

.detail { background: var(--panel); border-left: 1px solid var(--line); }
.detail-header { display: flex; align-items: center; gap: 8px; min-height: 65px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.detail-header h2 { font-size: 15px; overflow-wrap: anywhere; }
#copy-link { margin-left: auto; }
.detail-scroll { padding: 20px; }
.thread { display: grid; gap: 18px; max-width: 800px; margin: 0 auto; }
.thread-badges { display: flex; gap: 6px; }
.message { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 11px; }
.message.reply { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 12px; }
.message-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; overflow-wrap: anywhere; }
.message-meta time, .resolution, .no-reply { font-size: 12px; color: var(--muted); }
.message-text { margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; }
.resolution { border-left: 2px solid var(--green); padding: 6px 10px; overflow-wrap: anywhere; }
.admin-form { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.admin-form label, .compose-fields > label, .type-switch legend { font-weight: 650; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
textarea { width: 100%; resize: vertical; padding: 10px; }
.field-meta { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.error { color: var(--danger); overflow-wrap: anywhere; }
.error:empty { display: none; }

.compose { width: min(550px, calc(100% - 24px)); max-height: calc(100dvh - 24px); border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 0; box-shadow: 0 20px 70px var(--shadow); }
.compose::backdrop { background: #12131bc9; }
.compose form { display: flex; flex-direction: column; }
.compose-header, .compose-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; }
.compose-header { border-bottom: 1px solid var(--line); }
.compose-header h2 { font-size: 18px; }
.compose-fields { display: grid; gap: 8px; padding: 16px 18px; }
.type-switch { margin: 0 0 8px; padding: 0; min-width: 0; border: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.type-switch legend { padding: 0 0 7px; }
.type-switch label { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; }
.type-switch label:has(:checked) { color: var(--accent); background: var(--active); }
.type-switch input { accent-color: var(--primary); }
.compose-actions { justify-content: end; border-top: 1px solid var(--line); }
.notice { position: fixed; z-index: 3; inset: auto 18px 18px; width: fit-content; max-width: calc(100% - 36px); margin-inline: auto; padding: 9px 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: 0 6px 20px var(--shadow); }
.notice:empty { visibility: hidden; }

@media (max-width: 1099px) {
  .workspace.show-detail { grid-template-columns: 216px minmax(0, 1fr); }
  .show-detail .feed { display: none; }
  .detail { border-left: 0; }
}
@media (max-width: 719px) {
  .workspace, .workspace.show-detail { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--topbar) minmax(0, 1fr); }
  .mobile-bar { display: flex; align-items: center; gap: 12px; padding-inline: 10px; background: var(--rail); border-bottom: 1px solid var(--line); font-weight: 650; }
  .sidebar { display: none; position: fixed; z-index: 2; top: var(--topbar); bottom: 0; left: 0; width: min(280px, 85vw); box-shadow: 12px 0 36px var(--shadow); overflow: auto; }
  .channels-open .sidebar { display: flex; }
  .feed-header { padding: 14px 12px 12px; }
  .feed-title-row h1 { font-size: 19px; }
  .button, .filters input, .filters select, .channel-nav a { min-height: 44px; }
  .feed-scroll, .detail-scroll { padding: 12px; }
  .detail-header { padding-inline: 10px; }
  .compose { width: 100%; height: 100dvh; max-width: none; max-height: none; margin: 0; border: 0; border-radius: 0; }
  .compose form { min-height: 100%; }
  .compose-actions { margin-top: auto; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
