/* Seotica design system (loaded by base.html and base_landing.html), in this order:
   1. tokens (tokens.css)  2. base  3. app shell (sidebar, panel, header)  4. components  5. utilities  6. status tags.
   Every page is built from the components of section 4:
     .page > .page-header (.page-title, .page-subtitle, .page-actions) · .card (.card-header, .card-body)
     .kpis > .card.kpi · .toolbar · .pills > .pill · .tabs · .table · .tag (.tag-*, .status-*) · .empty-state
     .grid-2 / .grid-3 · .cell-input · .search-field · showToast() in base.html
   Page-specific rules (only what these do not cover) are in pages.css, scoped by the page class on <body>. */

/* ==========================================================================
   1. Tokens: static/css/tokens.css (linked before this file). Here only what Bootstrap 5.3 reads: its
   components on our palette and shapes.
   ========================================================================== */
:root {
    --bs-secondary-color: var(--text-secondary);         /* .text-muted, form text */
    --bs-border-radius: .25rem;
    --bs-border-radius-sm: .2rem;
    --bs-border-radius-lg: .3rem;
}

.form-check-input { --bs-border-color: rgba(0, 0, 0, .25); }
.list-group { --bs-list-group-action-color: var(--bs-body-color, var(--text-primary)); --bs-list-group-border-color: rgba(0, 0, 0, .125); }

.alert-primary { --bs-alert-color: var(--blue-800); }

/* ==========================================================================
   2. Base
   ========================================================================== */
body {
    background-color: var(--bg-app);
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: 1.4;
}
a { color: var(--primary-color); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }
h1 { font-size: var(--font-size-xl); }
h2 { font-size: 1.125rem; }
h3 { font-size: var(--font-size-lg); }
h4 { font-size: var(--font-size-base); }
h5 { font-size: var(--font-size-sm); }
h6 { font-size: var(--font-size-xs); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-500); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-600); }
.collapse { transition: height 0.2s ease; }
.fade { transition: opacity 0.1s linear; }
.fas, .far, .fab { font-size: var(--font-size-sm); }
.btn .fas, .btn .far { font-size: var(--font-size-xs); }

/* ==========================================================================
   3. App shell: sidebar, side panel, top header, notifications
   ========================================================================== */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

/* ===== SIDEBAR STYLES ===== */
.se-sidebar {
    width: 80px;
    height: 100vh;
    background: linear-gradient(180deg, var(--shell-from) 0%, var(--shell-to) 100%);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1001;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

/* Logo Section */
.se-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--header-height);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-weight: 600;
    font-size: 1.2rem;
}

.se-logo i {
    font-size: 1.5rem;
}

.se-logo span {
    display: none;
    margin-left: 10px;
}

/* Navigation */
.se-nav {
    padding: 20px 0;
}

.se-nav-item {
    position: relative;
    margin-bottom: 2px;
    opacity: 0;
    animation: slideIn 0.3s ease forwards;
}

.se-nav-item:nth-child(1) { animation-delay: 0.1s; }
.se-nav-item:nth-child(2) { animation-delay: 0.15s; }
.se-nav-item:nth-child(3) { animation-delay: 0.2s; }
.se-nav-item:nth-child(4) { animation-delay: 0.25s; }
.se-nav-item:nth-child(5) { animation-delay: 0.3s; }
.se-nav-item:nth-child(6) { animation-delay: 0.35s; }
.se-nav-item:nth-child(7) { animation-delay: 0.4s; }
.se-nav-item:nth-child(8) { animation-delay: 0.45s; }
.se-nav-item:nth-child(9) { animation-delay: 0.5s; }

@keyframes slideIn {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.se-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 5px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s ease;
    position: relative;
    cursor: pointer;
    min-height: 64px;
    background: transparent;
}

.se-nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--bg-primary);
    text-decoration: none;
}

.se-nav-link.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--bg-primary);
}

.se-nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 32px;
    width: 3px;
    background-color: var(--bg-primary);
    border-radius: 0 3px 3px 0;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.se-nav-link i {
    font-size: 20px;
    margin-bottom: 6px;
    display: block;
    transition: transform 0.2s ease;
}

