/* ============================================
   RESET & VARIABLES
   ============================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #1a56db;
    --primary-dark: #1340a8;
    --primary-light: #3b82f6;
    --primary-bg: #eff6ff;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #fff;
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --text-lighter: #94a3b8;
    --border: #e2e8f0;
    --success: #10b981;
    --success-bg: #d1fae5;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --transition: 0.2s ease;
    --cl-color: #3b82f6;
    --cv-color: #8b5cf6;
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #3b82f6;
        --primary-dark: #60a5fa;
        --primary-light: #2563eb;
        --primary-bg: #1e3a5f;
        --sidebar-bg: #0a0f1a;
        --sidebar-text: #94a3b8;
        --sidebar-active: #fff;
        --bg: #0f172a;
        --bg-card: #1e293b;
        --text: #e2e8f0;
        --text-light: #94a3b8;
        --text-lighter: #64748b;
        --border: #334155;
        --success: #34d399;
        --success-bg: #064e3b;
        --warning: #fbbf24;
        --warning-bg: #78350f;
        --danger: #f87171;
        --danger-bg: #7f1d1d;
        --shadow: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
    }
    body { color-scheme: dark; }
    .card { background: var(--bg-card); border-color: var(--border); }
    .btn { border-color: var(--border); }
    .btn-outline { color: var(--text); border-color: var(--border); }
    .btn-outline:hover { background: var(--border); }
    input, select, textarea { background: var(--bg-card) !important; color: var(--text) !important; border-color: var(--border) !important; }
    input::placeholder, textarea::placeholder { color: var(--text-lighter) !important; }
    .detail-tab { color: var(--text-light); }
    .detail-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
    .config-panel { background: var(--bg); }
    .modal-overlay { background: rgba(0,0,0,0.7); }
    .modal { background: var(--bg-card); color: var(--text); }
    table tr:hover { background: rgba(255,255,255,0.03); }
    .stats-grid > div { border: 1px solid var(--border); }
    img { opacity: 0.9; }
}

html { font-size: 15px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 800;
}

.sidebar-logo-icon {
    width: 34px;
    height: 34px;
    background: var(--primary);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-logo-icon svg { width: 20px; height: 20px; fill: #fff; }

.sidebar-badge {
    display: inline-block;
    font-size: 0.6rem;
    background: var(--primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 50px;
    margin-left: 8px;
    font-weight: 600;
    vertical-align: middle;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.sidebar-section {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.3);
    padding: 16px 12px 8px;
    font-weight: 600;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar-link.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-link svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    flex-shrink: 0;
}

.sidebar-count {
    margin-left: auto;
    background: rgba(255,255,255,0.15);
    padding: 2px 8px;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: 600;
}

.sidebar-link.active .sidebar-count {
    background: rgba(255,255,255,0.25);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main {
    margin-left: 260px;
    min-height: 100vh;
    width: calc(100vw - 260px);
    max-width: calc(100vw - 260px);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    height: 64px;
    min-height: 64px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
    flex: 1;
}

.topbar-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.topbar-right .btn {
    white-space: nowrap;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.mobile-menu-btn svg {
    width: 24px;
    height: 24px;
    stroke: var(--text);
    fill: none;
    stroke-width: 2;
}

.content {
    padding: 32px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    flex: 1;
    box-sizing: border-box;
}

.page {
    width: 100%;
    box-sizing: border-box;
}

.card {
    width: 100%;
    box-sizing: border-box;
}

/* ============================================
   STATS CARDS
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}
.stats-grid-6 {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow);
}

.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.stat-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.stat-card-label {
    font-size: 0.8rem;
    color: var(--text-light);
    font-weight: 500;
}

.stat-card-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text);
}

/* ============================================
   CARDS & PANELS
   ============================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
}

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

.card-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.card-body { padding: 24px; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    font-family: inherit;
}

.btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline:hover { background: var(--bg); }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; border-radius: 6px; cursor: pointer; border: 1px solid; font-weight: 500; transition: var(--transition); }

.btn-outline-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger-bg); }
.btn-outline-success { background: transparent; color: var(--success); border-color: var(--success); }
.btn-outline-success:hover { background: var(--success-bg); }
.btn-outline-primary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary-bg); }
.btn-outline-secondary { background: transparent; color: var(--text-light); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--bg); }

.btn-icon {
    padding: 8px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover { background: var(--bg); }

.btn-icon svg {
    width: 18px;
    height: 18px;
    stroke: var(--text-light);
    fill: none;
    stroke-width: 2;
}

/* ============================================
   TABLE
   ============================================ */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 14px 16px;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

tr:hover td { background: rgba(241,245,249,0.5); }

