@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Source+Serif+4:ital,wght@0,400;0,600;1,400&family=JetBrains+Mono:wght@400;600&display=swap');

/* ─── Design Tokens ─────────────────────────────────────────────
   "Institutional Intelligence" palette - deep blue for institutional
   trust, slate for secondary UI, purple/teal reserved for 5CBot AI
   content only (insight cards, AI badges, match scores). ────────── */
:root {
    /* Brand */
    --color-primary: #00236f;
    --color-on-primary: #ffffff;
    --color-secondary: #515f74;
    --color-accent: #1e3a8a;
    --color-accent-hover: #2c4694;
    --color-accent-light: #dce1ff;

    /* Surfaces */
    --color-background: #f8f9fa;
    --color-surface: #ffffff;
    --color-surface-raised: #ffffff;
    --color-foreground: #191c1d;
    --color-muted: #f3f4f5;
    --color-muted-foreground: #444651;
    --color-border: #c5c5d3;
    --color-border-hover: #757682;

    /* Sidebar - follows the theme like everything else, just aliased so it
       can be tuned independently of the main surface if needed later. */
    --color-sidebar-bg: var(--color-surface-raised);
    --color-sidebar-fg: var(--color-foreground);
    --color-sidebar-muted: var(--color-muted-foreground);
    --color-sidebar-hover: var(--color-muted);

    /* AI / 5CBot accents - use sparingly, only for AI-generated content */
    --color-ai-purple: #8b5cf6;
    --color-ai-purple-light: rgba(139, 92, 246, .08);
    --color-ai-teal: #14b8a6;

    /* Semantic */
    --color-destructive: #ba1a1a;
    --color-destructive-light: #ffdad6;
    --color-destructive-solid: #ba1a1a;
    --color-success: #14b8a6;
    --color-success-light: #f0fdf4;
    --color-warning: #b45309;
    --color-warning-light: #fffbeb;
    --color-info: #1e3a8a;
    --color-info-light: #dce1ff;
    --color-ring: #1e3a8a;

    /* Status */
    --color-status-open: #14b8a6;
    --color-status-draft: #757682;
    --color-status-closed: #ba1a1a;
    --color-status-archived: #8b5cf6;
    --color-status-submitted: #00236f;
    --color-status-queued: #b45309;
    --color-status-running: #1e3a8a;
    --color-status-completed: #14b8a6;
    --color-status-failed: #ba1a1a;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
    --space-6: 48px;
    --space-7: 64px;
    --space-8: 96px;
    --sidebar-width: 280px;

    /* Radii */
    --radius: 4px;
    --radius-sm: 2px;
    --radius-lg: 8px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
    --shadow-card: 0 1px 3px rgba(0,0,0,.05);
    --shadow-card-hover: 0 8px 25px -5px rgba(0,0,0,.1), 0 4px 10px -4px rgba(0,0,0,.04);

    /* Type */
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-serif: 'Source Serif 4', Georgia, serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace;

    /* Transitions */
    --ease-out: cubic-bezier(.16,1,.3,1);
    --duration: 180ms;
}

/* Explicit theme only - set via data-theme on <html> by the inline script in
   header.php, defaulting to light. Not gated on prefers-color-scheme: an
   unrequested auto dark-mode override was the original complaint. */
