body {
    overflow-x: hidden;
    width: 100%;
}

.health-shell {
    max-width: min(88%, 1600px);
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.health-header {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-start;
    margin-bottom: 24px;
}

.health-kicker {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    opacity: 0.75;
    font-size: calc(var(--font-size-controls) * 0.65);
}

.health-header h1,
.health-header .title {
    margin: 0;
    font-size: calc(var(--font-size-title) * 0.72);
    font-family: var(--font-family-main);
    font-weight: var(--font-weight-black);
    line-height: 1;
}

.health-page-intro {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    border: 1px solid var(--border-primary);
    background: color-mix(in srgb, var(--background-primary) 25%, transparent);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.health-page-intro > div {
    flex: 1;
    max-width: 62ch;
}

.health-page-intro p {
    margin: 0;
    font-size: var(--font-size-controls);
    color: var(--text-secondary);
    line-height: 1.5;
}

.health-keyboard-hint {
    margin-top: 0.45rem !important;
    font-size: calc(var(--font-size-controls) * 0.88) !important;
    color: var(--text-tertiary) !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.header-links {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.25rem;
    align-items: center;
    justify-content: flex-end;
}

.back-link {
    text-decoration: none;
    font-size: var(--font-size-controls);
    font-family: var(--font-family-main);
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    transition: color 0.15s ease;
}

.back-link:hover {
    color: var(--text-primary);
}

.back-link-button {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: var(--font-family-main);
}

.health-summary {
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 0.75rem;
}

.health-card {
    border: 1px solid var(--border-primary);
    padding: 0.35rem 0.45rem;
    background: var(--background-primary);
    text-align: left;
    min-width: 0;
}

.health-card-button {
    cursor: pointer;
    font: inherit;
    color: inherit;
    width: 100%;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.health-card-button:hover {
    border-color: var(--text-secondary);
    background: var(--background-secondary);
}

.health-card-button.active {
    border-color: var(--accent-success);
    background: color-mix(in srgb, var(--accent-success) 10%, var(--background-primary));
}

.health-card-label {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.15;
    opacity: 0.72;
    overflow-wrap: anywhere;
}

.health-card-value {
    margin-top: 0.12rem;
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;
}

.health-card-meta {
    display: none;
}

.health-card-good .health-card-value { color: var(--accent-success); }
.health-card-warn .health-card-value { color: var(--accent-warning); }
.health-card-bad .health-card-value { color: var(--accent-error); }

.health-panel,
.health-controls,
.health-issues-panel,
.health-duplicates-panel {
    border: 1px solid var(--border-primary);
    background: var(--background-primary);
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
}

.health-controls {
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.health-controls-filters {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.health-panel .section-title,
.health-filters .section-title {
    margin: 0 0 0.75rem;
    font-size: var(--font-size-text);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    text-transform: lowercase;
    border: none;
    padding: 0;
}

.health-panel .section-title::before,
.health-filters .section-title::before {
    content: '// ';
}

.health-panel-header .section-title {
    margin-bottom: 0;
}

.health-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
}

.health-filter-wrap {
    position: relative;
    flex: 1 1 11rem;
    max-width: 18rem;
    min-width: 8rem;
}

.health-filter-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.26rem 1.55rem 0.26rem 0.45rem;
    border: 1px solid var(--border-primary);
    background: color-mix(in srgb, var(--background-primary) 40%, transparent);
    color: var(--text-primary);
    font-family: var(--font-family-main);
    font-size: var(--font-size-controls);
    outline: none;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.health-filter-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-primary) 25%, transparent);
}

.health-filter-input::placeholder {
    color: var(--text-tertiary);
}

.health-filter-clear {
    position: absolute;
    right: 0.3rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0.15rem 0.35rem;
    color: var(--text-tertiary);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--font-size-controls);
    line-height: 1;
}

.health-filter-clear:hover {
    color: var(--text-secondary);
}

.health-page-filter-wrap--inline {
    flex-shrink: 0;
}

.health-page-filter,
.bulk-select.health-page-filter,
.bulk-select.health-sort-select {
    font-size: calc(var(--font-size-controls) * 0.92);
    padding: 0.22rem 0.35rem;
    border: 1px solid var(--border-primary);
    background: var(--background-primary);
    color: var(--text-primary);
    font-family: inherit;
    cursor: pointer;
}

.health-page-filter {
    min-width: 7.5rem;
    max-width: 11rem;
}

.health-duplicate-items small {
    opacity: 0.75;
    font-style: normal;
}

.health-filter-pills {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.health-period-btn,
.health-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1rem 0.45rem;
    font-size: calc(var(--font-size-controls) * 0.9);
    font-family: var(--font-family-main);
    border: 1px solid var(--border-primary);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.12s, border-color 0.12s, background 0.12s;
    letter-spacing: 0.02em;
}

.health-period-btn:hover,
.health-pill:hover {
    color: var(--text-primary);
    background: color-mix(in srgb, var(--background-secondary) 60%, transparent);
}

.health-period-btn.active,
.health-pill.active,
.health-pill[aria-pressed="true"] {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.health-pill span {
    padding: 0 0.25rem;
    font-size: calc(var(--font-size-controls) * 0.88);
    opacity: 0.85;
}

.health-panel-header {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.4rem;
}

.health-results-count {
    opacity: 0.72;
}

.health-panel-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.health-sort-label {
    font-size: var(--font-size-controls);
    color: var(--text-secondary);
    white-space: nowrap;
}

.health-sort-select {
    font-family: var(--font-family-main);
    font-size: var(--font-size-controls);
    color: var(--text-primary);
    background: var(--background-primary);
    border: 1px solid var(--border-primary);
    padding: 0.2rem 0.4rem;
    cursor: pointer;
}

.health-panel .health-list {
    border: 1px solid var(--border-primary);
}

.health-issues {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.health-selection-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.35rem;
    padding: 0.3rem 0.45rem;
    border: 1px solid var(--border-primary);
    background: color-mix(in srgb, var(--accent-primary) 8%, var(--background-primary));
}

.health-selection-toolbar[hidden] {
    display: none !important;
}

.health-selection-count {
    font-size: var(--font-size-controls);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin-right: 0.25rem;
}

.health-row {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    gap: 0.5rem 0.65rem;
    align-items: start;
    min-width: 0;
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border-primary);
    background: var(--background-primary);
    border-left: 3px solid transparent;
}

.health-row--selected {
    background: color-mix(in srgb, var(--accent-primary) 8%, var(--background-primary));
}

.health-row--focused {
    outline: 1px solid var(--accent-primary);
    outline-offset: -1px;
}

.health-row-select {
    display: flex;
    align-items: center;
    align-self: center;
    margin: 0;
    cursor: pointer;
}

.health-row-checkbox {
    width: 0.95rem;
    height: 0.95rem;
    cursor: pointer;
}

.health-row-leading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.health-row-favicon {
    width: 1.25rem;
    height: 1.25rem;
    object-fit: contain;
    flex-shrink: 0;
    border: 1px solid var(--border-primary);
    background: var(--background-secondary);
}

.health-row-favicon--empty {
    display: block;
    border-radius: 2px;
    opacity: 0.35;
}

.health-row-open {
    display: block;
    width: 100%;
    min-width: 0;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.health-row-open:hover .health-row-name {
    color: var(--accent-primary);
}

.health-row:last-child {
    border-bottom: none;
}

.health-row:hover {
    background: var(--background-secondary);
}

.health-row--broken { border-left-color: var(--accent-error); }
.health-row--duplicate,
.health-row--shortcut-conflict { border-left-color: var(--accent-warning); }
.health-row--unchecked,
.health-row--stale,
.health-row--unused,
.health-row--missing-preview { border-left-color: color-mix(in srgb, var(--accent-warning) 65%, var(--text-secondary)); }
.health-row--healthy { border-left-color: var(--accent-success); }

.health-row-score {
    min-width: 2.5rem;
    height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-black);
    font-size: var(--font-size-controls);
    background: color-mix(in srgb, var(--text-secondary) 10%, var(--background-secondary));
    flex-shrink: 0;
}

.health-row-score.good { color: var(--accent-success); }
.health-row-score.warn { color: var(--accent-warning); }
.health-row-score.bad { color: var(--accent-error); }

.health-row-main {
    min-width: 0;
}

.health-row-name {
    margin: 0;
    font-size: var(--font-size-controls);
    font-weight: var(--font-weight-semibold);
    overflow-wrap: anywhere;
}

.health-row-url {
    margin: 0.2rem 0 0;
    font-size: calc(var(--font-size-controls) * 0.92);
    color: var(--text-secondary);
    word-break: break-all;
    overflow-wrap: anywhere;
}

.health-row-meta,
.health-row-times,
.health-row-reasons,
.health-duplicate-items {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-top: 0.45rem;
}

.health-row-meta span,
.health-row-times span,
.health-row-reasons span,
.health-duplicate-items span {
    padding: 0.15rem 0.45rem;
    background: color-mix(in srgb, var(--text-secondary) 10%, var(--background-secondary));
    font-size: calc(var(--font-size-controls) * 0.88);
    border: 1px solid var(--border-primary);
}

.health-row-status {
    font-weight: var(--font-weight-semibold);
}

.health-row-actions-col {
    flex-shrink: 0;
    align-self: center;
}

.health-row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    justify-content: flex-end;
}

