:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --text: #1f2933;
    --muted: #667085;
    --line: #d9e0e8;
    --accent: #0f766e;
    --accent-strong: #115e59;
    --danger: #b42318;
    --warn: #9a6700;
    --success: #027a48;
    --info: #0369a1;
    --success-bg: #ecfdf3;
    --danger-bg: #fff1f2;
    --warn-bg: #fffbeb;
    --info-bg: #eff6ff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font: 14px/1.5 "Sarabun", "Segoe UI", Tahoma, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: #17212b;
    color: #fff;
    padding: 18px 14px;
    overflow-y: auto;
}

.brand {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: var(--accent);
    font-weight: 700;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    line-height: 1.2;
}

.brand small {
    color: #b8c2cc;
    font-size: 12px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.nav-group + .nav-group {
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.nav-heading {
    padding: 6px 8px;
    color: #7893ad;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0;
}

.nav-group-toggle {
    display: flex;
    width: 100%;
    min-height: 0;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 140ms ease, color 140ms ease;
}

.nav-group-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #b8c8d8;
}

.nav-group-toggle:focus-visible {
    outline: 2px solid rgba(45, 212, 191, 0.75);
    outline-offset: 1px;
}

.nav-group-chevron {
    flex: 0 0 14px;
    transition: transform 160ms ease;
}

.nav-group.is-open .nav-group-chevron {
    transform: rotate(90deg);
}

.nav-group-items {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.nav-group-items[hidden] {
    display: none;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 9px;
    color: #b8c8d8;
    text-decoration: none;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13.5px;
    transition: background 140ms ease, color 140ms ease;
}

.sidebar-nav a svg {
    flex: 0 0 16px;
    opacity: 0.5;
    transition: opacity 140ms ease;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #e8f0f8;
}

.sidebar-nav a:hover svg {
    opacity: 0.85;
}

.sidebar-nav a.active {
    background: rgba(15, 118, 110, 0.22);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--accent);
    font-weight: 500;
}

.sidebar-nav a.active svg {
    opacity: 1;
}

/* ─── Sidebar toggle button ─── */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #5e7a94;
    cursor: pointer;
    transition: background 140ms ease, color 140ms ease;
    min-height: 0;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #c8d8e8;
}

.sidebar-toggle-icon {
    transition: transform 220ms ease;
}

/* ─── Collapsed state ─── */
.shell {
    transition: grid-template-columns 220ms ease;
}

.shell.sidebar-collapsed {
    grid-template-columns: 56px 1fr;
}

.shell.sidebar-collapsed .sidebar {
    padding: 14px 8px;
}

.shell.sidebar-collapsed .brand {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
}

.shell.sidebar-collapsed .brand-copy {
    display: none;
}

.shell.sidebar-collapsed .sidebar-toggle {
    margin: 0;
}

.shell.sidebar-collapsed .sidebar-toggle-icon {
    transform: rotate(180deg);
}

.shell.sidebar-collapsed .nav-heading {
    display: none;
}

.shell.sidebar-collapsed .nav-group-items,
.shell.sidebar-collapsed .nav-group-items[hidden] {
    display: flex;
}

.shell.sidebar-collapsed .nav-group + .nav-group {
    margin-top: 4px;
    padding-top: 8px;
}

.shell.sidebar-collapsed .sidebar-nav a {
    justify-content: center;
    padding: 9px 0;
}

.shell.sidebar-collapsed .sidebar-nav a span {
    display: none;
}

.shell.sidebar-collapsed .sidebar-nav a svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    opacity: 0.65;
}

.shell.sidebar-collapsed .sidebar-nav a:hover svg,
.shell.sidebar-collapsed .sidebar-nav a.active svg {
    opacity: 1;
}

/* Tooltip on collapsed items */
.shell.sidebar-collapsed .sidebar-nav a {
    position: relative;
}

.shell.sidebar-collapsed .sidebar-nav a::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    padding: 5px 10px;
    background: #1a2b3c;
    color: #e8f0f8;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 200;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    transition: opacity 120ms ease;
}

.shell.sidebar-collapsed .sidebar-nav a:hover::after {
    opacity: 1;
}

/* ─────────────────────────── */

.content {
    display: flex;
    flex-direction: column;
    padding: 22px;
    min-width: 0;
}

.app-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 28px;
    color: var(--muted);
    font-size: 12px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.top-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.top-actions form {
    margin: 0;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    margin-bottom: 3px;
}

h2 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.1px;
    margin-bottom: 14px;
}

.topbar p,
.muted,
.empty {
    color: var(--muted);
}

.status,
.notice {
    border-radius: 6px;
    padding: 8px 10px;
}

.status {
    white-space: nowrap;
    border: 1px solid var(--line);
    background: #fff;
}

.status.ok {
    color: var(--success);
}

.status.warn {
    color: var(--warn);
}

.user-pill {
    white-space: nowrap;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--muted);
    padding: 8px 10px;
}

.button-logout.secondary {
    width: auto;
    min-height: 32px;
    margin-top: 0;
    background: #b80f0f;
    color: #eff6f5;
    border: 0px;
}

.bell-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    margin: auto 0;
}

.bell-icon[hidden] {
    display: none;
}

.bell-icon:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.bell-icon .badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

/* Spinner — ใช้ทั่วทั้งแอปกับ class="spinner" */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: progress-spin 0.7s linear infinite;
    flex-shrink: 0;
    margin-right: 6px;
    vertical-align: middle;
}

/* Bell dropdown panel */
.bell-wrap {
    position: relative;
}
.bg-jobs-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 300px;
    max-width: 420px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.13);
    z-index: 500;
    overflow: hidden;
}
.bg-jobs-panel-head {
    padding: 10px 14px 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--line);
}
.bg-jobs-panel-list {
    padding: 6px 0;
    max-height: 320px;
    overflow-y: auto;
}
.bg-jobs-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 14px;
}
.bg-jobs-item + .bg-jobs-item {
    border-top: 1px solid var(--line);
}
.bg-jobs-item-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 13px;
}
.bg-jobs-item-msg {
    font-size: 12px;
    color: var(--muted);
    padding-left: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bg-jobs-empty {
    padding: 14px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

.notif-panel {
    min-width: 320px;
    max-width: 380px;
}
.notif-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.notif-panel-head-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.notif-mark-all {
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
    text-decoration: none;
    cursor: pointer;
}
.notif-mark-all:hover {
    text-decoration: underline;
}

.notif-hub-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.notif-hub-head h2 {
    margin: 0;
}
.notif-hub-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.notif-hub-search-form {
    margin: 0;
}
.notif-hub-search-form input {
    width: 220px;
    min-height: 34px;
}
.notif-hub-head-actions button,
.notif-hub-head-actions .secondary-button {
    width: auto;
    min-height: 34px;
    margin: 0;
}

.notif-hub-filters {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin: 14px 0;
}
.notif-hub-pill {
    display: inline-block;
    height: 28px;
    line-height: 28px;
    font-size: 12px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
}
.notif-hub-pill:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.notif-hub-pill.active {
    background: var(--accent-strong);
    color: #fff;
    border-color: var(--accent-strong);
}
.notif-hub-range-form {
    margin: 0 0 0 auto;
}
.notif-hub-range-form select {
    height: 28px;
    min-height: 28px;
    font-size: 12px;
    border-radius: 14px;
    padding: 0 8px;
}

.notif-hub-list {
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}
.notif-hub-list .empty {
    margin: 0;
    padding: 20px;
}
.notif-hub-date-head {
    padding: 8px 16px;
    background: #fafaf9;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    border-top: 1px solid var(--line);
}
.notif-hub-list .notif-hub-date-head:first-child {
    border-top: none;
}

.notif-hub-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    align-items: flex-start;
}
.notif-hub-item.unread {
    background: rgba(15, 118, 110, 0.04);
}

.notif-hub-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 6px;
    flex-shrink: 0;
}
.notif-hub-dot.orange { background: var(--warn); }
.notif-hub-dot.green { background: var(--accent); }
.notif-hub-dot.none { background: transparent; }

.notif-hub-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}
.notif-hub-icon-warn { background: var(--warn-bg); }
.notif-hub-icon-fb { background: var(--info-bg); }
.notif-hub-icon-sys { background: #f3f4f6; }

.notif-hub-body {
    flex: 1;
    min-width: 0;
}
.notif-hub-title-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.notif-hub-title {
    font-weight: 700;
}
.notif-hub-title .from {
    font-weight: 400;
    color: var(--muted);
}
.notif-hub-time {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}
.notif-hub-preview {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}
.notif-hub-links {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}
.notif-hub-links a {
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}
.notif-hub-links a:hover {
    text-decoration: underline;
}

.notif-hub-group-items {
    display: none;
}
.notif-hub-group-items.open {
    display: block;
}
.notif-hub-group-item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 16px 8px 60px;
    border-top: 1px dashed var(--line);
    font-size: 12px;
    color: var(--muted);
    background: #fbfdfc;
}
.notif-hub-group-item a {
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
    font-weight: 600;
}
.notif-hub-group-item a:hover {
    text-decoration: underline;
}

.notif-hub-load-more {
    padding: 12px;
    text-align: center;
}
.notif-hub-load-more .secondary-button {
    width: auto;
    margin: 0;
}

@media (max-width: 720px) {
    .notif-hub-search-form input {
        width: 160px;
    }
    .notif-hub-range-form {
        margin-left: 0;
    }
}
.notif-panel-list {
    max-height: 380px;
}
.notif-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 14px;
    cursor: pointer;
}
.notif-item:hover {
    background: var(--info-bg);
}
.notif-item + .notif-item {
    border-top: 1px solid var(--line);
}
.notif-item-unread {
    position: relative;
    background: rgba(15, 118, 110, 0.05);
}
.notif-item-unread::before {
    content: '';
    position: absolute;
    top: 14px;
    left: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}
.notif-item-unread {
    padding-left: 20px;
}
.notif-item-title {
    font-weight: 600;
    font-size: 13px;
}
.notif-item-body {
    font-size: 12px;
    color: var(--muted);
    white-space: normal;
    overflow-wrap: break-word;
}
.notif-item-time {
    font-size: 11px;
    color: var(--muted);
}

/* Import step 1 — processing state */
.import-processing-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 20px 0 8px;
}
.import-processing-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
}
.import-processing-header .spinner {
    width: 18px;
    height: 18px;
    border-width: 3px;
}
.import-processing-msg {
    font-size: 13px;
    color: var(--muted);
    padding-left: 28px;
    min-height: 18px;
}
.import-steps-list {
    list-style: none;
    margin: 0;
    padding: 0 0 0 28px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.import-steps-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
}
.import-steps-list li.step-done {
    color: var(--success);
}
.import-steps-list li.step-active {
    color: var(--text);
    font-weight: 600;
}
.import-step-icon {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.notice {
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-left-width: 4px;
    background: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}

.notice.success {
    color: var(--success);
    border-color: #a6d8bf;
    background: var(--success-bg);
}

.notice.error {
    color: var(--danger);
    border-color: #f1b8b3;
    background: var(--danger-bg);
}

.toast-region {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 10000;
    display: grid;
    gap: 10px;
    width: min(420px, calc(100vw - 32px));
    pointer-events: none;
}

.app-toast {
    display: grid;
    grid-template-columns: 10px 1fr auto;
    gap: 10px;
    align-items: start;
    padding: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
    pointer-events: auto;
    animation: toast-in 160ms ease-out;
}

.app-toast::before {
    content: "";
    width: 10px;
    height: 10px;
    margin-top: 5px;
    border-radius: 50%;
    background: currentColor;
}

.app-toast.success {
    color: var(--success);
    background: var(--success-bg);
    border-color: #a6d8bf;
}

.app-toast.error {
    color: var(--danger);
    background: var(--danger-bg);
    border-color: #f1b8b3;
}

.app-toast.warn {
    color: var(--warn);
    background: var(--warn-bg);
    border-color: #fedf89;
}

.app-toast.info {
    color: var(--info);
    background: var(--info-bg);
    border-color: #bfdbfe;
}

.app-toast-message {
    color: var(--text);
    font-weight: 600;
}

.app-toast-close {
    width: 28px;
    min-height: 28px;
    margin: -4px -4px 0 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: currentColor;
    font-size: 20px;
    line-height: 1;
}

.app-toast-close:hover {
    background: rgba(15, 23, 42, 0.08);
}

.app-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.46);
}

.app-confirm-overlay[hidden] {
    display: none;
}

.app-confirm-dialog {
    width: min(460px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 22px 60px rgba(15, 23, 42, 0.26);
}

.app-confirm-body {
    padding: 18px;
}

.app-confirm-title {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 700;
}

.app-confirm-message {
    margin: 0;
    color: var(--muted);
    white-space: pre-line;
}

.app-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px 18px;
}

.app-confirm-actions button {
    width: auto;
    min-width: 92px;
    margin: 0;
}

.app-confirm-actions .secondary {
    background: #fff;
    color: var(--accent);
}

.app-confirm-actions .secondary:hover {
    background: #f0fdfa;
}

body.modal-open {
    overflow: hidden;
}

.app-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.42);
}

.app-modal-overlay[hidden] {
    display: none;
}

.app-modal-dialog {
    width: min(720px, 100%);
    max-height: calc(100vh - 36px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 22px 60px rgba(15, 23, 42, 0.26);
    padding: 18px;
}

.app-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}

.app-modal-head h2 {
    margin: 0 0 3px;
}

.app-modal-head p {
    margin: 0;
}

.app-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.app-modal-actions button {
    width: auto;
    min-width: 120px;
    margin: 0;
}

.records-revision-dialog {
    width: min(820px, 100%);
}

.records-revision-current {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid #c7e4ef;
    border-radius: 8px;
    background: #f0f9ff;
    color: var(--text);
}

.records-revision-current > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
}

.records-revision-current p {
    margin: 0;
    font-weight: 700;
}

.records-revision-current small {
    color: var(--muted);
}

.records-revision-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.records-revision-form label {
    margin: 0;
}

.records-revision-form label:nth-child(1),
.records-revision-form label:nth-child(2) {
    grid-column: 1 / -1;
}

.records-revision-form textarea {
    width: 100%;
    resize: vertical;
}

.dictionary-history-example-wrap {
    margin: 12px 0 0;
}

.dictionary-history-example-wrap a.secondary-button {
    display: inline-flex;
    width: auto;
    min-height: 32px;
    padding: 6px 12px;
    margin: 0;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font: inherit;
    text-decoration: none;
    box-sizing: border-box;
}

.records-revision-feedback {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(15, 118, 110, 0.04);
}

.records-revision-feedback label {
    margin: 0;
}

.records-revision-feedback textarea {
    width: 100%;
    resize: vertical;
}

.records-revision-feedback-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

.records-revision-feedback-actions button {
    width: auto;
    margin: 0;
}

.records-revision-history-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.records-revision-history-section h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.records-revision-history {
    display: grid;
    gap: 8px;
    max-height: 270px;
    overflow: auto;
}

.record-revision-item {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdff;
}

.record-revision-item-head,
.record-revision-code-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.record-revision-item-head span,
.record-revision-item small {
    color: var(--muted);
}

.record-revision-code-line {
    justify-content: flex-start;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-weight: 800;
}

.record-revision-item p {
    margin: 0;
    white-space: pre-wrap;
}

.record-feedback-status {
    display: inline-block;
    width: fit-content;
    padding: 1px 8px;
    border-radius: 999px;
    font-weight: 700;
}

.record-feedback-status-unread {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
}

.record-feedback-status-read {
    background: rgba(15, 118, 110, 0.1);
    color: var(--accent);
}

.chat-shell {
    --chat-teal: #0f6e56;
    --chat-teal-2: #1d9e75;
    --chat-teal-3: #0c5a47;
    --chat-teal-bg: #e1f5ee;
    --chat-teal-bg-2: #d3eee2;
    --chat-teal-border: #bfe6d6;
    --chat-warn: #b45309;
    --chat-warn-bg: #fbeedd;
    --chat-bad: #b42318;
    --chat-bad-bg: #fdeae8;
    display: flex;
    height: calc(100vh - 210px);
    min-height: 560px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
}

.chat-sidebar {
    width: 220px;
    flex: 0 0 220px;
    display: flex;
    flex-direction: column;
    background: #fafbfc;
    border-right: 1px solid #e6e9ee;
    min-width: 0;
}

.chat-sidebar-top {
    padding: 12px 10px;
    border-bottom: 1px solid #e6e9ee;
}

.chat-new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    min-height: 38px;
    margin: 0 0 8px;
    padding: 8px 12px;
    background: var(--chat-teal);
    border: 0;
    border-radius: 8px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.chat-new-btn:hover,
.chat-send-btn:hover {
    background: var(--chat-teal-3);
}

.chat-search-wrap {
    position: relative;
}

.chat-search-wrap .chat-icon {
    position: absolute;
    top: 50%;
    left: 10px;
    width: 14px;
    height: 14px;
    color: #94a1ac;
    transform: translateY(-50%);
    pointer-events: none;
}

.chat-search {
    width: 100%;
    height: 34px;
    padding: 0 10px 0 30px;
    border: 1px solid #d7dce2;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
}

.chat-conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}

.chat-conversation-group {
    padding: 10px 8px 4px;
    color: #94a1ac;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chat-conversation-item {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-height: 36px;
    margin: 0;
    padding: 2px;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: #64727f;
    font-size: 12px;
    text-align: left;
}

.chat-conversation-item:hover {
    background: #eef1f4;
}

.chat-conversation-item.active {
    background: var(--chat-teal-bg);
    border-color: var(--chat-teal-border);
    color: var(--chat-teal);
    font-weight: 700;
}

.chat-conversation-open {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    min-height: 32px;
    margin: 0;
    padding: 6px 8px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.chat-conversation-edit {
    display: inline-grid;
    place-items: center;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    margin: 0 2px 0 0;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: #7b8792;
    cursor: pointer;
    opacity: 0;
}

.chat-conversation-item:hover .chat-conversation-edit,
.chat-conversation-item:focus-within .chat-conversation-edit {
    opacity: 1;
}

.chat-conversation-edit:hover {
    border-color: var(--chat-teal-border);
    background: #fff;
    color: var(--chat-teal);
}

.chat-conversation-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 54px;
    padding: 11px 16px;
    border-bottom: 1px solid #e6e9ee;
    background: #fff;
}

.chat-avatar,
.chat-message-avatar {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--chat-teal);
    color: #fff;
}

.chat-avatar {
    width: 32px;
    height: 32px;
}

.chat-message-avatar {
    width: 26px;
    height: 26px;
    margin-top: 2px;
    font-size: 11px;
}

.chat-header-meta {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.chat-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--chat-teal);
    font-size: 11px;
}

.chat-reference-status {
    margin-top: 2px;
    color: #64727f;
    font-size: 11px;
}

.chat-header-status .dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--chat-teal-2);
}

.chat-clear-btn,
.chat-card-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: auto;
    min-height: 32px;
    min-width: 0;
    margin: 0;
    padding: 6px 11px;
    border: 1px solid #d7dce2;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.chat-clear-btn:hover,
.chat-card-action:hover {
    background: #fafbfc;
}

.chat-message-pane {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    background: #fafbfc;
}

.chat-empty {
    display: grid;
    gap: 4px;
    max-width: 520px;
    margin: 64px auto 0;
    padding: 18px;
    border: 1px dashed var(--chat-teal-border);
    border-radius: 12px;
    background: #fff;
    color: #64727f;
    text-align: center;
}

.chat-empty strong {
    color: var(--chat-teal);
}

.chat-message {
    display: flex;
    gap: 10px;
    max-width: 88%;
    margin-bottom: 14px;
}

.chat-message--user {
    justify-content: flex-end;
    margin-left: auto;
}

.chat-message-content {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.chat-bubble {
    width: fit-content;
    max-width: 100%;
    padding: 9px 13px;
    border: 1px solid #e6e9ee;
    border-radius: 14px;
    background: #fff;
    color: var(--text);
    font-size: 13px;
    line-height: 1.55;
}

.chat-message--user .chat-bubble {
    margin-left: auto;
    background: var(--chat-teal-bg);
    border-color: transparent;
    color: var(--chat-teal);
    font-weight: 600;
}

.chat-bubble--placeholder {
    color: #64727f;
    font-style: italic;
}

.chat-bubble-text {
    white-space: normal;
}

.chat-typing-dots {
    display: inline-flex;
    gap: 4px;
    vertical-align: middle;
}

.chat-typing-dots i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #94a1ac;
    animation: chat-dot 1s infinite ease-in-out;
}

