:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --border: #e5e7ec;
    --border-strong: #d5d9e1;
    --text: #1f2329;
    --muted: #6f7683;
    --muted-2: #9aa2ae;
    --accent: #2f6bfb;
    --accent-hover: #2159e0;
    --accent-soft: #eef3ff;
    --green: #1f7a4d;
    --green-bg: #e7f6ed;
    --amber: #8a5a00;
    --amber-bg: #fdf1d6;
    --danger: #b42318;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font: inherit;
    cursor: pointer;
}

input,
textarea,
select {
    font: inherit;
    color: inherit;
}

/* App bar */

.appbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 24px;
    height: 64px;
    padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.brand-mark {
    display: block;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--surface-2);
}

.tabs {
    display: flex;
    gap: 4px;
    margin: 0 auto;
    padding: 4px;
    border-radius: 10px;
    background: var(--bg);
}

.tab {
    padding: 6px 16px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

.tab.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--border);
}

.appbar-user {
    display: flex;
    flex: none;
    align-items: center;
    gap: 10px;
}

.appbar-user form {
    display: flex;
    margin: 0;
}

.appbar-user-name {
    max-width: 160px;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-quiet {
    padding: 7px 12px;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}

.btn-quiet:hover {
    background: var(--surface-2);
    color: var(--text);
}

/* Page shell */

.page {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 28px 40px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
}

.page-title h2 {
    margin: 0;
    font-size: 20px;
    letter-spacing: -0.01em;
}

.page-title p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.page-actions {
    display: flex;
    gap: 10px;
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: var(--shadow);
}

.btn:hover {
    background: var(--surface-2);
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
}

.btn-primary:disabled:hover {
    background: var(--accent);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-danger-link {
    padding: 9px 10px;
    border: 0;
    background: none;
    color: var(--danger);
    font-size: 14px;
    font-weight: 500;
    box-shadow: none;
}

.btn-danger-link:hover {
    background: none;
    text-decoration: underline;
}

/* Filters */

.filters {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 16px;
}

.search {
    position: relative;
    flex: 0 1 420px;
    min-width: 240px;
}

.search svg {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    color: var(--muted-2);
}

.search input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
}

.search input:focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.stats {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

.stats .dot {
    color: var(--border-strong);
}

.select {
    margin-left: auto;
}

.select select {
    padding: 9px 34px 9px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background-color: var(--surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236f7683' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    appearance: none;
    font-size: 14px;
}

.select select:focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
    outline-offset: 1px;
    border-color: var(--accent);
}

/* Three panels */

.panels {
    display: grid;
    grid-template-columns: 276px 356px minmax(0, 1fr);
    height: auto;
    min-height: 0;
    overflow: visible;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid var(--border);
}

.panel:last-child {
    border-right: 0;
}

.panel:first-child > .panel-head {
    border-bottom: 1px solid var(--border);
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px 12px;
}

.panel-head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.panel-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.panel-count {
    color: var(--muted);
    font-size: 13px;
}

.panel-sub {
    margin: 0;
    padding: 0 20px 10px;
    color: var(--muted);
    font-size: 12px;
}

.panel-body {
    flex: 1;
    min-height: 0;
    padding: 0 12px 14px;
    overflow: visible;
}

.panel-note {
    margin: 0;
    padding: 12px 20px 16px;
    border-top: 1px solid var(--border);
    color: var(--muted-2);
    font-size: 11px;
    line-height: 1.5;
}

/* Lists */

.list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.sortable-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid transparent;
    border-radius: 8px;
}

.sortable-item:hover {
    background: var(--surface-2);
}

.sortable-item.is-selected {
    background: var(--accent-soft);
    border-color: #d9e3ff;
}

.grip {
    flex: none;
    width: 16px;
    color: #c3c9d4;
    font-size: 13px;
    text-align: center;
    cursor: grab;
    user-select: none;
    opacity: 0.4;
    transition: opacity 0.12s ease;
}

.sortable-item:hover .grip,
.sortable-item.is-selected .grip {
    opacity: 1;
}

.list-link {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
    padding: 10px 8px;
    border-radius: 8px;
    text-align: left;
}

.list-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.list-label {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
}

.is-selected .list-label {
    color: var(--accent);
    font-weight: 600;
}

.list-count {
    flex: none;
    color: var(--muted);
    font-size: 12px;
}

.question-row .list-link {
    align-items: flex-start;
    padding: 11px 6px 11px 8px;
}

.row-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.question-row .list-label {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.row-status {
    color: var(--muted);
    font-size: 11.5px;
}

.row-status.is-draft {
    color: var(--amber);
}

.chevron {
    flex: none;
    color: var(--muted-2);
    font-size: 18px;
    line-height: 1.3;
}

.is-selected .chevron {
    color: var(--accent);
}

/* Add blocks */

.add-block {
    margin-top: 10px;
}

.add-block > summary,
.add-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border: 1px dashed var(--border-strong);
    border-radius: 9px;
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    list-style: none;
}

.add-block > summary::-webkit-details-marker {
    display: none;
}

.add-block > summary:hover,
.add-link:hover {
    border-color: var(--muted-2);
    color: var(--text);
}

.add-block[open] > summary {
    margin-bottom: 8px;
}

.add-block form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.add-link {
    margin-top: 10px;
    text-decoration: none;
}

/* Category header rename */

.category-edit > summary {
    cursor: pointer;
    list-style: none;
}

.category-edit > summary::-webkit-details-marker {
    display: none;
}

.edit-link {
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
}

.category-edit[open] > summary .edit-link {
    color: var(--muted);
}

.category-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 20px 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
}