.se-nav-link:hover i {
    transform: scale(1.1);
}

.se-nav-link span:not(.indicator) {
    font-size: 11px;
    text-align: center;
    line-height: 1.2;
    font-weight: 400;
    opacity: 0.9;
    letter-spacing: 0.3px;
}

/* Indicator */
.indicator {
    position: absolute;
    top: 12px;
    right: 18px;
    width: 6px;
    height: 6px;
    background-color: var(--green-500);
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 6px rgba(74, 222, 128, 0.6); }
    50% { box-shadow: 0 0 12px rgba(74, 222, 128, 0.8); }
}

/* Expandable Panel */
.se-panel {
    position: fixed;
    left: 80px;
    top: 0;
    width: 260px;
    height: 100vh;
    background: var(--bg-primary);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.1);
    transform: translateX(-100%);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    overflow-y: auto;
    border-right: 1px solid var(--gray-200);
}

.se-panel.show {
    transform: translateX(0);
}

/* When panel is shown, add margin to wrapper */
.se-panel.show ~ .app-wrapper {
    margin-left: 340px; /* 80px sidebar + 260px panel */
}

.se-panel-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.se-panel-header h5 {
    margin: 0;
    color: var(--gray-800);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.panel-close {
    background: none;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.panel-close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

/* Panel Navigation */
.panel-nav-section {
    padding: 16px 0;
    border-bottom: 1px solid var(--gray-100);
}

.panel-nav-section:last-child {
    border-bottom: none;
}

.panel-section-title {
    color: var(--gray-400);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 0 20px 12px;
    font-weight: 600;
    margin: 0;
}

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

.panel-nav-item {
    margin: 0;
}

.panel-nav-link {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: var(--gray-600);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s ease;
    position: relative;
}

.panel-nav-link:hover {
    background-color: var(--gray-50);
    color: var(--gray-800);
    padding-left: 24px;
    text-decoration: none;
}

.panel-nav-link i {
    width: 20px;
    margin-right: 12px;
    font-size: 14px;
    color: var(--gray-400);
}

.panel-nav-link:hover i {
    color: var(--primary-color);
}

.panel-badge {
    margin-left: auto;
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 600;
}

.panel-badge.beta {
    background-color: var(--primary-subtle);
    color: var(--primary-dark);
}

/* A menu item that is not built yet */
.panel-nav-link.is-soon, .panel-nav-link.is-soon:hover { color: var(--gray-400); cursor: default; padding-left: 20px; background: none; }
.panel-nav-link.is-soon:hover i { color: var(--gray-400); }
.panel-badge.soon, .panel-nav-link.is-soon .panel-badge { background-color: var(--gray-100); color: var(--gray-500); }

/* Expanded state for sidebar */
.se-sidebar.expanded {
    width: 200px;
}

.se-sidebar.expanded .se-logo span {
    display: block;
}

.se-sidebar.expanded .se-nav-link {
    flex-direction: row;
    justify-content: flex-start;
    padding: 12px 20px;
}

.se-sidebar.expanded .se-nav-link i {
    margin-bottom: 0;
    margin-right: 12px;
}

.se-sidebar.expanded .se-nav-link span:not(.indicator) {
    font-size: 14px;
    opacity: 1;
}

/* Update panel position when sidebar is expanded */
.se-sidebar.expanded ~ .se-panel {
    left: 200px;
}

/* Add expand button */
.sidebar-expand-btn {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sidebar-expand-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.se-sidebar.expanded .sidebar-expand-btn {
    transform: translateX(-50%) rotate(180deg);
}

/* Mobile Backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

.sidebar-backdrop.show {
    display: block;
}

/* Main Layout with Sidebar */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    margin-left: 80px;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.se-sidebar.expanded ~ .app-wrapper {
    margin-left: 200px;
}

.app-content {
    flex: 1;
    min-width: 0;  /* a wide table scrolls in its own box instead of stretching the page (and the navbar) */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Navbar Styles */
.navbar {
    /* Bootstrap's navbar colours, as variables: no need to outrank .navbar-dark */
    --bs-navbar-color: var(--text-light);
    --bs-navbar-hover-color: white;
    --bs-navbar-active-color: white;
    --bs-navbar-brand-color: white;
    --bs-navbar-brand-hover-color: white;
    --bs-navbar-nav-link-padding-x: 1rem;
    background-color: var(--shell-header);
    position: sticky;
    top: 0;
    width: 100%;
    z-index: 900;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-height: var(--header-height);
    padding: var(--spacing-sm) var(--spacing-md);
}

.navbar-brand {
    font-weight: 600;
    font-size: var(--font-size-lg);
    padding: var(--spacing-xs) 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-brand i {
    font-size: 1.5rem;
}

.navbar .nav-link {
    padding: 0.5rem 1rem;
    font-size: var(--font-size-sm);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar .nav-link:hover {
    background-color: rgba(255,255,255,0.1);
    border-radius: 0.25rem;
}

/* Project Switcher Styles */
/* first in the header, beside the sidebar (the actions take the right) */
.project-switcher {
    position: relative;
    margin-right: 20px;
}

.project-switcher-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
    min-width: 200px;
}

.project-switcher-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.project-switcher-toggle .project-info {
    flex: 1;
    text-align: left;
}

.project-switcher-toggle .project-name {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
}

.project-switcher-toggle .project-domain {
    font-size: 12px;
    opacity: 1;  /* 0.8 (and 0.95) on the header blue was below WCAG AA (4.5:1) at 12px */
    margin-top: 2px;
}

.project-switcher-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    max-height: 400px;
    overflow-y: auto;
    min-width: 280px;
}

.project-switcher.show .project-switcher-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.project-search {
    padding: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.project-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-size: 14px;
}

.project-search input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.project-list {
    padding: 8px;
}

.project-list-title {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--gray-500);
    padding: 8px 12px 4px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.project-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
    text-decoration: none;
    color: var(--gray-800);
    margin-bottom: 2px;
}

.project-item:hover {
    background: var(--gray-100);
    text-decoration: none;
    color: var(--gray-800);
}

.project-item.active {
    background: var(--primary-subtle);
    color: var(--primary-dark);
}

.project-item .project-icon {
    width: 40px;
    height: 40px;
    background: var(--gray-200);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-size: 18px;
    color: var(--gray-500);
}

.project-item.active .project-icon {
    background: var(--primary-light);
    color: white;
}

.project-item .project-details {
    flex: 1;
}

.project-item .project-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.project-item .project-domain {
    font-size: 12px;
    color: var(--gray-500);
}

.project-item .project-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--gray-500);
}

.project-item .project-stats span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.create-project-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    margin: 8px;
    width: calc(100% - 16px);
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.create-project-btn:hover {
    background: var(--primary-dark);
}

/* Header actions (notifications, user menu): one 40px row, centred on the same line */
.navbar .header-actions {
    --header-control: 40px;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.header-actions > .nav-item {
    display: flex;
    align-items: center;
}

/* the menu button and the logo are the phone's (below 768px the sidebar, with its own logo, is hidden) */
.header-menu-btn,
.navbar-brand-mobile {
    display: none;
}

/* Notification Styles */
.notifications-wrapper {
    position: relative;
    display: flex;
}

.notifications-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--header-control);
    height: var(--header-control);
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-light);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.notifications-toggle:hover,
.notifications-wrapper.show .notifications-toggle {
    color: white;
    background: rgba(255, 255, 255, 0.12);
}