.chat-typing-dots i:nth-child(2) {
    animation-delay: 0.14s;
}

.chat-typing-dots i:nth-child(3) {
    animation-delay: 0.28s;
}

@keyframes chat-dot {
    0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.chat-suggestion-card {
    width: min(420px, 100%);
    overflow: hidden;
    border: 1px solid #e6e9ee;
    border-radius: 12px;
    background: #fff;
}

.chat-card-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 13px 4px;
    color: #94a1ac;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chat-card-body {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 4px 16px 14px;
}

.chat-code-big {
    padding: 8px 14px;
    border-radius: 8px;
    background: var(--chat-teal-bg);
    color: var(--chat-teal);
    font: 700 34px/1 ui-monospace, Menlo, Consolas, monospace;
    letter-spacing: 1px;
}

.chat-code-big.warn {
    background: var(--chat-warn-bg);
    color: var(--chat-warn);
}

.chat-code-big.bad {
    background: var(--chat-bad-bg);
    color: var(--chat-bad);
}

.chat-code-label {
    color: #64727f;
    font-size: 12px;
    line-height: 1.45;
}

.chat-confidence {
    padding: 0 16px 12px;
}

.chat-confidence-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    color: #94a1ac;
    font-size: 11px;
}

.chat-confidence-row strong {
    color: var(--chat-teal);
}

.chat-confidence-row.warn strong {
    color: var(--chat-warn);
}

.chat-confidence-row.bad strong {
    color: var(--chat-bad);
}

.chat-confidence-bar {
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: #eef1f4;
}

.chat-confidence-bar i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--chat-teal-2), var(--chat-teal));
}

.chat-confidence-bar.warn i {
    background: linear-gradient(90deg, #f0a93a, var(--chat-warn));
}

.chat-confidence-bar.bad i {
    background: linear-gradient(90deg, #e8857d, var(--chat-bad));
}

.chat-card-reason,
.chat-card-alternatives {
    padding: 10px 16px;
    border-top: 1px solid #e6e9ee;
    background: #fafbfc;
    color: #64727f;
    font-size: 12px;
    line-height: 1.55;
}

.chat-card-alternatives[hidden] {
    display: none;
}

.chat-alt-item {
    display: inline-flex;
    width: auto;
    min-height: 0;
    margin: 2px 4px 2px 0;
    padding: 3px 8px;
    border: 1px solid var(--chat-teal-border);
    border-radius: 999px;
    background: var(--chat-teal-bg);
    color: var(--chat-teal);
    cursor: pointer;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-weight: 700;
}

.chat-alt-item:hover {
    background: var(--chat-teal-bg-2);
}

.chat-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 9px 13px;
    border-top: 1px solid #e6e9ee;
}

.chat-card-action.primary {
    background: var(--chat-teal);
    border-color: transparent;
    color: #fff;
}

.chat-card-action.primary:hover {
    background: var(--chat-teal-3);
}

.chat-card-action[disabled] {
    opacity: 0.65;
    cursor: not-allowed;
}

.chat-already-dict-note {
    display: inline-flex;
    align-items: center;
    padding: 6px 0;
    color: var(--chat-teal);
    font-size: 12px;
    font-weight: 600;
}

.chat-applied-badge,
.chat-feedback-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--success-bg);
    color: var(--success);
    font-weight: 700;
}

.chat-feedback-badge {
    background: var(--warn-bg);
    color: var(--warn);
}

.chat-input-wrap {
    padding: 10px 16px 12px;
    border-top: 1px solid #e6e9ee;
    background: #fff;
}

.chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.chat-chip {
    width: auto;
    min-height: 28px;
    margin: 0;
    padding: 5px 11px;
    border: 1px solid var(--chat-teal-border);
    border-radius: 999px;
    background: var(--chat-teal-bg);
    color: var(--chat-teal);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.chat-chip:hover {
    background: var(--chat-teal-bg-2);
}

.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 0;
    padding: 8px 8px 8px 12px;
    border: 1px solid #d7dce2;
    border-radius: 8px;
    background: #fff;
}

.chat-input-bar textarea {
    flex: 1;
    max-height: 92px;
    min-height: 34px;
    padding: 6px 0;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    line-height: 1.5;
}

.chat-send-btn {
    display: inline-grid;
    place-items: center;
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: var(--chat-teal);
    color: #fff;
    cursor: pointer;
}

.chat-send-btn:disabled {
    background: #cdd3d8;
    cursor: not-allowed;
}

.chat-hint {
    margin-top: 5px;
    color: #94a1ac;
    font-size: 10.5px;
}

.chat-icon {
    width: 16px;
    height: 16px;
}

.chat-widget {
    --chat-teal: #0f6e56;
    --chat-teal-2: #1d9e75;
    --chat-teal-3: #0c5a47;
    --chat-teal-bg: #e1f5ee;
    --chat-teal-bg-2: #d3eee2;
    --chat-teal-border: #bfe6d6;
    --chat-warn: #b45309;
    --chat-warn-bg: #fbeedd;
    --chat-bad: #b42318;
    --chat-bad-bg: #fdeae8;
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;
}

.chat-widget-bubble {
    display: inline-grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--chat-teal);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(15, 110, 86, 0.35);
}

.chat-widget-bubble:hover {
    background: var(--chat-teal-3);
}

.chat-widget-bubble .chat-icon {
    width: 24px;
    height: 24px;
}

.chat-widget-bubble-icon-close {
    display: none;
}

.chat-widget-bubble.is-open .chat-widget-bubble-icon-open {
    display: none;
}

.chat-widget-bubble.is-open .chat-widget-bubble-icon-close {
    display: block;
}

.chat-widget-panel {
    position: absolute;
    right: 0;
    bottom: 68px;
    display: flex;
    flex-direction: column;
    width: min(380px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 120px));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
}

.chat-widget-panel[hidden] {
    display: none;
}

.chat-widget-header {
    border-radius: 14px 14px 0 0;
}

.chat-widget-icon-btn {
    display: inline-grid;
    place-items: center;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #64727f;
    cursor: pointer;
}

.chat-widget-icon-btn:hover {
    background: #eef1f4;
    color: var(--chat-teal);
}

.chat-widget-message-pane {
    padding: 14px;
}

.chat-widget-input-bar {
    margin: 0;
    border-radius: 0;
    border-width: 1px 0 0;
    border-color: #e6e9ee;
}

@media (max-width: 480px) {
    .chat-widget {
        right: 12px;
        bottom: 12px;
    }

    .chat-widget-panel {
        right: -8px;
        bottom: 64px;
    }
}

.settings-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 12px 0 16px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.settings-checkbox input[type="checkbox"] {
    width: auto;
    margin-top: 4px;
}

.ai-settings-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.ai-settings-header h2 {
    margin: 0 0 4px;
}

.ai-settings-header .muted {
    margin: 0;
    max-width: 640px;
}

.ai-model-pill {
    text-align: center;
    line-height: 1.5;
    background: #f0fdfa;
    border-color: var(--accent);
    color: var(--accent-strong);
}

.ai-model-pill strong {
    font-size: 15px;
}

.ai-settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(320px, 1fr));
    gap: 14px;
    align-items: start;
}

.ai-settings-card label {
    display: block;
    margin-bottom: 14px;
}

.ai-settings-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.ai-settings-card-head h3 {
    margin: 0;
    font-size: 16px;
}

.ai-settings-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #f0fdfa;
    font-size: 15px;
}

.ai-settings-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.ai-settings-row-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ai-model-input-row {
    display: flex;
    gap: 8px;
}

.ai-model-input-row input {
    flex: 1;
}

.ai-slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-slider-row input[type="range"] {
    flex: 1;
}

.ai-slider-row output {
    min-width: 28px;
    text-align: right;
    font-weight: 600;
    color: var(--accent-strong);
}

.ai-settings-metric-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
    margin-top: 4px;
    margin-bottom: 0;
}

.ai-settings-metric-grid .metric strong {
    font-size: 15px;
}

.ai-settings-advanced {
    margin-top: 14px;
}

.ai-settings-save {
    margin-top: 14px;
    width: 100%;
    padding: 12px;
    font-size: 15px;
}

@media (max-width: 900px) {
    .ai-settings-grid,
    .ai-settings-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .chat-shell {
        flex-direction: column;
        height: auto;
        min-height: 620px;
    }

    .chat-sidebar {
        width: 100%;
        flex-basis: auto;
        max-height: 190px;
        border-right: 0;
        border-bottom: 1px solid #e6e9ee;
    }

    .chat-message-pane {
        min-height: 420px;
    }

    .chat-message {
        max-width: 100%;
    }
}

.icon-button {
    width: 36px;
    min-height: 36px;
    padding: 0;
    border-color: var(--line);
    background: #fff;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
}

.icon-button:hover {
    color: var(--accent);
    background: #f0fdfa;
}

body.progress-open {
    cursor: progress;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes progress-spin {
    to {
        transform: rotate(360deg);
    }
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.metric-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-height: 82px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

.metric-card span {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    line-height: 1.3;
}

.metric-card strong {
    font-size: 21px;
    font-weight: 800;
    line-height: 1.15;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.metric,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

.metric {
    padding: 14px;
    border-top: 3px solid var(--accent);
}

.metric span {
    color: var(--muted);
    display: block;
    font-size: 12px;
}

.metric strong {
    display: block;
    font-size: 24px;
    margin-top: 4px;
}

.panel {
    padding: 16px;
    margin-bottom: 14px;
}

.split {
    display: grid;
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

.section-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.section-head > div {
    flex: 1 1 240px;
    min-width: 0;
}

.section-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.section-actions button {
    width: auto;
    margin: 0;
}

label {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    margin: 12px 0 4px;
}

input,
select,
button,
.button {
    width: 100%;
    min-height: 38px;
    border-radius: 6px;
    font: inherit;
}

input,
select {
    border: 1px solid var(--line);
    padding: 7px 9px;
    background: #fff;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

input[type="checkbox"],
input[type="radio"] {
    width: 13px;
    height: 13px;
    min-height: 0;
    margin: 0;
    vertical-align: middle;
    accent-color: var(--accent);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    padding: 8px 12px;
    margin-top: 14px;
    cursor: pointer;
    transition: background 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

button:hover,
.button:hover {
    background: var(--accent-strong);
    box-shadow: 0 2px 8px rgba(15, 118, 110, 0.25);
}

button:disabled,
.button[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.55;
}

.button.secondary {
    width: auto;
    min-height: 32px;
    margin-top: 0;
    background: #fcf8f8;
    color: #0f766e;
    border: 0.5px solid #0f766e;
}

.button.small,
button.small {
    padding: 4px 10px;
    font-size: 12px;
    min-height: 28px;
    margin-top: 0;
}

button.secondary-button,
.secondary-button {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--accent);
    transition: background 140ms ease, border-color 140ms ease;
}

button.secondary-button:hover,
.secondary-button:hover {
    border-color: var(--accent);
    background: #f0fdfa;
    color: var(--accent-strong);
}

.danger-button {
    border-color: var(--danger);
    background: var(--danger);
}

.danger-button:hover {
    background: #8f1f17;
}

.danger-panel {
    border-color: rgba(185, 28, 28, 0.35);
}

.delete-lot-form {
    margin-top: 16px;
}

.chart-wrap {
    position: relative;
    height: 240px;
    margin-bottom: 16px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.table-wrap.table-scroll-draggable,
.dt-container .dt-scroll-body.table-scroll-draggable {
    cursor: grab;
}

.table-wrap.table-scroll-draggable.is-table-dragging,
.dt-container .dt-scroll-body.table-scroll-draggable.is-table-dragging {
    cursor: grabbing;
}

body.table-dragging,
body.table-dragging * {
    user-select: none !important;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 8px 9px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

th {
    color: var(--muted);
    background: #f8fafc;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.floating-table-header {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 80;
    display: none;
    overflow: hidden;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: #f8fafc;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
    pointer-events: none;
}

.floating-table-header.is-visible {
    display: block;
}

.floating-table-header-inner {
    overflow: hidden;
}

.floating-table-header table {
    width: auto;
    margin: 0 !important;
    border-collapse: collapse;
}

.floating-table-header th,
.floating-table-header td {
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    white-space: nowrap;
}

tbody tr:hover > td {
    background: #f5f7fa;
}

.number {
    text-align: right;
}

.batch-coded {
    color: #0284c7;
    font-weight: 600;
}

.waiting-coder {
    color: #e11d48;
    font-weight: 600;
}

.audited {
    color: #059669;
    font-weight: 600;
}

.progress-cell {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 190px;
}

.progress-track {
    width: 150px;
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: #e5e7eb;
}

.progress-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #5b5ce2, #0ea5e9);
}

.audit-status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.audit-status.done {
    color: #047857;
    background: #d1fae5;
}

.audit-status.running {
    color: #0369a1;
    background: #e0f2fe;
}

.audit-status.waiting {
    color: #be123c;
    background: #ffe4e6;
}

.audit-status.muted {
    color: var(--muted);
    background: #eef2f7;
}

.audit-overview-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.audit-metric-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-height: 86px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
}

.audit-metric-card span {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.audit-metric-card strong {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.1;
    color: var(--accent-strong);
    font-variant-numeric: tabular-nums;
}

.audit-metric-card.wide strong {
    font-size: 18px;
    color: var(--text);
}

/* ── Coder comparison table (admin view of ?page=audit) ── */
.audit-coder-table th,
.audit-coder-table td {
    padding: 12px 14px;
}

.audit-coder-table tbody tr {
    border-bottom: 1px solid var(--line);
    transition: background 0.12s ease;
}

.audit-coder-table tbody tr:hover {
    background: var(--panel);
}

.audit-coder-row-top {
    background: #f0fdfa;
    box-shadow: inset 3px 0 0 var(--accent);
}

.audit-coder-row-top:hover {
    background: #e6fbf7 !important;
}

.audit-coder-identity {
    display: flex;
    align-items: center;
    gap: 10px;
}

.audit-coder-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.audit-coder-role-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: #eef2f7;
    color: var(--muted);
}

.audit-coder-role-superadmin,
.audit-coder-role-admin {
    background: #fdf4e7;
    color: #9a6700;
}

.audit-coder-role-coder {
    background: #f0fdfa;
    color: var(--accent-strong);
}

.audit-coder-total {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.audit-coder-today-active {
    color: var(--accent-strong);
    font-weight: 700;
}

/* ── Personal "สถิติของฉัน" card shown to coders on ?page=audit instead of
   the multi-user KPI grid + comparison table (those stay for admins) ── */
.my-audit-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 16px;
    padding: 22px 26px;
}

.my-audit-card-head {
    display: flex;
    align-items: center;
    gap: 14px;
}

.my-audit-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    flex-shrink: 0;
}

.my-audit-identity {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.my-audit-identity strong {
    font-size: 17px;
    color: var(--text);
}

.my-audit-username {
    font-size: 13px;
    color: var(--muted);
}

.my-audit-role-badge {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 999px;
    background: #f0fdfa;
    border: 1px solid #99f6e4;
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.my-audit-hero {
    display: flex;
    align-items: baseline;
    gap: 12px;
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.my-audit-hero-value {
    font-size: 44px;
    font-weight: 800;
    line-height: 1;
    color: var(--accent-strong);
    font-variant-numeric: tabular-nums;
}

.my-audit-hero-label {
    font-size: 14px;
    color: var(--muted);
}

.my-audit-substats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.my-audit-substat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
}

.my-audit-substat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.my-audit-substat-value-small {
    font-size: 14px;
    font-weight: 600;
}

.my-audit-substat-label {
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

@media (max-width: 720px) {
    .my-audit-substats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.audit-filter-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    align-items: end;
    margin: 14px 0 16px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.audit-filter-grid label {
    margin: 0;
}

.audit-filter-grid button {
    margin: 0;
    min-height: 38px;
}

.audit-coder-table td:first-child strong {
    display: block;
}

.audit-action-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 9px;
    border-radius: 999px;
    background: #eef2f7;
    color: #475569;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.audit-action-badge.create {
    background: #dcfce7;
    color: #15803d;
}

.audit-action-badge.update {
    background: #e0f2fe;
    color: #0369a1;
}

.audit-action-badge.danger {
    background: #fee2e2;
    color: #b91c1c;
}

.audit-action-badge.work {
    background: #ede9fe;
    color: #6d28d9;
}

.audit-action-badge.session {
    background: #fef3c7;
    color: #92400e;
}

.audit-action-badge.ai,
.audit-action-badge.retro {
    background: #ccfbf1;
    color: #0f766e;
}

.audit-entity-link {
    color: var(--accent);
    font-weight: 800;
}

.audit-change-cell {
    display: grid;
    gap: 4px;
    min-width: 280px;
    max-width: 520px;
}

.audit-change-cell span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}

.audit-change-cell strong {
    margin-right: 6px;
    color: var(--text);
}

.audit-detail-cell {
    text-align: center;
    min-width: 72px;
}

.audit-detail-button {
    width: auto;
    min-height: 30px;
    margin: 0;
    padding: 4px 12px;
}

.audit-log-dialog {
    width: min(1040px, 100%);
}

.audit-log-detail-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.audit-log-detail-summary > div {
    display: grid;
    gap: 4px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.audit-log-detail-summary span,
.audit-log-detail-summary small {
    color: var(--muted);
}

.audit-log-detail-summary strong,
.audit-log-detail-summary small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audit-log-diff-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.audit-log-diff-grid h3 {
    margin: 0 0 6px;
    font-size: 14px;
}

.audit-log-diff-grid pre {
    min-height: 220px;
    max-height: 420px;
    margin: 0;
    padding: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

@media (max-width: 1100px) {
    .audit-overview-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .audit-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .audit-log-detail-summary,
    .audit-log-diff-grid {
        grid-template-columns: 1fr;
    }
}

.sortable-heading {
    cursor: pointer;
}

.sortable-heading:hover {
    color: var(--accent);
}

pre {
    overflow-x: auto;
    background: #111827;
    color: #eef2f7;
    border-radius: 6px;
    padding: 12px;
}

@media (max-width: 960px) {
    .shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .sidebar-nav {
        gap: 12px;
    }

    .nav-group {
        display: flex;
    }

    .nav-group-items {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 2px;
    }

    .nav-group-items[hidden] {
        display: none;
    }

    .metric-grid,
    .split {
        grid-template-columns: 1fr;
    }

    .dictionary-add-form,
    .import-note-grid,
    .hospital-add-form,
    .health-office-upload-form,
    .hospital-edit-grid,
    .health-office-manage-summary,
    .health-office-manage-grid {
        grid-template-columns: 1fr;
    }
}

.mapping-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(110px, 1fr)) 72px;
    gap: 6px;
    min-width: 520px;
}

.mapping-form input,
.mapping-form button {
    min-height: 32px;
    margin: 0;
}

.login-panel {
    max-width: 420px;
    width: 100%;
    padding: 28px 32px;
    box-shadow: 0 8px 40px rgba(15, 23, 42, 0.12);
}

.login-panel .cf-turnstile {
    margin-top: 14px;
}

.login-note {
    margin: 10px 0 0;
    font-size: 12px;
}

/* Login page full-screen layout */
[data-page="login"] .shell {
    grid-template-columns: 1fr;
}

[data-page="login"] .sidebar {
    display: none;
}

[data-page="login"] .content {
    min-height: 100vh;
    padding: 48px 20px;
    justify-content: center;
    align-items: center;
    background: linear-gradient(160deg, #f0fdfa 0%, #f5f7fa 55%);
}

[data-page="login"] .topbar {
    display: none;
}

[data-page="login"] .notice {
    max-width: 420px;
    width: 100%;
    margin-bottom: 0;
}

.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    width: 100%;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.login-brand-logo {
    width: 54px;
    height: 54px;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(15, 118, 110, 0.28);
}

.login-brand-text strong {
    display: block;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

.login-brand-text small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 13px;
}

.dictionary-add-form {
    display: grid;
    grid-template-columns: minmax(220px, 1.4fr) minmax(280px, 1.6fr) minmax(280px, 1.6fr) minmax(140px, 0.9fr) minmax(110px, 0.7fr) 80px;
    gap: 8px;
    align-items: end;
}

.dictionary-add-form label {
    margin: 0;
}

.dictionary-add-form button {
    margin: 0;
}

.dictionary-code-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin: 0;
    padding: 6px 8px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.dictionary-code-group legend {
    grid-column: 1 / -1;
    padding: 0 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.dictionary-code-group label {
    margin: 0;
    font-size: 12px;
    color: #3b5876;
}

.dictionary-code-group input {
    display: block;
    width: 100%;
    min-height: 34px;
    margin: 3px 0 0;
    padding: 6px 9px;
    font-size: 13px;
}

.dictionary-code-row {
    display: flex;
    align-items: baseline;
    gap: 4px;
    white-space: nowrap;
}

.dictionary-sex-label {
    color: var(--muted);
    font-size: 11px;
    min-width: 36px;
}

.hospital-add-form {
    display: grid;
    grid-template-columns: minmax(120px, 0.7fr) minmax(220px, 1.3fr) minmax(220px, 1.3fr) minmax(80px, 0.5fr) minmax(120px, 0.7fr) 80px;
    gap: 8px;
    align-items: end;
}

.hospital-add-form label {
    margin: 0;
}

.hospital-add-form button {
    margin: 0;
}

.health-office-upload-form {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 180px;
    gap: 10px;
    align-items: end;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.health-office-upload-form label {
    margin: 0;
}

.health-office-upload-form button {
    margin: 0;
}

.hospital-edit-form {
    display: grid;
    gap: 10px;
    min-width: 760px;
}

.hospital-edit-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 10px;
}

.hospital-edit-form label {
    color: #3b5876;
    font-size: 12px;
    margin: 0;
}

.hospital-edit-form input {
    display: block;
    width: 100%;
    min-height: 34px;
    margin: 3px 0 0;
    padding: 6px 9px;
    font-size: 13px;
}

.hospital-registry-cell,
.hospital-source-cell {
    display: grid;
    gap: 3px;
    min-width: 130px;
    line-height: 1.25;
}

.hospital-registry-cell span,
.hospital-source-cell span {
    display: block;
}

.hospital-registry-cell strong {
    font-weight: 700;
}

.health-office-manage-dialog {
    width: min(980px, calc(100vw - 28px));
}

.health-office-manage-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin: 12px 0 14px;
}

.health-office-manage-summary div,
.health-office-manage-card {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.health-office-manage-summary span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
}

.health-office-manage-summary strong {
    display: block;
    overflow-wrap: anywhere;
}

.health-office-manage-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.health-office-manage-card h3 {
    margin: 0 0 6px;
    font-size: 16px;
}

.health-office-manage-card p {
    margin: 0 0 10px;
}

.health-office-manage-card form {
    display: grid;
    gap: 10px;
}

.health-office-manage-card label {
    margin: 0;
    color: #3b5876;
    font-size: 13px;
}

.health-office-manage-card input {
    display: block;
    width: 100%;
    min-height: 38px;
    margin-top: 4px;
    padding: 8px 10px;
}

.health-office-manage-card button {
    margin: 2px 0 0;
}

.import-note-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.import-note-grid div {
    min-height: 74px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
}

.import-note-grid strong,
.import-note-grid span {
    display: block;
}

.import-note-grid strong {
    margin-bottom: 4px;
}

.import-note-grid span {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
    white-space: normal;
}

.field-help {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.25;
    white-space: normal;
}

.status-select.active {
    border-color: #a6d8bf;
    background: var(--success-bg);
    color: var(--success);
    font-weight: 700;
}

.status-select.inactive {
    border-color: #fedf89;
    background: var(--warn-bg);
    color: #b45309;
    font-weight: 700;
}

.dictionary-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
    white-space: nowrap;
}

.dictionary-actions button,
.dictionary-actions a.secondary-button {
    width: auto;
    min-width: 56px;
    min-height: 32px;
    padding: 5px 10px;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font: inherit;
    text-decoration: none;
    box-sizing: border-box;
}

.dictionary-delete-form button {
    min-height: 30px;
    margin: 0;
}

.dictionary-cause-cell {
    min-width: 320px;
    max-width: 640px;
    white-space: normal;
}

.dictionary-cause-title {
    font-weight: 700;
    line-height: 1.35;
}

.dictionary-row-meta {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.3;
    margin-top: 3px;
}

.dictionary-user-cell {
    display: grid;
    gap: 2px;
    min-width: 150px;
    white-space: normal;
}

.dictionary-user-cell strong {
    font-size: 12px;
    line-height: 1.25;
}

.dictionary-user-cell span {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.25;
}

.dictionary-history-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    min-height: 0;
    margin: 0 0 0 4px;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    vertical-align: middle;
}

.dictionary-history-btn:hover,
.dictionary-history-btn:focus,
.dictionary-history-btn:focus-visible,
.dictionary-history-btn:active {
    background: transparent;
    border: none;
    box-shadow: none;
    outline: none;
    color: var(--muted);
}

.dictionary-history-btn svg {
    width: 12px;
    height: 12px;
}

.dictionary-history-action {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
    font-style: italic;
}

.dictionary-history-change {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.dictionary-history-old {
    color: var(--danger);
    text-decoration: line-through;
}

.dictionary-history-new {
    color: var(--accent);
    font-weight: 600;
}

.dictionary-code {
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
}

.dictionary-dim {
    color: var(--muted);
}

.dictionary-status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.dictionary-status-pill.active {
    background: var(--success-bg);
    color: var(--success);
}

.dictionary-status-pill.inactive,
.dictionary-status-pill.warn {
    background: var(--warn-bg);
    color: #b45309;
}

.reference-title-cell {
    display: grid;
    gap: 3px;
    min-width: 280px;
    white-space: normal;
}

.reference-title-cell strong {
    line-height: 1.35;
}

.reference-title-cell span {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.25;
}

#dictionary-table tr.dictionary-editing-row > td {
    background: #f8fbff;
}

#dictionary-table tr.dictionary-editor-row > td {
    background: #f8fbff;
    padding: 8px 10px;
}

.dictionary-edit-panel {
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: var(--info-bg);
    padding: 14px;
}

.dictionary-edit-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    min-width: 720px;
}

.dictionary-editor-title {
    color: var(--info);
    font-size: 12px;
    font-weight: 700;
}

.dictionary-editor-title span {
    color: var(--muted);
    font-weight: 500;
}

.dictionary-edit-form label {
    display: block;
    color: #3b5876;
    font-size: 12px;
    margin: 0;
}

.dictionary-edit-row {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) minmax(130px, 0.65fr);
    gap: 10px;
}

.dictionary-edit-form input,
.dictionary-edit-form select {
    display: block;
    width: 100%;
    min-height: 34px;
    margin: 3px 0 0;
    padding: 6px 9px;
    font-size: 13px;
}

.dictionary-edit-form .mapping-source-input {
    font-weight: 700;
}

.dictionary-edit-actions {
    display: flex;
    gap: 6px;
    align-items: end;
    justify-content: flex-end;
    padding-top: 2px;
}

.dictionary-edit-actions button {
    width: auto;
    min-width: 70px;
    min-height: 34px;
    margin: 0;
    padding: 6px 12px;
}

.user-add-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr)) 90px;
    gap: 8px;
    align-items: end;
}