.category-form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Forms */

.field {
    display: block;
    font-size: 13px;
    font-weight: 500;
}

.field > span {
    display: block;
    margin-bottom: 6px;
    color: var(--text);
}

.field input,
.field textarea {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    background: var(--surface);
    font-size: 14px;
    line-height: 1.55;
    resize: vertical;
}

.field input:focus,
.field textarea:focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.form-error {
    margin: 0;
    color: var(--danger);
    font-size: 12.5px;
}

/* Editor */

.panel-editor .panel-head {
    min-height: 58px;
}

.editor {
    flex: 1;
    min-height: 0;
    padding: 0 24px 22px;
    overflow: visible;
}

.crumbs {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 12.5px;
}

.editor-form .field {
    margin-bottom: 16px;
}

.editor-form .field textarea {
    font-weight: 400;
}

.hint {
    margin: -8px 0 16px;
    color: var(--muted-2);
    font-size: 11.5px;
}

/* Answer attachment editor */

.attachment-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-bottom: 8px;
}

.attachment-label {
    color: var(--text);
}

.attachment-hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.35;
}

.attachment-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
}

.attachment-thumb {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--border);
    background: var(--surface);
}

.attachment-doc {
    display: grid;
    place-items: center;
    font-size: 16px;
    line-height: 1;
}

.attachment-name {
    min-width: 0;
    overflow: hidden;
    font-weight: 400;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-remove {
    flex: none;
    margin-left: auto;
    padding: 0;
    border: 0;
    background: none;
    color: var(--danger);
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
}

.attachment-remove:hover {
    text-decoration: underline;
}

.attachment-picker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    cursor: pointer;
}

.attachment-picker input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    overflow: hidden;
}

.attachment-picker-button {
    flex: none;
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.2;
}

.attachment-picker:hover .attachment-picker-button {
    border-color: var(--accent);
}

.attachment-picker:focus-within .attachment-picker-button {
    outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
    outline-offset: 1px;
}

.attachment-picker-name {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-preview {
    width: 30px;
    height: 30px;
}

/* Rich text editor */

.rich-toolbar,
.rich-body {
    display: none;
}

.rich-field.is-rich .rich-toolbar {
    display: flex;
}

.rich-field.is-rich .rich-body {
    display: flex;
    flex-direction: column;
}

.rich-field.is-rich .rich-source {
    display: none;
}

.rich-body {
    height: clamp(240px, 40vh, 440px);
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    background: var(--surface);
}

.panel-editor .rich-body {
    height: clamp(200px, 26vh, 320px);
}

.rich-body:focus-within {
    outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.rich-footer {
    display: flex;
    justify-content: flex-end;
    padding: 0 10px 5px;
    background: var(--surface);
}

.rich-counter {
    color: var(--muted-2);
    font-size: 11.5px;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
}

.rich-counter.is-over {
    color: var(--danger);
    font-weight: 600;
}

.rich-toolbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 3px;
    margin-bottom: 6px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-2);
}

.rich-icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.rich-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    height: 32px;
    padding: 0 6px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    touch-action: manipulation;
}

.rich-icon {
    width: 15px;
    height: 15px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.rich-btn:hover {
    background: var(--surface);
    color: var(--text);
}

.rich-btn-danger:hover {
    color: var(--danger);
}

.rich-btn.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.rich-sep {
    width: 1px;
    height: 20px;
    margin: 0 1px;
    background: var(--border);
}

.rich-editor {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.rich-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--muted-2);
    pointer-events: none;
}

.rich-editor .rich-spoiler {
    border-radius: 3px;
    background: var(--accent-soft);
    color: var(--accent);
}