.notifications-toggle:focus-visible,
.user-menu-toggle:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* the count on the bell's top right corner, ringed with the navbar colour so it reads over the icon */
.notifications-badge {
    position: absolute;
    top: 3px;
    right: -1px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--danger-color);
    box-shadow: 0 0 0 2px var(--primary-color);
    color: white;
    font-size: 10px;
    font-weight: 700;
    line-height: 17px;
    text-align: center;
}

/* User menu: avatar (initial) + name, as tall as the bell */
.navbar .user-menu-toggle {
    height: var(--header-control);
    padding: 0 0.625rem 0 0.25rem;
    border-radius: calc(var(--header-control) / 2);
    gap: 0.5rem;
}

.user-avatar {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
}

.user-menu-name {
    color: var(--white);  /* the navbar's rgba(255,255,255,.55) fails WCAG AA on the brand blue */
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.navbar .user-menu-toggle,
.navbar .user-menu-toggle:hover,
.navbar .user-menu-toggle:focus {
    text-decoration: none;
}

.user-menu {
    min-width: 240px;
}

/* icons of one width: the item labels start on one line */
.user-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.user-menu .dropdown-item i {
    width: 1.125rem;
    text-align: center;
    color: var(--gray-500);
}

.user-menu-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
}

.user-menu-header .user-avatar-lg {
    width: 40px;
    height: 40px;
    background: var(--primary-subtle);
    color: var(--primary-color);
    font-size: 16px;
}