.tenant-name {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tenant-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    color: #fff;
    flex-shrink: 0;
}

.tenant-info strong {
    display: block;
    font-size: 0.9rem;
}

.tenant-info small {
    color: var(--text-light);
    font-size: 0.75rem;
}

/* Status badge */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: var(--success-bg); color: #065f46; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Product badges */
.product-badge-cl {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: 600;
    background: #dbeafe;
    color: #1d4ed8;
}
.product-badge-cv {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: 600;
    background: #ede9fe;
    color: #6d28d9;
}

/* Toggle switch */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd5e1;
    border-radius: 24px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    top: 3px;
    left: 3px;
    transition: var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle input:checked + .toggle-slider { background: var(--success); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease;
}

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

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

.modal-header h3 { font-size: 1.1rem; }

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: var(--transition);
}

.modal-close:hover { background: var(--bg); }

.modal-close svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-light);
    fill: none;
    stroke-width: 2;
}

.modal-body { padding: 24px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* ============================================
   FORM
   ============================================ */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition);
    background: var(--bg);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
    background: #fff;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-help {
    font-size: 0.75rem;
    color: var(--text-lighter);
    margin-top: 4px;
}

/* Color picker row */
.color-picker-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.color-picker-row input[type="color"] {
    width: 44px;
    height: 36px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    background: #fff;
}

.color-picker-row input[type="text"] {
    flex: 1;
}

/* Color preview */
.color-swatch {
    width: 48px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* ============================================
   ASSET UPLOAD (logo / favicon / bannière)
   ============================================ */
.asset-group .asset-row {
    display: flex;
    gap: 14px;
    align-items: stretch;
    margin-top: 6px;
}

.asset-preview {
    flex: 0 0 auto;
    width: 96px;
    height: 96px;
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    color: var(--text-lighter);
    font-size: 0.72rem;
    text-align: center;
    padding: 6px;
}

.asset-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.asset-preview-small {
    width: 56px;
    height: 56px;
    border-radius: 12px;
}

.asset-preview-banner {
    width: 100%;
    height: 140px;
    aspect-ratio: auto;
    flex: 1 1 auto;
}

.asset-preview-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.asset-placeholder {
    color: var(--text-lighter);
    font-size: 0.72rem;
    line-height: 1.3;
}

.asset-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
    flex: 1 1 auto;
    min-width: 0;
}

.asset-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #1a56db, #2563eb);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    width: fit-content;
}

.asset-upload-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.asset-upload-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

.asset-upload-icon {
    display: inline-block;
    flex-shrink: 0;
}

.asset-clear-btn {
    padding: 8px 12px;
    background: transparent;
    color: var(--text-light);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: var(--transition);
    width: fit-content;
}

.asset-clear-btn:hover {
    background: #fef2f2;
    color: var(--danger);
    border-color: #fecaca;
}

.asset-url-input {
    margin-top: 8px !important;
    font-size: 0.8rem !important;
    color: var(--text-light);
}

.asset-hint {
    display: block;
    margin-top: 6px;
    font-size: 0.7rem;
    color: var(--text-lighter);
}

/* ============================================
   MODULES GRID
   ============================================ */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.module-card {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px 12px;
    padding: 14px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: var(--transition);
}

.module-card.enabled {
    border-color: var(--success);
    background: var(--success-bg);
}

.module-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.module-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.8);
}

.module-icon svg {
    width: 16px;
    height: 16px;
    stroke: var(--text-light);
    fill: none;
    stroke-width: 2;
}

.module-card.enabled .module-icon svg { stroke: #065f46; }

.module-name {
    font-size: 0.85rem;
    font-weight: 600;
}

/* ============================================
   DETAIL PANEL
   ============================================ */
.detail-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 28px;
}

.detail-logo {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.5rem;
    color: #fff;
}

.detail-info h2 { font-size: 1.5rem; margin-bottom: 4px; }
.detail-info p { color: var(--text-light); font-size: 0.9rem; }

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* ============================================
   DETAIL TABS
   ============================================ */
.detail-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.detail-tabs::-webkit-scrollbar { display: none; }

.detail-tab {
    padding: 10px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    background: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-light);
    transition: var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
    font-family: inherit;
}

.detail-tab:hover {
    color: var(--text);
    background: rgba(255,255,255,0.5);
}

.detail-tab.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: var(--shadow);
}

.detail-tab-content {
    display: none;
}

.detail-tab-content.active {
    display: block;
}

/* ============================================
   TOAST
   ============================================ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--text);
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

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

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    stroke: var(--text-lighter);
    fill: none;
    stroke-width: 1;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

/* ============================================
   CONFIG PANEL
   ============================================ */