.rich-editor a {
    color: var(--accent);
    text-decoration: underline;
}

.rich-editor code {
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--surface-2);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
}

.rich-editor pre {
    margin: 8px 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--surface-2);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.rich-editor pre code {
    padding: 0;
    background: none;
    font-size: inherit;
}

.rich-editor blockquote {
    margin: 8px 0;
    padding-left: 10px;
    border-left: 3px solid var(--border-strong);
    color: var(--muted);
}

.rich-editor ul,
.rich-editor ol {
    margin: 6px 0;
    padding-left: 22px;
}

.switch-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: center;
    gap: 8px;
    margin: 0;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    font-size: 12.5px;
}

.switch-side {
    color: var(--muted);
    white-space: nowrap;
    transition: color 0.15s ease;
}

.switch-draft.is-active {
    color: var(--amber);
    font-weight: 600;
}

.switch-published.is-active {
    color: var(--green);
    font-weight: 600;
}

.switch {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.switch input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
}

.switch-track {
    position: relative;
    width: 36px;
    height: 20px;
    border-radius: 999px;
    background: #d5d9e0;
    transition: background 0.15s ease;
}

.switch-track::after {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    content: "";
    transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
    background: var(--accent);
}

.switch input:checked + .switch-track::after {
    transform: translateX(16px);
}

.switch input:focus-visible + .switch-track {
    outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
    outline-offset: 2px;
}

.status {
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.status-published {
    background: var(--green-bg);
    color: var(--green);
}

.status-draft {
    background: var(--amber-bg);
    color: var(--amber);
}

.editor-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding: 12px 0 4px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.editor-delete {
    justify-self: start;
}

.editor-save {
    justify-self: end;
}

.editor-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.saved {
    margin: 0;
    color: var(--muted-2);
    font-size: 11.5px;
    white-space: nowrap;
}

.editor-empty {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 40px;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
}

.editor-empty p {
    margin: 0;
}

.empty {
    margin: 6px 4px 12px;
    color: var(--muted);
    font-size: 13px;
}

.footnote {
    margin: 18px 2px 0;
    color: var(--muted);
    font-size: 12px;
}

/* Drag feedback */

.sortable-item.is-dragging {
    opacity: 0.45;
}

.sortable-item.drop-before::before,
.sortable-item.drop-after::after {
    position: absolute;
    right: 4px;
    left: 4px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
    content: "";
}

.sortable-item.drop-before::before {
    top: -2px;
}

.sortable-item.drop-after::after {
    bottom: -2px;
}

/* Preview dialog */

.preview-dialog {
    width: min(560px, 92vw);
    padding: 0;
    border: 0;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(16, 24, 40, 0.24);
}

.preview-dialog::backdrop {
    background: rgba(16, 24, 40, 0.35);
}

.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--muted);
    font-size: 13px;
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.preview-body {
    padding: 20px;
}

.chat-bubble {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}

.chat-question {
    margin: 0 0 8px;
    font-weight: 600;
}

.chat-answer {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-answer .rich-spoiler {
    border-radius: 3px;
    background: var(--text);
    color: transparent;
}

.chat-answer a {
    color: var(--accent);
    text-decoration: underline;
}

.chat-answer code {
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--surface);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
}

.chat-answer pre {
    margin: 8px 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--surface);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-answer pre code {
    padding: 0;
    background: none;
    font-size: inherit;
}

.chat-answer blockquote {
    margin: 8px 0;
    padding-left: 10px;
    border-left: 3px solid var(--border-strong);
    color: var(--muted);
}

.chat-answer ul,
.chat-answer ol {
    margin: 6px 0;
    padding-left: 22px;
}

.preview-body .hint {
    margin: 14px 0 0;
}

/* Broadcast */

.broadcast-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: stretch;
}

.broadcast-card,
.broadcast-status {
    padding: 22px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.broadcast-status {
    min-height: 250px;
}

.broadcast-card {
    display: flex;
    flex-direction: column;
}

.broadcast-form {
    display: flex;
    flex: 1;
    flex-direction: column;
}

.broadcast-form .field {
    display: flex;
    flex: 1;
    flex-direction: column;
    margin: 0 0 14px;
}

.broadcast-form .field textarea {
    flex: 1;
    min-height: 220px;
    resize: vertical;
}

.broadcast-form .rich-field {
    display: flex;
    flex: 1;
    flex-direction: column;
}

.broadcast-form .rich-body {
    flex: 1;
    height: auto;
    min-height: 220px;
}

.broadcast-side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: 100%;
}