.user-add-form label {
    margin: 0;
}

.user-add-form button {
    margin: 0;
}

.user-row-form {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(160px, 1fr) minmax(180px, 1fr) 70px;
    gap: 6px;
    min-width: 620px;
}

.user-status-form {
    display: grid;
    grid-template-columns: 100px 100px 70px;
    gap: 6px;
    min-width: 290px;
}

.user-row-form input,
.user-row-form button,
.user-status-form select,
.user-status-form button {
    min-height: 30px;
    margin: 0;
}

.lot-action-form {
    padding-top: 4px;
}

.lot-action-form + .lot-action-form {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.lot-action-form button {
    margin-top: 10px;
}

.import-steps {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.import-step {
    display: inline-flex;
    align-items: center;
    width: auto;
    min-height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    gap: 8px;
}

.import-step:hover {
    background: transparent;
    color: var(--accent);
}

.import-step span {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
}

.import-step.now {
    color: var(--info);
}

.import-step.done {
    color: var(--success);
}

.import-step.now span {
    border-color: #bfdbfe;
    background: var(--info-bg);
    color: var(--info);
}

.import-step.done span {
    border-color: #a6d8bf;
    background: var(--success-bg);
    color: var(--success);
}

.import-step-line {
    flex: 1;
    min-width: 20px;
    height: 1px;
    background: var(--line);
}

.import-panel[hidden] {
    display: none;
}

.import-upload-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(160px, 1fr));
    gap: 10px;
}

.import-actions,
.table-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.import-actions .button,
.import-actions button,
.table-actions .button,
.inline-form button {
    width: auto;
    min-height: 34px;
    margin: 0;
}

.inline-form {
    margin: 0;
}

.import-check {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.import-check + .import-check {
    margin-top: 8px;
}

.import-check-head {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 11px 13px;
}

.import-check-icon {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    font-weight: 700;
}

.import-check-icon.ok {
    background: var(--success-bg);
    color: var(--success);
}

.import-check-icon.warning,
.import-check-icon.error {
    background: var(--warn-bg);
    color: var(--warn);
}

.import-check-icon.error {
    background: var(--danger-bg);
    color: var(--danger);
}

.import-check-title {
    flex: 1;
    min-width: 0;
    font-weight: 700;
}

.import-check-count {
    font-weight: 700;
    white-space: nowrap;
}

.import-detail-button {
    width: auto;
    min-height: 28px;
    margin: 0;
    padding: 4px 8px;
    border: 0;
    background: transparent;
    color: var(--info);
}

.import-check-detail {
    display: none;
    padding: 0 13px 12px 47px;
}

.import-check-detail.show {
    display: block;
}

.import-sample-list {
    display: grid;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--muted);
    font-size: 12px;
}

.import-sample-list code {
    display: inline-block;
    margin-right: 4px;
    padding: 1px 6px;
    border-radius: 4px;
    background: #f1f5f9;
    color: var(--text);
    font-family: Consolas, "Courier New", monospace;
}

.import-result-grid {
    margin-bottom: 14px;
}

.retro-card label {
    display: block;
    margin: 14px 0 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.retro-card label:first-of-type {
    margin-top: 0;
}

.retro-scope-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1.4fr;
    gap: 10px;
}

.retro-targets {
    display: grid;
    gap: 8px;
}

.retro-target {
    display: flex !important;
    gap: 10px;
    align-items: flex-start;
    margin: 0 !important;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text) !important;
    cursor: pointer;
}

.retro-target input {
    flex: 0 0 auto;
    width: auto;
    min-height: 0;
    margin: 3px 0 0;
}

.retro-target strong,
.retro-target small {
    display: block;
}

.retro-target small {
    color: var(--muted);
    font-weight: 400;
}

.retro-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.retro-mode label {
    margin: 0 !important;
    padding: 12px;
    color: var(--muted);
    cursor: pointer;
}

.retro-mode label + label {
    border-left: 1px solid var(--line);
}

.retro-mode label.active {
    background: var(--info-bg);
    color: var(--info);
}

.retro-mode input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.retro-mode strong,
.retro-mode small {
    display: block;
}

.retro-mode small {
    font-weight: 400;
}

.retro-preview table td {
    vertical-align: top;
}

.mono {
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
}

.wrap-cell {
    min-width: 260px;
    max-width: 520px;
    white-space: normal;
}

.records-coded-date-field {
    display: flex;
    gap: 6px;
}

.records-coded-date-field input[type="date"] {
    flex: 1;
    min-width: 0;
}

.records-coded-date-field button {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(120px, 1fr));
    gap: 10px;
    align-items: end;
    margin-bottom: 14px;
}

.filters-grid label {
    margin: 0;
}

.filters-grid button {
    margin: 0;
}

.dictionary-conflict-overview .section-head {
    align-items: flex-start;
}

.dictionary-conflict-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 12px;
    align-items: stretch;
    margin: 16px 0;
}

.dictionary-conflict-summary .summary-card {
    display: flex;
    min-width: 0;
    min-height: 104px;
    margin: 0;
    padding: 14px 16px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    text-align: left;
    box-shadow: none;
}

button.dictionary-conflict-card {
    width: 100%;
}

button.dictionary-conflict-card:hover,
button.dictionary-conflict-card:focus-visible {
    border-color: var(--accent);
    background: #f0fdfa;
    color: var(--ink);
}

.dictionary-conflict-card.warn {
    border-color: #f4d58d;
    background: #fffbeb;
}

.dictionary-conflict-card.danger {
    border-color: #fecaca;
    background: #fff7f7;
}

.dictionary-conflict-summary .summary-card span,
.dictionary-conflict-summary .summary-card strong,
.dictionary-conflict-summary .summary-card small {
    display: block;
}

.dictionary-conflict-summary .summary-card strong {
    margin: 5px 0;
    font-size: 26px;
    line-height: 1;
}

.dictionary-conflict-summary .summary-card small {
    color: var(--muted);
}

.dictionary-conflict-filters {
    grid-template-columns: minmax(240px, 360px) minmax(160px, 220px);
    margin-bottom: 0;
}

.dictionary-conflict-source {
    min-width: 280px;
    white-space: normal;
}

.dictionary-conflict-source strong,
.dictionary-conflict-source small {
    display: block;
}

.dictionary-conflict-source small {
    margin-top: 3px;
    color: var(--muted);
}

.dictionary-conflict-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 9px;
    border-radius: 999px;
    background: #ecfdf5;
    color: #047857;
    white-space: nowrap;
}

.dictionary-conflict-pill.warn {
    background: #fffbeb;
    color: #a16207;
}

.dictionary-conflict-pill.danger {
    background: #fef2f2;
    color: #b91c1c;
}

.dictionary-conflict-dialog {
    width: min(1040px, 100%);
}

.dictionary-conflict-members {
    display: grid;
    gap: 8px;
    max-height: 260px;
    overflow: auto;
    padding-right: 3px;
}

.dictionary-conflict-member {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
}

.dictionary-conflict-member-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.dictionary-conflict-member-head span {
    color: var(--muted);
    white-space: nowrap;
}

.dictionary-conflict-member-codes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.dictionary-conflict-member-codes > span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 7px;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    background: #eff6ff;
}

.dictionary-conflict-member-codes small {
    color: var(--muted);
}

.dictionary-conflict-resolve-form {
    margin-top: 14px;
}

.dictionary-conflict-keeper-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}

.dictionary-conflict-keeper-options label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 5px;
}

.dictionary-conflict-keeper-options input {
    flex: 0 0 auto;
    width: auto;
    margin-top: 3px;
}

.dictionary-conflict-code-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.dictionary-conflict-input-warning {
    border-color: #f59e0b !important;
    background: #fffbeb !important;
}

@media (max-width: 900px) {
    .dictionary-conflict-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dictionary-conflict-code-groups,
    .dictionary-conflict-keeper-options {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .dictionary-conflict-summary {
        grid-template-columns: 1fr;
    }
}

.validation-filters {
    grid-template-columns: minmax(320px, 1.8fr) minmax(170px, 1fr) minmax(130px, 0.75fr) minmax(150px, 0.9fr) minmax(140px, 0.9fr) minmax(140px, 0.9fr);
}

.validation-resolve-bar {
    display: grid;
    grid-template-columns: minmax(150px, 0.7fr) minmax(260px, 1.6fr) minmax(170px, 0.8fr);
    gap: 10px;
    align-items: end;
    margin: 0 0 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
}

.validation-resolve-bar label,
.validation-resolve-bar button {
    margin: 0;
}

#validation-select-page,
#validation-results-table [data-role="validation-select-row"] {
    width: auto;
    min-height: 0;
    margin: 0;
}

.validation-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    white-space: nowrap;
}

.validation-actions .button,
.validation-actions button {
    width: auto;
    min-height: 30px;
    margin: 0;
    padding: 6px 10px;
}

.dashboard-v2 {
    display: grid;
    gap: 18px;
}

.dashboard-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
}

.dashboard-kpi-card {
    display: grid;
    gap: 4px;
    min-height: 102px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    text-decoration: none;
}

.dashboard-kpi-card:hover {
    border-color: #bfd1dc;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}

.dashboard-kpi-card strong {
    font-size: 27px;
    line-height: 1.12;
}

.dashboard-kpi-card small,
.dashboard-kpi-label {
    color: var(--muted);
}

.dashboard-kpi-label {
    font-size: 13px;
}

.dashboard-kpi-card.ok strong {
    color: var(--success);
    font-size: 20px;
}

.dashboard-kpi-card.warn {
    background: var(--warn-bg);
    border-color: #f5ddb0;
}

.dashboard-kpi-card.warn strong {
    color: var(--warn);
}

.dashboard-panel {
    margin: 0;
}

.dashboard-wide-progress,
.dashboard-progress-bar,
.dashboard-mini-progress {
    display: block;
    overflow: hidden;
    border-radius: 999px;
    background: #e8edf2;
}

.dashboard-wide-progress {
    height: 10px;
    margin-bottom: 10px;
}

.dashboard-progress-bar {
    height: 100%;
}

.dashboard-progress-bar i,
.dashboard-mini-progress i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), #24a4d8);
}

.dashboard-mini-progress {
    display: inline-block;
    width: 72px;
    height: 7px;
    margin-right: 7px;
    vertical-align: middle;
}

.dashboard-table-wrap {
    overflow: visible;
}

.dashboard-lot-table th,
.dashboard-lot-table td {
    vertical-align: middle;
}

.dashboard-actions-col {
    width: 46px;
}

.dashboard-menu-cell {
    text-align: right;
}

.dashboard-menu-wrap {
    position: relative;
    display: inline-block;
}

.dashboard-kebab {
    width: 32px;
    min-height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
}

.dashboard-kebab:hover {
    background: #eef3f7;
    color: var(--text);
}

.dashboard-menu {
    position: absolute;
    top: 36px;
    right: 0;
    z-index: 30;
    display: none;
    min-width: 168px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.14);
    text-align: left;
}

.dashboard-menu.show {
    display: block;
}

.dashboard-menu a,
.dashboard-menu button {
    display: block;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 10px 13px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    text-decoration: none;
}

.dashboard-menu a:hover,
.dashboard-menu button:hover {
    background: #f4f7fa;
}

.dashboard-menu form {
    margin: 0;
}

.dashboard-menu .danger {
    color: var(--danger);
    border-top: 1px solid var(--line);
}

.dashboard-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.dashboard-filter-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.dashboard-filter-row .dashboard-chips {
    margin-bottom: 0;
}

.dashboard-lot-filter {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    min-width: min(100%, 420px);
    margin: 0;
}

.dashboard-lot-filter label {
    width: 100%;
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.dashboard-lot-filter select {
    width: 100%;
    margin-top: 4px;
}

.dashboard-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: auto;
    min-height: 32px;
    margin: 0;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f7fafc;
    color: var(--text);
    font-size: 12px;
}

.dashboard-chip.off {
    opacity: 0.46;
    background: #fff;
}

.dashboard-chip-line {
    width: 18px;
    height: 0;
    border-top-width: 3px;
    border-top-style: solid;
}

.dashboard-chart {
    position: relative;
    height: 320px;
}

.dashboard-chart.large {
    height: 340px;
}

.dashboard-chart.xlarge {
    height: 360px;
}

.dashboard-grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
}

.dashboard-grid-2 .dashboard-panel {
    display: flex;
    flex-direction: column;
}

.dashboard-grid-2 .section-head {
    margin-bottom: 10px;
}

.dashboard-grid-2 .dashboard-legend {
    margin-bottom: 6px;
}

.dashboard-grid-2 .dashboard-chart {
    margin-top: auto;
    margin-bottom: auto;
}

@media (max-width: 900px) {
    .dashboard-grid-2 {
        grid-template-columns: 1fr;
    }
}