.user-menu-identity {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-menu-fullname {
    font-weight: 600;
    color: var(--gray-800);
}

.user-menu-email {
    font-size: 12px;
    color: var(--gray-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notifications-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 360px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    max-height: 480px;
    display: flex;
    flex-direction: column;
}

.notifications-wrapper.show .notifications-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.notifications-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notifications-header h6 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--gray-800);
}

.notifications-header .mark-all-read {
    font-size: 12px;
    color: var(--primary-color);
    cursor: pointer;
    text-decoration: none;
}

.notifications-header .mark-all-read:hover {
    text-decoration: underline;
}

.notifications-list {
    flex: 1;
    overflow-y: auto;
}

.notification-item {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}

a.notification-item { display: block; color: inherit; text-decoration: none; }
.notification-item:hover {
    background: var(--gray-50);
}

.notification-item.unread {
    background: var(--primary-subtle);
}

.notification-item.unread::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: var(--info-color);
    border-radius: 50%;
}

.notification-item .notification-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    float: left;
    margin-right: 12px;
}

.notification-item .notification-icon.success {
    background: var(--success-subtle);
    color: var(--success-color);
}

.notification-item .notification-icon.warning {
    background: var(--amber-300);
    color: var(--orange-500);
}

.notification-item .notification-icon.error {
    background: var(--danger-subtle);
    color: var(--danger-color);
}

.notification-item .notification-icon.info {
    background: var(--primary-subtle);
    color: var(--info-color);
}

.notification-item .notification-content {
    overflow: hidden;
}

.notification-item .notification-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--gray-800);
    margin-bottom: 4px;
}

.notification-item .notification-text {
    font-size: 13px;
    color: var(--gray-500);
    line-height: 1.4;
}

.notification-item .notification-time {
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 4px;
}

.notifications-footer {
    padding: 12px;
    border-top: 1px solid var(--gray-200);
    text-align: center;
}

.notifications-footer a {
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.notifications-footer a:hover {
    text-decoration: underline;
}

/* Content Wrapper */
.content-wrapper {
    flex: 1;
    background-color: var(--bg-app);
    overflow-x: hidden;
}

/* Search Bar in Header */
.header-search {
    position: relative;
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.header-search-input {
    width: 100%;
    padding: 8px 36px 8px 40px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-size: 14px;
    transition: all 0.2s ease;
}

.header-search-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.header-search-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.header-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.6);
    pointer-events: none;
}

/* the native clear button of type=search: hidden, Escape clears */
.header-search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

/* the "/" shortcut hint, gone while typing */
.header-search-key {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    padding: 1px 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-family: inherit;
    font-size: 11px;
    pointer-events: none;
}

.header-search-input:focus ~ .header-search-key,
.header-search-input:not(:placeholder-shown) ~ .header-search-key {
    display: none;
}

.header-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    min-width: 360px;
    max-height: min(70vh, 520px);
    overflow-y: auto;
    padding: 6px;
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    z-index: 1060;
}

.header-search-group + .header-search-group {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--gray-100);
}