.broadcast-side .broadcast-notes {
    flex: 1;
    margin: 0;
    padding: 14px 16px 14px 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.broadcast-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.broadcast-actions .hint {
    margin: 0;
}

.broadcast-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Broadcast preview: the Telegram chat surface comes from preview.css, the
   same file the full /preview page uses. Only the dialog frame and the
   placement of the single message are specific to this page. */
.broadcast-preview-dialog {
    width: min(560px, calc(100vw - 32px));
    max-width: none;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
}

.broadcast-preview-dialog::backdrop {
    background: rgba(16, 35, 47, 0.46);
}

.broadcast-preview-dialog .preview-window {
    width: 100%;
    max-width: none;
    height: min(560px, calc(100vh - 80px));
    min-height: 380px;
}

.broadcast-preview-chat {
    display: flex;
    flex-direction: column;
}

.broadcast-preview-chat .preview-msg {
    margin-top: auto;
}

.broadcast-preview-dialog .preview-bubble {
    white-space: normal;
}

.broadcast-preview-dialog .preview-bubble::after {
    content: attr(data-time);
}

.broadcast-preview-dialog .preview-composer {
    pointer-events: none;
}

.broadcast-preview-dialog .preview-composer input {
    cursor: default;
}

.broadcast-notes {
    margin: 20px 0 0;
    padding: 14px 0 0 18px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.55;
}

.broadcast-notes li + li {
    margin-top: 6px;
}

.status-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.status-card-head h3 {
    margin: 0;
    font-size: 16px;
    letter-spacing: -0.01em;
}

.broadcast-state {
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.broadcast-state.is-running {
    background: var(--accent-soft);
    color: var(--accent);
}

.broadcast-state.is-done {
    background: var(--green-bg);
    color: var(--green);
}

.broadcast-state.is-error {
    background: #fde8e7;
    color: var(--danger);
}

.broadcast-state.is-idle {
    background: var(--surface-2);
    color: var(--muted);
}

.broadcast-progress {
    height: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
}

.broadcast-progress-bar {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 0.3s ease;
}

.broadcast-progress-bar.is-error {
    background: var(--danger);
}

.broadcast-facts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 16px 0 0;
}

.broadcast-facts div {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-2);
}

.broadcast-facts dt {
    color: var(--muted);
    font-size: 11px;
}

.broadcast-facts dd {
    margin: 2px 0 0;
    font-size: 20px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.broadcast-pulse {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.broadcast-times {
    margin: 14px 0 0;
    color: var(--muted-2);
    font-size: 11.5px;
}

.broadcast-status .empty {
    margin: 8px 0 0;
}

@media (max-width: 980px) {
    .broadcast-layout {
        grid-template-columns: 1fr;
    }
}

/* Login */

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 28px 18px;
    background:
        radial-gradient(900px 420px at 50% -10%, #e8eeff 0%, transparent 65%),
        var(--bg);
}

.login-shell {
    width: min(420px, 100%);
}

.login-card {
    padding: 34px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 18px 48px rgba(16, 24, 40, 0.08);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
    font-weight: 600;
}

.login-card h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: -0.02em;
}

.login-sub {
    margin: 5px 0 24px;
    color: var(--muted);
    font-size: 13.5px;
}

.notice {
    margin-bottom: 18px;
    padding: 11px 13px;
    border: 1px solid #f0dca4;
    border-radius: 9px;
    background: var(--amber-bg);
    color: var(--amber);
    font-size: 12.5px;
    line-height: 1.55;
}

.notice code,
.login-error code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
}

.login-error {
    margin: 0 0 18px;
    padding: 11px 13px;
    border: 1px solid #f3c6c2;
    border-radius: 9px;
    background: #fef3f2;
    color: var(--danger);
    font-size: 12.5px;
}

.login-form .field {
    margin-bottom: 16px;
}

.login-submit {
    width: 100%;
    margin-top: 6px;
    padding: 10px 16px;
}

/* Responsive */

@media (max-width: 1180px) {
    .panels {
        grid-template-columns: 240px minmax(0, 1fr);
        height: auto;
    }

    .panel-editor {
        grid-column: 1 / -1;
        min-height: 520px;
        border-top: 1px solid var(--border);
        border-right: 0;
    }
}