.health-row-actions-primary,
.health-row-actions-secondary {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
}

.health-actions-divider {
    width: 1px;
    height: 1.25rem;
    background: var(--border-primary);
    flex-shrink: 0;
}

.health-btn-with-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.health-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.health-btn-icon svg {
    width: 0.85rem;
    height: 0.85rem;
    fill: currentColor;
    display: block;
}

.health-btn-label {
    white-space: nowrap;
}

.btn-icon-only {
    width: 1.75rem;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.btn-icon-only svg {
    width: 0.85rem;
    height: 0.85rem;
    fill: currentColor;
    display: block;
}

.health-row-actions .btn-icon-only[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.2rem 0.45rem;
    border: 1px solid var(--border-primary);
    background: var(--background-secondary);
    color: var(--text-primary);
    font-size: 0.72rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 20;
}

.health-row-actions .btn-icon-only[data-tooltip]:hover::after {
    opacity: 1;
}

.health-actions-menu-wrap {
    position: relative;
}

.health-actions-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 30;
    min-width: 11rem;
    padding: 0.25rem 0;
    border: 1px solid var(--border-primary);
    background: var(--background-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.health-actions-menu--up {
    top: auto;
    bottom: calc(100% + 4px);
}

.health-actions-menu-item {
    display: block;
    width: 100%;
    padding: 0.45rem 0.65rem;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: var(--font-size-controls);
    text-align: left;
    cursor: pointer;
}

.health-actions-menu-item:hover {
    background: var(--background-secondary);
}

.health-actions-menu-item-danger {
    color: var(--accent-error);
}

.health-actions-menu-item-danger:hover {
    background: color-mix(in srgb, var(--accent-error) 12%, var(--background-primary));
}

.health-actions-menu-label {
    margin: 0.35rem 0.65rem 0.15rem;
    font-size: calc(var(--font-size-controls) * 0.78);
    font-weight: var(--font-weight-semibold);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.health-actions-menu-label-danger {
    margin-top: 0.5rem;
    padding-top: 0.35rem;
    border-top: 1px solid var(--border-primary);
    color: var(--accent-error);
}

.health-action-link {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.health-action-link:hover {
    text-decoration: none;
}

.health-duplicate-item-link {
    margin-left: 0.35rem;
    font-size: 0.85em;
    font-style: normal;
    text-decoration: none;
    opacity: 0.85;
}

.health-duplicate-item-link:hover {
    opacity: 1;
    text-decoration: underline;
}

.health-duplicates.health-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.health-duplicate-group {
    border-bottom: 1px solid var(--border-primary);
    padding: 0.65rem 0.75rem;
    background: var(--background-primary);
    margin-bottom: 0;
}

.health-duplicate-group:last-child {
    border-bottom: none;
}

.health-duplicate-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 10px;
}

.health-duplicate-url {
    font-weight: 700;
    word-break: break-all;
    flex: 1;
}

.health-keep-first-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.health-duplicate-keep {
    border-color: var(--accent-success) !important;
    color: var(--accent-success) !important;
}

.health-duplicate-remove {
    opacity: 0.6;
    text-decoration: line-through;
}

.health-duplicate-badge {
    font-size: 0.7em;
    padding: 1px 5px;
    margin-left: 4px;
    border: 1px solid currentColor;
    vertical-align: middle;
}

.health-duplicate-badge.keep {
    color: var(--accent-success);
}

.health-duplicate-badge.remove {
    color: var(--accent-error);
    text-decoration: none;
}

.health-empty {
    padding: 18px;
    border: 1px dashed var(--border-secondary);
    opacity: 0.78;
}

.health-bulk-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px solid color-mix(in srgb, var(--border-primary) 65%, transparent);
}

.health-issues-panel {
    padding: 0.5rem 0.65rem;
    margin-bottom: 0.5rem;
}

.health-bulk-status {
    margin-top: 0.15rem;
    padding: 0.25rem 0.45rem;
    border: 1px solid var(--border-primary);
    background: var(--background-secondary);
    color: var(--text-secondary);
    font-size: calc(var(--font-size-controls) * 0.92);
}

.health-bulk-status[hidden] {
    display: none !important;
}

body.health-action-busy #health-main {
    cursor: progress;
}

body.health-action-busy #health-main .health-row-actions button,
body.health-action-busy #health-main .health-bulk-toolbar button,
body.health-action-busy #health-header .btn {
    pointer-events: none;
}