.header-search-group-title {
    padding: 6px 10px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--gray-500);
}

.header-search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    color: var(--gray-800);
    text-decoration: none;
}

.header-search-item:hover,
.header-search-item.active {
    background: var(--primary-subtle);
    color: var(--gray-900);
    text-decoration: none;
}

.header-search-item > i {
    width: 16px;
    text-align: center;
    color: var(--gray-400);
}

.header-search-item.active > i {
    color: var(--primary-color);
}

.header-search-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
}

.header-search-label mark {
    padding: 0;
    background: none;
    color: inherit;
    font-weight: 700;
}

.header-search-hint {
    margin-left: auto;
    flex-shrink: 0;
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--gray-500);
}

.header-search-empty {
    padding: 14px 10px;
    font-size: 13px;
    color: var(--gray-500);
    text-align: center;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .se-sidebar, .se-sidebar.expanded {
        left: -200px;
        width: 200px;
    }

    .se-sidebar.show {
        left: 0;
        z-index: 1045;
    }

    .se-sidebar.show .se-logo span {
        display: block;
    }

    .se-sidebar.show .se-nav-link {
        flex-direction: row;
        justify-content: flex-start;
        padding: 12px 20px;
    }

    .se-sidebar.show .se-nav-link i {
        margin-bottom: 0;
        margin-right: 12px;
    }

    .se-sidebar.show .se-nav-link span:not(.indicator) {
        font-size: 14px;
    }

    .app-wrapper, .se-sidebar.expanded ~ .app-wrapper {
        margin-left: 0;
    }

    .se-panel.show ~ .app-wrapper {
        margin-left: 0;
    }

    .sidebar-expand-btn {
        display: none;
    }

    /* header: menu, logo, the project (takes the room left), bell, avatar */
    .navbar {
        padding: 8px 12px;
        min-height: 48px;  /* no sidebar beside it on a phone */
    }

    .navbar .container-fluid {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 0;
    }

    .header-menu-btn {
        display: inline-flex;
        flex-shrink: 0;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        padding: 0;
        border: none;
        border-radius: 8px;
        background: transparent;
        color: white;
        font-size: 18px;
    }

    .header-menu-btn:hover,
    .header-menu-btn[aria-expanded="true"] {
        background: rgba(255, 255, 255, 0.12);
    }

    .navbar-brand-mobile {
        display: flex;
        margin-right: 0;
        padding: 0;
    }

    .project-switcher {
        flex: 1 1 auto;
        min-width: 0;
        margin: 0;
    }

    .project-switcher-toggle {
        width: 100%;
        min-width: 0;
        padding: 6px 10px;
        gap: 8px;
    }

    .project-switcher-toggle .project-info {
        min-width: 0;
        text-align: left;
    }

    .project-switcher-toggle .project-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .project-switcher-toggle .project-domain {
        display: none;
    }

    /* the screen's width under the header (from the switcher's left it went past the edge, even hidden) */
    .project-switcher-dropdown {
        position: fixed;
        top: 60px;
        left: 12px;
        right: 12px;
        width: auto;
    }

    .navbar .header-actions {
        flex-shrink: 0;
        gap: 2px;
    }

    /* the avatar alone: the name is in its menu */
    .user-menu-name,
    .navbar .user-menu-toggle::after {
        display: none;
    }

    .navbar .user-menu-toggle {
        padding: 0 4px;
    }

    .notifications-dropdown {
        width: min(360px, calc(100vw - 24px));
    }

    .header-search {
        display: none;
    }

    /* a section's panel covers the menu (it opened beside it, past the screen's edge) */
    .se-panel {
        left: 0;
        width: min(320px, 100vw);
        z-index: 1046;
    }

    .se-panel.show {
        left: 0;
    }
}

html { scroll-behavior: smooth; }

/* ==========================================================================
   4. Components — the one set of building blocks every page is made of.
   Bootstrap classes (btn, card, table, badge, form-*) are styled here once;
   the rest (page, kpi, pills, tabs, tag, empty-state, toolbar) are ours.
   ========================================================================== */