:root[data-theme="dark"] {
    --color-primary: #90a8ff;
    --color-on-primary: #00164e;
    --color-secondary: #a8b4c7;
    --color-accent: #3b52a0;
    --color-accent-hover: #4a60ac;
    --color-accent-light: #1e2a52;

    --color-background: #14161a;
    --color-surface: #1e2124;
    --color-surface-raised: #25282c;
    --color-foreground: #f0f1f2;
    --color-muted: #2a2d31;
    --color-muted-foreground: #b8bac2;
    --color-border: #3a3d44;
    --color-border-hover: #8b8d99;

    --color-sidebar-bg: var(--color-surface-raised);
    --color-sidebar-fg: var(--color-foreground);
    --color-sidebar-muted: var(--color-muted-foreground);
    --color-sidebar-hover: var(--color-muted);

    --color-ai-purple: #b39dff;
    --color-ai-purple-light: rgba(179, 157, 255, .1);
    --color-ai-teal: #4fd8c4;

    /* Text/icon tone - light enough to read on a dark surface. */
    --color-destructive: #ffb4ab;
    --color-destructive-light: #4a0f0c;
    --color-success: #4fd8c4;
    --color-success-light: #052e16;
    --color-warning: #fbbf24;
    --color-warning-light: #451a03;
    --color-info: #90a8ff;
    --color-info-light: #1e2a52;
    --color-ring: #90a8ff;

    /* Solid-fill tone - stays dark/saturated enough for white text on top
       (badges, buttons, count pills), unlike the pastel --color-destructive
       text tone above which would be nearly unreadable under white text. */
    --color-destructive-solid: #e5484d;

    /* Status badges are always a solid fill + white text, in both themes -
       reuse light mode's own values instead of inverting to a pastel tone. */
    --color-status-open: #14b8a6;
    --color-status-draft: #757682;
    --color-status-closed: #ba1a1a;
    --color-status-archived: #8b5cf6;
    --color-status-submitted: #00236f;
    --color-status-queued: #b45309;
    --color-status-running: #1e3a8a;
    --color-status-completed: #14b8a6;
    --color-status-failed: #ba1a1a;

    --shadow-xs: 0 1px 2px rgba(0,0,0,.2);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.4), 0 2px 4px -2px rgba(0,0,0,.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.5), 0 4px 6px -4px rgba(0,0,0,.3);
    --shadow-card: 0 1px 3px rgba(0,0,0,.2);
    --shadow-card-hover: 0 8px 25px -5px rgba(0,0,0,.4), 0 4px 10px -4px rgba(0,0,0,.3);
}

/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

/* Tells the browser to render native form controls (file picker button,
   checkboxes, scrollbars) in dark chrome instead of always-light - without
   this a plain <input type="file"> stays a jarring light-grey box on a dark
   page since we can't restyle its native button any other way. */
:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

body {
    margin: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-foreground);
    background: var(--color-background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--duration) ease, color var(--duration) ease;
}

/* Pins the footer to the bottom of the viewport on short pages instead of
   floating right after the content with dead space below it. */
main {
    flex: 1 0 auto;
}

.shell-main {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

h1, h2, h3, h4 {
    line-height: 1.25;
    font-weight: 700;
    letter-spacing: -0.01em;
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; font-weight: 600; }

a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color var(--duration) ease;
}

a:hover {
    color: var(--color-accent-hover);
}

img {
    max-width: 100%;
}

:focus-visible {
    outline: 2px solid var(--color-ring);
    outline-offset: 2px;
}

::selection {
    background: var(--color-accent);
    color: white;
}

/* ─── Container ────────────────────────────────────────────── */
.container {
    width: 100%;
    max-width: 1120px;
    margin-inline: auto;
    padding-inline: var(--space-4);
}

/* ─── Header / Nav ─────────────────────────────────────────── */
.site-header {
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    background: color-mix(in srgb, var(--color-surface) 85%, transparent);
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding-block: var(--space-3);
}

.brand {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--color-foreground);
    text-decoration: none;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.brand img {
    flex-shrink: 0;
}

