:root {
    --color-bg: #F4F5F7;
    --color-surface: #FFFFFF;
    --color-text: #1A1D21;
    --color-text-muted: #6B7280;
    --color-border: #E5E7EB;
    --color-accent: #F97316;
    --color-accent-hover: #EA580C;
    --color-accent-subtle: #FFF7ED;
    --color-success: #059669;
    --color-error: #DC2626;
    --color-bell: #9CA3AF;
    --header-height: 3.5rem;
    --sidebar-width: 15rem;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
}

a {
    color: var(--color-accent);
}

a:hover {
    color: var(--color-accent-hover);
}

/* --- App shell (authenticated) --- */

body.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    flex-shrink: 0;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    text-decoration: none;
    color: var(--color-text);
    font-weight: 600;
    font-size: 1.125rem;
}

.app-brand:hover {
    color: var(--color-text);
}

.logo-mark {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 6px;
    background: var(--color-accent);
    flex-shrink: 0;
}

.app-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-shell {
    flex: 1;
    display: flex;
    min-height: 0;
}

.app-sidebar {
    flex-shrink: 0;
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 1rem 0;
}

.app-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-main {
    flex: 1;
    padding: 1.5rem 1.75rem;
    overflow-x: auto;
}

.app-footer {
    flex-shrink: 0;
    padding: 0.75rem 1.75rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

/* --- Sidebar nav --- */

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-nav a {
    display: block;
    padding: 0.5rem 1.25rem;
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.9375rem;
}

.sidebar-nav a:hover {
    background: var(--color-bg);
    color: var(--color-accent-hover);
}

.sidebar-nav a.is-active {
    background: var(--color-accent-subtle);
    color: var(--color-accent-hover);
    font-weight: 500;
    border-right: 3px solid var(--color-accent);
}

/* --- Header dropdowns (details/summary) --- */

.header-dropdown {
    position: relative;
}

.header-dropdown > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    font: inherit;
}

.header-dropdown > summary::-webkit-details-marker {
    display: none;
}

.header-dropdown > summary:hover {
    background: var(--color-bg);
}

.header-dropdown[open] > summary {
    background: var(--color-bg);
    border-color: var(--color-border);
}

.header-dropdown-panel {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    min-width: 12rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    z-index: 100;
    padding: 0.375rem 0;
}

.header-dropdown-panel--wide {
    min-width: 16rem;
}

.header-dropdown-title {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.25rem;
}

.header-dropdown-empty {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin: 0;
}

.header-dropdown-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.header-dropdown-menu a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.9375rem;
}

.header-dropdown-menu a:hover {
    background: var(--color-bg);
}

.user-menu-item--switch {
    border-top: 1px solid var(--color-border);
    margin-top: 0.25rem;
    padding-top: 0.25rem;
}

.agency-switcher > summary {
    list-style: none;
    cursor: pointer;
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.9375rem;
    color: var(--color-text);
}

.agency-switcher > summary::-webkit-details-marker {
    display: none;
}

.agency-switcher > summary:hover {
    background: var(--color-bg);
}

.agency-switcher-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--color-border);
}

.agency-switch-form {
    margin: 0;
}

.agency-switch-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 1.5rem;
    border: none;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}

.agency-switch-option:hover {
    background: var(--color-bg);
}

.agency-switch-option.is-current {
    background: var(--color-accent-subtle);
    color: var(--color-accent);
    font-weight: 500;
}

.agency-switch-check {
    margin-left: 0.5rem;
    font-size: 0.75rem;
}

.account-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

.notif-bell-icon {
    width: 1.25rem;
    height: 1.25rem;
    color: var(--color-bell);
}

.user-menu-trigger {
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
    color: var(--color-text);
}

/* --- Guest layout (login) --- */

body.guest {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.guest-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 1.5rem;
    text-decoration: none;
    color: var(--color-text);
    font-weight: 600;
    font-size: 1.25rem;
}