/* Buttons */
.btn { border-radius: var(--radius-sm); font-size: var(--font-size-sm); font-weight: 500;
       padding: var(--btn-padding-y-sm) var(--btn-padding-x-sm); transition: all 0.2s ease;
       display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn-sm { font-size: var(--font-size-xs); padding: 3px 8px; }
.btn-lg { font-size: var(--font-size-base); padding: 8px 16px; }

.btn-link { padding-left: 0; padding-right: 0; }
.btn-primary { background-color: var(--primary-color); border-color: var(--primary-color); color: var(--bg-primary); }
.btn-primary:hover { background-color: var(--primary-dark); border-color: var(--primary-dark); color: var(--bg-primary); }

.btn-light { background: var(--bg-primary); border-color: var(--gray-300); color: var(--gray-700); }
.btn-light:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--gray-900); }

/* Forms */
.form-label { font-size: var(--font-size-sm); font-weight: 500; margin-bottom: var(--spacing-xs); color: var(--gray-700); }
.form-control, .form-select { font-size: var(--font-size-sm); padding: var(--spacing-xs) var(--spacing-sm); min-height: var(--input-height-sm);
                              border-color: var(--gray-300); border-radius: var(--radius-sm); }
.form-select { padding-right: 28px; }
.form-control-sm, .form-select-sm { font-size: var(--font-size-xs); min-height: 28px; }

textarea.form-control { height: auto; }
.form-control:focus, .form-select:focus { border-color: var(--primary-color); box-shadow: 0 0 0 0.2rem rgba(0, 102, 204, 0.2); }
.form-text { font-size: var(--font-size-xs); margin-top: var(--spacing-xs); }

/* Page: <div class="page"> → .page-header (.page-title, .page-subtitle, .page-actions) → content */
.page { padding: 20px 24px 32px; }
.page-narrow { max-width: 1100px; }
.page-medium { max-width: 1320px; }
.page-wide { max-width: 1600px; }
.page-narrow, .page-medium, .page-wide { margin-left: auto; margin-right: auto; }
.page-header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 16px; }
.page-title { font-size: 1.35rem; font-weight: 600; color: var(--text-primary); margin: 0; display: flex; align-items: center; gap: 8px; }
.page-title > i { color: var(--primary-color); font-size: 1.1rem; }
.page-subtitle { color: var(--text-secondary); font-size: var(--font-size-sm); margin: 2px 0 0; }
.page-subtitle a { text-decoration: underline; } /* a link in text is not told by its colour alone */
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }

.section-title { font-size: var(--font-size-base); font-weight: 600; margin: 0 0 var(--spacing-md); display: flex; align-items: center; gap: 8px; }
@media (max-width: 768px) { .page { padding: 12px; } .page-actions { margin-left: 0; } }