.brand:hover {
    color: var(--color-foreground);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* :not(.btn) so a button-styled link (e.g. the Register CTA) keeps its own
   .btn-primary/.btn-outline text color instead of losing to this rule on
   specificity - both are a single-class selector, so source order alone
   wouldn't decide it reliably. */
.nav-actions a:not(.btn) {
    text-decoration: none;
    color: var(--color-muted-foreground);
    font-weight: 500;
    font-size: 0.9rem;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    transition: color var(--duration) ease, background var(--duration) ease;
}

.nav-actions a:not(.btn):hover {
    color: var(--color-foreground);
    background: var(--color-muted);
}

/* ─── Header utility icons (theme toggle, notifications) ──────── */
.notif-dropdown {
    position: relative;
}

.notif-bell {
    position: relative;
    display: inline-flex;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    color: var(--color-foreground);
    border-radius: var(--radius-sm);
}

.notif-bell:hover {
    background: var(--color-muted);
}

.notif-bell svg {
    width: 22px;
    height: 22px;
    display: block;
}

.notif-count {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    background: var(--color-destructive-solid);
    color: #fff;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
}

.notif-panel {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    width: 340px;
    max-height: 420px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    visibility: hidden;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity var(--duration) var(--ease-out), transform var(--duration) var(--ease-out), visibility var(--duration);
}

.notif-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

.notif-panel-title {
    margin: 0;
    font-weight: 700;
    font-size: 0.85rem;
}

.notif-mark-all {
    background: none;
    border: none;
    color: var(--color-accent);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    padding: 0;
}

.notif-mark-all:hover {
    text-decoration: underline;
}

.notif-dropdown.open .notif-panel {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

.notif-empty {
    padding: var(--space-5) var(--space-3);
    color: var(--color-muted-foreground);
    text-align: center;
    font-size: 0.9rem;
    margin: 0;
}

.notif-item {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    transition: background var(--duration) ease;
}

.notif-item:hover {
    background: var(--color-muted);
}

.notif-item:last-child {
    border-bottom: none;
}

.notif-item.notif-unread::before {
    content: '';
    position: absolute;
    left: var(--space-2);
    top: var(--space-3);
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: var(--color-accent);
}

.notif-body {
    display: block;
    flex: 1;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.notif-title {
    font-weight: 600;
    margin: 0;
    font-size: 0.9rem;
}

.notif-message,
.notif-time {
    margin: var(--space-1) 0 0;
    font-size: 13px;
    color: var(--color-muted-foreground);
}

.notif-mark-read {
    background: none;
    border: none;
    color: var(--color-accent);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    padding: 0;
}

.notif-mark-read:hover {
    text-decoration: underline;
}

.nav-toggle,
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    color: var(--color-foreground);
    border-radius: var(--radius-sm);
}

.nav-toggle {
    display: none;
}

.nav-toggle:hover,
.theme-toggle:hover {
    background: var(--color-muted);
}

.nav-toggle svg,
.theme-toggle svg {
    width: 20px;
    height: 20px;
    display: block;
}

.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--color-accent-light);
    color: var(--color-primary);
    font-weight: 700;
    font-size: 0.85rem;
    border: 2px solid var(--color-accent-light);
    flex-shrink: 0;
}

.topbar-page-label {
    display: none;
    margin: 0;
    font-weight: 700;
    font-size: 1rem;
    color: var(--color-foreground);
}

.topbar-page-label .breadcrumb-sep {
    font-weight: 400;
    margin: 0 var(--space-1);
}

/* Sidebar already shows the brand + full nav on desktop - the topbar only
   needs the brand as a fallback once the sidebar disappears on mobile, and
   the current page name instead of repeating the same nav links. */
@media (min-width: 993px) {
    .app-shell .site-header .brand {
        display: none;
    }

    .app-shell .site-header .nav-actions {
        display: none;
    }

    .app-shell .topbar-page-label {
        display: block;
    }
}

/* ─── Profile dropdown ─────────────────────────────────────── */
.profile-dropdown {
    position: relative;
}

.profile-trigger {
    display: inline-flex;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    border-radius: var(--radius-full);
}

.profile-panel {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    width: 240px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    padding: var(--space-2);
    visibility: hidden;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity var(--duration) var(--ease-out), transform var(--duration) var(--ease-out), visibility var(--duration);
}

.profile-dropdown.open .profile-panel {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

.profile-panel-header {
    padding: var(--space-2) var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-1);
}