.dashboard-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    color: var(--muted);
    font-size: 12px;
}

.dashboard-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dashboard-legend i {
    width: 11px;
    height: 11px;
    border-radius: 3px;
}

.dashboard-chart-note {
    margin: 9px 0 0;
}

.record-column-panel {
    margin: 0 0 12px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.record-column-main {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

.record-column-main strong {
    display: inline-flex;
    margin-right: 8px;
}

.record-column-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.record-column-actions button {
    width: auto;
    min-height: 32px;
    margin: 0;
}

.record-column-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.record-column-picker[hidden] {
    display: none;
}

.record-column-option {
    display: flex;
    gap: 7px;
    align-items: center;
    margin: 0;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
    color: var(--text);
    font-size: 13px;
}

.record-column-option input {
    width: auto;
    min-height: 0;
    margin: 0;
}

.record-column-option small {
    margin-left: auto;
    color: var(--muted);
    font-size: 11px;
}

.record-column-option.required {
    background: #f0fdfa;
    border-color: #ccfbf1;
}

.bulk-action-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
    margin: 0 0 12px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-left: 3px solid transparent;
    border-radius: 8px;
    background: #f8fafc;
    transition: background 180ms ease, border-color 180ms ease, border-left-color 180ms ease, box-shadow 180ms ease;
}

.bulk-action-bar.is-active {
    position: sticky;
    top: 10px;
    z-index: 35;
    background: rgba(255, 255, 255, 0.97);
    border-color: #d1fae5;
    border-left-color: var(--accent);
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.10), 0 1px 4px rgba(15, 23, 42, 0.05);
    backdrop-filter: blur(10px);
}

.bulk-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    align-items: center;
    flex-shrink: 0;
    padding: 2px 0;
}

.bulk-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 999px;
    background: #cbd5e1;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.5px;
    transition: background 180ms ease;
}

.bulk-action-bar.is-active .bulk-count-badge {
    background: var(--accent);
}

.bulk-count-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.bulk-group-tag {
    display: none;
    align-items: center;
    height: 22px;
    padding: 0 9px;
    border-radius: 4px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.bulk-group-tag:not(:empty) {
    display: inline-flex;
}

.bulk-group-tag[data-state="ok"] {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
}

.bulk-group-tag[data-state="warn"] {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    color: #b45309;
}

.bulk-group-tag[data-state="error"] {
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #be123c;
}

.bulk-divider {
    width: 1px;
    height: 32px;
    background: var(--line);
    margin: 0 14px;
    flex-shrink: 0;
    align-self: center;
}

.bulk-action-section {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    flex: 1;
    min-width: 260px;
}

.bulk-ncause-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--muted);
}

.bulk-ncause-label input {
    width: 110px;
}

.bulk-action-section > button {
    margin: 0;
    align-self: flex-end;
    width: auto;
    padding-left: 18px;
    padding-right: 18px;
}

.bulk-action-section > .inline-message {
    flex: 1;
    min-width: 160px;
    margin: 0;
    font-size: 12.5px;
    align-self: flex-end;
}

.bulk-action-section > .inline-message:not(:empty) {
    padding: 5px 10px;
}

.ai-coding-dict-scope {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    max-width: 100%;
    padding: 7px 10px;
    border: 1px solid #d7ece8;
    border-radius: 8px;
    background: #f8fffd;
    color: var(--text);
}

.ai-coding-dict-scope-title {
    font-size: 12px;
    font-weight: 800;
    color: #0f766e;
    white-space: nowrap;
}

.ai-coding-scope-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

.ai-coding-scope-group > span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.ai-coding-scope-group label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    min-height: 24px;
    margin: 0;
    padding: 2px 7px 2px 5px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: #334155;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.ai-coding-scope-group input[type="radio"] {
    width: 13px;
    height: 13px;
    margin: 0;
    accent-color: var(--accent);
}

.ai-coding-dict-scope small {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}

.select-cell {
    min-width: 38px;
    text-align: center;
}

#death-records-table tbody tr {
    cursor: pointer;
}

#death-records-table tbody tr.records-row-selected > * {
    background: #ecfeff;
}

#death-records-table tbody tr.records-row-selected:hover > * {
    background: #cffafe;
}

#records-select-page,
.select-cell input {
    width: auto;
    min-height: 0;
    margin: 0;
}

.ncause-edit-cell {
    min-width: 120px;
}

.ncause-control,
.ncause-validate-wrap {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.ncause-control {
    min-width: 110px;
}

.record-row-dict-scope {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
    max-width: 220px;
    padding: 5px 7px;
    border: 1px solid #bfdbfe;
    border-radius: 7px;
    background: #f8fbff;
    color: #475569;
    font-size: 11px;
    line-height: 1.2;
}

#death-records-table tbody tr.records-row-selected .record-row-dict-scope {
    display: grid;
}

.record-row-dict-scope label {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    min-width: 0;
    margin: 0;
}

.record-row-dict-scope label span {
    color: #64748b;
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
}

.record-row-dict-scope select {
    width: 100%;
    max-width: 100%;
    min-height: 26px;
    height: 26px;
    padding: 2px 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: #0f172a;
    font-size: 11px;
}

.record-row-dict-scope select:disabled {
    cursor: not-allowed;
    background: #f1f5f9;
    color: #94a3b8;
}

.ncause-validate-wrap > input {
    width: 100%;
}

.ncause-inline-input {
    min-width: 100px;
    min-height: 30px;
    margin: 0;
    padding: 5px 8px;
}

.ncause-inline-input.invalid,
.ncause-field-invalid {
    border-color: #f43f5e;
    background: var(--danger-bg);
    box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.12);
}

.ncause-reference-warning {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    padding: 4px 8px;
    border: 1px solid #fecdd3;
    border-radius: 6px;
    background: var(--danger-bg);
    color: #be123c;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
    white-space: normal;
}

.ncause-reference-warning[hidden] {
    display: none;
}

.record-status-cell {
    min-width: 120px;
}

.record-revision-cell {
    min-width: 128px;
    text-align: center;
}

#death-records-table th.record-revision-cell,
#death-records-table td.record-revision-cell {
    text-align: center;
}

.record-revision-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

.record-revision-actions .record-revision-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    min-width: 34px;
    min-height: 30px;
    height: 30px;
    margin: 0;
    padding: 0;
    line-height: 1.2;
}

.record-revision-button svg {
    width: 15px;
    height: 15px;
}

.record-revision-count {
    position: absolute;
    top: -7px;
    right: -7px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #0f766e;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 13px;
}

.record-feedback-dot {
    position: absolute;
    top: -3px;
    left: -3px;
    width: 11px;
    height: 11px;
    border: 2px solid #fff;
    border-radius: 999px;
}

.record-feedback-dot-received {
    background: var(--danger);
}

.record-feedback-dot-sent {
    background: #94a3b8;
}

.record-status-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}

.record-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.record-status.missing {
    color: #be123c;
    background: #ffe4e6;
}

.record-status.coded {
    color: #0369a1;
    background: #e0f2fe;
}

.record-status.audited {
    color: #047857;
    background: #d1fae5;
}

.claim-status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}

.claim-status-pill.mine {
    color: #0f766e;
    background: #ccfbf1;
}

.claim-status-pill.other {
    color: #92400e;
    background: #fef3c7;
}

.claim-status-pill.expired {
    color: #7c2d12;
    background: #ffedd5;
}

.claim-status-pill.open {
    color: #475569;
    background: #e2e8f0;
}

.records-claim-bar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto;
    gap: 12px;
    align-items: center;
    margin: 14px 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.records-claim-copy {
    display: grid;
    gap: 6px;
    min-width: 240px;
}

.records-claim-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    justify-content: flex-end;
}

.records-claim-controls label {
    min-width: 120px;
    margin: 0;
}

.records-claim-controls select {
    min-height: 38px;
}

.records-claim-controls button {
    width: auto;
    margin: 0;
    min-height: 38px;
    padding-left: 16px;
    padding-right: 16px;
}

.records-claim-bar .inline-message {
    grid-column: 1 / -1;
    margin: 0;
    justify-self: start;
}

.records-audit-controls {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--line);
}

.records-audit-controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    min-width: 280px;
    color: var(--muted);
}

.records-audit-controls select {
    min-height: 38px;
}

.records-audit-controls button {
    width: auto;
    margin: 0;
    min-height: 38px;
    padding-left: 16px;
    padding-right: 16px;
}

.lot-collaboration-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    max-width: 100%;
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.online-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: #94a3b8;
    flex: 0 0 auto;
}

.online-dot.active {
    background: #10b981;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.14);
    animation: online-pulse 1.5s ease-in-out infinite;
}

.online-dot.loading {
    background: #3b82f6;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.online-dot.error {
    background: #ef4444;
}

.lot-coder-avatars {
    display: inline-flex;
    align-items: center;
    margin-left: 1px;
}

.lot-coder-avatar {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    margin-left: -6px;
    border: 2px solid #2c2926;
    border-radius: 999px;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
}

.lot-coder-avatar:first-child {
    margin-left: 0;
}

.lot-coder-avatar.tone-1 {
    background: #27ae60;
}

.lot-coder-avatar.tone-2 {
    background: #14b8a6;
}

.lot-coder-avatar.tone-3 {
    background: #2563eb;
}

.lot-coder-avatar.tone-4 {
    background: #8b5cf6;
}

.lot-coder-avatar.more {
    background: #475569;
    font-size: 10px;
}

.lot-online-label {
    color: inherit;
    font-weight: 800;
}

@keyframes online-pulse {
    0%,
    100% {
        box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.14);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.26);
    }
}

.records-claim-copy .lot-collaboration-badge {
    margin-top: 2px;
}

/* Records page — card-based header layout */
.records-stat-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0 0 12px;
    padding: 14px 18px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fafaf9;
}

.records-stat-group {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.records-stat-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.records-stat-label {
    font-size: 12px;
    color: var(--muted);
}

.records-stat-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
}

.records-stat-divider {
    width: 1px;
    height: 32px;
    background: var(--line);
}

.records-stat-sub {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

.records-stat-item {
    font-size: 13px;
    color: var(--muted);
}

.records-stat-item b {
    color: var(--text);
    margin-left: 4px;
}

.records-ai-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    margin-left: auto;
}

.records-ai-link:hover {
    text-decoration: underline;
    color: var(--accent-strong);
}

.records-block {
    padding: 14px 18px;
    margin: 0 0 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
}

.records-block .filters-grid {
    margin-bottom: 0;
}

.records-claim-bar {
    background: var(--panel);
    border-radius: 10px;
}

.records-claim-copy {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

.records-status-label {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.records-audit-controls {
    grid-column: auto;
    border-top: none;
    padding-top: 0;
    justify-content: flex-end;
}

.records-audit-controls label {
    min-width: 0;
}

.record-column-panel {
    border-radius: 10px;
}

.record-column-panel.is-floating {
    position: sticky;
    top: 12px;
    z-index: 900;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 16px 44px rgba(15, 23, 42, 0.16), 0 2px 8px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(10px);
}

.record-column-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.record-column-info-divider {
    width: 1px;
    height: 20px;
    background: var(--line);
    margin: 0 4px;
}

#records-bulk-bar {
    position: static;
    width: auto;
    margin: 0;
    padding: 0;
    border: none;
    border-left: none;
    background: transparent;
    box-shadow: none;
}

#records-bulk-bar #records-bulk-save {
    width: auto;
    margin: 0;
    min-height: 32px;
}

.record-column-panel.is-floating #records-bulk-save {
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.22);
}

#records-bulk-message:not(:empty) {
    margin-top: 8px;
}

@media (max-width: 900px) {
    .records-claim-bar {
        grid-template-columns: 1fr;
    }

    .records-audit-controls {
        justify-content: flex-start;
    }

    .records-claim-controls {
        justify-content: flex-start;
    }
}

.lot-collaboration-badge.active {
    border-color: rgba(255, 255, 255, 0.18);
    background: #2c2926;
    color: #fff;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
}

.lot-collaboration-badge.idle {
    background: #f8fafc;
    color: #64748b;
}

.lot-collaboration-badge.loading {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
}

.lot-collaboration-badge.error {
    border-color: #fecdd3;
    background: #fff1f2;
    color: #be123c;
}

.inline-message {
    min-height: 24px;
    margin: 4px 0 10px;
    color: var(--muted);
}

.inline-message:empty {
    display: none;
}

.inline-message:not(:empty) {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    font-weight: 600;
}

.inline-message.ok {
    color: var(--success);
    border-color: #a6d8bf;
    background: var(--success-bg);
}

.inline-message.error {
    color: var(--danger);
    border-color: #f1b8b3;
    background: var(--danger-bg);
}

.inline-message.warn {
    color: #b45309;
    border-color: #fedf89;
    background: var(--warn-bg);
}

.inline-message.info {
    color: var(--info);
    border-color: #bfdbfe;
    background: var(--info-bg);
}

.import-all-done-banner:not(:empty) {
    display: flex;
    width: 100%;
    box-sizing: border-box;
    padding: 14px 16px;
    font-size: 15px;
    line-height: 1.5;
}

.dplace-gap-metrics {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
}

tr.export-job-new > td {
    background-color: var(--info-bg);
}

td.export-job-actions {
    white-space: nowrap;
}

.export-job-delete-form {
    display: inline;
}

#export-range-fields .export-date-triplet {
    display: flex;
    gap: 8px;
}

#export-range-fields .export-date-triplet select {
    width: auto;
    flex: 1 1 0;
    min-width: 0;
}

button.btn-table-danger {
    width: auto;
    min-height: 24px;
    margin: 0;
    padding: 2px 10px;
    font-size: 0.8em;
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

button.btn-table-danger:hover {
    background: var(--danger);
    color: #fff;
    box-shadow: none;
}

.icd-u1-metrics {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
}

.icd-u1-add-form,
.icd-u1-edit-grid {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(140px, 0.8fr) minmax(140px, 0.8fr) 100px;
    gap: 10px;
    align-items: end;
}

.icd-u1-edit-grid {
    grid-template-columns: minmax(160px, 1fr) minmax(140px, 0.8fr) minmax(140px, 0.8fr);
}

.icd-u1-add-form label,
.icd-u1-add-form button,
.icd-u1-edit-grid label {
    margin: 0;
}

.metric small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.gap-group-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 108px;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.gap-group-pill.review {
    color: var(--danger);
    background: var(--danger-bg);
}

.gap-group-pill.non-hospital {
    color: var(--info);
    background: var(--info-bg);
}

.gap-group-pill.other {
    color: var(--warn);
    background: var(--warn-bg);
}

.dplace-gap-name-cell,
.dplace-gap-actions {
    display: grid;
    gap: 3px;
}

.dplace-gap-name-cell strong {
    font-weight: 700;
}

.dplace-gap-name-cell span,
.dplace-gap-actions span {
    color: var(--muted);
    font-size: 12px;
}

.dplace-gap-actions {
    grid-template-columns: repeat(2, max-content);
    align-items: center;
    justify-content: end;
    gap: 6px;
}

.dplace-gap-actions .button {
    margin: 0;
    padding: 6px 10px;
    min-height: 30px;
    white-space: nowrap;
}

.lot-filter-note {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    margin: 2px 0 14px;
    color: var(--muted);
}

.lot-filter-main {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.lot-filter-note strong {
    color: var(--text);
}

.lot-filter-note a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.lot-filter-note button {
    width: auto;
    margin: 0;
}

.records-pager {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
}

.records-pager button {
    width: auto;
    min-height: 30px;
    margin: 0;
    padding: 6px 10px;
}

.dt-container {
    font-size: 13px;
}

.dt-container .dt-layout-row {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.dt-container .dt-layout-cell {
    display: block !important;
    width: auto;
    padding: 4px 0 !important;
}

.dt-container .dt-layout-cell.dt-end {
    margin-left: auto;
}

.dt-container .dt-layout-row.dt-layout-table {
    display: block !important;
}

.dt-container .dt-layout-row.dt-layout-table .dt-layout-cell {
    width: 100%;
}

.dt-container .dt-length,
.dt-container .dt-search,
.dt-container .dt-paging {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dt-container .dt-search {
    justify-content: flex-end;
}

.dt-container input.dt-input,
.dt-container select.dt-input {
    width: auto !important;
    min-height: 32px;
    margin: 0 !important;
    padding: 5px 8px;
}

.dt-container .dt-search input.dt-input {
    width: min(320px, 35vw) !important;
}

.dt-container .dt-paging {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.dt-container .dt-paging button.dt-paging-button {
    width: auto !important;
    min-width: 34px;
    min-height: 32px;
    margin: 0 !important;
    padding: 4px 9px !important;
    border: 1px solid var(--line) !important;
    border-radius: 6px;
    background: #fff !important;
    color: var(--text) !important;
}

.dt-container .dt-paging button.dt-paging-button.current {
    border-color: var(--accent) !important;
    background: var(--accent) !important;
    color: #fff !important;
}

.dt-container .dt-paging button.dt-paging-button.disabled {
    opacity: 0.5;
}

.dt-container table.dataTable {
    width: 100% !important;
}

.dt-container .dt-scroll-body {
    border-bottom: 1px solid var(--line);
}

.dt-container .dt-processing {
    display: none !important;
}

.records-pager button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

@media (max-width: 960px) {
    .toast-region {
        right: 16px;
        left: 16px;
        width: auto;
    }

    .app-confirm-actions {
        flex-direction: column-reverse;
    }

    .app-confirm-actions button {
        width: 100%;
    }

    .mapping-form {
        grid-template-columns: 1fr;
        min-width: 220px;
    }

    .import-steps {
        align-items: stretch;
        flex-direction: column;
    }

    .import-step-line {
        display: none;
    }

    .import-step,
    .import-upload-grid,
    .import-note-grid,
    .retro-scope-grid,
    .retro-mode {
        width: 100%;
        grid-template-columns: 1fr;
    }

    .retro-mode label + label {
        border-top: 1px solid var(--line);
        border-left: 0;
    }

    .dictionary-add-form,
    .dictionary-edit-form,
    .dictionary-edit-row,
    .dictionary-code-group,
    .user-add-form,
    .user-row-form,
    .user-status-form {
        grid-template-columns: 1fr;
        min-width: 220px;
    }

    .filters-grid {
        grid-template-columns: 1fr 1fr;
    }

    .dashboard-grid-2 {
        grid-template-columns: 1fr;
    }

    .dashboard-chart,
    .dashboard-chart.large,
    .dashboard-chart.xlarge {
        height: 300px;
    }

    .dplace-gap-metrics {
        grid-template-columns: 1fr;
    }

    .icd-u1-metrics,
    .icd-u1-add-form,
    .icd-u1-edit-grid {
        grid-template-columns: 1fr;
    }

    .dplace-gap-actions {
        grid-template-columns: 1fr;
        justify-items: stretch;
    }

    .dplace-gap-actions .button {
        width: 100%;
        text-align: center;
    }

}

/* ═══════════════════════════════════════════════════════════════════════════
   Filter-based Dashboard (db-v3)
   ══════════════════════════════════════════════════════════════════════════ */

.db-v3 {
    display: grid;
    gap: 16px;
}

/* ── Tab navigation ─────────────────────────────────────────────────────── */
.db-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--line);
    padding-bottom: 0;
}

.db-tab {
    padding: 8px 18px;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    border-radius: 6px 6px 0 0;
    transition: color 0.15s, border-color 0.15s;
}

.db-tab:hover {
    color: var(--text);
    background: var(--hover);
}

.db-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: transparent;
}

/* ── Filter bar ─────────────────────────────────────────────────────────── */
.db-filter-bar {
    padding: 12px 16px;
}

.db-filter-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.db-filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    align-items: end;
}

.db-filter-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
    min-width: 0;
}

.db-filter-select {
    width: 100%;
    font-size: 13px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    height: 32px;
}

.db-filter-mock .db-filter-select {
    color: var(--muted);
    cursor: not-allowed;
}

.db-filter-apply {
    display: flex;
    gap: 8px;
    align-items: center;
}

.db-filter-apply-btn {
    width: auto;
    flex: 1;
    margin-top: 0;
    min-height: 32px;
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    font-weight: 600;
}

