/* Shared components: forms, dialogs, menus, lists, badges. Uses tokens only. */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack { display: grid; gap: 16px; }
.stack-sm { display: grid; gap: 8px; }
.cluster { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.hidden { display: none !important; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head .h1 { margin: 0; }

.btn-danger { background: var(--c-danger); color: #fff; border-color: transparent; }
.btn-danger:hover { background: var(--c-danger); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled], .icon-btn[disabled], .fmt-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn svg { flex: none; }

.field { display: grid; gap: 4px; align-content: start; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; }
.field-hint { font-size: 12px; }
.field-error { color: var(--c-danger); font-size: 12px; min-height: 0; }
.field-error:empty { display: none; }
.input { width: 100%; box-sizing: border-box; min-height: 40px; padding: 8px 10px; border: 1px solid var(--c-line); border-radius: var(--r-md); background: var(--c-surface); color: var(--c-ink); font: inherit; }
textarea.input { resize: vertical; }
.input:focus-visible { outline: none; box-shadow: var(--focus); border-color: var(--c-accent); }
.input[aria-invalid='true'] { border-color: var(--c-danger); }
.check-row { display: flex; gap: 8px; align-items: center; min-height: 32px; cursor: pointer; }
.check { width: 18px; height: 18px; accent-color: var(--c-accent); }
.seg { display: inline-flex; border: 1px solid var(--c-line); border-radius: var(--r-md); overflow: hidden; }
.seg-btn { min-height: 34px; padding: 0 12px; border: 0; background: var(--c-surface); color: var(--c-muted); font: inherit; font-size: 13px; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--c-line); }
.seg-btn[aria-pressed='true'] { background: var(--c-accent); color: var(--c-accent-ink); }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--c-surface-2); color: var(--c-muted); white-space: nowrap; }
.badge-ok { color: var(--c-ok); } .badge-warn { color: var(--c-warn); } .badge-danger { color: var(--c-danger); }
.empty { text-align: center; padding: 40px 16px; color: var(--c-muted); }
.empty h2 { color: var(--c-ink); margin: 8px 0 4px; font-size: 17px; }

/* dialogs */
.dlg { border: 1px solid var(--c-line); border-radius: var(--r-lg); background: var(--c-surface); color: var(--c-ink); padding: 0; width: min(94vw, 560px); max-height: 90dvh; box-shadow: var(--shadow-2); }
.dlg-sm { width: min(94vw, 420px); } .dlg-lg { width: min(96vw, 860px); }
.dlg::backdrop { background: rgb(10 14 20 / 0.5); }
.dlg[open] { display: flex; flex-direction: column; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 8px 8px 20px; border-bottom: 1px solid var(--c-line); }
.dlg-title { margin: 0; font-size: 17px; }
.dlg-body { padding: 16px 20px; overflow: auto; display: grid; gap: 12px; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--c-line); }

.menu { position: fixed; z-index: 120; min-width: 200px; max-width: 92vw; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: 4px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 0 10px; border: 0; background: none; color: var(--c-ink); font: inherit; text-align: left; border-radius: var(--r-sm); cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--c-surface-2); }
.menu-item.danger { color: var(--c-danger); } .menu-item[disabled] { opacity: .45; }
.menu-gap { width: 18px; } .menu-sep { border: 0; border-top: 1px solid var(--c-line); margin: 4px 0; }

/* lists & cards */
.card-list { display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; padding: 12px; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-md); }
.item:hover { border-color: color-mix(in srgb, var(--c-accent) 40%, var(--c-line)); }
.item-main { min-width: 0; }
.item-title { margin: 0 0 4px; font-weight: 600; overflow-wrap: anywhere; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--c-muted); }
.item-actions { display: flex; gap: 2px; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { padding: 16px; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-lg); }
.stat b { display: block; font-size: 28px; line-height: 1.1; letter-spacing: -0.02em; }
.stat span { color: var(--c-muted); font-size: 13px; }
.toolbar-row { display: grid; gap: 8px; margin-bottom: 12px; }
.filters { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 16px; }
.bulkbar { position: sticky; top: 56px; z-index: 10; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; margin-bottom: 8px; background: var(--c-accent); color: var(--c-accent-ink); border-radius: var(--r-md); }
.bulkbar .btn { min-height: 32px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--c-line); border-radius: var(--r-md); }
.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--c-line); text-align: left; vertical-align: top; }
.tbl th { background: var(--c-surface-2); font-weight: 600; white-space: nowrap; }
.tbl tr.bad td { background: color-mix(in srgb, var(--c-danger) 10%, transparent); }
.notice { padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--c-line); background: var(--c-surface-2); font-size: 13px; }
.notice-warn { border-color: var(--c-warn); } .notice-danger { border-color: var(--c-danger); } .notice-ok { border-color: var(--c-ok); }
.progress { height: 8px; background: var(--c-surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--c-accent); transition: width var(--t-base); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--c-surface-2); font-size: 12px; }

/* rich text + formatting toolbar */
.rich { min-height: 72px; padding: 8px 10px; border: 1px solid var(--c-line); border-radius: var(--r-md); background: var(--c-surface); line-height: 1.6; overflow-wrap: anywhere; font-family: var(--f-serif); font-size: 16px; }
.rich:focus { outline: none; box-shadow: var(--focus); border-color: var(--c-accent); }
.rich:empty::before, .rich:has(> br:only-child)::before { content: attr(data-placeholder); color: var(--c-muted); pointer-events: none; }
.rich-single { min-height: 40px; }
.rich img { max-width: 100%; height: auto; vertical-align: middle; }
.rich img.img-missing { min-width: 80px; min-height: 40px; background: var(--c-surface-2); outline: 1px dashed var(--c-warn); }
.rich table, .pb-p table, .pb-stem table { border-collapse: collapse; } .rich td, .rich th { border: 1px solid var(--c-line); padding: 4px 8px; min-width: 40px; }
.fmt { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; padding: 4px; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-md); }
.fmt-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 0; background: none; color: var(--c-ink); border-radius: var(--r-sm); cursor: pointer; }
.fmt-btn:hover { background: var(--c-surface-2); } .fmt-btn[aria-pressed='true'] { background: color-mix(in srgb, var(--c-accent) 20%, transparent); color: var(--c-accent); }
.fmt-sep { width: 1px; height: 22px; background: var(--c-line); margin: 0 4px; }
.sticky-fmt { position: sticky; top: 56px; z-index: 12; }
.option-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; align-items: start; }
.option-key { display: inline-flex; width: 28px; height: 40px; align-items: center; justify-content: center; font-weight: 600; color: var(--c-muted); }
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(100%, 440px); }
.auth-card .brand-lg { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 700; font-size: 20px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--c-accent); font: inherit; text-decoration: underline; cursor: pointer; }
.shell.bare .sidebar, .shell.bare .topbar, .shell.bare .bottom-bar, .shell.bare .backdrop { display: none !important; }
.shell.bare .main { padding: 0; }
.shell.bare #outlet { max-width: none; }
@media (max-width: 640px) { .item { grid-template-columns: auto 1fr; } .item-actions { grid-column: 1 / -1; justify-content: flex-end; } }