.profile-name {
    margin: 0;
    font-weight: 700;
    font-size: 0.9rem;
}

.profile-role {
    margin: 2px 0 0;
    font-size: 0.75rem;
    color: var(--color-muted-foreground);
}

.profile-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    background: none;
    border: none;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-foreground);
    cursor: pointer;
    text-align: left;
}

.profile-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--color-muted-foreground);
}

.profile-item:hover {
    background: var(--color-muted);
}

.profile-item.disabled {
    color: var(--color-muted-foreground);
    cursor: not-allowed;
}

.profile-item.disabled:hover {
    background: none;
}

.profile-item-danger {
    color: var(--color-destructive);
}

.profile-item-danger svg {
    color: var(--color-destructive);
}

.profile-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-1) 0;
}

.profile-panel form {
    margin: 0;
}

.profile-lang-select {
    appearance: none;
    -webkit-appearance: none;
    background: none;
    border: 1px solid var(--color-border);
}

@media (max-width: 992px) {
    .nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .nav-actions {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        padding: var(--space-3);
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-1);
        box-shadow: var(--shadow-lg);
    }

    .nav-actions.open {
        display: flex;
    }

    .nav-actions a {
        padding: var(--space-3);
        border-radius: var(--radius-sm);
    }

    .nav-actions form {
        padding: 0;
    }

    .nav-actions .btn {
        width: 100%;
    }
}

/* ─── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 42px;
    padding: 0 var(--space-4);
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--duration) var(--ease-out);
    white-space: nowrap;
    line-height: 1;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--color-primary);
    color: var(--color-on-primary);
    border-color: var(--color-primary);
}

.btn-primary:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
    box-shadow: var(--shadow-md);
    color: white;
}

.btn-outline {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-foreground);
}

.btn-outline:hover {
    border-color: var(--color-border-hover);
    background: var(--color-muted);
    box-shadow: var(--shadow-xs);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--color-muted-foreground);
}

.btn-ghost:hover {
    background: var(--color-muted);
    color: var(--color-foreground);
}

.btn-danger {
    background: var(--color-destructive-solid);
    color: white;
    border-color: var(--color-destructive-solid);
}

.btn-danger:hover {
    filter: brightness(0.9);
    box-shadow: 0 4px 12px rgba(229,72,77,.3);
}

.btn-sm {
    min-height: 34px;
    padding: 0 var(--space-3);
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

/* ─── Hero ─────────────────────────────────────────────────── */
.hero {
    padding-block: var(--space-8);
    text-align: center;
    background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-background) 100%);
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: -200px;
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    height: 800px;
    background: radial-gradient(circle, var(--color-accent-light) 0%, transparent 70%);
    opacity: 0.5;
    pointer-events: none;
}

.hero h1 {
    font-size: clamp(2.25rem, 5vw, 3.25rem);
    max-width: 48ch;
    margin: 0 auto var(--space-4);
    letter-spacing: -0.03em;
    position: relative;
}

.hero p {
    max-width: 56ch;
    margin: 0 auto var(--space-5);
    color: var(--color-muted-foreground);
    font-size: 1.125rem;
    line-height: 1.7;
    position: relative;
}

.hero-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    flex-wrap: wrap;
    position: relative;
}

.hero-actions .btn {
    min-height: 48px;
    padding-inline: var(--space-5);
    font-size: 1rem;
}

/* ─── Sections ─────────────────────────────────────────────── */
.section {
    padding-block: var(--space-7);
}

.section-title {
    text-align: center;
    margin-bottom: var(--space-6);
    font-size: 1.5rem;
}

/* ─── Grid ─────────────────────────────────────────────────── */
.grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-1 {
    grid-template-columns: 1fr;
}

/* ─── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    transition: all var(--duration) var(--ease-out);
    box-shadow: var(--shadow-card);
}

.card h3 {
    margin-top: 0;
}

a.card {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

a.card:hover {
    border-color: var(--color-border-hover);
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

/* ─── Feature Cards (landing) ──────────────────────────────── */
.feature-card {
    text-align: center;
    padding: var(--space-5);
}

