:root {
    /* Color Palette - Premium Light */
    --bg-main: #f8fafc;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --border-color: rgba(0, 0, 0, 0.08);
    --border-soft: rgba(0, 0, 0, 0.04);
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    
    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    /* Gradients for metric cards */
    --grad-projets: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    --grad-recettes: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    --grad-depenses: linear-gradient(135deg, #ffedd5 0%, #fed7aa 100%);
    --grad-balance: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 100%);

    /* Sizing */
    --sidebar-width: 260px;
    --top-header-height: 80px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;

    /* Font Families */
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Outfit', 'Inter', sans-serif;
}

[data-theme="dark"] {
    --bg-main: #0b0f19;
    --bg-sidebar: #111827;
    --bg-card: #1f2937;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border-color: rgba(255, 255, 255, 0.1);
    --border-soft: rgba(255, 255, 255, 0.05);
    --card-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);

    --grad-projets: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    --grad-recettes: linear-gradient(135deg, #064e3b 0%, #065f46 100%);
    --grad-depenses: linear-gradient(135deg, #7c2d12 0%, #9a3412 100%);
    --grad-balance: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    transition: background-color 0.3s ease;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
    z-index: 100;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sidebar collapsed (toggle bouton ⊞) — desktop uniquement */
@media (min-width: 769px) {
    .sidebar.collapsed { width: 72px; }
    .sidebar.collapsed .logo span,
    .sidebar.collapsed .nav-link span,
    .sidebar.collapsed .nav-section-title,
    .sidebar.collapsed .user-info,
    .sidebar.collapsed #role-switcher { display: none; }
    .sidebar.collapsed .nav-link { justify-content: center; padding: 0.7rem; }
    .sidebar.collapsed .sidebar-header { padding: 0 0.5rem 1rem; justify-content: center; }
    .sidebar.collapsed .logo { justify-content: center; }
    .sidebar.collapsed .user-profile { justify-content: center; }
}

.sidebar-header {
    padding: 0 1.5rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: var(--font-heading);
    font-weight: 700;
    letter-spacing: 0.05em;
    font-size: 1.25rem;
}

.logo-icon {
    width: 32px;
    height: 32px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.75rem;
}

.nav-section {
    margin-bottom: 2rem;
}

.nav-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    padding: 0 0.75rem 0.75rem;
    letter-spacing: 0.1em;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    margin-bottom: 2px;
}

.nav-link:hover {
    background-color: var(--border-soft);
    color: var(--text-primary);
}

.nav-link.active {
    background-color: rgba(37, 99, 235, 0.12);
    color: var(--accent);
    font-weight: 600;
}

[data-theme="dark"] .nav-link.active {
    background-color: rgba(96, 165, 250, 0.15);
    color: #93c5fd;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-header {
    height: var(--top-header-height);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-sidebar);
}

.header-breadcrumb span {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.header-breadcrumb h1 {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 700;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: transform 0.1s ease, opacity 0.2s ease;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--accent);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

[data-theme="dark"] .btn-primary {
    color: white;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border-color);
    cursor: pointer;
    color: var(--text-primary);
    transition: background-color 0.2s ease;
}

.icon-btn:hover {
    background-color: var(--border-soft);
}

/* Metric Cards */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    padding: 2rem;
}

.metric-card {
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.metric-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.metric-value {
    font-size: 1.75rem;
    font-weight: 700;
    font-family: var(--font-heading);
}

.metric-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--grad-balance);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* View Container */
#view-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 0;
    scrollbar-width: thin;
    scrollbar-gutter: stable;
}
#view-container::-webkit-scrollbar { width: 8px; }
#view-container::-webkit-scrollbar-track { background: transparent; }
#view-container::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 4px; }
#view-container::-webkit-scrollbar-thumb:hover { background: var(--border-color); }

/* Projects Table */
.section-container {
    padding: 0 2rem 2rem;
}

.table-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    margin-top: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    padding: 1rem 1.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.9rem;
}

.project-name {
    font-weight: 600;
    display: block;
    margin-bottom: 0.25rem;
}

