/* ==========================================================================
   Page-level patterns: toolbar cards, search, tabs, data tables, drawer, empty states
   ========================================================================== */
.toolbar-card { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-3); margin-bottom: var(--space-4);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1); }

/* search */
.search { position: relative; flex: 1 1 320px; display: flex; align-items: center; }
.search input { width: 100%; padding-left: 40px; padding-right: 80px; }
.search__icon { position: absolute; left: 12px; display: grid; color: var(--text-muted); pointer-events: none; }
.search__icon svg { width: 18px; height: 18px; }
.search__hint { position: absolute; right: 8px; padding: 3px 10px; font-size: .72rem; font-weight: 650; color: var(--text-muted); background: var(--surface-2); border-radius: var(--radius-pill); cursor: help; outline: none; }
.search__pop { position: absolute; right: 0; top: calc(100% + 10px); z-index: 50; width: min(340px, 86vw); padding: var(--space-3) var(--space-4); text-align: left; font-weight: 400; font-size: .8rem; line-height: 1.8; color: var(--text-2);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-3); opacity: 0; visibility: hidden; transform: translateY(-4px); transition: all var(--t) var(--ease); }
.search__hint:hover .search__pop, .search__hint:focus .search__pop { opacity: 1; visibility: visible; transform: none; }
.search__pop b { display: block; margin-bottom: 4px; color: var(--text); }

/* tabs */
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: var(--radius-sm); overflow-x: auto; max-width: 100%; }
.tab { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; font: 600 .82rem var(--font-sans); white-space: nowrap; color: var(--text-muted); background: transparent; border: 0; border-radius: 7px; cursor: pointer; transition: all var(--t-fast); }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); background: var(--surface); box-shadow: var(--shadow-1); }
.tab__count { min-width: 22px; padding: 1px 7px; font-size: .7rem; text-align: center; color: var(--text-muted); background: var(--surface-3); border-radius: var(--radius-pill); }
.tab.is-active .tab__count { color: var(--primary); background: var(--primary-soft); }

/* data table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { padding: 11px 16px; text-align: left; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 12px 16px; vertical-align: middle; border-bottom: 1px solid var(--border); }
.data-table tbody tr { cursor: pointer; transition: background var(--t-fast); }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--primary-soft) 60%, transparent); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tr.is-muted td:not(.row-actions) { opacity: .55; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { width: 1%; text-align: right; }
.cell-account { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.cell-account b { display: block; font-weight: 650; }
.cell-account small { display: block; color: var(--text-muted); font-size: .78rem; }
.avatar--lg { width: 38px; height: 38px; font-size: .85rem; flex: none; color: #fff; }
.avatar--logo { width: 38px; height: 38px; flex: none; display: grid; place-items: center; background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.avatar--logo img { max-width: 80%; max-height: 80%; object-fit: contain; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: var(--space-3) 4px; }

/* empty + loading */
.empty { padding: 56px 20px; text-align: center; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty__icon { width: 52px; height: 52px; margin: 0 auto var(--space-3); display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 50%; }
.empty__icon svg { width: 24px; height: 24px; }
.skeleton { height: 260px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* side drawer */
.drawer-wrap { position: fixed; inset: 0; z-index: 99000; visibility: hidden; }
.drawer-wrap.is-open { visibility: visible; }
.drawer-scrim { position: absolute; inset: 0; background: var(--backdrop); opacity: 0; transition: opacity var(--t); }
.drawer-wrap.is-open .drawer-scrim { opacity: 1; }
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-3);
    transform: translateX(102%); transition: transform 260ms var(--ease); }
.drawer-wrap.is-open .drawer { transform: none; }
.drawer-form { display: flex; flex-direction: column; height: 100%; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-5) var(--space-3); border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0 0 6px; font-size: 1.15rem; }
.drawer-head .icon-btn { font-size: 1.6rem; line-height: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--space-5); }
.drawer-foot { display: flex; justify-content: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); background: var(--surface); }