.feature-card .icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    background: var(--color-accent-light);
    color: var(--color-accent);
    margin-bottom: var(--space-3);
    font-size: 1.5rem;
}

.feature-card h3 {
    margin-bottom: var(--space-2);
}

.feature-card p {
    color: var(--color-muted-foreground);
    font-size: 0.9rem;
    margin: 0;
}

/* ─── Supported-format badges (landing page) ───────────────── */
.format-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-3);
}

.format-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    width: 96px;
    padding: var(--space-3);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-muted-foreground);
    text-align: center;
}

.format-badge svg {
    width: 28px;
    height: 28px;
}

/* ─── Pills / Status Badges ────────────────────────────────── */
.pill-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
}

.pill {
    background: var(--color-muted);
    color: var(--color-muted-foreground);
    border-radius: var(--radius-full);
    padding: var(--space-1) var(--space-3);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.dashboard-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    background: var(--color-muted);
    color: var(--color-muted-foreground);
    border-radius: var(--radius-full);
    padding: 3px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    line-height: 1.6;
}

/* Status-specific badge colors */
.badge-open,
.badge-draft,
.badge-closed,
.badge-archived,
.badge-submitted,
.badge-queued,
.badge-running,
.badge-completed,
.badge-failed,
.badge-pending_approval {
    color: white;
}

.badge-open    { background: var(--color-status-open); }
.badge-draft   { background: var(--color-status-draft); }
/* Fixed value in both themes, not var(--color-warning) - that token is a
   light-on-dark TEXT tone in dark mode (bright yellow) and would fail the
   same white-text-on-pastel-fill contrast bug fixed elsewhere for badges. */
.badge-pending_approval { background: #b45309; }
.badge-closed  { background: var(--color-status-closed); }
.badge-archived { background: var(--color-status-archived); }
.badge-submitted { background: var(--color-status-submitted); }
.badge-queued  { background: var(--color-status-queued); }
.badge-running { background: var(--color-status-running); }
.badge-completed { background: var(--color-status-completed); }
.badge-failed  { background: var(--color-status-failed); }

/* ─── Steps ────────────────────────────────────────────────── */
.steps {
    counter-reset: step;
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.steps li {
    list-style: none;
    counter-increment: step;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: var(--shadow-xs);
}

.steps li::before {
    content: counter(step);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-accent);
    color: white;
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: var(--space-3);
}

/* ─── Forms ────────────────────────────────────────────────── */
.auth-card {
    max-width: 420px;
    margin: var(--space-7) auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.auth-card h1 {
    margin-top: 0;
    margin-bottom: var(--space-4);
}

.auth-card h2 {
    font-size: 1.125rem;
    margin-top: 0;
    margin-bottom: var(--space-3);
}

.form-field {
    margin-bottom: var(--space-4);
}

.form-field label {
    display: block;
    margin-bottom: var(--space-1);
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-foreground);
}

.form-field label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 400;
}

.form-field input[type="checkbox"] {
    width: auto;
    min-height: auto;
}

.form-field input:not([type="checkbox"]),
.form-field select,
.form-field textarea {
    width: 100%;
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.95rem;
    color: var(--color-foreground);
    background: var(--color-background);
    transition: border-color var(--duration) ease, box-shadow var(--duration) ease;
}

.form-field textarea {
    min-height: auto;
    resize: vertical;
    line-height: 1.6;
}

.form-field select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