.project-ref {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.status-active { background: #dcfce7; color: #15803d; }
.status-completed { background: #f1f5f9; color: #475569; }
.status-pending { background: #fff7ed; color: #c2410c; }

/* Phase Pills */
.phase-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 1rem;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 0.5rem;
}

.phase-pill:hover {
    background: var(--accent);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .phase-pill:hover {
    color: black;
}

.phase-pill::before {
    content: "✨";
    font-size: 0.75rem;
}

/* Theme Toggle icons */
#theme-toggle .moon { display: none; }
[data-theme="dark"] #theme-toggle .sun { display: none; }
[data-theme="dark"] #theme-toggle .moon { display: block; }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
}

.ai-overlay.hidden {
    display: none;
}

/* ── Toast notifications (remplace window.alert) ───────────────────── */
.toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: calc(100vw - 2rem);
}
.toast {
  pointer-events: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem 0.75rem 0.875rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  min-width: 280px;
  max-width: 420px;
  font-size: 0.875rem;
  color: var(--text-primary);
  line-height: 1.4;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.toast-leave { opacity: 0; transform: translateX(20px); }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; line-height: 1.2; }
.toast-msg { flex: 1; min-width: 0; word-wrap: break-word; }
.toast-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); font-size: 1.1rem;
  padding: 0; line-height: 1; flex-shrink: 0;
}
.toast-close:hover { color: var(--text-primary); }
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--error); }
.toast.toast-warn    { border-left-color: #f59e0b; }
.toast.toast-info    { border-left-color: var(--accent); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Confirm modal (remplace window.confirm) ───────────────────────── */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(3px);
  z-index: 10001;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.confirm-overlay.hidden { display: none; }
.confirm-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  max-width: 420px;
  width: 100%;
  padding: 1.5rem;
  animation: modalAppear 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.confirm-icon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
  display: block;
}
.confirm-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}
.confirm-message {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 1.25rem;
  white-space: pre-line;
}
.confirm-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}
.confirm-actions button {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-main);
  color: var(--text-primary);
  transition: background 0.15s ease;
}
.confirm-actions button:hover { background: var(--border-soft); }
.confirm-actions button.confirm-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.confirm-actions button.confirm-primary:hover { background: var(--accent-hover); }
.confirm-actions button.confirm-danger {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

/* Command Palette (Cmd+K) */
.cmdk-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
}
.cmdk-overlay.hidden { display: none; }
.cmdk-modal {
    width: min(640px, 92vw);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.35);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 70vh;
}
.cmdk-input-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.cmdk-input-wrap input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 1rem;
    color: var(--text-primary);
    font-family: inherit;
}
.cmdk-esc {
    font-size: 0.7rem;
    font-family: inherit;
    background: var(--border-soft);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.cmdk-results {
    overflow-y: auto;
    padding: 0.4rem;
}
.cmdk-section {
    padding: 0.5rem 0.75rem 0.3rem;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.cmdk-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-primary);
}
.cmdk-item:hover, .cmdk-item.selected {
    background: var(--border-soft);
}
.cmdk-item-icon {
    width: 28px; height: 28px;
    border-radius: 6px;
    background: var(--border-soft);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 0.85rem;
}
.cmdk-item-main { flex: 1; min-width: 0; }
.cmdk-item-title {
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cmdk-item-sub {
    font-size: 0.74rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cmdk-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.modal-content {
    background: var(--bg-card);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalAppear 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-body-content {
    overflow-y: auto;
    flex: 1;
}

@keyframes modalAppear {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body-content {
    padding: 1.5rem;
}

/* AI Pulse Animation */
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}
@keyframes rec-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

.ai-pulse {
    animation: pulse 2s infinite;
}

/* Inputs */
input {
    background: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    outline: none;
    transition: border-color 0.2s ease;
}

input:focus {
    border-color: var(--accent);
}

/* AI Command Center */
.ai-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    color: white;
    font-size: 1.5rem;
    border: none;
    box-shadow: 0 10px 25px rgba(139, 92, 246, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ai-fab:hover {
    transform: scale(1.1) rotate(5deg);
}

.ai-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.ai-modal {
    width: 90%;
    max-width: 600px;
    background: #0f172a;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 50px rgba(59, 130, 246, 0.2);
    display: flex;
    flex-direction: column;
    height: 600px;
    color: white;
    overflow: hidden;
}

.ai-modal-header {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.ai-sparkle {
    font-size: 1.2rem;
    animation: sparkle 2s infinite;
}

@keyframes sparkle {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

.ai-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.ai-message {
    max-width: 80%;
    padding: 1rem 1.25rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.ai-bot {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.1);
    border-bottom-left-radius: 4px;
}

.ai-user {
    align-self: flex-end;
    background: #3b82f6;
    border-bottom-right-radius: 4px;
}

.ai-suggestions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.ai-suggestions button {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-suggestions button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.ai-modal-footer {
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
}

#ai-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: white;
}

/* ── Sidebar footer ───────────────────────────────────────────────────────── */
.sidebar-footer {
    padding: 1rem 1rem 0.5rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.5rem;
    border-radius: var(--radius-md);
}
.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.user-name { font-size: 0.85rem; font-weight: 600; display: block; }
.user-email { font-size: 0.72rem; color: var(--text-secondary); display: block; }

/* ── Role Switcher ─────────────────────────────────────────────────────────── */
#role-switcher {
    margin-bottom: 0.5rem;
}
#role-select {
    width: 100%;
    background: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

/* ── Phase color bands ─────────────────────────────────────────────────────── */
.phase-band-1 { border-left: 3px solid #8b5cf6; }
.phase-band-2 { border-left: 3px solid #3b82f6; }
.phase-band-3 { border-left: 3px solid #0ea5e9; }
.phase-band-4 { border-left: 3px solid #10b981; }
.phase-band-5 { border-left: 3px solid #f59e0b; }
.phase-band-6 { border-left: 3px solid #ef4444; }

/* ── Engagement tracking table ─────────────────────────────────────────────── */
.eng-bar-wrap {
    background: var(--border-soft);
    border-radius: 999px;
    height: 6px;
    overflow: hidden;
    min-width: 80px;
}
.eng-bar-fill { height: 100%; border-radius: 999px; transition: width 0.3s; }

/* Responsive adjustments */
@media (max-width: 1024px) {
    .sidebar { width: 80px; }
    .sidebar span, .sidebar .nav-section-title, .sidebar .user-info { display: none; }
    .sidebar .nav-link { justify-content: center; padding: 1rem; }
    .logo span { display: none; }
    .top-header { padding: 0 1rem; }
}

@media (max-width: 768px) {
    #app { flex-direction: column; }
    .sidebar { width: 100%; height: auto; flex-direction: row; padding: 0.5rem 1rem; overflow-x: auto; }
    .sidebar-header { padding: 0; border: none; margin-bottom: 0; }
    .sidebar-nav { display: flex; padding: 0; }
    .nav-section { margin-bottom: 0; display: flex; }
    .nav-section-title { display: none; }
    .sidebar-footer { display: none; }
    .top-header h1 { font-size: 1.25rem; }
}

/* Mobile (≤ 600px) : header compact, grilles wrap, tableaux scrollables */
@media (max-width: 600px) {
    .top-header { padding: 0 0.75rem; height: auto; min-height: var(--top-header-height); }
    .top-header h1 { font-size: 1rem; line-height: 1.2; }
    .header-breadcrumb { min-width: 0; flex: 1; overflow: hidden; }
    .header-breadcrumb h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .header-breadcrumb span { font-size: 0.6rem; }
    .header-actions { gap: 0.4rem; flex-shrink: 0; }
    .header-actions .icon-btn { width: 36px; height: 36px; }
    /* Bouton d'action "+ Nouveau projet" → juste l'icône + sur mobile */
    #btn-action-main { padding: 0.5rem 0.7rem; }
    #btn-action-main span { display: none; }
    /* Métriques inline 3-col qui débordent → wrap auto */
    [style*="grid-template-columns:repeat(3,1fr)"],
    [style*="grid-template-columns: repeat(3,1fr)"],
    [style*="grid-template-columns:repeat(3, 1fr)"],
    [style*="grid-template-columns: repeat(3, 1fr)"] {
        grid-template-columns: 1fr 1fr !important;
    }
    /* KPI projet inline (4 cartes) → 2x2 sur mobile */
    [style*="display:flex;gap:0.6rem;margin-bottom:1rem;flex-wrap:wrap"] > div {
        min-width: calc(50% - 0.3rem);
    }
    /* Tableaux : permettre le scroll horizontal sans clipper */
    .table-container { overflow-x: auto; }
    /* Inputs / boutons : zone de tap minimale (Apple HIG = 44px) */
    .btn { min-height: 38px; }
    input[type=text], input[type=email], input[type=tel], input[type=password],
    input[type=number], input[type=date], select, textarea {
        font-size: 16px; /* évite le zoom auto iOS sur focus */
    }
    /* Modale : pleine largeur avec marges */
    .modal-content { width: 95%; max-width: 95vw; max-height: 92vh; }
    .modal-body-content { padding: 1rem; }
    /* Onglets projet : déjà overflow-x:auto, on resserre */
    [style*="border-bottom:1px solid var(--border-color)"][style*="overflow-x:auto"] button {
        padding: 0.6rem 0.7rem !important;
        font-size: 0.78rem !important;
    }
}

/* Très petit (≤ 380px, vieux iPhones) : encore plus compact */
@media (max-width: 380px) {
    .top-header h1 { font-size: 0.9rem; }
    .header-actions { gap: 0.25rem; }
    .header-actions .icon-btn { width: 32px; height: 32px; }
    [style*="grid-template-columns:repeat(3,1fr)"],
    [style*="grid-template-columns: repeat(3,1fr)"] {
        grid-template-columns: 1fr !important;
    }
}