.guest-card {
    width: 100%;
    max-width: 24rem;
    padding: 1.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

/* --- Content --- */

h1 {
    margin: 0 0 1rem;
    font-size: 1.5rem;
    font-weight: 600;
}

h2 {
    margin: 1.5rem 0 0.75rem;
    font-size: 1.125rem;
    font-weight: 600;
}

p {
    margin: 0 0 0.75rem;
}

.flash-stack {
    margin-bottom: 1rem;
}

.flash-success,
.flash-error {
    padding: 0.625rem 0.875rem;
    border-radius: 6px;
    margin: 0 0 0.5rem;
    font-size: 0.9375rem;
}

.flash-success {
    color: var(--color-success);
    background: #ECFDF5;
    border: 1px solid #A7F3D0;
}

.flash-error {
    color: var(--color-error);
    background: #FEF2F2;
    border: 1px solid #FECACA;
}

table {
    border-collapse: collapse;
    width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    overflow: hidden;
}

th,
td {
    border-bottom: 1px solid var(--color-border);
    padding: 0.625rem 0.75rem;
    text-align: left;
}

th {
    background: var(--color-bg);
    font-weight: 600;
    font-size: 0.875rem;
}

tr:last-child td {
    border-bottom: none;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    font-size: 0.85rem;
}

button,
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    font: inherit;
    font-size: 0.9375rem;
    color: var(--color-surface);
    background: var(--color-accent);
    border: 1px solid var(--color-accent);
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
}

button:hover,
.btn:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    color: var(--color-surface);
}

input[type="email"],
input[type="password"],
input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.625rem;
    font: inherit;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
}

label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
}

form p {
    margin-bottom: 1rem;
}

.page-actions {
    margin-bottom: 1rem;
}

.page-actions a {
    margin-right: 0.75rem;
}

.status-success {
    color: var(--color-success);
    font-weight: 600;
}

.status-warning {
    color: var(--color-error);
    font-weight: 600;
}

.fleet-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.fleet-stat-card {
    padding: 1rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.fleet-stat-label {
    display: block;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 0.35rem;
}

.fleet-stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.2;
}

.attention-site-list {
    margin: 0 0 1rem;
    padding-left: 1.25rem;
}

.attention-site-list li {
    margin-bottom: 0.35rem;
}