.form-field input:hover,
.form-field select:hover,
.form-field textarea:hover {
    border-color: var(--color-border-hover);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

.form-field small {
    display: block;
    margin-top: var(--space-1);
    color: var(--color-muted-foreground);
    font-size: 0.8rem;
}

.form-error {
    background: var(--color-destructive-light);
    border: 1px solid color-mix(in srgb, var(--color-destructive) 30%, transparent);
    color: var(--color-destructive);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.form-error::before {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    background: var(--color-destructive);
    border-radius: 50%;
    flex-shrink: 0;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") center/contain no-repeat;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") center/contain no-repeat;
}

.form-success {
    background: var(--color-success-light);
    border: 1px solid color-mix(in srgb, var(--color-success) 30%, transparent);
    color: var(--color-success);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    font-size: 0.9rem;
    font-weight: 500;
}

.form-footnote {
    margin-top: var(--space-4);
    text-align: center;
    font-size: 0.9rem;
    color: var(--color-muted-foreground);
}

.form-footnote a {
    font-weight: 500;
}

/* ─── Dashboard ────────────────────────────────────────────── */
.dashboard-header {
    padding-block: var(--space-5);
    border-bottom: 1px solid var(--color-border);
}

.dashboard-header h1 {
    margin: var(--space-2) 0 0;
}

.dashboard-header p {
    color: var(--color-muted-foreground);
}

/* ─── Empty State ──────────────────────────────────────────── */
.empty-state {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-7);
    text-align: center;
    color: var(--color-muted-foreground);
    font-size: 0.95rem;
}

.empty-state a {
    font-weight: 600;
}

/* ─── Tables ───────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--color-muted);
}

th {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted-foreground);
    border-bottom: 1px solid var(--color-border);
}

td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--color-muted);
}

/* ─── File Upload Area ─────────────────────────────────────── */
.upload-area {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    text-align: center;
    color: var(--color-muted-foreground);
    background: var(--color-muted);
    transition: all var(--duration) ease;
    cursor: pointer;
}

.upload-area:hover {
    border-color: var(--color-accent);
    background: var(--color-accent-light);
    color: var(--color-accent);
}

.upload-area input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

/* ─── Recommendation Card ─────────────────────────────────────
   This is 5CBot's own AI-generated output, so it gets the AI-card
   treatment (purple accent) rather than a plain surface. ────────── */
.recommendation-card {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-ai-purple);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.recommendation-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--color-ai-purple-light);
    pointer-events: none;
}

.recommendation-card > * {
    position: relative;
}

.recommendation-card .rec-header {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-3);
}

.recommendation-card .rec-section {
    margin-top: var(--space-3);
}

.recommendation-card .rec-section-title {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-muted-foreground);
    margin-bottom: var(--space-1);
}

.recommendation-card ul {
    margin-top: var(--space-1);
    padding-left: var(--space-4);
}

.recommendation-card li {
    margin-bottom: var(--space-1);
    color: var(--color-foreground);
    font-size: 0.9rem;
    line-height: 1.5;
}

/* ─── Activity Feed ────────────────────────────────────────── */
.activity-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.activity-list li {
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
}

.activity-list li:last-child {
    border-bottom: none;
}