/* Cards: the one surface for panels, widgets, tables and charts */
.card { border: 1px solid var(--border-color); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); margin-bottom: var(--spacing-lg); background: var(--bg-primary); }
.card > .table-responsive:last-child, .card > .table:last-child { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-header { background-color: transparent; border-bottom: 1px solid var(--border-color); font-weight: 600;
               padding: 10px var(--spacing-lg); font-size: var(--font-size-base);
               display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.card-header:first-child { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.card-header > .card-title:not(:last-child) { margin-right: auto; }
.card-title { font-size: var(--font-size-base); font-weight: 600; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-body { padding: var(--spacing-lg); }

/* Grids of cards */
.grid-2 { display: grid; gap: 16px; margin-bottom: var(--spacing-lg); grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }

.grid-2 > .card { margin-bottom: 0; }

/* KPI tiles: <div class="kpis"><div class="card kpi"><div class="kpi-label">…<div class="kpi-value">… */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: var(--spacing-lg); }
.kpis > .card { margin-bottom: 0; }
.kpi { padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi-icon { width: 36px; height: 36px; border-radius: var(--radius); display: inline-grid; place-items: center;
            background: var(--primary-subtle); color: var(--primary-color); margin-bottom: 6px; }
.kpi-label { font-size: var(--font-size-xs); color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi-sub { font-size: var(--font-size-xs); color: var(--text-secondary); }
.kpi .spark { height: 40px; margin-top: 6px; }
.up, .table > :not(caption) > * > .up { color: var(--success-dark); }
.down, .table > :not(caption) > * > .down { color: var(--danger-color); }
.flat { color: var(--text-tertiary); }

/* Pills: segmented filters, date ranges, chip filters (.pill.active, optional .count inside) */
.pills { display: flex; flex-wrap: wrap; gap: 6px; } /* white on it: 4.5:1 (was 3.5) */

/* Tabs: underlined (links or buttons with .active) */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--border-color); margin-bottom: var(--spacing-lg); }
.tabs > a, .tabs > button, .tab { padding: 8px 14px; color: var(--gray-600); background: none; border: 0; border-bottom: 2px solid transparent;
        margin-bottom: -1px; font-weight: 500; font-size: var(--font-size-sm); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.tabs > a:hover, .tabs > button:hover, .tab:hover { color: var(--text-primary); text-decoration: none; }
.tabs > .active, .tab.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
.card > .tabs { padding: 0 var(--spacing-md); margin-bottom: 0; }

/* Tables */
/* cells take the row's colour and background (Bootstrap 5.3 paints every cell), so row states and colour
   classes on <td> keep working */
.table { --bs-table-color: currentColor; --bs-table-bg: transparent; font-size: var(--font-size-sm); margin-bottom: 0; }
.table > :not(:first-child) { border-top: 0; }
.table th, .table td { padding: 8px 10px; vertical-align: middle; border-color: var(--border-color); }
.table thead th { font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; font-size: var(--font-size-xs);
                  color: var(--text-secondary); background: var(--gray-50); white-space: nowrap; border-bottom-width: 1px; }

.table tr.selected > * { background: var(--primary-subtle); }

/* an inline-edited cell that looks like text until hovered or focused */
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--text-primary); }
@media (max-width: 768px) { .table { font-size: var(--font-size-xs); } }

/* Tags: small soft-coloured labels for statuses and categories */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-full); font-size: .7rem;
       font-weight: 600; line-height: 1.5; white-space: nowrap; background: var(--gray-100); color: var(--gray-600); }
.tag-primary { background: var(--primary-subtle); color: var(--primary-dark); }
.tag-info { background: var(--info-subtle); color: var(--info-text); }
.tag-success { background: var(--success-subtle); color: var(--success-text); }
.tag-warning { background: var(--warning-subtle); color: var(--warning-text); }
.tag-danger { background: var(--danger-subtle); color: var(--danger-text); }
.tag .btn-close { width: .45em; height: .45em; padding: 0; margin-left: 2px; background-size: .45em; }

/* Badges and alerts */
.badge {
    --bs-success-rgb: 16, 185, 129; --bs-info-rgb: 59, 130, 246; --bs-primary-rgb: 0, 102, 204;  /* bg-* utilities in our hues */
    font-size: var(--font-size-xs); font-weight: 500; padding: 2px 6px; border-radius: var(--radius-sm);
}
.alert { border: none; border-radius: var(--radius); padding: var(--spacing-sm) var(--spacing-md); font-size: var(--font-size-sm); }
.alert-dismissible .btn-close { padding: var(--spacing-sm); }

/* Toolbar: a row of filters/controls above a table or chart */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin-bottom: var(--spacing-md); }
.toolbar .form-label { font-size: var(--font-size-xs); margin-bottom: 2px; color: var(--text-secondary); }

/* Empty state */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-secondary); }
/* the single row of a table with nothing to show */

.card.empty-state { display: block; }
.empty-state > i { display: block; font-size: 2.25rem; color: var(--gray-300); margin-bottom: 12px; }
.empty-state h3 { font-size: var(--font-size-lg); font-weight: 600; color: var(--text-primary); margin: 0 0 6px; }
.empty-state p { margin: 0 auto 16px; max-width: 460px; }