.attention-site-meta {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.fleet-filter {
    margin-bottom: 1rem;
    max-width: 24rem;
}

.fleet-table-toolbar {
    margin-bottom: 1rem;
}

.fleet-filter-row {
    max-width: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: center;
}

.fleet-filter-row label {
    margin-right: 0.25rem;
}

.fleet-visible-count {
    margin: 0 0 0.75rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.fleet-table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.25rem;
}

.fleet-table-scroll-hint {
    margin: 0 0 1rem;
}

.fleet-table {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
}

.fleet-table .fleet-col-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fleet-table .fleet-col-site {
    width: 15rem;
    max-width: 15rem;
    min-width: 15rem;
}

.fleet-site-cell {
    min-width: 0;
    max-width: 15rem;
}

.fleet-site-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fleet-site-name a {
    font-weight: 500;
}

.fleet-site-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.15rem 0.35rem;
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.fleet-site-actions > :not(:first-child)::before {
    content: '·';
    margin-right: 0.35rem;
    color: var(--color-text-muted);
    text-decoration: none;
}

.fleet-site-actions a {
    text-decoration: none;
}

.fleet-site-actions a:hover {
    text-decoration: underline;
}

.fleet-site-actions .fleet-site-action-form {
    display: inline-flex;
    align-items: baseline;
    margin: 0;
    padding: 0;
    border: 0;
}

.fleet-site-actions a.fleet-site-action-link--danger {
    color: var(--color-text-muted);
}

.fleet-site-actions a.fleet-site-action-link--danger:hover {
    color: var(--color-error);
}

.fleet-table .fleet-col-profile {
    max-width: 10rem;
}

.fleet-table .fleet-col-status {
    white-space: nowrap;
}

.fleet-table .fleet-col-select {
    width: 2.5rem;
}

.fleet-table .fleet-col-sticky-left {
    position: sticky;
    z-index: 1;
    background: var(--color-surface);
}

.fleet-table thead .fleet-col-sticky-left {
    z-index: 3;
    background: var(--color-bg);
}

.fleet-table .fleet-col-select.fleet-col-sticky-left {
    left: 0;
}

.fleet-table .fleet-col-site.fleet-col-sticky-left {
    left: 2.5rem;
    box-shadow: 4px 0 8px -4px rgba(15, 23, 42, 0.08);
}

.fleet-bulk-actions--danger {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

@media (max-width: 1200px) {
    .fleet-table .fleet-col-compact {
        display: none;
    }
}

.fleet-sort {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-weight: 600;
    color: inherit;
    cursor: pointer;
    text-align: left;
}

.fleet-sort:hover {
    text-decoration: underline;
}

.fleet-sort--asc::after {
    content: ' ↑';
    font-size: 0.75rem;
}

.fleet-sort--desc::after {
    content: ' ↓';
    font-size: 0.75rem;
}

.fleet-bulk-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.fleet-bulk-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: center;
}

.fleet-bulk-actions {
    margin-top: 0.5rem;
}

.fleet-bulk-preview {
    margin-bottom: 1.5rem;
}

.queue-bulk-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.queue-bulk-actions {
    margin-top: 0.5rem;
}

.queue-select-col {
    width: 2.5rem;
    text-align: center;
}

.queue-pending-form,
.queue-failed-form {
    margin-bottom: 0.5rem;
}

.form-help {
    margin-top: 0.35rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.inline-form {
    display: inline-block;
    margin-left: 0.75rem;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-danger {
    background: #b42318;
    color: #fff;
    border-color: #b42318;
}

.btn-danger:hover {
    background: #912018;
    color: #fff;
    border-color: #912018;
}

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
}

.snapshot-section {
    margin-top: 2rem;
}

.snapshot-section h2 {
    margin-top: 0;
}

.snapshot-section h3 {
    margin: 1rem 0 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.snapshot-health-list,
.snapshot-alerts {
    list-style: none;
    margin: 0;
    padding: 0;
}

.snapshot-health-line,
.snapshot-alert {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
}

.snapshot-health-line--ok,
.snapshot-alert--info {
    background: #ECFDF5;
    border: 1px solid #A7F3D0;
    color: var(--color-text);
}

.snapshot-health-line--warn,
.snapshot-alert--warning {
    background: #FFF7ED;
    border: 1px solid #FED7AA;
    color: var(--color-text);
}

.snapshot-usage {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 1rem;
    margin: 0;
}

.snapshot-usage dt {
    font-weight: 600;
    font-size: 0.875rem;
}

.snapshot-usage dd {
    margin: 0;
}

.row-update td {
    background: #FFFBEB;
}

.badge-warn {
    background: #FFF7ED;
    border-color: #FED7AA;
    color: #C2410C;
}

.snapshot-raw {
    margin-top: 2rem;
}

.snapshot-raw pre {
    overflow-x: auto;
    padding: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.8125rem;
}

.badge-info {
    background: #EFF6FF;
    border-color: #BFDBFE;
    color: #1D4ED8;
}

.queue-pending-banner {
    background: #FFFBEB;
    border: 1px solid #FED7AA;
    border-radius: 6px;
    padding: 0.75rem 1rem;
}

.queue-status-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.fleet-bulk-refresh .inline-form p {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.catalog-tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin: 0.75rem 0 1.25rem;
    padding: 0.3125rem;
    background: #E5E7EB;
    border-radius: 10px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.catalog-tabs__link {
    display: inline-block;
    padding: 0.5rem 1.125rem;
    border-radius: 7px;
    text-decoration: none;
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: 0.9375rem;
    line-height: 1.25;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.catalog-tabs__link:hover {
    color: var(--color-text);
    background: rgba(255, 255, 255, 0.55);
}

.catalog-tabs__link.is-active {
    color: var(--color-text);
    font-weight: 600;
    background: var(--color-surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.catalog-tabs__link:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.extensions-section-title {
    margin: 0 0 1rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.badge-artifact--ok {
    background: #ECFDF5;
    border-color: #A7F3D0;
    color: var(--color-success);
}

.badge-artifact--missing {
    background: #FEF2F2;
    border-color: #FECACA;
    color: var(--color-error);
}

.badge-artifact--not_configured {
    background: #F3F4F6;
    border-color: var(--color-border);
    color: var(--color-text-muted);
}

.artifact-path {
    display: block;
    font-size: 0.75rem;
    margin-top: 0.25rem;
    word-break: break-all;
}

.compliance-row--missing td,
.compliance-row--inactive td,
.compliance-row--wrong_theme td {
    background: #FFFBEB;
}

.profile-plugin-checklist {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}

.profile-plugin-checklist li {
    margin-bottom: 0.5rem;
}

.profile-apply-run-list {
    margin: 0.75rem 0 0;
    padding-left: 1.25rem;
}