.db-filter-apply-btn:hover {
    background: #0a3f3c;
    border-color: #0a3f3c;
}

/* ── Quick year chips ───────────────────────────────────────────────────── */
.db-quick-years {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.db-quick-label {
    font-size: 12px;
    white-space: nowrap;
}

.db-year-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    background: var(--panel);
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.db-year-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.db-year-chip.active {
    border-color: var(--accent);
    background: rgba(15, 118, 110, 0.10);
    color: var(--accent);
}

.db-year-chip.warn {
    border-color: #f5ddb0;
    background: var(--warn-bg);
    color: var(--warn);
}

button.db-year-chip {
    font-family: inherit;
    cursor: pointer;
}

/* ── Filter bar header ──────────────────────────────────────────────────── */
.db-filter-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.db-filter-title {
    font-size: 14px;
    font-weight: 600;
}

/* ── KPI cards ──────────────────────────────────────────────────────────── */
.db-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.db-kpi-card {
    display: grid;
    align-content: center;
    gap: 5px;
    min-height: 112px;
    padding: 18px 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.db-kpi-card:hover {
    border-color: #bfd1dc;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

.db-kpi-card strong {
    font-size: 30px;
    line-height: 1.1;
}

.db-kpi-label {
    font-size: 12px;
    color: var(--muted);
}

.db-kpi-card small {
    font-size: 12px;
    color: var(--muted);
}

.db-kpi-card.ok strong {
    color: var(--success);
    font-size: 20px;
}

.db-kpi-card.warn {
    background: var(--warn-bg);
    border-color: #fbe8b6;
}

.db-kpi-card.warn strong {
    color: #b08200;
}

.db-kpi-card.error {
    background: #fef4f3;
    border-color: #fbd5d2;
}

.db-kpi-card.error strong {
    color: #c0392b;
}

/* ── Main grid: trend chart + lot table ─────────────────────────────────── */
.db-main-grid {
    display: grid;
    grid-template-columns: minmax(0, 72%) minmax(260px, 1fr);
    gap: 16px;
    align-items: start;
}

@media (max-width: 1200px) {
    .db-main-grid {
        grid-template-columns: 1fr;
    }
}

.db-trend-panel {
    margin: 0;
}

.db-lot-panel {
    margin: 0;
}

.db-lot-scroll {
    max-height: 360px;
    overflow-y: auto;
    overflow-x: hidden;
}

.db-lot-compact {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 12.5px;
}

.db-lot-compact th,
.db-lot-compact td {
    padding: 6px 6px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

.db-lot-compact th:first-child,
.db-lot-compact td:first-child {
    width: 42%;
}

.db-lot-compact th.number,
.db-lot-compact td.number {
    width: 19%;
    text-align: right;
    white-space: nowrap;
}

.db-lot-compact th {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
    background: var(--panel);
    z-index: 1;
}

.db-lot-compact tbody tr:hover {
    background: var(--hover);
}

.db-lot-name {
    display: block;
    width: 100%;
}

.db-lot-name .dashboard-kebab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    width: 100%;
    min-height: 28px;
    padding: 2px 4px;
    border-radius: 6px;
    font-size: 12.5px;
    text-align: left;
    white-space: normal;
}

.db-lot-caret {
    flex-shrink: 0;
    font-size: 15px;
    line-height: 1;
    color: var(--muted);
}

.db-lot-mini {
    display: block;
    width: 100%;
    margin: 4px 0 0;
}

/* ── Cause ranking toggles ──────────────────────────────────────────────── */
.db-cause-toggles {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    flex-shrink: 0;
    justify-content: flex-end;
}

.db-cause-toggle {
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--muted);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.db-cause-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.db-cause-toggle.active {
    border-color: var(--accent);
    background: rgba(15, 118, 110, 0.10);
    color: var(--accent);
}

.db-cause-toggle-r {
    margin-left: 8px;
    border-color: #f5ddb0;
    color: var(--warn);
}

.db-cause-toggle-r.active {
    background: var(--warn-bg);
    border-color: var(--warn);
    color: var(--warn);
}

.db-cause-toggle-sep {
    width: 1px;
    margin: 0 2px;
    align-self: stretch;
    background: var(--line);
}

/* ── Year-over-Year panel ───────────────────────────────────────────────── */
.db-yoy-panel {
    margin: 0;
}

.db-yoy-totals {
    display: flex;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 13px;
}

.db-yoy-totals strong {
    font-weight: 600;
}

.db-yoy-change {
    font-weight: 600;
    font-size: 13px;
}

.db-yoy-change.up   { color: #c0392b; }
.db-yoy-change.down { color: var(--success); }

.db-yoy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.db-yoy-month {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.db-yoy-month-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
}

.db-yoy-month-vals {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.db-yoy-cur {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
}

.db-yoy-pri {
    font-size: 12px;
}

.db-yoy-pct {
    font-size: 12px;
    font-weight: 600;
    margin-top: 2px;
}

.db-yoy-pct.up   { color: #c0392b; }
.db-yoy-pct.down { color: var(--success); }

.db-yoy-bar {
    height: 4px;
    background: #e8edf2;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 6px;
}

.db-yoy-bar i {
    display: block;
    height: 100%;
    border-radius: inherit;
}

.db-yoy-bar i.up   { background: #c0392b; }
.db-yoy-bar i.down { background: var(--success); }

.db-yoy-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 36px 16px;
    text-align: center;
}

.db-yoy-empty-icon {
    font-size: 32px;
    opacity: 0.5;
}

/* ── Validation Center mock layout ──────────────────────────────────────── */
.db-validation-mock {
    opacity: 0.85;
}

.db-table-placeholder {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
}

.db-table-placeholder table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.db-table-placeholder th,
.db-table-placeholder td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.db-table-placeholder th {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.skeleton-bar {
    display: block;
    height: 10px;
    width: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, #eef1f4 25%, #e4e9ee 37%, #eef1f4 63%);
    background-size: 400% 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
}

.skeleton-bar.short {
    width: 60%;
}

@keyframes skeleton-shimmer {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

.db-table-placeholder-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.78);
    text-align: center;
}

/* ── Responsive overrides ───────────────────────────────────────────────── */
@media (max-width: 900px) {
    .db-filter-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    }

    .db-filter-apply {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

    .db-filter-apply-btn {
        flex: 0 0 auto;
    }

    .db-kpis {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }

    .db-yoy-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

/* === Dashboard final polish by ChatGPT === */
/* Scope: หน้า dashboard เท่านั้น เพื่อลดผลกระทบกับหน้า import/records/export อื่น ๆ */
.db-v3 {
    display: grid;
    gap: 16px;
}

.db-v3 .panel {
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

.db-tabs {
    display: flex;
    gap: 20px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 4px;
}

.db-tab {
    display: inline-flex;
    width: auto;
    min-height: 36px;
    align-items: center;
    margin: 0;
    padding: 0 2px 10px;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--muted);
    font-weight: 700;
    text-decoration: none;
}

.db-tab.active,
.db-tab:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: transparent;
    box-shadow: none;
}

/* Filter bar */
.db-filter-bar {
    padding: 16px 18px !important;
    margin-bottom: 0;
}

.db-filter-form {
    gap: 12px;
}

.db-filter-head {
    margin-bottom: 4px;
}

.db-filter-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--text);
}

.db-filter-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(120px, 1fr)) auto;
    gap: 12px;
    align-items: end;
}

.db-filter-label {
    margin: 0;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

.db-filter-select {
    height: 40px;
    border-radius: 8px;
    background: #fff;
    font-size: 13px;
    padding: 0 11px;
}

.db-filter-mock .db-filter-select {
    background: #f3f6fa;
    color: #98a2b3;
}

.db-filter-apply {
    display: flex;
    align-items: end;
    gap: 8px;
    min-width: 148px;
}

.db-filter-apply-btn,
.db-filter-apply .button {
    width: auto !important;
    min-width: 82px;
    flex: 0 0 auto !important;
    margin-top: 0 !important;
    border-radius: 8px;
}

.db-filter-apply .button.secondary.small {
    min-width: 52px;
}

/* Quick chips */
.db-quick-years {
    gap: 8px;
    margin: 0;
}

.db-year-chip,
button.db-year-chip {
    width: auto !important;
    min-height: 30px;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    line-height: 1;
    box-shadow: none;
}

/* KPI cards */
.db-kpis {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
}

.db-kpi-card {
    min-height: 114px;
    padding: 16px 18px;
    border-radius: 12px;
    align-content: center;
}

.db-kpi-card strong {
    font-size: 32px;
    line-height: 1;
    letter-spacing: -0.03em;
}

.db-kpi-card.ok strong {
    font-size: 20px;
}

.db-kpi-label,
.db-kpi-card small {
    line-height: 1.35;
}

.db-kpi-card.error {
    background: #fff6f5;
    border-color: #f2c9c5;
}

/* Trend + lot */
.db-main-grid {
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 16px;
}

.db-trend-panel,
.db-lot-panel,
.dashboard-panel,
.db-yoy-panel {
    padding: 16px;
    margin-bottom: 0;
}

.db-trend-panel .section-head,
.db-lot-panel .section-head,
.dashboard-panel .section-head,
.db-yoy-panel .section-head {
    align-items: flex-start;
    margin-bottom: 10px;
}

.dashboard-chart.large {
    height: 305px;
}

.db-lot-panel {
    overflow: hidden;
}

.db-lot-scroll {
    max-height: 310px;
    overflow-y: auto;
    overflow-x: hidden;
}

.db-lot-compact {
    table-layout: fixed;
    font-size: 12px;
}

.db-lot-compact th,
.db-lot-compact td {
    padding: 8px 5px;
    white-space: nowrap;
}

.db-lot-compact th:first-child,
.db-lot-compact td:first-child {
    width: 46%;
}

.db-lot-compact .dashboard-actions-col,
.db-lot-compact .dashboard-menu-cell {
    display: none;
}

.db-lot-compact th:nth-child(4),
.db-lot-compact td:nth-child(4) {
    display: none;
}

.dashboard-wide-progress {
    margin: 8px 0 10px;
}

/* Cause ranking */
.dashboard-panel > .section-head:has(.db-cause-toggles) {
    align-items: flex-start;
}

.db-cause-toggles {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    max-width: 520px;
}

.db-cause-toggle {
    width: auto !important;
    min-width: 0 !important;
    min-height: 32px;
    margin: 0 !important;
    padding: 7px 12px;
    border-radius: 999px;
    background: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    box-shadow: none;
}

.db-cause-toggle.active {
    background: #ecfdf5;
    border-color: #85d7c0;
    color: var(--accent);
}

.db-cause-toggle-r {
    margin-left: 0;
    background: #fffaf0;
    border-color: #f1d49a;
    color: var(--warn);
}

.db-cause-toggle-r.active {
    background: #fff1cf;
    color: #8a5a00;
}

.db-cause-toggle-sep {
    display: none;
}

.dashboard-chart.xlarge {
    height: 360px;
    margin-top: 6px;
}

.dashboard-chart-note {
    margin: 8px 0 0;
}

/* Age/place */
.dashboard-grid-2 {
    gap: 16px;
}

.dashboard-grid-2 .dashboard-chart {
    height: 300px;
}

/* Year over year */
.db-yoy-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

@media (max-width: 1500px) {
    .db-filter-grid {
        grid-template-columns: repeat(4, minmax(150px, 1fr));
    }

    .db-filter-apply {
        min-width: 0;
    }
}

@media (max-width: 1320px) {
    .db-kpis {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .db-main-grid,
    .dashboard-grid-2 {
        grid-template-columns: 1fr;
    }

    .db-lot-scroll {
        max-height: none;
    }
}

@media (max-width: 780px) {
    .db-filter-grid,
    .db-kpis,
    .db-yoy-grid {
        grid-template-columns: 1fr;
    }

    .db-filter-apply,
    .db-filter-apply-btn,
    .db-filter-apply .button {
        width: 100% !important;
    }

    .dashboard-panel > .section-head:has(.db-cause-toggles) {
        flex-direction: column;
    }

    .db-cause-toggles {
        justify-content: flex-start;
        max-width: 100%;
    }
}
/* === End Dashboard final polish by ChatGPT === */


/* === Global loading screen === */
.app-loading-screen {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: var(--app-loader-left, 240px);
    z-index: 9500;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(248, 250, 252, 0.22);
    transition: opacity 220ms ease, visibility 220ms ease;
}

.app-loading-screen[hidden] {
    display: none !important;
}

.app-loading-screen.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.app-loading-card {
    display: grid;
    justify-items: center;
    gap: 12px;
    width: min(220px, calc(100vw - 48px));
    min-height: 78px;
    padding: 18px 22px;
    border: 1px solid #cfe0f2;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 18px 38px rgba(15, 23, 42, 0.15);
    text-align: center;
}

.app-loading-card strong {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    font-size: 18px;
    color: var(--text);
}

.app-loading-card > p:not(.app-loading-note) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    margin: 0;
    white-space: nowrap;
}

.app-loading-track {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.app-loading-progress-bar {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), #22a6d5);
    transition: width 260ms ease;
}

.app-loading-meta {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.app-loading-note {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.app-loading-note[hidden] {
    display: none;
}

.app-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #d9f4ef;
    border-top-color: var(--accent);
    border-radius: 999px;
    animation: app-loading-spin 780ms linear infinite;
}

.app-loading-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 11px;
}

.app-loading-dots i {
    display: block;
    width: 13px;
    height: 13px;
    border-radius: 999px;
    background: #1473f8;
    animation: app-loading-dot-bounce 980ms ease-in-out infinite;
}

.app-loading-dots i:nth-child(2) {
    animation-delay: 120ms;
}

.app-loading-dots i:nth-child(3) {
    animation-delay: 240ms;
}

@keyframes app-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes app-loading-dot-bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.86;
    }
    40% {
        transform: translateY(-3px);
        opacity: 1;
    }
}

@keyframes app-loading-dots-pulse {
    0%, 100% {
        opacity: 0.72;
        transform: translateY(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-2px);
    }
}


@media (max-width: 860px) {
    .app-loading-screen {
        left: 0;
    }
}


/* === Dashboard Lot panel reposition: full-width below trend chart === */
.db-main-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 16px !important;
    align-items: stretch !important;
}

.db-main-grid .db-trend-panel {
    min-width: 0;
}

.db-main-grid .db-lot-panel {
    width: 100%;
    min-width: 0;
}

.db-lot-panel .section-head {
    align-items: flex-start;
}

.db-lot-panel .dashboard-wide-progress {
    margin: 10px 0 14px;
}

.db-lot-panel .table-wrap {
    max-height: 420px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.db-lot-panel .db-lot-compact {
    min-width: 820px;
    margin: 0;
}

.db-lot-panel .db-lot-compact th,
.db-lot-panel .db-lot-compact td {
    padding: 10px 12px;
    vertical-align: middle;
}

.db-lot-panel .db-lot-compact thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
}

.db-lot-panel .dashboard-actions-col,
.db-lot-panel .dashboard-menu-cell {
    display: table-cell;
}

.db-lot-panel .db-lot-compact .hide-sm {
    display: table-cell;
}

.db-lot-panel .dashboard-menu-wrap {
    display: flex;
    justify-content: flex-end;
}

.db-lot-panel .dashboard-kebab {
    width: 34px;
    min-height: 30px;
    margin: 0;
    border-color: var(--line);
    background: #fff;
    color: var(--muted);
}

.db-lot-panel .dashboard-kebab:hover {
    border-color: var(--accent);
    background: #f0fdfa;
    color: var(--accent);
}

.db-lot-panel .dashboard-mini-progress {
    min-width: 110px;
}

.db-lot-panel .status-pill,
.db-lot-panel .status,
.db-lot-panel .audit-status {
    white-space: nowrap;
}

/* Make chart area slightly calmer now that Lot is below */
.db-trend-panel .dashboard-chart.large {
    height: 340px;
}

@media (max-width: 900px) {
    .db-lot-panel .db-lot-compact {
        min-width: 720px;
    }

    .db-trend-panel .dashboard-chart.large {
        height: 300px;
    }
}


/* === Dashboard Lot full table layout === */
.db-lot-panel .db-lot-scroll {
    max-height: 460px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.db-lot-full {
    width: 100%;
    min-width: 1120px;
    border-collapse: collapse;
    font-size: 13px;
}

.db-lot-full th,
.db-lot-full td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    white-space: nowrap;
}

.db-lot-full thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.db-lot-full tbody tr:hover td {
    background: #f8fbfd;
}

.db-lot-id {
    display: inline-block;
    margin-left: 6px;
    font-size: 12px;
}

.db-lot-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

.db-lot-actions .button,
.db-lot-actions button {
    width: auto;
    margin-top: 0;
    white-space: nowrap;
}

.db-lot-actions form {
    margin: 0;
}

.db-lot-actions-col {
    text-align: right;
}

@media (max-width: 900px) {
    .db-lot-full {
        min-width: 1040px;
    }
}


.ai-coding-page {
    display: grid;
    gap: 18px;
}

.ai-coding-top-actions {
    display: flex;
    justify-content: flex-end;
}

.ai-coding-back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding-inline: 18px;
    white-space: nowrap;
}

.ai-coding-scope-note {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 15px 18px;
    border: 1px solid #f4d79b;
    border-radius: 12px;
    background: #fffbeb;
    color: #9a6a13;
}

.ai-coding-scope-note span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    border-radius: 8px;
    background: #fef3c7;
    color: #b7791f;
}

.ai-coding-scope-note p {
    margin: 0;
}

.ai-coding-progress-wrap {
    display: grid;
    gap: 8px;
    flex: 1 1 520px;
    min-width: min(520px, 100%);
    margin: 0;
}

.ai-coding-progress-wrap[hidden] {
    display: none;
}

.ai-coding-progress-wrap.ai-coding-message-only .ai-coding-progress-bar,
.ai-coding-progress-wrap.ai-coding-message-only #ai-coding-progress-label {
    display: none;
}

.ai-coding-progress-bar {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8eef2;
}

.ai-coding-progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.ai-coding-progress-fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, #0f766e, #14b8a6);
    transition: width 0.3s ease;
}

.ai-coding-confidence {
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
}

.ai-coding-confidence.good {
    color: var(--success);
    background: var(--success-bg);
}

.ai-coding-confidence.warn {
    color: #b45309;
    background: var(--warn-bg);
}

.ai-coding-confidence.bad {
    color: var(--danger);
    background: var(--danger-bg);
}

.ai-coding-prompt-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    color: var(--info);
    background: var(--info-bg);
    white-space: nowrap;
    cursor: help;
}

.ai-coding-case-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
}

.ai-coding-cause-main {
    display: block;
    flex: 0 1 auto;
    max-width: 100%;
    color: var(--text);
    font-size: 12px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    overflow-wrap: normal;
    word-break: keep-all;
    text-overflow: ellipsis;
}

.ai-coding-case-meta {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 6px;
    min-width: 0;
    margin-top: 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.25;
    white-space: nowrap;
}

.ai-coding-reasoning {
    max-width: 320px;
    color: #64727f;
    font-size: 12px;
    line-height: 1.5;
}

.ai-coding-alt-list {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}

.ai-coding-row-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    width: 100%;
    white-space: nowrap;
}

.ai-coding-reason-link {
    display: inline-block;
    min-height: 0;
    min-width: 42px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #0f766e;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.3;
    text-align: right;
    cursor: pointer;
    text-decoration: none;
    box-shadow: none;
}

.ai-coding-reason-link:hover,
.ai-coding-reason-link:focus-visible,
.ai-coding-reason-link.is-open {
    background: transparent;
    color: #0b5f59;
    text-decoration: underline;
    box-shadow: none;
    outline: none;
}

.ai-coding-reason-link:disabled {
    background: transparent;
    color: var(--muted);
    cursor: not-allowed;
    opacity: 0.55;
    text-decoration: none;
    box-shadow: none;
}

.ai-coding-reason-panel {
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafaf9;
    color: #4b5563;
    font-size: 12px;
    line-height: 1.6;
    white-space: normal;
}

.ai-coding-reason-panel strong {
    display: block;
    margin-bottom: 3px;
    color: var(--text);
    font-size: 12px;
}