@media (max-width: 980px) {
    .health-summary {
        grid-template-columns: repeat(9, minmax(4.5rem, 1fr));
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        padding-bottom: 0.15rem;
    }

    .health-header {
        flex-direction: column;
        gap: 16px;
    }

    .header-links {
        justify-content: flex-start;
    }
}

/* Density modes (classic layout) */
body[data-density-mode="comfortable"] .health-row {
    padding: 0.85rem 0.95rem;
    gap: 0.65rem 0.85rem;
}

body[data-density-mode="dense"] .health-row {
    padding: 0.45rem 0.55rem;
    gap: 0.35rem 0.5rem;
}

body[data-density-mode="comfortable"] .health-card {
    padding: 0.5rem 0.55rem;
}

body[data-density-mode="dense"] .health-card {
    padding: 0.25rem 0.35rem;
}

@media (max-width: 768px) {
    .health-shell {
        padding: 1.25rem 1rem;
    }

    .health-header {
        gap: 12px;
        margin-bottom: 16px;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--border-primary);
    }

    .health-header h1,
    .health-header .title {
        font-size: calc(var(--font-size-title) * 0.55);
    }

    .header-links {
        gap: 0.75rem 1rem;
    }

    .health-row {
        grid-template-columns: auto auto 1fr;
    }

    .health-row-actions-col {
        grid-column: 1 / -1;
        align-self: stretch;
    }

    .health-row-actions {
        justify-content: flex-start;
    }

    .health-row-actions-primary .health-btn-label {
        display: inline;
    }

    .health-row-actions-secondary .health-btn-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .health-actions-divider {
        display: none;
    }
}

@media (max-width: 720px) {
    .health-summary {
        grid-template-columns: repeat(9, minmax(4.25rem, 1fr));
    }
}

/* Merge duplicates picker (AppModal) */
.health-merge-pick-intro {
    margin: 0 0 0.75rem;
    color: var(--text-secondary);
    font-size: var(--font-size-text);
    line-height: 1.45;
}

.health-merge-pick-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    max-height: min(50vh, 22rem);
    overflow-y: auto;
}

.health-merge-pick-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border-primary);
    background: var(--background-primary);
    color: var(--text-primary);
    font: inherit;
    font-size: var(--font-size-controls);
    text-align: left;
    cursor: pointer;
    border-radius: 0.35rem;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.health-merge-pick-btn:hover {
    border-color: var(--accent-primary);
    background: color-mix(in srgb, var(--accent-primary) 8%, var(--background-primary));
}

.health-merge-pick-url {
    font-weight: var(--font-weight-semibold);
    word-break: break-all;
}

.health-merge-pick-names {
    color: var(--text-secondary);
    font-size: calc(var(--font-size-controls) * 0.92);
}

.health-merge-pick-meta {
    color: var(--accent-warning);
    font-size: calc(var(--font-size-controls) * 0.88);
}