.config-panel {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.config-panel h4 {
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.config-panel p {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* ============================================
   PAGES
   ============================================ */
.page { display: none; }
.page.active { display: block; }

/* ============================================
   SEARCH & FILTER BAR
   ============================================ */
.filter-bar {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.filter-bar input[type="text"] {
    flex: 1;
    min-width: 200px;
    padding: 9px 14px 9px 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    transition: var(--transition);
}

.filter-bar input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
    background: #fff;
}

.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-wrapper svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    stroke: var(--text-lighter);
    fill: none;
    stroke-width: 2;
}

.filter-bar select {
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
}

.filter-bar select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Password modal body */
.password-modal-body {
    text-align: center;
    padding: 8px 0;
}

.password-modal-body .lock-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    background: var(--warning-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-modal-body .lock-icon svg {
    width: 24px;
    height: 24px;
    stroke: var(--warning);
    fill: none;
    stroke-width: 2;
}

.password-modal-body p {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 16px;
}

.password-modal-body input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    text-align: center;
    transition: var(--transition);
    background: var(--bg);
}

.password-modal-body input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
    background: #fff;
}

.password-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 8px;
    display: none;
}

.update-date {
    font-size: 0.75rem;
    color: var(--text-lighter);
}

/* Slider style */
input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    background: var(--border);
    border-radius: 3px;
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (min-width: 769px) and (hover: hover) {
    .sidebar { transform: translateX(0) !important; display: flex !important; }
    .main { margin-left: 260px !important; }
}

/* Force mobile layout for touch devices (iPhone/iPad Safari in-app browsers
   that may report wide viewports despite being held in portrait) */
@media (max-width: 768px), (hover: none) and (pointer: coarse) and (max-width: 1024px) {
    .mobile-menu-btn { display: block !important; }
}

@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-grid-6 { grid-template-columns: repeat(3, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
}

/* Force inline 2-column grids down to 1 column on touch devices. The
   tenant detail page renders several `style="grid-template-columns:1fr 1fr"`
   blocks for config panels and maintenance form rows — inline styles
   beat class selectors, so we target them with attribute + !important
   to keep the tenant edit UI usable on phones. */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:2fr 1fr"],
    [style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    .commune-danger-zone .btn { width: 100%; justify-content: center; }
}

@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
    }

    .sidebar.open { transform: translateX(0); z-index: 200; }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 150;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.open { display: block; }

    .main { margin-left: 0 !important; width: 100% !important; max-width: 100% !important; }

    .mobile-menu-btn { display: block; }

    .content { padding: 10px; }

    .topbar { padding: 0 10px; height: 52px; }
    .topbar-title { font-size: 1rem; }
    .topbar .btn { font-size: 0.75rem; padding: 6px 10px; }
    .topbar .btn svg { display: none; }
    .topbar-right { gap: 6px; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stats-grid-6 { grid-template-columns: 1fr 1fr; gap: 8px; }

    .stat-card { padding: 12px; border-radius: 10px; }
    .stat-card-value { font-size: 1.3rem; }
    .stat-card-label { font-size: 0.7rem; }

    .form-row { grid-template-columns: 1fr; gap: 10px; }
    .form-group input, .form-group select, .form-group textarea { font-size: 16px; } /* prevent zoom on iOS */

    .modules-grid { grid-template-columns: 1fr; }

    .filter-bar { padding: 10px; flex-wrap: wrap; gap: 8px; }
    .filter-bar select, .filter-bar input { font-size: 0.8rem; min-width: 0; flex: 1 1 45%; }

    .card { border-radius: 10px; margin-bottom: 10px; }
    .card-header { padding: 12px; flex-wrap: wrap; gap: 8px; }
    .card-header h3 { font-size: 0.95rem; }
    .card-body { padding: 12px; }

    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -12px; padding: 0 12px; }
    table { font-size: 0.78rem; min-width: 500px; }
    table th, table td { padding: 8px 6px; white-space: nowrap; }
    table th:nth-child(5), table td:nth-child(5) { display: none; }
    table th:nth-child(6), table td:nth-child(6) { display: none; }

    .btn-icon { width: 30px; height: 30px; min-width: 30px; } /* bigger tap target */
    .btn-icon svg { width: 14px; height: 14px; }

    .modal { width: 96%; max-height: 90vh; border-radius: 14px; margin: 5vh auto; }
    .modal-header { padding: 14px 16px; }
    .modal-body { padding: 14px 16px; }

    .detail-tabs { flex-wrap: wrap; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
    .detail-tabs button { font-size: 0.75rem; padding: 8px 12px; white-space: nowrap; }

    .detail-header { flex-wrap: wrap; gap: 12px; padding: 14px; }
    .detail-header .detail-logo { width: 44px; height: 44px; font-size: 1rem; }
    .detail-info h2 { font-size: 1.1rem; }
    .detail-info p { font-size: 0.8rem; }

    .color-picker-row { flex-wrap: wrap; }

    /* Chat IA mobile */
    .chat-messages { max-height: 50vh; }
    .chat-input-row { flex-wrap: wrap; }
    .chat-input-row textarea { font-size: 16px; }

    body { overflow-x: hidden; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stats-grid-6 { grid-template-columns: 1fr; }

    table th:nth-child(3), table td:nth-child(3) { display: none; }
    table th:nth-child(4), table td:nth-child(4) { display: none; }

    .topbar-title { font-size: 0.9rem; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .detail-tabs button { font-size: 0.7rem; padding: 6px 8px; }

    .card-header { flex-direction: column; align-items: flex-start; }
}

/* ============================================
   PIN GATE (2-factor dashboard)
   ============================================ */
.pin-card {
    background: #fff;
    padding: 40px 36px;
    border-radius: 20px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
    max-width: 420px;
    width: 90%;
    text-align: center;
}

.pin-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #1a56db, #3b82f6);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.pin-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 6px;
}

.pin-subtitle {
    color: #64748b;
    font-size: 0.88rem;
    margin-bottom: 24px;
    line-height: 1.4;
}

.pin-inputs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 8px;
}