.ai-coding-reason-panel p {
    margin: 0;
}

.ai-coding-alt-badge {
    display: inline-block;
    box-sizing: border-box;
    width: auto;
    min-height: 0;
    margin: 1px 3px 1px 0;
    margin-top: 0;
    padding: 2px 7px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f5f6f8;
    font: 600 11px ui-monospace, Menlo, Consolas, monospace;
    line-height: 1.4;
    vertical-align: middle;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    color: inherit;
    outline: none;
}

.ai-coding-alt-badge::-moz-focus-inner {
    border: 0;
    padding: 0;
}

.ai-coding-alt-badge:hover,
.ai-coding-alt-badge:focus-visible {
    border-color: var(--accent);
    background: #f0fdfa;
    color: var(--accent-strong);
}

.ai-coding-alt-badge:disabled {
    cursor: not-allowed;
    opacity: 0.46;
}

.ai-coding-alt-badge:disabled:hover,
.ai-coding-alt-badge:disabled:focus-visible {
    border-color: var(--line);
    background: #f5f6f8;
    color: inherit;
}

.ai-coding-ncause-input {
    width: 90px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: 600 13px ui-monospace, Menlo, Consolas, monospace;
}

.ai-coding-ncause-input:disabled {
    cursor: not-allowed;
    background: #f8fafc;
    color: #64748b;
    opacity: 0.72;
}

.ai-coding-code-cell {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
}

.ai-coding-code-warning {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    max-width: 190px;
    padding: 3px 7px;
    border: 1px solid #fecdd3;
    border-radius: 999px;
    background: var(--danger-bg);
    color: #be123c;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.35;
}

#ai-coding-table tbody tr.ai-coding-row-selected > * {
    background: #ecfeff;
}

#ai-coding-table tbody tr.ai-coding-row-selected:hover > * {
    background: #cffafe;
}

#ai-coding-table tbody tr.ai-coding-row-locked > * {
    background: #fff7ed;
}

#ai-coding-table tbody tr.ai-coding-row-locked:hover > * {
    background: #ffedd5;
}

body[data-page="ai_ncause_coding"] #ai-coding-table {
    width: 100% !important;
    min-width: 0;
    table-layout: fixed;
    font-size: 12px;
}

/* overflow-x:hidden stays scoped to .table-wrap/.dt-container (around the
   table itself) only — NOT the outer .ai-coding-results-panel. Per the CSS
   overflow spec, setting overflow-x to a non-visible value on an element
   forces its overflow-y to compute as "auto" too (even with an explicit
   `overflow-y: visible !important`), which silently breaks position:sticky
   for any descendant (it was pinning #ai-coding-bulk-bar's sticky container
   to the panel instead of the viewport, so it never actually stuck while
   scrolling). The panel doesn't need its own horizontal clipping — table-wrap
   already contains the wide table. */
body[data-page="ai_ncause_coding"] .ai-coding-results-panel {
    max-width: 100%;
}

body[data-page="ai_ncause_coding"] .ai-coding-results-panel .table-wrap,
body[data-page="ai_ncause_coding"] .ai-coding-results-panel .dt-container {
    max-width: 100%;
    overflow-x: hidden;
}

body[data-page="ai_ncause_coding"] #ai-coding-table th,
body[data-page="ai_ncause_coding"] #ai-coding-table td {
    padding: 6px 7px;
    vertical-align: middle;
}

body[data-page="ai_ncause_coding"] #ai-coding-table thead th {
    font-size: 11px;
    letter-spacing: 0.2px;
}

body[data-page="ai_ncause_coding"] #ai-coding-table th:nth-child(1),
body[data-page="ai_ncause_coding"] #ai-coding-table td:nth-child(1) {
    width: 3%;
    text-align: center;
}

body[data-page="ai_ncause_coding"] #ai-coding-table th:nth-child(2),
body[data-page="ai_ncause_coding"] #ai-coding-table td:nth-child(2) {
    width: 52%;
}

body[data-page="ai_ncause_coding"] #ai-coding-table th:nth-child(3),
body[data-page="ai_ncause_coding"] #ai-coding-table td:nth-child(3) {
    width: 7%;
}

body[data-page="ai_ncause_coding"] #ai-coding-table th:nth-child(4),
body[data-page="ai_ncause_coding"] #ai-coding-table td:nth-child(4) {
    width: 11%;
}

body[data-page="ai_ncause_coding"] #ai-coding-table th:nth-child(5),
body[data-page="ai_ncause_coding"] #ai-coding-table td:nth-child(5) {
    width: 7%;
    text-align: center;
}

body[data-page="ai_ncause_coding"] #ai-coding-table th:nth-child(6),
body[data-page="ai_ncause_coding"] #ai-coding-table td:nth-child(6) {
    width: 11%;
}

body[data-page="ai_ncause_coding"] #ai-coding-table th:nth-child(7),
body[data-page="ai_ncause_coding"] #ai-coding-table td:nth-child(7) {
    width: 9%;
    text-align: center;
}

body[data-page="ai_ncause_coding"] #ai-coding-table .ai-coding-code-cell {
    min-width: 0;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
}

.ai-coding-child-row-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-coding-save-panel {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 6px 0;
}

.ai-coding-save-panel-label {
    align-self: center;
    color: #64748b;
    font-weight: 600;
    font-size: 11px;
    white-space: nowrap;
}

#ai-coding-table .ai-coding-save-panel select {
    align-self: center;
    width: auto;
    height: 28px;
    min-height: 28px;
    max-height: 28px;
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: #0f172a;
    font-size: 12px;
    line-height: 1.2;
    cursor: pointer;
}

.ai-coding-save-panel select:disabled {
    cursor: not-allowed;
    background: #f1f5f9;
    color: #94a3b8;
}

.ai-coding-save-panel-divider {
    align-self: center;
    width: 1px;
    height: 18px;
    background: #cbd5e1;
}

#ai-coding-table .ai-coding-save-panel-save-btn {
    align-self: center;
    width: auto;
    margin: 0;
    height: 28px;
    min-height: 28px;
    max-height: 28px;
    padding: 0 14px;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    line-height: 28px;
    white-space: nowrap;
    cursor: pointer;
}

.ai-coding-save-panel-save-btn:hover:not(:disabled) {
    background: var(--accent-strong);
}

.ai-coding-save-panel-save-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

body[data-page="ai_ncause_coding"] #ai-coding-table .secondary-button.small {
    min-height: 28px;
    padding: 3px 9px;
    font-size: 11px;
}

body[data-page="ai_ncause_coding"] #ai-coding-table tr.dt-hasChild > td,
body[data-page="ai_ncause_coding"] #ai-coding-table tr.child > td {
    background: #fafaf9;
}

.bulk-action-bar[hidden] {
    display: none;
}

/* Sticky at the top, same pattern as the records page's bulk bar (via the
   generic .bulk-action-bar.is-active rule) — not fixed/floating, so it stays
   inside the normal grid column and can never drift under the sidebar. */
body[data-page="ai_ncause_coding"] #ai-coding-bulk-bar.is-active {
    background: rgba(255, 255, 255, 0.98);
}

body[data-page="ai_ncause_coding"] #ai-coding-bulk-bar.is-active .bulk-action-section {
    min-width: min(360px, 100%);
}

.ai-coding-table-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.ai-coding-table-toolbar[hidden] {
    display: none;
}

.ai-coding-table-toolbar select {
    margin-left: 6px;
}

.ai-coding-confidence-custom {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-coding-confidence-custom[hidden] {
    display: none;
}

.ai-coding-confidence-custom label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    font-size: 13px;
}

.ai-coding-confidence-custom input[type="number"] {
    width: 64px;
}

.ai-coding-filter-note {
    display: inline-flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin-left: auto;
    padding: 6px 8px;
    border: 1px solid #c7f0e6;
    border-radius: 8px;
    background: #ecfdf5;
    color: var(--brand-dark);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.ai-coding-filter-note[hidden] {
    display: none;
}

.ai-coding-filter-note > span {
    white-space: nowrap;
}

@media (max-width: 760px) {
    .ai-coding-filter-note {
        width: 100%;
        margin-left: 0;
        overflow-x: auto;
    }
}

.ai-coding-results-panel {
    padding: 16px;
}

.ai-coding-results-panel .ai-coding-stats {
    margin-top: 0;
}

/* ── Numbered step cards (filters / run) ───────────────────────────────── */
.ai-coding-step {
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    overflow: hidden;
}

.ai-coding-step-head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 0;
    padding: 22px 26px 18px;
}

.ai-coding-run-panel .ai-coding-step-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
}

.ai-coding-step-head .ai-settings-header {
    margin: 0;
}

.ai-coding-model-status {
    justify-content: flex-end;
    align-self: start;
    min-width: 0;
}

.ai-coding-model-status .ai-model-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: min(360px, 34vw);
    padding: 8px 12px;
    text-align: left;
    line-height: 1.2;
}

.ai-coding-model-status .ai-model-pill span {
    color: var(--accent-strong);
    font-weight: 800;
    white-space: nowrap;
}

.ai-coding-model-status .ai-model-pill strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-coding-step-head p {
    margin: 5px 0 0;
}

.ai-coding-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
}

.ai-coding-step-head h3 {
    margin: 0;
    font-size: 17px;
}

.ai-coding-step-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.ai-coding-run-panel .validation-filters {
    margin: 0;
    padding: 24px 26px;
    border-top: 1px solid var(--line);
}

.ai-coding-run-row {
    display: flex;
    align-items: center;
    gap: 20px;
    margin: 0 26px 24px;
    padding: 18px 20px;
    border: 1px solid #d8ebe8;
    border-radius: 12px;
    background: #f7fcfb;
    flex-wrap: wrap;
}

.ai-coding-run-row .ai-coding-step-actions {
    display: grid;
    grid-template-columns: 180px 140px;
    flex: 0 0 auto;
}

.ai-coding-run-row #ai-coding-start {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    min-height: 50px;
    box-shadow: 0 10px 18px rgba(15, 118, 110, 0.18);
}

.ai-coding-run-row #ai-coding-start.danger-button {
    box-shadow: 0 10px 18px rgba(185, 28, 28, 0.2);
}

.ai-coding-run-row #ai-coding-reset {
    min-height: 50px;
    padding-inline: 24px;
}

.ai-benchmark-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    align-items: end;
    margin: 0;
    padding: 16px 26px 12px;
    border-top: 1px solid var(--line);
}

.ai-benchmark-filters label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 160px;
    min-width: 140px;
    max-width: 300px;
    margin: 0;
}

.ai-benchmark-panel .ai-benchmark-form {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) minmax(240px, 0.45fr);
    gap: 18px;
    align-items: start;
    margin: 0;
    padding: 22px 26px 16px;
    border-top: 1px solid var(--line);
}

.ai-benchmark-panel .ai-benchmark-form label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    margin: 0;
}

.ai-benchmark-form textarea {
    width: 100%;
    box-sizing: border-box;
    min-height: 98px;
    max-height: 180px;
    resize: vertical;
}

.ai-benchmark-form select {
    width: 100%;
}

.ai-benchmark-form .field-help {
    display: block;
    max-width: 620px;
    line-height: 1.4;
}

.ai-benchmark-run-row {
    margin-top: 0;
}

.ai-benchmark-run-row #ai-benchmark-start,
.ai-benchmark-run-row #ai-benchmark-refresh {
    min-height: 50px;
}

.ai-benchmark-run-row #ai-benchmark-start {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 10px 18px rgba(15, 118, 110, 0.18);
}

.ai-benchmark-summary {
    margin: 0 26px 22px;
}

.ai-benchmark-summary h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.ai-benchmark-detail {
    margin: 0 26px 24px;
    border: 1px solid #d8e2ec;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
}

.ai-benchmark-detail[hidden] {
    display: none;
}

.ai-benchmark-detail-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.ai-benchmark-detail-head h3 {
    margin: 0;
    color: #0f172a;
    font-size: 16px;
}

.ai-benchmark-detail-head p {
    margin: 5px 0 0;
}

.benchmark-toolbar {
    margin: 0;
    padding: 14px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
}

.benchmark-toolbar label {
    display: grid;
    gap: 6px;
    min-width: 220px;
    margin: 0;
}

.benchmark-toolbar select {
    margin-left: 0;
}

.ai-benchmark-table-wrap {
    padding: 0;
    overflow-x: auto;
}

.ai-benchmark-summary .table-wrap {
    overflow-x: auto;
}

.ai-benchmark-summary table.compact {
    border-collapse: separate;
    border-spacing: 0 10px;
}

.ai-benchmark-summary table.compact thead th {
    border-bottom: 0;
    color: #64748b;
    font-size: 12px;
    text-transform: none;
}

.ai-benchmark-summary table.compact tbody td {
    background: #fff;
    border-top: 1px solid #d8e2ec;
    border-bottom: 1px solid #d8e2ec;
    vertical-align: middle;
}

.ai-benchmark-summary table.compact tbody td:first-child {
    border-left: 1px solid #d8e2ec;
    border-radius: 8px 0 0 8px;
}

.ai-benchmark-summary table.compact tbody td:last-child {
    border-right: 1px solid #d8e2ec;
    border-radius: 0 8px 8px 0;
}

.benchmark-summary-model {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 210px;
}

.benchmark-summary-model strong,
.benchmark-summary-model small {
    display: block;
}

.benchmark-summary-model small,
.benchmark-score-main + .benchmark-mini-bar + small,
.benchmark-pill + small {
    margin-top: 4px;
    color: #64748b;
    font-size: 12px;
}

.benchmark-rank {
    display: inline-grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 999px;
    background: #e8f4f1;
    color: #0f766e;
    font-weight: 800;
}

.benchmark-summary-model.is-best .benchmark-rank {
    background: #0f766e;
    color: #fff;
}

.benchmark-score-main {
    color: #0f766e;
    font-size: 24px;
    font-weight: 800;
    line-height: 1;
}

.benchmark-mini-bar {
    width: min(220px, 100%);
    height: 8px;
    margin-top: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e5e7eb;
}

.benchmark-mini-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #0f766e, #14b8a6);
}

.benchmark-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 800;
}

.benchmark-pill.ok {
    background: #dffaf0;
    color: #047857;
}

.benchmark-pill.miss {
    background: #eef2f7;
    color: #475569;
}

.benchmark-pill.error {
    background: #fee2e2;
    color: #b91c1c;
}

.benchmark-pill.warn {
    background: #fef3c7;
    color: #92400e;
}

.benchmark-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.benchmark-badge.ok {
    background: #dffaf0;
    color: #047857;
}

.benchmark-badge.warn {
    background: #fff4d6;
    color: #a16207;
}

.benchmark-badge.error {
    background: #fee2e2;
    color: #b91c1c;
}

.benchmark-badge.miss {
    background: #eef2f7;
    color: #475569;
}

#ai-benchmark-results-table {
    min-width: 1120px;
}

#ai-benchmark-results-table td {
    vertical-align: top;
}

#ai-benchmark-results-table tbody tr.benchmark-result-row td {
    border-top: 1px solid #d8e2ec;
}

#ai-benchmark-results-table tbody tr.benchmark-row-match td {
    background: #f7fffb;
}

#ai-benchmark-results-table tbody tr.benchmark-row-miss td,
#ai-benchmark-results-table tbody tr.benchmark-row-invalid td {
    background: #fffdf4;
}

#ai-benchmark-results-table tbody tr.benchmark-row-error td {
    background: #fff7f7;
}

.benchmark-model-chip,
.benchmark-code-chip,
.benchmark-time-chip {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 7px;
    font-weight: 800;
    white-space: nowrap;
}

.benchmark-model-chip {
    max-width: 185px;
    overflow: hidden;
    background: #edf7f5;
    color: #0f766e;
    text-overflow: ellipsis;
}

.benchmark-case-cell strong,
.benchmark-case-cell span {
    display: block;
}

.benchmark-case-cell span {
    margin-top: 3px;
    color: #64748b;
    font-size: 12px;
}

.benchmark-cause-cell {
    display: -webkit-box;
    max-width: 360px;
    overflow: hidden;
    color: #0f172a;
    font-weight: 700;
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.benchmark-code-chip {
    min-width: 58px;
    justify-content: center;
    border: 1px solid #d6e1ea;
    background: #fff;
    color: #0f172a;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.benchmark-code-chip.suggested.ok {
    border-color: #8be0bd;
    background: #dffaf0;
    color: #047857;
}

.benchmark-code-chip.suggested.warn {
    border-color: #f7d77a;
    background: #fff4d6;
    color: #a16207;
}

.benchmark-code-chip.suggested.miss {
    border-color: #cbd5e1;
    background: #f8fafc;
    color: #475569;
}

.benchmark-code-chip.suggested.error,
.benchmark-code-chip.empty {
    border-color: #fecaca;
    background: #fee2e2;
    color: #b91c1c;
}

.benchmark-confidence-cell .ai-coding-confidence {
    min-width: 54px;
    justify-content: center;
}

.benchmark-time-chip {
    background: #f1f5f9;
    color: #475569;
    font-weight: 700;
}

.benchmark-reason-cell {
    display: -webkit-box;
    max-width: 440px;
    overflow: hidden;
    color: #475569;
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

@media (max-width: 900px) {
    .ai-benchmark-panel .ai-benchmark-form {
        grid-template-columns: 1fr;
    }
}

#ai-benchmark-results-table.benchmark-pivot-table {
    min-width: 980px;
}

#ai-benchmark-results-table.benchmark-pivot-table,
.ai-benchmark-detail .dt-scroll-head table {
    border-collapse: separate;
    border-spacing: 0;
}

#ai-benchmark-results-table.benchmark-pivot-table thead {
    display: table-header-group;
}

/* DataTables' scrollX mode keeps the table's own original <thead> in the DOM
   inside .dt-scroll-body purely as an invisible sizing template — the rule
   above re-enables display on every thead under the table, which
   un-hides that sizing thead too and shows it stacked directly under the
   real sticky header in .dt-scroll-head. Force it back off, without
   touching the sticky header (a separate table under .dt-scroll-headInner).
   Needs the #id repeated here too — the rule above is an ID selector, so a
   plain class-only override never wins on specificity. */
.ai-benchmark-detail .dt-scroll-body #ai-benchmark-results-table.benchmark-pivot-table thead {
    display: none;
}

.ai-benchmark-detail .dt-container {
    padding: 0;
}

.ai-benchmark-detail .dt-layout-row {
    margin: 0;
    padding: 12px 20px;
}

.ai-benchmark-detail .dt-layout-row:first-child {
    align-items: center;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
}

.ai-benchmark-detail .dt-layout-row.dt-layout-table {
    padding: 0;
}

.ai-benchmark-detail .dt-layout-row:last-child {
    border-top: 1px solid #e2e8f0;
    background: #fff;
}

.ai-benchmark-detail .dt-search input.dt-input {
    width: min(380px, 36vw) !important;
}

.ai-benchmark-detail .dt-scroll {
    border-top: 0;
}

.ai-benchmark-detail .dt-scroll-head {
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom: 1px solid #cbd5e1 !important;
    background: #f1f5f9;
    box-shadow: 0 2px 0 rgba(148, 163, 184, 0.16);
}

.ai-benchmark-detail .dt-scroll-headInner,
.ai-benchmark-detail .dt-scroll-head table {
    background: #f1f5f9;
}

#ai-benchmark-results-table.benchmark-pivot-table th,
.ai-benchmark-detail .dt-scroll-head th,
#ai-benchmark-results-table.benchmark-pivot-table td {
    border-right: 1px solid #d8e2ec;
}

#ai-benchmark-results-table.benchmark-pivot-table th:last-child,
.ai-benchmark-detail .dt-scroll-head th:last-child,
#ai-benchmark-results-table.benchmark-pivot-table td:last-child {
    border-right: 0;
}

#ai-benchmark-results-table.benchmark-pivot-table thead th,
.ai-benchmark-detail .dt-scroll-head th {
    padding: 12px 14px;
    border-bottom: 1px solid #cbd5e1 !important;
    background: #f1f5f9 !important;
    color: #334155;
    vertical-align: bottom;
    white-space: nowrap;
}