@media (max-width: 820px) {
    .appbar {
        flex-wrap: wrap;
        height: auto;
        min-height: 64px;
        gap: 8px 12px;
        padding: 10px 16px;
    }

    .tabs {
        order: 3;
        width: 100%;
        margin: 0;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab {
        flex: none;
    }

    .appbar-user {
        margin-left: auto;
    }

    .appbar-user-name {
        display: none;
    }

    .page {
        padding: 16px;
    }

    .page-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .filters {
        flex-wrap: wrap;
    }

    .search {
        flex-basis: 100%;
    }

    .select {
        margin-left: 0;
    }

    .panels {
        display: block;
        border-radius: 12px;
    }

    .panel {
        min-height: 0;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .panel:last-child {
        border-bottom: 0;
    }

    .panel-body {
        max-height: none;
    }

    .panel-note {
        display: none;
    }

    .editor {
        overflow: visible;
    }

    .editor-actions {
        grid-template-columns: 1fr;
        justify-items: stretch;
    }

    .editor-delete,
    .editor-save {
        justify-self: stretch;
    }

    .switch-row {
        justify-self: stretch;
    }

    .rich-btn {
        min-width: 34px;
        height: 34px;
    }

    .broadcast-card,
    .broadcast-status {
        padding: 18px;
    }

    .broadcast-actions {
        flex-wrap: wrap;
    }

    .broadcast-facts {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

/* Admin accounts and invites */

.admin-page .page-head {
    margin-bottom: 16px;
}

.admin-card {
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.admin-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.admin-card h2 {
    margin: 0;
    font-size: 16px;
    letter-spacing: -0.01em;
}

.admin-count {
    min-width: 24px;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    text-align: center;
}

.admin-account {
    padding: 14px 0;
    border-top: 1px solid var(--border);
}

.admin-account:first-of-type {
    padding-top: 0;
    border-top: 0;
}

.admin-account-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.admin-account-name {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
    min-width: 0;
    font-size: 14px;
}

.admin-account-name strong {
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-badge {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
}

.admin-badge-muted {
    background: var(--surface-2);
    color: var(--muted);
}

.admin-perms-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.admin-perms {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.admin-perms-static {
    margin-top: 10px;
}

.perm-toggle {
    position: relative;
    display: inline-flex;
}

.perm-toggle input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.perm-toggle span,
.perm-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
}

.perm-toggle span {
    cursor: pointer;
    user-select: none;
}

.perm-toggle span::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted-2);
}

.perm-toggle input:checked + span,
.perm-pill.is-on {
    border-color: color-mix(in srgb, var(--accent) 28%, var(--border));
    background: var(--accent-soft);
    color: var(--accent);
}

.perm-toggle input:checked + span::before {
    background: var(--accent);
}

.perm-toggle input:focus-visible + span {
    outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
    outline-offset: 1px;
}

.admin-save {
    padding: 5px 10px;
    box-shadow: none;
    font-size: 12px;
}

.admin-delete-form {
    flex: none;
}

.admin-delete-link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--danger);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.admin-delete-link:hover {
    text-decoration: underline;
}

.admin-invite-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.admin-perms-block {
    width: 100%;
}

.admin-invite-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 16px;
}

.admin-form-label {
    display: block;
    margin-bottom: 6px;
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
}

.admin-perms-label {
    align-self: center;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.admin-invite-intro {
    margin: -2px 0 0;
}

.admin-field {
    flex: 0 0 170px;
    margin: 0;
}

.admin-field > span {
    margin-bottom: 6px;
    font-size: 12px;
}

.admin-field select {
    width: 100%;
}

.admin-invite-form .btn {
    flex: none;
}

.admin-note {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.admin-backup-form {
    margin-top: 12px;
}

.admin-invite-actions .admin-note {
    flex: 1 1 280px;
    align-self: center;
}

.admin-accounts {
    margin-top: 18px;
}

.admin-bottom {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
    gap: 18px;
    margin-top: 18px;
}

.admin-invite-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.admin-invite-list li {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.admin-invite-list li:first-child {
    padding-top: 0;
    border-top: 0;
}

.admin-invite-main {
    min-width: 0;
}

.admin-invite-perms {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 5px;
}

.admin-invite-perms .perm-pill {
    padding: 3px 8px;
    font-size: 11px;
}

.admin-invite-meta {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.admin-empty {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.admin-invite-link {
    margin-bottom: 18px;
}

.admin-invite-link-head h2 {
    margin: 0;
    font-size: 16px;
    letter-spacing: -0.01em;
}

.admin-invite-link-head p {
    margin: 4px 0 12px;
    color: var(--muted);
    font-size: 12.5px;
}

.admin-invite-url {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
}

@media (max-width: 960px) {
    .admin-bottom {
        grid-template-columns: 1fr;
    }

    .admin-invite-actions .admin-field {
        flex-basis: 100%;
    }

    .admin-invite-actions .btn {
        width: 100%;
    }

    .admin-invite-actions .admin-note {
        flex-basis: 100%;
    }
}