.pin-input {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1.25rem;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    letter-spacing: 0.25em;
    text-align: center;
    outline: none;
    transition: border 0.2s, background 0.2s;
    background: #f8fafc;
    font-feature-settings: 'tnum' 1;
}

.pin-input:focus {
    border-color: #3b82f6;
    background: #fff;
}

.pin-input.error {
    border-color: var(--danger);
    background: #fef2f2;
    animation: pin-shake 0.35s ease-in-out;
}

@keyframes pin-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.pin-error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--danger-bg);
    border-radius: 10px;
    line-height: 1.4;
}

.pin-success {
    color: var(--success);
    font-size: 0.85rem;
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--success-bg);
    border-radius: 10px;
}

.pin-submit {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #1a56db, #2563eb);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 16px;
    transition: opacity 0.2s, transform 0.1s;
}

.pin-submit:hover:not(:disabled) {
    opacity: 0.9;
}

.pin-submit:active:not(:disabled) {
    transform: scale(0.98);
}

.pin-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pin-links {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    font-size: 0.8rem;
}

.pin-links a {
    color: #64748b;
    text-decoration: none;
    transition: color 0.2s;
}

.pin-links a:hover {
    color: #1a56db;
    text-decoration: underline;
}

.pin-links a#pinForgotLink {
    color: #3b82f6;
    font-weight: 500;
}

/* ============================================
   CATEGORY ICON PICKER
   ============================================ */
.icon-picker-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color var(--transition), background var(--transition);
    min-height: 42px;
    text-align: left;
}
.icon-picker-btn:hover {
    border-color: var(--primary-light);
    background: var(--primary-bg);
}
.icon-picker-btn[aria-expanded="true"] {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}
.icon-picker-btn .material-symbols-rounded {
    font-size: 22px;
    color: var(--primary);
    flex-shrink: 0;
}
.icon-picker-btn-label {
    flex: 1;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.icon-picker-btn-caret {
    color: var(--text-lighter);
    flex-shrink: 0;
    transition: transform var(--transition);
}
.icon-picker-btn[aria-expanded="true"] .icon-picker-btn-caret {
    transform: rotate(180deg);
}

.icon-picker-wrap {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-top: -4px;
}
.icon-picker-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    background: var(--bg-card);
    color: var(--text);
    margin-bottom: 10px;
}
.icon-picker-search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}
.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
    padding: 2px;
}
.icon-picker-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    background: var(--bg-card);
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
    color: var(--text);
}
.icon-picker-option:hover {
    background: var(--primary-bg);
    border-color: var(--primary-light);
    transform: translateY(-1px);
}
.icon-picker-option.selected {
    background: var(--primary-bg);
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary) inset;
}
.icon-picker-option .material-symbols-rounded {
    font-size: 22px;
    color: var(--primary);
}
.icon-picker-option-label {
    font-size: 0.62rem;
    color: var(--text-light);
    text-align: center;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.icon-picker-option.hidden { display: none; }
.icon-picker-grid::-webkit-scrollbar { width: 8px; }
.icon-picker-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Category list row — small icon chip in the first column. */
.cat-icon-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    margin-right: 8px;
    vertical-align: middle;
}
.cat-icon-chip .material-symbols-rounded {
    font-size: 18px;
}