.activity-list .activity-time {
    color: var(--color-muted-foreground);
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.activity-list .activity-user {
    font-weight: 600;
}

.activity-list .activity-action {
    color: var(--color-muted-foreground);
}

/* ─── Notification Cards ───────────────────────────────────── */
.notification-unread {
    border-left: 3px solid var(--color-accent);
}

.notification-read {
    opacity: 0.7;
}

/* ─── Footer ───────────────────────────────────────────────── */
.site-footer {
    border-top: 1px solid var(--color-border);
    padding-block: var(--space-6);
    color: var(--color-muted-foreground);
    font-size: 0.85rem;
    text-align: center;
}

/* ─── Utilities ────────────────────────────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

.text-muted { color: var(--color-muted-foreground); }
.text-left  { text-align: left; }
.text-sm    { font-size: 0.875rem; }
.text-xs    { font-size: 0.8rem; }
.font-mono  { font-family: var(--font-mono); }

.text-display-lg {
    font-size: clamp(1.75rem, 4vw, 3rem);
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.text-body-lg {
    font-size: 1.125rem;
    line-height: 1.6;
}

.text-document {
    font-family: var(--font-serif);
    font-size: 1.0625rem;
    line-height: 1.75;
}

.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }

.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-start { justify-content: flex-start; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-wrap  { flex-wrap: wrap; }
.flex-1     { flex: 1; }

.icon-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.icon-link svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Sidebar (authenticated shell) ───────────────────────────
   Always dark, in both light and dark theme - a fixed anchor for
   the app distinct from the page content behind it. ─────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 60;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-4) var(--space-3);
    color: var(--color-sidebar-fg);
    text-decoration: none;
}

.sidebar-brand img {
    flex-shrink: 0;
}

.sidebar-brand:hover {
    color: var(--color-sidebar-fg);
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.sidebar-brand-name {
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}

.sidebar-brand-tag {
    font-size: 0.7rem;
    color: var(--color-sidebar-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-3) var(--space-2);
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    color: var(--color-sidebar-muted);
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    transition: background var(--duration) ease, color var(--duration) ease;
}

.sidebar-nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-nav a:hover {
    background: var(--color-sidebar-hover);
    color: var(--color-sidebar-fg);
}

.sidebar-nav a.active {
    background: var(--color-primary);
    color: var(--color-on-primary);
}

@media (min-width: 993px) {
    .app-shell .sidebar {
        display: flex;
    }

    .app-shell .shell-main {
        margin-left: var(--sidebar-width);
    }

    .app-shell .site-header .container {
        max-width: none;
        margin-inline: 0;
        padding-inline: var(--space-4);
    }
}

@media (max-width: 992px) {
    .sidebar {
        display: none;
    }
}

/* ─── Breadcrumb ───────────────────────────────────────────── */
.breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-1);
    font-size: 0.85rem;
    color: var(--color-muted-foreground);
    margin-bottom: var(--space-2);
}

.breadcrumb a {
    color: var(--color-muted-foreground);
}

.breadcrumb a:hover {
    color: var(--color-primary);
}

.breadcrumb .breadcrumb-current {
    color: var(--color-foreground);
    font-weight: 600;
}

.breadcrumb-sep {
    color: var(--color-border-hover);
}

/* ─── AI / 5CBot Insight Card ───────────────────────────────
   Reserved for content the LLM actually generated - never used
   for plain human-authored UI. ───────────────────────────────── */
.ai-card {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-ai-purple);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.ai-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--color-ai-purple-light);
    pointer-events: none;
}

.ai-card > * {
    position: relative;
}

.ai-card-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--color-ai-purple);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.ai-card-label svg {
    width: 14px;
    height: 14px;
}

/* ─── Tabs (knowledge source type picker) ───────────────────── */
.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.tab-btn {
    padding: var(--space-2) var(--space-3);
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    color: var(--color-muted-foreground);
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    margin-bottom: -1px;
}

.tab-btn:hover {
    color: var(--color-foreground);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ─── Bento grid (two-column content + side panel) ──────────── */
.bento-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-4);
    align-items: start;
}

@media (max-width: 900px) {
    .bento-grid {
        grid-template-columns: 1fr;
    }
}

/* ─── Reduced Motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }
}

/* ─── RTL (Arabic) ───────────────────────────────────────────── */

[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
}

[dir="rtl"] .shell-main {
    margin-left: 0;
    margin-right: 260px;
}

[dir="rtl"] .sidebar-nav a svg,
[dir="rtl"] .nav-actions a svg {
    margin-right: 0;
    margin-left: 0.5rem;
}

[dir="rtl"] .form-field label {
    text-align: right;
}

[dir="rtl"] .profile-panel {
    right: auto;
    left: 0;
}

[dir="rtl"] textarea,
[dir="rtl"] input[type="text"],
[dir="rtl"] input[type="email"],
[dir="rtl"] input[type="password"],
[dir="rtl"] input[type="search"],
[dir="rtl"] input[type="url"],
[dir="rtl"] input[type="number"],
[dir="rtl"] select {
    text-align: right;
    direction: rtl;
}