/* Lists of label/value pairs */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: var(--font-size-sm); }
.kv dt { color: var(--text-secondary); font-weight: 500; }
.kv dd { margin: 0; }

/* Bootstrap leftovers: navigation, overlays, lists */
.breadcrumb { background: transparent; padding: var(--spacing-xs) 0; margin-bottom: var(--spacing-xs); font-size: var(--font-size-sm); }

.dropdown-menu { font-size: var(--font-size-sm); }
.dropdown-item { padding: var(--spacing-xs) var(--spacing-md); }
.pagination { --bs-pagination-font-size: var(--font-size-sm); --bs-pagination-disabled-bg: var(--bg-white); font-size: var(--font-size-sm); margin: 0; }
.page-link { padding: var(--spacing-xs) var(--spacing-sm); }

.list-group-item { padding: var(--spacing-sm) var(--spacing-md); font-size: var(--font-size-sm); }
.tooltip { font-size: var(--font-size-xs); }
.progress { height: 8px; font-size: var(--font-size-xs); background: var(--gray-200); border-radius: var(--radius-full); }
.progress-bar { background-color: var(--primary-color); }

/* ==========================================================================
   5. Utilities
   ========================================================================== */
.text-soft { color: var(--text-tertiary); } /* 4.5:1 on white (WCAG AA); gray-400 was 2.5:1 */
/* Sizes that used to be style="" attributes (the CSP has no 'unsafe-inline' for styles outside the admin;
   values computed per row are data-w / data-bg / data-fg / data-c / data-heat, applied by app.js) */

.mw-220 { max-width: 220px; }

.mw-720 { max-width: 720px; }
/* htmx request indicators (htmx's own inline <style> is off: base.html sets includeIndicatorStyles false) */
.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; transition: opacity 200ms ease-in; }
/* a fragment being reloaded (app.js loadFragment / core/htmx.py) */
[data-fragment].is-loading { opacity: .55; pointer-events: none; transition: opacity 150ms ease-in; }

.flex { display: flex; } /* unlike .d-flex, the hidden attribute still hides it */

.clickable { cursor: pointer; }

@media print {
    body { font-size: 10pt; }
    .card { break-inside: avoid; }
}

/* ==========================================================================
   6. Status tags shared by several pages (value → colour)
   ========================================================================== */

.late { color: var(--red-600); font-weight: 600; }

/* Resizable table columns (app.js, <table data-resizable="key">; the React tables: shared/ui/DataTable, .app-resizable) */
:is(table[data-resizable], table.app-resizable) thead th { position: relative; }
:is(table[data-resizable], table.app-resizable) .col-resizer { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 2; touch-action: none; }
table.is-resizing .col-resizer:hover { background: color-mix(in srgb, var(--primary-color) 35%, transparent); }
table.is-resizing { user-select: none; cursor: col-resize; }
table.is-resized { table-layout: fixed; }
table.is-resized td, table.is-resized th { overflow: hidden; overflow-wrap: anywhere; }
/* stylelint-disable-next-line declaration-no-important -- over Bootstrap's !important max-width utilities: the column decides */
table.is-resized td { max-width: none !important; }
table.is-resized td .form-select, table.is-resized td textarea { width: 100%; min-width: 0; }

/* Warning-coloured text: Bootstrap's .text-warning is 1.6:1 on white; this amber reads (WCAG AA) */

/* Bootstrap's outline-danger red is just under WCAG AA on the light page background: a darker one */
.btn-outline-danger {
    --bs-btn-color: var(--red-700);
    --bs-btn-border-color: var(--red-700);
}

/* The user menu's dark theme switch (base.html, static/js/theme.js): an iPhone-sized toggle at the row's end */
.dropdown-item.theme-switch { display: flex; align-items: center; gap: 8px; cursor: pointer; padding-left: var(--bs-dropdown-item-padding-x, 1rem); }
.dropdown-item.theme-switch .form-check-input { margin: 0 0 0 auto; width: 2.75rem; height: 1.625rem; cursor: pointer; float: none; }