/* account / profile */
.profile-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: var(--space-5); align-items: start; }
@media (max-width: 860px) { .profile-grid { grid-template-columns: 1fr; } }
.logo-box { display: grid; place-items: center; min-height: 140px; padding: var(--space-4); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.logo-box img { max-width: 100%; max-height: 120px; object-fit: contain; }
.img-missing { display: inline-block; padding: 8px 12px; font-size: .8rem; color: var(--text-muted); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }

.cell-sub { display: block; margin-top: 2px; font-size: .76rem; font-weight: 400; color: var(--text-muted); }
.cell-wrap { max-width: 360px; }
.kv { display: flex; gap: var(--space-4); padding: 9px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.kv span { flex: 0 0 38%; color: var(--text-muted); }
.kv b { flex: 1; font-weight: 600; word-break: break-word; }
.drawer-foot { flex-wrap: wrap; }
/* classification popup (legacy wizard content) */
.flow-overlay { position: fixed !important; inset: 0 !important; z-index: 99600; width: auto !important; padding: var(--space-5); overflow: auto; background: var(--backdrop) !important; backdrop-filter: blur(5px); color: var(--text) !important; }
.flow-overlay > * { max-width: 980px; margin-left: auto; margin-right: auto; }

tr.is-unread td:first-child { box-shadow: inset 4px 0 0 var(--primary); }
.fb-msg { padding: 16px; margin-bottom: 18px; line-height: 1.6; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); white-space: pre-wrap; word-break: break-word; }
.lk-analysis { padding: 14px 16px; background: var(--surface-2); border-radius: var(--radius); line-height: 1.6; } .lk-analysis img { max-width: 100%; height: auto; }

.ins-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-4); } .ins-grid .card.wide { grid-column: 1 / -1; } .ins-grid h3 { margin-bottom: 12px; font-size: .95rem; }
@media print { .app-topbar, .app-toolbar, .page-head button, .page-head select, .drawer-backdrop, #ui-toasts { display: none !important; } body { background: #fff; } .card { break-inside: avoid; box-shadow: none; } .is-workspace { padding-top: 0; } }

/* glossary highlighting + popup (bottom sheet on phones) */
.gl-term { border-bottom: 1.5px dotted var(--primary); cursor: help; transition: background var(--t-fast); } .gl-term:hover, .gl-term:focus { background: var(--primary-soft); outline: none; border-radius: 3px; }
.gl-pop { position: fixed; z-index: 99990; width: min(380px, calc(100vw - 16px)); max-height: 60vh; overflow-y: auto; padding: 16px 18px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-3); animation: gl-in .16s ease; }
.gl-pop h4 { margin: 0 24px 8px 0; } .gl-pop__x { position: absolute; top: 6px; right: 6px; font-size: 1.4rem; line-height: 1; } .gl-pop__body { font-size: .88rem; line-height: 1.55; } .gl-pop__body img { max-width: 100%; height: auto; border-radius: 8px; }
.gl-pop__files { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); font-size: .82rem; }
@keyframes gl-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) { .gl-pop { left: 8px !important; right: 8px; bottom: 8px; top: auto !important; width: auto; max-height: 55vh; } }
.jodit-container { border-radius: var(--radius-sm) !important; }

