/* Elegant Theme-Aware Custom Scrollbars (UX Specialist Design) */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 9999px;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.24);
    border-radius: 9999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.45);
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* Scrollbar styling for Light Theme */
:root[data-theme="light"] ::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.22);
    border: 2px solid transparent;
    background-clip: padding-box;
}

:root[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.45);
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* Firefox compatibility */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.24) rgba(0, 0, 0, 0.05);
}

:root[data-theme="light"] * {
    scrollbar-color: rgba(0, 0, 0, 0.22) rgba(0, 0, 0, 0.05);
}


@media (max-width: 768px) {
    body {
        overflow: auto;
        height: auto;
        min-height: 100vh;
    }

    .app-container {
        min-height: 100vh;
        height: auto;
        overflow: visible;
    }

    .main-content {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .page-container {
        height: auto;
        overflow-y: visible;
    }
}

/* App Container Layout */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar Navigation */
.sidebar {
    /* Fixed dark forest green in both themes: re-map themed tokens locally
       so all descendants resolve to the sidebar palette regardless of data-theme. */
    --bg-sidebar: var(--side-bg);
    --bg-elevated: var(--side-bg);
    --surface: var(--side-bg-2);
    --surface-2: var(--side-bg-2);
    --line: var(--side-line);
    --text: var(--side-text);
    --text-muted: var(--side-text-muted);

    /* Map legacy aliases and text helpers locally to prevent light-theme overrides */
    --text-primary: var(--side-text);
    --text-secondary: var(--side-text-muted);
    --text-faint: #6b7d74;
    --border-color: var(--side-line);

    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    background: linear-gradient(135deg, var(--primary), #059669);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

.logo-icon i {
    width: 22px;
    height: 22px;
}

.logo-text h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #ffffff, #a7f3d0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text span {
    font-size: 10px;
    color: var(--text-secondary);
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 1px;
}

.sidebar-nav {
    flex-grow: 1;
    padding: 24px 16px;
    overflow-y: auto;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li {
    margin-bottom: 8px;
}

.nav-group-label {
  list-style: none; font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-faint);
  padding: 16px 16px 6px;
  margin-bottom: 0;
}
.nav-group-label:first-child { padding-top: 4px; }

.nav-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    transition: all var(--transition-speed);
    position: relative;
}

.nav-btn i {
    width: 18px;
    height: 18px;
    transition: color var(--transition-speed);
}

.nav-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.03);
}

.nav-btn.active {
    color: white;
    background: linear-gradient(90deg, var(--primary-glow), rgba(16, 185, 129, 0.02));
    box-shadow: inset 3px 0 0 var(--primary);
}

.nav-btn.active i {
    color: var(--primary);
}

.badge {
    margin-left: auto;
    background-color: var(--warning);
    color: #000000;
    font-weight: 700;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
}

.badge-secondary { background: var(--bg-muted); color: var(--text-muted); border: 1px solid var(--line); }
.badge-success   { background: var(--ok-weak);   color: var(--ok);   border: 1px solid var(--ok-weak); }
.badge-warning   { background: var(--warn-weak); color: var(--warn); border: 1px solid var(--warn-weak); }
.badge-info      { background: var(--info-weak); color: var(--info); border: 1px solid var(--info-weak); }
.badge-danger    { background: var(--danger-weak); color: var(--danger); border: 1px solid var(--danger-weak); }
.badge-role      { background: var(--bg-muted); color: var(--text-muted); border: 1px solid var(--line); }


.badge:empty, .badge[id="review-badge"][data-count="0"] {
    display: none;
}

.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success);
}

.dot.pulse {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse 1.6s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Header Banner */
.content-header {
    height: var(--header-height);
    padding: 0 40px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background-color: var(--bg-elevated);
    z-index: 10;
}

.header-title h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

.header-title p { display: none; }

/* Global Controls */
.global-controls {
    display: flex;
    align-items: center;
    gap: 24px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    font-weight: 600;
}

.toggle-buttons {
    display: flex;
    background-color: rgba(255, 255, 255, 0.05);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.toggle-btn {
    background: none;
    border: none;
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all var(--transition-speed);
}

.toggle-btn:hover {
    color: var(--text-primary);
}

.toggle-btn.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.25);
}

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-muted); cursor: pointer; transition: all var(--transition-speed);
}
.theme-toggle:hover { color: var(--text); border-color: var(--line-strong); }
.theme-toggle i { width: 18px; height: 18px; }

/* Page Containers */
.page-container {
    flex-grow: 1;
    padding: 32px 40px;
    overflow-y: auto;
    position: relative;
    height: calc(100% - var(--header-height));
}

.tab-content {
    display: none;
    min-height: 100%;
}

.tab-content:not(#tab-review):not(#tab-ask):not(#tab-marches):not(#tab-contracts):not(#tab-manuels) {
    padding-bottom: 60px; /* Ensure space at the bottom for scrolling */
}

/* Specific tabs that need a full-height layout (e.g. side-by-side view or chat assistant) */
#tab-review,
#tab-ask,
#tab-marches,
#tab-contracts,
#tab-manuels {
    height: 100%;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

/* Ensure full-height layout tabs flex properly when active */
#tab-review.active,
#tab-ask.active,
#tab-marches.active,
#tab-contracts.active,
#tab-manuels.active {
    display: flex;
    flex-direction: column;
}

/* Contracts tab: expand the card to fill the height (like Marchés) so the
   table scrolls inside the box instead of leaving empty space below it. */
#tab-contracts .filter-bar {
    flex-shrink: 0;
}
#tab-contracts .table-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#tab-contracts .table-panel .table-container {
    flex: 1;
    max-height: none;
    overflow-y: auto;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