#ai-benchmark-results-table.benchmark-pivot-table tbody td {
    padding: 12px 14px;
}

.benchmark-model-head {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 150px;
}

.benchmark-model-head strong {
    color: #334155;
    font-size: 13px;
    line-height: 1.2;
}

.benchmark-model-head span {
    color: #64748b;
    font-size: 11px;
    line-height: 1.25;
    white-space: nowrap;
}

.benchmark-pivot-case {
    min-width: 280px;
}

.benchmark-pivot-case strong {
    display: -webkit-box;
    overflow: hidden;
    color: #0f172a;
    font-weight: 800;
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.benchmark-pivot-case span {
    
    margin-top: 5px;
    color: #64748b;
    font-size: 12px;
    font-weight: 700;
}

.benchmark-mismatch-badge {
    display: inline-flex;
    align-items: center;
    margin-bottom: 5px;
    padding: 2px 8px;
    border: 1px solid #fbbf24;
    border-radius: 999px;
    background: #fffbeb;
    color: #92400e;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
}

#ai-benchmark-results-table.benchmark-pivot-table tbody tr.benchmark-row-mismatch td:first-child {
    border-left: 3px solid #f59e0b;
}

.benchmark-compare-cell {
    min-width: 180px;
    max-width: 240px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
}

.benchmark-compare-cell.is-empty {
    display: flex;
    align-items: center;
    min-height: 42px;
}

.benchmark-compare-cell.ok {
    border-color: #b8ead3;
    background: #effaf3;
}

.benchmark-compare-cell.warn,
.benchmark-compare-cell.miss {
    border-color: #f5dfa3;
    background: #fef8ea;
}

.benchmark-compare-cell.error {
    border-color: #f5c2c2;
    background: #fdeded;
}

.benchmark-compare-top {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.benchmark-status-dot {
    display: inline-grid;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    place-items: center;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 900;
}

.benchmark-status-dot.ok {
    background: #dffaf0;
    color: #047857;
}

.benchmark-status-dot.warn,
.benchmark-status-dot.miss {
    background: #fff4d6;
    color: #b45309;
}

.benchmark-status-dot.error {
    background: #fee2e2;
    color: #b91c1c;
}

.benchmark-compare-code {
    color: #0f172a;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 14px;
    font-weight: 900;
    white-space: nowrap;
}

.benchmark-compare-code.bad {
    color: #dc2626;
    text-decoration: line-through;
    text-decoration-thickness: 2px;
}

.benchmark-compare-code.expected {
    color: #0f766e;
}

.benchmark-arrow {
    color: #94a3b8;
    font-weight: 800;
}

.benchmark-compare-time {
    margin-left: auto;
    color: #64748b;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.benchmark-compare-sub {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    margin-top: 7px;
    color: #64748b;
    font-size: 11px;
    line-height: 1.35;
}

.benchmark-compare-sub span:first-child {
    white-space: nowrap;
}

.benchmark-compare-sub span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#ai-benchmark-results-table.benchmark-pivot-table tbody tr.benchmark-row-match td {
    background: #fbfffd;
}

#ai-benchmark-results-table.benchmark-pivot-table tbody tr.benchmark-row-miss td,
#ai-benchmark-results-table.benchmark-pivot-table tbody tr.benchmark-row-invalid td {
    background: #fffaf0;
}

#ai-benchmark-results-table.benchmark-pivot-table tbody tr.benchmark-row-error td {
    background: #fff5f5;
}

.ai-coding-run-status {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1 1 520px;
    min-width: min(520px, 100%);
}

.ai-coding-run-message {
    margin: 0;
    min-height: 0;
    white-space: nowrap;
}

.ai-coding-run-message:not(:empty) {
    border: 0;
    background: transparent;
    padding: 0;
}

.ai-coding-run-message.ok:not(:empty) {
    color: var(--success);
}

.ai-coding-run-message.error:not(:empty) {
    color: var(--danger);
}

.ai-coding-run-message.warn:not(:empty) {
    color: #b45309;
}

.ai-coding-run-message.info:not(:empty) {
    color: var(--info);
}

#ai-coding-progress-label {
    flex: 0 0 auto;
    font-weight: 700;
    white-space: nowrap;
}

@media (max-width: 900px) {
    .ai-coding-back-link {
        width: 100%;
        justify-content: center;
    }

    .ai-coding-run-status,
    .ai-coding-progress-wrap {
        flex-basis: 100%;
        min-width: 100%;
    }
}