/* classification wizard */
body.wz-open { overflow: hidden; }
.wz { position: fixed; inset: 0; z-index: 1500; background: var(--bg); overflow: auto; }
.wz-shell { display: flex; flex-direction: column; min-height: 100%; position: relative; }
.wz-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.wz-body { flex: 1; padding: 20px; max-width: 1100px; width: 100%; margin: 0 auto; }
.wz-pick h4 { margin: 24px 0 10px; }
.wz-part, .wz-q, .wz-final, .wz-side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.wz-mods { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.wz-mod { text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; color: inherit; }
.wz-mod:hover { border-color: var(--primary); }
.wz-flow { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.wz-tl { list-style: none; margin: 12px 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.wz-tl li { display: flex; flex-direction: column; border-left: 3px solid var(--primary); padding-left: 10px; }
.wz-ctl { display: flex; gap: 8px; margin-top: 12px; }
.wz-answers { display: grid; gap: 10px; margin-top: 16px; }
.wz-ans { text-align: left; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: inherit; cursor: pointer; font-size: 1rem; }
.wz-ans:hover, .wz-ans:focus-visible { border-color: var(--primary); background: var(--primary-soft, var(--surface)); }
.wz-codebig { font: 700 2rem/1.2 monospace; letter-spacing: .05em; margin: 16px 0; }
.wz-chat { position: fixed; right: 0; top: 56px; bottom: 0; width: min(340px, 100%); background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 3; }
.wz-msgs { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.wz-msg { background: var(--bg); border-radius: var(--radius); padding: 8px 10px; max-width: 90%; }
.wz-msg.is-mine { align-self: flex-end; background: var(--primary-soft, var(--bg)); }
.wz-send { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.wz-send input { flex: 1; }
@media (max-width: 760px) { .wz-flow { grid-template-columns: 1fr; } .wz-body { padding: 12px; } }

/* ---------- toggle switch (shared) ---------- */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: 0 0 44px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch > span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong); transition: background var(--t) var(--ease), border-color var(--t); }
.switch > span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: transform var(--t) var(--ease); }
.switch input:checked + span { background: var(--primary); border-color: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch input:disabled { cursor: not-allowed; } .switch input:disabled + span { opacity: .45; }

/* ---------- permissions ---------- */
.perm { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.perm-left { position: sticky; top: calc(var(--topbar-h) + 16px); display: flex; flex-direction: column; gap: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); box-shadow: var(--shadow-1); }
.perm-tabs { align-self: stretch; } .perm-tabs .tab { flex: 1; justify-content: center; }
.perm-list { display: flex; flex-direction: column; gap: 4px; max-height: calc(100vh - 290px); min-height: 160px; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.perm-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left; padding: 10px 12px; border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--text); font: inherit; cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast); }
.perm-row:hover { background: var(--surface-2); }
.perm-row.is-active { background: var(--primary-soft); border-color: var(--primary); }
.perm-row__name { display: flex; flex-direction: column; min-width: 0; font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; }
.perm-row__name small { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-weight: 500; font-size: .76rem; color: var(--text-muted); }
.perm-row__name small i { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
.perm-row .badge { flex: 0 0 auto; white-space: nowrap; }
.perm-right { min-width: 0; }
.perm-card { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-5); }
.perm-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); padding-bottom: var(--space-4); border-bottom: 1px solid var(--border); }
.perm-head h3 { margin: 0 0 4px; font-size: 1.25rem; overflow-wrap: anywhere; }
.perm-mode { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.perm-opt { position: relative; display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 16px 16px 16px 48px; border-radius: var(--radius); border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; transition: border-color var(--t), background var(--t), box-shadow var(--t); }
.perm-opt::before { content: ""; position: absolute; left: 16px; top: 18px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface); transition: .2s; }
.perm-opt:hover { border-color: var(--primary); }
.perm-opt.is-on { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.perm-opt.is-on::before { border-color: var(--primary); background: radial-gradient(circle, var(--primary) 0 45%, var(--surface) 50%); }
.perm-opt b { font-size: .98rem; } .perm-opt small { color: var(--text-muted); font-size: .82rem; line-height: 1.4; }
.perm-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.perm-tools .search { flex: 1 1 220px; } .perm-tools .btn { flex: 0 0 auto; }
.perm-tools > .muted { flex: 1 1 100%; }
.perm-cos { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; max-height: 520px; overflow-y: auto; }
.perm-co { display: flex; align-items: center; gap: var(--space-3); padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--t-fast); }
.perm-co:last-child { border-bottom: 0; } .perm-co:hover { background: var(--surface-2); }
.perm-co::before { content: attr(data-i); flex: 0 0 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font: 700 .8rem var(--font-sans); color: var(--primary); background: var(--primary-soft); }
.perm-co__name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.perm-co__name b { font-size: .95rem; overflow-wrap: anywhere; } .perm-co__name small { color: var(--text-muted); font-size: .8rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.perm-co.is-disabled { cursor: default; } .perm-co.is-disabled .perm-co__name b { color: var(--text-2); }
.perm-co .btn { flex: 0 0 auto; }
.perm-foot { padding-top: var(--space-3); border-top: 1px solid var(--border); }
@media (max-width: 900px) {
  .perm { grid-template-columns: minmax(0, 1fr); }
  .perm-left { position: static; } .perm-list { max-height: 280px; }
  .perm-mode { grid-template-columns: minmax(0, 1fr); }
}
.perm-left .search, .perm-tools .search { flex: 0 0 auto; width: 100%; } .perm-tools .search { flex: 1 1 220px; width: auto; }