@media (max-width: 640px) {
    .ai-coding-scope-note,
    .ai-coding-step-head,
    .ai-coding-run-panel .validation-filters,
    .ai-benchmark-panel .validation-filters {
        padding-inline: 16px;
    }

    .ai-coding-run-row,
    .ai-benchmark-summary {
        margin-inline: 16px;
    }

    .ai-coding-step-actions,
    .ai-coding-run-row #ai-coding-start,
    .ai-coding-run-row #ai-coding-reset,
    .ai-benchmark-run-row #ai-benchmark-start,
    .ai-benchmark-run-row #ai-benchmark-refresh {
        width: 100%;
    }

    .ai-coding-run-row .ai-coding-step-actions,
    .ai-benchmark-run-row .ai-coding-step-actions {
        grid-template-columns: 1fr;
    }

    .ai-coding-progress-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
    }

    .ai-coding-run-panel .ai-coding-step-head {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .ai-coding-model-status {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .ai-coding-model-status .ai-model-pill {
        max-width: 100%;
    }

    .ai-coding-run-message {
        white-space: normal;
    }
}

/* ── Stat breakdown cards ───────────────────────────────────────────────── */
.ai-coding-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.ai-coding-stat-card {
    display: grid;
    align-content: center;
    gap: 5px;
    min-height: 108px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-coding-stat-card[role="button"] {
    user-select: none;
}

.ai-coding-stat-card:hover,
.ai-coding-stat-card:focus-visible {
    border-color: var(--brand);
    background: #f0fdfa;
    color: var(--text);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
    outline: none;
}

.ai-coding-stat-card.is-active {
    border-color: var(--brand);
    background: #f0fdfa;
    color: var(--text);
    box-shadow: inset 3px 0 0 var(--brand), 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.ai-coding-stat-card strong {
    font-size: 26px;
    line-height: 1.1;
}

.ai-coding-stat-label {
    font-size: 12px;
    color: var(--muted);
}

.ai-coding-stat-hint {
    min-height: 30px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}

.ai-coding-stat-card.good strong {
    color: var(--success);
}

.ai-coding-stat-card.info {
    background: #f2fbfa;
    border-color: #bfe8e3;
}

.ai-coding-stat-card.info:hover,
.ai-coding-stat-card.info:focus-visible,
.ai-coding-stat-card.info.is-active {
    background: #e8f8f6;
    border-color: #79cbc1;
}

.ai-coding-stat-card.info strong {
    color: var(--brand);
}

.ai-coding-stat-card.warn {
    background: var(--warn-bg);
    border-color: #fbe8b6;
}

.ai-coding-stat-card.warn:hover,
.ai-coding-stat-card.warn:focus-visible,
.ai-coding-stat-card.warn.is-active {
    background: #fff8df;
    border-color: #f6d36f;
}

.ai-coding-stat-card.warn strong {
    color: #b08200;
}

.ai-coding-stat-card.error {
    background: #fef4f3;
    border-color: #fbd5d2;
}

.ai-coding-stat-card.error:hover,
.ai-coding-stat-card.error:focus-visible,
.ai-coding-stat-card.error.is-active {
    background: #fff1f1;
    border-color: #f8b6b0;
}

.ai-coding-stat-card.error strong {
    color: #c0392b;
}

.ai-coding-card-retry {
    display: none;
    width: 100%;
    margin-top: 3px;
    border-color: #e6c66d;
    background: #fff;
    color: #8a6500;
    white-space: nowrap;
}

.ai-coding-stat-card.is-active .ai-coding-card-retry {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ai-coding-card-retry.danger {
    border-color: #f1b8b3;
    color: #b42318;
}

.ai-coding-card-retry:hover,
.ai-coding-card-retry:focus-visible {
    border-color: var(--brand);
    background: #fff;
    color: var(--brand-dark);
}

/* === System status page === */
.status-summary-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-radius: 8px;
    border: 1px solid var(--line);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
}

.status-summary-banner.ok {
    color: var(--success);
    border-color: #a6d8bf;
    background: var(--success-bg);
}

.status-summary-banner.warn {
    color: #b45309;
    border-color: #fedf89;
    background: var(--warn-bg);
}

.status-summary-banner.fail {
    color: var(--danger);
    border-color: #f1b8b3;
    background: var(--danger-bg);
}

.status-group {
    margin-bottom: 18px;
}

.status-group h3 {
    margin: 0 0 8px;
    font-size: 14px;
}

.status-check-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.status-check-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}

.status-check-row .status-dot {
    margin-top: 6px;
    flex-shrink: 0;
}

.status-check-row.ok .status-dot {
    color: var(--success);
}

.status-check-row.warn .status-dot {
    color: var(--warn);
}

.status-check-row.fail .status-dot {
    color: var(--danger);
}

.status-check-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.status-check-label {
    font-weight: 600;
}

.status-check-detail {
    font-size: 13px;
    color: var(--muted);
    word-break: break-word;
}

/* ── AI accuracy report (?page=ai_accuracy_report) ── */
.acc-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.acc-stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-top: 4px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

.acc-stat-card.teal { border-top-color: #0d9488; }
.acc-stat-card.blue { border-top-color: #2563eb; }
.acc-stat-card.yellow { border-top-color: #eab308; }

.acc-stat-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 4px;
}

.acc-stat-value {
    display: block;
    font-size: 22px;
    font-weight: 800;
    color: #1e293b;
    line-height: 1.2;
}

.acc-stat-note {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

.acc-stat-bar {
    width: 100%;
    height: 4px;
    background: #f1f5f9;
    border-radius: 999px;
    margin-top: 8px;
    overflow: hidden;
}

.acc-stat-bar span {
    display: block;
    height: 100%;
    background: #14b8a6;
    border-radius: 999px;
}

.acc-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid transparent;
    white-space: nowrap;
}

.acc-badge.ok { background: #ecfdf5; color: #059669; border-color: #a7f3d0; }
.acc-badge.warn { background: #fffbeb; color: #d97706; border-color: #fde68a; }
.acc-badge.bad { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.acc-badge.muted { background: #f8fafc; color: #64748b; border-color: #e2e8f0; }

.acc-pct-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 700;
    background: #eff6ff;
    color: #1d4ed8;
}

.acc-chart-wrap {
    height: 280px;
    width: 100%;
}

.acc-case-cell strong {
    display: block;
}

.acc-case-cell small {
    display: block;
    color: var(--muted);
    margin-top: 2px;
}

.acc-top-grid {
    display: grid;
    grid-template-columns: minmax(240px, 300px) 1fr;
    gap: 16px;
    margin-bottom: 14px;
    align-items: start;
}

.acc-filter-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.acc-filter-stack label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.acc-date-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.acc-update-btn {
    width: 100%;
    margin-top: 4px;
}

.acc-stat-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.acc-mid-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 14px;
    align-items: stretch;
}

.acc-case-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.acc-quick-filters {
    display: inline-flex;
    background: #f1f5f9;
    border-radius: 10px;
    padding: 4px;
    gap: 2px;
}

.acc-quick-filter {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    cursor: pointer;
    margin-top: 0;
}

.acc-quick-filter:hover,
.acc-quick-filter:focus {
    background: transparent;
    box-shadow: none;
    color: #334155;
}

.acc-quick-filter.active,
.acc-quick-filter.active:hover {
    background: #fff;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

@media (max-width: 1100px) {
    .acc-top-grid,
    .acc-mid-grid {
        grid-template-columns: 1fr;
    }
}

/* ── AI accuracy report v2 — funnel / confidence-bars / confused-pairs redesign ── */
.acc-funnel-card {
    background: #fafaf9;
}

.acc-funnel {
    display: flex;
    align-items: stretch;
    flex-wrap: wrap;
}

.acc-funnel-step {
    flex: 1;
    min-width: 140px;
    padding: 0 18px;
}

.acc-funnel-step:first-child {
    padding-left: 0;
}

.acc-funnel-step.bordered {
    border-left: 1px solid var(--line);
}

.acc-funnel-step.wide {
    flex: 1.3;
}

.acc-funnel-label {
    font-size: 12px;
    color: var(--muted);
}

.acc-funnel-value {
    font-size: 26px;
    font-weight: 700;
    margin-top: 2px;
}

.acc-funnel-value.green { color: #0e7c6b; }
.acc-funnel-value.red { color: #c2410c; }
.acc-funnel-value.big { font-size: 30px; color: #0f3d3e; }

.acc-funnel-hint {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
}

.acc-funnel-arrow {
    display: flex;
    align-items: center;
    color: #d1d5db;
    font-size: 20px;
    padding: 0 2px;
}

.acc-progress-bar {
    display: flex;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 16px;
    gap: 2px;
}

.acc-legend {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    font-size: 11px;
    color: var(--muted);
    flex-wrap: wrap;
}

.acc-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.acc-swatch {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    display: inline-block;
}

.acc-conf-grid {
    display: grid;
    grid-template-columns: 90px 1fr 130px;
    gap: 8px 12px;
    align-items: center;
    font-size: 12px;
    margin-top: 14px;
}

.acc-conf-track {
    background: #f1f0ec;
    border-radius: 3px;
    height: 20px;
    overflow: hidden;
}

.acc-conf-fill {
    height: 100%;
    border-radius: 3px 0 0 3px;
}

.acc-conf-value b {
    font-weight: 700;
}

.acc-conf-value .n {
    color: #9ca3af;
}

.acc-note {
    margin-top: 14px;
    padding: 10px 12px;
    background: #fdf3e7;
    border: 1px solid #f0d9b5;
    border-radius: 6px;
    font-size: 12px;
    color: #8a5a17;
    display: flex;
    gap: 8px;
    align-items: flex-start;
    line-height: 1.5;
}

.acc-pair-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.acc-pair {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #fafaf9;
    border-radius: 6px;
    font-size: 12px;
    flex-wrap: wrap;
}

.acc-pair-desc {
    color: var(--muted);
}

.acc-pair-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.acc-code {
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.acc-code.wrong { background: #fdeaea; color: #b91c1c; }
.acc-code.right { background: #e0efed; color: #0b6657; }

.acc-current-code,
.acc-coder-name {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
}

.acc-code-history {
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.acc-code-history code {
    color: inherit;
    font-size: inherit;
}

.acc-conf-high { color: #0e7c6b; font-weight: 700; }
.acc-conf-low { color: #c2410c; font-weight: 700; }

.acc-coder-name {
    color: var(--muted);
    font-size: 11px;
}

.acc-coder-name small {
    color: var(--muted);
    font-size: 10px;
    white-space: nowrap;
}

@media (max-width: 800px) {
    .acc-funnel-step {
        min-width: 45%;
        padding: 8px 0;
        border-left: none !important;
    }

    .acc-funnel-arrow {
        display: none;
    }
}

/* AI rule proposal and governance */
.ai-rule-page {
    display: grid;
    gap: 14px;
}

.ai-rule-intro,
.ai-rule-intro .section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.ai-rule-intro h2,
.ai-rule-page .section-head h2 {
    margin: 0 0 4px;
    font-size: 18px;
}

.ai-rule-intro p,
.ai-rule-page .section-head p {
    margin: 0;
}

.ai-rule-mode-pill,
.ai-rule-kpi,
.ai-rule-review-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.ai-rule-mode-pill {
    flex: 0 0 auto;
    padding: 7px 11px;
    color: #536273;
    font-size: 12px;
    font-weight: 700;
}

.ai-rule-mode-pill.active {
    border-color: #8fd5c9;
    background: #e7f8f4;
    color: #087564;
}

.ai-rule-mode-pill.shadow,
.ai-rule-mode-pill.collect {
    border-color: #efd698;
    background: #fff8e6;
    color: #946a00;
}

.ai-rule-mode-pill.off {
    border-color: #f0b8b8;
    background: #fff0f0;
    color: #b42318;
}

.ai-rule-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.ai-rule-kpi {
    padding: 14px 16px;
}

.ai-rule-kpi span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.ai-rule-kpi strong {
    display: block;
    margin-top: 4px;
    font-size: 25px;
    line-height: 1;
}

.ai-rule-kpi.pending {
    border-color: #efd698;
    background: #fffaf0;
}

.ai-rule-kpi.approved {
    border-color: #a9dfd5;
    background: #f0fbf8;
}

.ai-rule-kpi.returned {
    border-color: #d7dee7;
    background: #f7f9fb;
}

.ai-rule-engine-form,
.ai-rule-form-grid {
    display: grid;
    gap: 12px;
}

.ai-rule-engine-form {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    align-items: end;
}

.ai-rule-engine-form label,
.ai-rule-review-form label,
.ai-rule-resubmit label,
.ai-rule-proposal-form label {
    display: grid;
    gap: 5px;
    color: #43546a;
    font-size: 12px;
    font-weight: 600;
}

.ai-rule-emergency-control {
    display: flex !important;
    align-items: center;
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid #f0b8b8;
    border-radius: 6px;
    background: #fff5f5;
}

.ai-rule-emergency-control span,
.ai-rule-table td small {
    display: block;
}

.ai-rule-emergency-control small,
.ai-rule-table td small {
    margin-top: 2px;
    color: var(--muted);
    font-weight: 400;
}

.ai-rule-table td small {
    overflow-wrap: anywhere;
}

.ai-rule-review-list {
    display: grid;
    gap: 10px;
}

.ai-rule-review-card {
    overflow: clip;
}

.ai-rule-review-card > summary {
    display: grid;
    grid-template-columns: auto minmax(220px, 1fr) auto auto;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    cursor: pointer;
    list-style: none;
}

.ai-rule-review-card > summary::-webkit-details-marker {
    display: none;
}

.ai-rule-review-card[open] > summary {
    border-bottom: 1px solid var(--border);
    background: #f7fbfb;
}

.ai-rule-proposal-id {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.ai-rule-review-cause {
    min-width: 0;
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-rule-review-form,
.ai-rule-resubmit form {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.ai-rule-case-context {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.ai-rule-case-context > div {
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fafcfd;
}

.ai-rule-case-context span,
.ai-rule-case-context strong {
    display: block;
}

.ai-rule-case-context span {
    color: var(--muted);
    font-size: 11px;
}

.ai-rule-form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ai-rule-review-actions,
.ai-rule-operate-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-rule-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
}

.ai-rule-table th,
.ai-rule-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
    /* Overrides the global `td { white-space: nowrap }` base rule (app.css,
       meant for plain data tables) — without this, overflow-wrap below has
       no effect at all, since nowrap blocks every kind of line break. */
    white-space: normal;
    overflow-wrap: anywhere;
}

.ai-rule-table th:first-child,
.ai-rule-table td:first-child {
    width: 34%;
}

.ai-rule-table th {
    background: #f5f7fa;
    color: #627084;
    font-size: 11px;
    text-transform: uppercase;
}

.ai-rule-table code {
    white-space: nowrap;
}

.ai-rule-table details {
    margin-top: 5px;
}

.ai-rule-operate-form select {
    min-width: 145px;
}

.ai-rule-readiness {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-left: 4px solid #d49b22;
}

.ai-rule-readiness.ready {
    border-left-color: #14927e;
}

.ai-rule-readiness-label,
.ai-rule-readiness strong,
.ai-rule-readiness p {
    display: block;
}

.ai-rule-readiness-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.ai-rule-readiness strong {
    margin-top: 2px;
    font-size: 17px;
}

.ai-rule-readiness p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.ai-rule-readiness-actions {
    display: flex;
    align-items: center;
    gap: 9px;
}

.ai-rule-thresholds {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.ai-rule-thresholds legend {
    padding: 0 5px;
    color: #43546a;
    font-size: 12px;
    font-weight: 700;
}

.ai-rule-engine-form > button {
    justify-self: start;
}

.ai-rule-operate-form {
    align-items: stretch;
    flex-direction: column;
    min-width: 190px;
}

.ai-rule-operate-form input {
    min-width: 190px;
}

.ai-rule-force-control {
    display: flex !important;
    align-items: center;
    gap: 6px !important;
    color: #8a5d00 !important;
    font-size: 11px !important;
    font-weight: 500 !important;
}

.ai-rule-force-control input {
    min-width: 0;
}

.ai-rule-report-filters {
    display: grid;
    grid-template-columns: minmax(300px, 2fr) minmax(150px, 0.7fr) minmax(210px, 1fr) auto;
    align-items: end;
    gap: 10px;
    margin-bottom: 14px;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafb;
}

.ai-rule-report-filters label {
    display: grid;
    gap: 5px;
    color: #43546a;
    font-size: 12px;
    font-weight: 600;
}

.ai-rule-report-kpis {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.ai-rule-report-kpis > div {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

.ai-rule-report-kpis span,
.ai-rule-report-kpis strong {
    display: block;
}

.ai-rule-report-kpis span {
    color: var(--muted);
    font-size: 11px;
}

.ai-rule-report-kpis strong {
    margin-top: 3px;
    font-size: 20px;
}

.ai-rule-report-kpis .good {
    border-color: #a9dfd5;
    background: #f0fbf8;
}

.ai-rule-report-kpis .pending {
    border-color: #efd698;
    background: #fffaf0;
}

.ai-rule-report-kpis .danger {
    border-color: #f0b8b8;
    background: #fff5f5;
}

.ai-rule-report-table td:first-child {
    width: 36%;
}

.ai-rule-outcome {
    display: inline-flex;
    padding: 4px 7px;
    border-radius: 999px;
    background: #eef2f6;
    color: #536273;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.ai-rule-outcome.improvement,
.ai-rule-outcome.unchanged {
    background: #ddf7ef;
    color: #087564;
}

.ai-rule-outcome.pending {
    background: #fff2cf;
    color: #8a5d00;
}

.ai-rule-outcome.regression,
.ai-rule-outcome.disagreement {
    background: #fde4e4;
    color: #b42318;
}

.ai-rule-resubmit {
    margin-top: 8px;
    border-top: 1px dashed var(--border);
}

.ai-rule-resubmit > summary {
    padding-top: 7px;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
}

.ai-rule-proposal-dialog {
    width: min(820px, calc(100vw - 32px));
    max-width: 820px;
    max-height: calc(100vh - 40px);
    overflow: auto;
}

.ai-rule-proposal-form {
    display: grid;
    gap: 12px;
    padding: 16px 20px 20px;
}

.ai-rule-proposal-context {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid #b9dcd7;
    border-radius: 6px;
    background: #f1faf8;
}

.ai-rule-proposal-context strong,
.ai-rule-proposal-context small {
    display: block;
}

.ai-rule-proposal-context small {
    margin-top: 3px;
    color: var(--muted);
}

.ai-rule-proposal-context code {
    align-self: center;
    font-size: 15px;
    font-weight: 700;
}

.ai-rule-propose-btn {
    white-space: nowrap;
}

@media (max-width: 980px) {
    .ai-rule-kpis,
    .ai-rule-case-context {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ai-rule-engine-form,
    .ai-rule-form-grid {
        grid-template-columns: 1fr 1fr;
    }

    .ai-rule-thresholds,
    .ai-rule-report-filters {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ai-rule-report-kpis {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .ai-rule-engine-form > button {
        justify-self: start;
    }
}

@media (max-width: 640px) {
    .ai-rule-intro,
    .ai-rule-page .section-head,
    .ai-rule-readiness {
        align-items: flex-start;
        flex-direction: column;
    }

    .ai-rule-kpis,
    .ai-rule-case-context,
    .ai-rule-engine-form,
    .ai-rule-form-grid,
    .ai-rule-thresholds,
    .ai-rule-report-filters,
    .ai-rule-report-kpis,
    .ai-rule-review-card > summary {
        grid-template-columns: 1fr;
    }

    .ai-rule-review-actions {
        align-items: stretch;
        flex-direction: column;
    }
}

/* ICD-10 tree browser (?page=icd10) — ported from the icd-11-to-th reference
   UI (icd_project/ui/index.html), scoped under .icd10-browse with an i10-
   class prefix so nothing here can collide with the rest of the app. */
.icd10-browse {
    --i10-bg: #eef2f7;
    --i10-surface: #ffffff;
    --i10-surface-2: #f6f8fb;
    --i10-border: #e5eaf1;
    --i10-border-strong: #d5dde8;
    --i10-ink: #101b2d;
    --i10-ink-2: #4a5a70;
    --i10-ink-3: #8695a9;
    --i10-accent: #0d9488;
    --i10-accent-strong: #0f766e;
    --i10-accent-soft: #eefaf7;
    --i10-accent-line: #a7e8dc;
    --i10-rose: #e11d48;
    --i10-shadow: 0 1px 2px rgba(16, 27, 45, .04), 0 2px 8px rgba(16, 27, 45, .06);
    color: var(--i10-ink);
}

.icd10-browse button,
.icd10-browse input,
.icd10-browse select {
    font: inherit;
}

.icd10-browse .i10-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .7rem 1.1rem;
    background: var(--i10-surface);
    border: 1px solid var(--i10-border);
    border-top: 3px solid var(--i10-accent);
    border-radius: 12px;
    box-shadow: var(--i10-shadow);
    margin-bottom: 14px;
}

.icd10-browse .i10-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -.01em;
    white-space: nowrap;
}

.icd10-browse .i10-glyph {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    background: linear-gradient(135deg, var(--i10-accent), var(--i10-accent-strong));
    box-shadow: 0 2px 6px rgba(13, 148, 136, .4), inset 0 1px 0 rgba(255, 255, 255, .25);
}

.icd10-browse .i10-glyph svg {
    width: 19px;
    height: 19px;
    display: block;
}

.icd10-browse .i10-name {
    color: var(--i10-ink);
}

.icd10-browse .i10-sub {
    color: var(--i10-ink-3);
    font-weight: 500;
    font-size: .8rem;
}

.icd10-browse .i10-search {
    flex: 1;
    max-width: 460px;
    display: flex;
    gap: .4rem;
    min-width: 0;
}

.icd10-browse .i10-search input {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 0;
    padding: .5rem .8rem;
    font-size: .9rem;
    color: var(--i10-ink);
    background: var(--i10-surface-2);
    border: 1px solid var(--i10-border-strong);
    border-radius: 9px;
    outline: none;
    transition: border-color .12s, box-shadow .12s;
}

.icd10-browse .i10-search input::placeholder {
    color: var(--i10-ink-3);
}

.icd10-browse .i10-search input:focus {
    border-color: var(--i10-accent);
    box-shadow: 0 0 0 3px var(--i10-accent-soft);
}

.icd10-browse .i10-btn-teal {
    width: auto;
    min-height: 0;
    padding: .5rem .9rem;
    font-size: .88rem;
    font-weight: 500;
    color: #fff;
    cursor: pointer;
    background: var(--i10-accent);
    border: none;
    border-radius: 9px;
    transition: background .12s;
    flex: 0 0 auto;
}

.icd10-browse .i10-btn-teal:hover {
    background: var(--i10-accent-strong);
}

.icd10-browse .i10-btn-ghost {
    width: auto;
    min-height: 0;
    padding: .5rem .7rem;
    font-size: .88rem;
    color: var(--i10-ink-2);
    cursor: pointer;
    background: transparent;
    border: 1px solid var(--i10-border-strong);
    border-radius: 9px;
    transition: background .12s, color .12s;
    flex: 0 0 auto;
}

.icd10-browse .i10-btn-ghost:hover {
    background: var(--i10-surface-2);
    color: var(--i10-accent-strong);
}

.icd10-browse .i10-topnav {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1.1rem;
    font-size: .9rem;
}

.icd10-browse .i10-topnav a {
    color: var(--i10-ink-2);
    text-decoration: none;
    font-weight: 600;
}

.icd10-browse .i10-topnav a:hover {
    color: var(--i10-accent-strong);
}

.icd10-browse .i10-switch {
    display: flex;
    align-items: center;
    gap: .45rem;
    font-size: .85rem;
    color: var(--i10-ink-2);
    cursor: pointer;
    user-select: none;
}

.icd10-browse .i10-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.icd10-browse .i10-track {
    width: 38px;
    height: 22px;
    border-radius: 11px;
    background: var(--i10-border-strong);
    position: relative;
    transition: background .15s;
}

.icd10-browse .i10-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
    transition: transform .15s;
}

.icd10-browse .i10-switch input:checked + .i10-track {
    background: var(--i10-accent);
}

.icd10-browse .i10-switch input:checked + .i10-track::after {
    transform: translateX(16px);
}

.icd10-browse .i10-wrap {
    padding: 0 0 16px;
}

.icd10-browse .i10-row {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.icd10-browse .i10-col-tree {
    flex: 0 0 380px;
    min-width: 0;
}

.icd10-browse .i10-col-detail {
    flex: 1;
    min-width: 0;
}

.icd10-browse .i10-card {
    height: calc(100vh - 240px);
    min-height: 480px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--i10-surface);
    border: 1px solid var(--i10-border);
    border-radius: 14px;
    box-shadow: var(--i10-shadow);
}

.icd10-browse .i10-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--i10-border);
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--i10-ink-3);
}

.icd10-browse .i10-pane {
    flex: 1;
    overflow-y: auto;
    padding: .6rem;
}

.icd10-browse .i10-tree ul {
    list-style: none;
    margin: 0;
    padding-left: 1rem;
}

.icd10-browse .i10-tree > ul {
    padding-left: 0;
}

.icd10-browse .i10-tree ul ul {
    border-left: 1px solid var(--i10-border);
    margin-left: .55rem;
}

.icd10-browse .i10-tree-msg {
    color: var(--i10-ink-3);
    font-size: .82rem;
    padding: .3rem .5rem;
    list-style: none;
}

.icd10-browse .i10-node-row {
    display: flex;
    align-items: baseline;
    gap: .4rem;
    padding: .34rem .5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background .12s;
    position: relative;
}

.icd10-browse .i10-node-row:hover {
    background: var(--i10-accent-soft);
}

.icd10-browse .i10-node-row.active {
    background: var(--i10-accent-soft);
    box-shadow: inset 3px 0 0 var(--i10-accent);
}

.icd10-browse .i10-caret {
    width: 1rem;
    flex: 0 0 auto;
    text-align: center;
    user-select: none;
    color: var(--i10-ink-3);
    font-size: .62rem;
    line-height: 1.4;
    transition: transform .15s;
}

.icd10-browse .i10-caret.open {
    transform: rotate(90deg);
}

.icd10-browse .i10-caret.leaf {
    visibility: hidden;
}

.icd10-browse .i10-node-code {
    flex: 0 0 auto;
    font-family: Consolas, monospace;
    font-size: .72rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--i10-accent), var(--i10-accent-strong));
    padding: .14rem .45rem;
    border-radius: 6px;
    letter-spacing: .02em;
}

.icd10-browse .i10-node-title-en {
    font-size: .9rem;
    color: var(--i10-ink);
    line-height: 1.35;
}

.icd10-browse .i10-node-title-th {
    display: block;
    font-size: .82rem;
    color: var(--i10-accent-strong);
    line-height: 1.5;
    margin-top: .05rem;
}

.icd10-browse .i10-node-title-th.missing {
    color: var(--i10-ink-3);
    font-style: italic;
}

.icd10-browse .i10-kind-chapter > .i10-node-row .i10-node-title-en {
    font-weight: 600;
}

.icd10-browse .i10-detail {
    padding: 1.4rem 1.7rem;
}

.icd10-browse .i10-head-row {
    overflow: hidden;
    margin-bottom: .6rem;
}

.icd10-browse .i10-head-row .i10-backbtn,
.icd10-browse .i10-head-row .i10-kind-pill,
.icd10-browse .i10-head-row .i10-kind-code {
    float: left;
    margin: 0 .6rem .4rem 0;
}

.icd10-browse .i10-backbtn {
    display: inline-flex;
    width: auto;
    min-height: 0;
    align-items: center;
    gap: .35rem;
    font-size: .83rem;
    color: var(--i10-ink-2);
    background: transparent;
    border: 1px solid var(--i10-border-strong);
    border-radius: 8px;
    padding: .32rem .7rem;
    cursor: pointer;
    transition: background .12s, border-color .12s;
    flex: 0 0 auto;
}

.icd10-browse .i10-backbtn:hover:not(:disabled) {
    background: var(--i10-accent-soft);
    border-color: var(--i10-accent-line);
    color: var(--i10-accent-strong);
}

.icd10-browse .i10-backbtn:disabled {
    opacity: .4;
    cursor: default;
}

.icd10-browse .i10-kind-pill {
    display: inline-block;
    flex: 0 0 auto;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--i10-ink-2);
    background: var(--i10-surface-2);
    border: 1px solid var(--i10-border-strong);
    padding: .16rem .5rem;
    border-radius: 6px;
}

.icd10-browse .i10-kind-code {
    display: inline-block;
    flex: 0 0 auto;
    font-family: Consolas, monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--i10-accent), var(--i10-accent-strong));
    padding: .26rem .8rem;
    border-radius: 9px;
    letter-spacing: .02em;
    box-shadow: 0 2px 6px rgba(13, 148, 136, .35);
}

.icd10-browse .i10-title-en {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.35;
    margin: .1rem 0 0;
    letter-spacing: -.01em;
}

.icd10-browse .i10-title-th {
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.5;
    color: var(--i10-accent-strong);
    margin: 0 0 .2rem;
}

.icd10-browse .i10-title-th.missing {
    color: var(--i10-ink-3);
    font-style: italic;
    font-weight: 500;
}

.icd10-browse .i10-eyebrow {
    display: flex;
    gap: .5rem;
    align-items: baseline;
    margin: 1.5rem 0 .5rem;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--i10-ink-3);
}

.icd10-browse .i10-eyebrow .i10-th {
    letter-spacing: .02em;
}

.icd10-browse .i10-eyebrow::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--i10-border);
    align-self: center;
    margin-left: .4rem;
}

.icd10-browse .i10-def-en {
    font-size: .95rem;
    line-height: 1.7;
    color: var(--i10-ink-2);
    margin: 0 0 .7rem;
}

.icd10-browse .i10-def-th {
    font-size: .98rem;
    line-height: 1.85;
    color: var(--i10-ink);
    margin: 0;
}

.icd10-browse .i10-warn {
    margin: 1.1rem 0 0;
    padding: .7rem .9rem;
    font-size: .9rem;
    line-height: 1.6;
    background: #fffbeb;
    border: 1px solid #fde9b8;
    border-radius: 9px;
    color: #7a5b12;
}

.icd10-browse .i10-children-section {
    border: 1px solid var(--i10-border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--i10-surface);
    margin-top: .4rem;
}

.icd10-browse .i10-children-head {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
    padding: 0 .9rem;
    background: var(--i10-surface-2);
    border-bottom: 1px solid var(--i10-border);
}

.icd10-browse .i10-children-label {
    display: flex;
    align-items: center;
    gap: .45rem;
    color: var(--i10-ink-2);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.icd10-browse .i10-count {
    min-width: 24px;
    height: 22px;
    padding: 0 .45rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: var(--i10-accent-soft);
    color: var(--i10-accent-strong);
    font-size: .68rem;
    font-weight: 800;
}

.icd10-browse .i10-hint {
    color: var(--i10-ink-3);
    font-size: .68rem;
}

.icd10-browse .i10-child-list {
    display: flex;
    flex-direction: column;
}

.icd10-browse .i10-child-row {
    width: 100%;
    display: grid;
    grid-template-columns: 100px minmax(0, 1fr) minmax(160px, 320px) 22px;
    align-items: center;
    gap: .75rem;
    min-height: 50px;
    padding: .45rem .75rem;
    border: 0;
    border-bottom: 1px solid var(--i10-border);
    background: var(--i10-surface);
    color: var(--i10-ink);
    text-align: left;
    cursor: pointer;
    transition: background .12s;
}

.icd10-browse .i10-child-row:last-child {
    border-bottom: 0;
}

.icd10-browse .i10-child-row:hover {
    background: var(--i10-accent-soft);
}

.icd10-browse .i10-child-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: max-content;
    min-width: 78px;
    height: 28px;
    padding: 0 .55rem;
    border-radius: 7px;
    background: linear-gradient(135deg, var(--i10-accent), var(--i10-accent-strong));
    color: #fff;
    font-family: Consolas, monospace;
    font-size: .72rem;
    font-weight: 800;
    white-space: nowrap;
}

.icd10-browse .i10-child-name {
    min-width: 0;
    overflow-wrap: break-word;
    font-size: .88rem;
    font-weight: 600;
}

.icd10-browse .i10-child-thai {
    min-width: 0;
    overflow-wrap: break-word;
    color: var(--i10-accent-strong);
    font-size: .82rem;
}

.icd10-browse .i10-child-thai.i10-missing {
    color: var(--i10-ink-3);
    font-style: italic;
}

.icd10-browse .i10-child-row .i10-arrow {
    color: var(--i10-ink-3);
    font-size: 1.1rem;
    text-align: center;
}

@media (max-width: 640px) {
    .icd10-browse .i10-child-row {
        grid-template-columns: 88px minmax(0, 1fr) 20px;
    }

    .icd10-browse .i10-child-thai {
        display: none;
    }

    .icd10-browse .i10-hint {
        display: none;
    }
}

.icd10-browse .i10-placeholder {
    color: var(--i10-ink-3);
    text-align: center;
    padding: 3.5rem 1rem;
    font-size: .95rem;
}

.icd10-browse .i10-spin {
    display: inline-block;
    width: 1.1rem;
    height: 1.1rem;
    border: 2px solid var(--i10-border-strong);
    border-top-color: var(--i10-accent);
    border-radius: 50%;
    animation: icd10Spin .7s linear infinite;
    vertical-align: -.2rem;
}

@keyframes icd10Spin {
    to {
        transform: rotate(360deg);
    }
}

.icd10-browse .i10-fade {
    animation: icd10Fade .25s ease;
}

@keyframes icd10Fade {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.icd10-browse.i10-hide-th .i10-node-title-th,
.icd10-browse.i10-hide-th .i10-title-th,
.icd10-browse.i10-hide-th .i10-def-th,
.icd10-browse.i10-hide-th .i10-child-thai {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .icd10-browse * {
        animation: none !important;
        transition: none !important;
    }
}

@media (max-width: 900px) {
    .icd10-browse .i10-row {
        flex-direction: column;
    }

    .icd10-browse .i10-col-tree {
        flex: none;
        width: 100%;
    }

    .icd10-browse .i10-card {
        height: auto;
        min-height: 360px;
    }
}

.icd10-btn-primary,
.icd10-btn-outline {
    width: auto;
    min-height: 0;
    height: 34px;
    padding: 0 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.icd10-btn-primary {
    border: 0;
    background: var(--accent);
    color: #fff;
}

.icd10-btn-primary:hover {
    background: var(--accent-strong);
}

.icd10-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.icd10-btn-outline {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
}

.icd10-btn-danger {
    border-color: var(--danger);
    color: var(--danger);
    margin-left: auto;
}

.icd10-btn-danger:hover {
    background: var(--danger-bg);
}

.icd10-manage-link {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
}

.icd10-manage-link:hover {
    text-decoration: underline;
}

/* ICD-10 translation manager (?page=icd10_translations) */
.icd10-tm-stats {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    background: var(--info-bg);
    border-radius: 8px;
}

.icd10-tm-batch {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.icd10-tm-batch input[type="number"] {
    width: 80px;
}

.icd10-tm-status-filter {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.icd10-tm-status-filter button {
    width: auto;
    min-height: 0;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
}

.icd10-tm-status-filter button.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.icd10-tm-progress {
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--muted);
    min-height: 16px;
}

.icd10-tm-th-input {
    width: 100%;
    min-width: 200px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.icd10-tm-th-input.has-value {
    background: var(--success-bg);
    border-color: var(--success);
}

.icd10-tm-row-actions {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

.icd10-tm-row-actions button {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 6px;
    cursor: pointer;
}

.icd10-tm-row-actions .icd10-btn-primary {
    height: auto;
}

.icd10-tm-row-actions .icd10-btn-outline {
    height: auto;
    padding: 4px 10px;
}
