/* ==========================================================================
   Espace Com' - Mairie - System Design & Styling
   ========================================================================== */

/* Variables & Design Tokens */
:root {
    /* Color Palette */
    --primary: #1e3a8a;       /* Elegant Navy/Blue (French Institutional) */
    --primary-light: #3b82f6; /* Accent Blue */
    --primary-hover: #172554;
    --secondary: #64748b;     /* Slate */
    --secondary-light: #f1f5f9;
    --success: #10b981;       /* Emerald */
    --success-light: #d1fae5;
    --danger: #ef4444;        /* Rose/Red */
    --danger-light: #fee2e2;
    --warning: #f59e0b;       /* Amber */
    --warning-light: #fef3c7;
    
    /* Backgrounds & Neutral Colors */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --text-main: #1e293b;     /* Slate 800 */
    --text-muted: #64748b;    /* Slate 500 */
    --text-light: #94a3b8;
    
    /* Structure & Shadows */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-premium: 0 20px 25px -5px rgba(30, 58, 138, 0.05), 0 8px 10px -6px rgba(30, 58, 138, 0.05);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --max-width: 1200px;
}

/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

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

.logo-icon {
    width: 2.75rem;
    height: 2.75rem;
    color: var(--primary);
    background: var(--secondary-light);
    padding: 0.6rem;
    border-radius: var(--radius-md);
}

.header-titles h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.025em;
}

.header-titles p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.btn-icon {
    width: 1.1rem;
    height: 1.1rem;
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #ffffff;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: var(--secondary-light);
    border-color: var(--text-muted);
}

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

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-icon-danger {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.btn-icon-danger:hover {
    color: var(--danger);
    background-color: var(--danger-light);
}

/* Tabs Navigation */
.nav-tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 2px;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: -2px;
}

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

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-icon {
    width: 1.2rem;
    height: 1.2rem;
}

/* Main Content & Tab Content */
.main-content {
    flex: 1;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

/* Card layout */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-premium);
    border: 1px solid var(--border-color);
    padding: 2rem;
}

.card-header {
    margin-bottom: 1.75rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.25rem;
}

.card-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.card-header p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Form Styles */
.form-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1.5rem;
}

.col-span-6 {
    grid-column: span 6;
}

.col-span-12 {
    grid-column: span 12;
}

@media (max-width: 992px) {
    .col-span-6 {
        grid-column: span 12;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}

.required {
    color: var(--danger);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group textarea,
.form-group select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0.75rem 1rem;
    font-size: 16px; /* Évite le zoom automatique sur iOS et améliore la lisibilité */
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    transition: var(--transition);
    background-color: #ffffff;
    font-family: inherit;
}

.form-group input[type="date"] {
    max-width: 240px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Checkbox group styling */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.5rem 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.custom-checkbox {
    width: 1.25rem;
    height: 1.25rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    display: inline-block;
    position: relative;
    transition: var(--transition);
    background-color: #ffffff;
}

.checkbox-label:hover input ~ .custom-checkbox {
    border-color: var(--primary-light);
}

.checkbox-label input:checked ~ .custom-checkbox {
    background-color: var(--primary);
    border-color: var(--primary);
}

.checkbox-label input:checked ~ .custom-checkbox::after {
    content: "";
    position: absolute;
    left: 6px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Select wrapper styling */
.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: "▼";
    font-size: 0.6rem;
    color: var(--text-muted);
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    position: absolute;
    pointer-events: none;
}

.select-wrapper select {
    appearance: none;
    padding-right: 2.5rem;
}

/* Drag and Drop Zone */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    text-align: center;
    background-color: var(--secondary-light);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--primary-light);
    background-color: rgba(59, 130, 246, 0.03);
}

.drop-icon {
    width: 2.5rem;
    height: 2.5rem;
    color: var(--primary-light);
    margin-bottom: 0.25rem;
}

.drop-text {
    font-weight: 600;
    font-size: 0.95rem;
}

.drop-text span {
    color: var(--primary);
    text-decoration: underline;
}

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

.hidden-file-input {
    display: none;
}

/* File Preview Block */
.file-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-top: 0.75rem;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.file-icon {
    color: var(--primary-light);
    width: 1.5rem;
    height: 1.5rem;
}

.file-details {
    display: flex;
    flex-direction: column;
}

.file-name {
    font-size: 0.875rem;
    font-weight: 600;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
    margin-top: 0.5rem;
}

/* Tracker styling */
.tracker-header {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.filter-bar {
    display: flex;
    gap: 1rem;
    align-items: center;
}

@media (max-width: 768px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

.search-input-wrapper {
    position: relative;
    flex: 1;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.1rem;
    height: 1.1rem;
    color: var(--text-light);
}

.search-input-wrapper input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.search-input-wrapper input:focus {
    border-color: var(--primary-light);
}

.select-small select {
    padding: 0.625rem 2rem 0.625rem 1rem;
    font-size: 0.9rem;
}

/* Publications Grid/List */
.publications-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Publication Card */
.pub-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: var(--transition);
    position: relative;
}

.pub-card:hover {
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}

.pub-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.pub-meta {
    display: flex;
    flex-direction: column;
}

.pub-title-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.pub-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
}

.pub-info-line {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.25rem;
}

.pub-info-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pub-info-item svg {
    width: 0.9rem;
    height: 0.9rem;
}

.author-badge {
    background-color: var(--secondary-light);
    color: var(--text-main);
    padding: 0.15rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

/* Dropdown Options for cards */
.pub-actions {
    display: flex;
    gap: 0.5rem;
}

/* Details area */
.pub-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.pub-description {
    font-size: 0.925rem;
    color: var(--text-main);
    white-space: pre-wrap; /* Keeps indentation and linebreaks! */
    word-break: break-word;
    background: #f8fafc;
    padding: 1rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary-light);
}

/* Linked files inside publication card */
.pub-attachment {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: var(--secondary-light);
    border-radius: var(--radius-md);
    padding: 0.5rem 1rem;
    width: fit-content;
    border: 1px solid var(--border-color);
}

.pub-attachment-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition);
}

.pub-attachment-link:hover {
    color: var(--primary-light);
}

.pub-attachment-icon {
    width: 1.1rem;
    height: 1.1rem;
}

/* Grid of status targets */
.pub-targets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.target-badge {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
}

.target-label {
    font-weight: 600;
    color: var(--text-main);
}

/* Status state indicators */
.status-pill {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    text-transform: uppercase;
}

.status-pill.todo {
    background-color: var(--warning-light);
    color: #b45309; /* Dark Amber */
}

.status-pill.done {
    background-color: var(--success-light);
    color: #047857; /* Dark Emerald */
}

/* Admin status toggle behavior (Interactive) */
.admin-mode .status-pill-toggle {
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.admin-mode .status-pill-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Modals Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.6); /* Slate 900 translucent */
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: var(--transition);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-card {
    background: #ffffff;
    width: 90%;
    max-width: 480px;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    overflow: hidden;
    animation: modalSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--danger);
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-body p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--secondary-light);
}

.error-text {
    font-size: 0.8rem;
    color: var(--danger);
    font-weight: 500;
    margin-top: 0.25rem;
}

/* Success Pin Display Modal specific styles */
.text-center {
    text-align: center;
}

.success-title {
    color: var(--success) !important;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.success-icon {
    color: var(--success);
}

.pin-display-box {
    background: var(--secondary-light);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    margin: 0.5rem 0;
}

.pin-code-large {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: 0.15em;
    margin: 0.75rem 0;
    font-family: monospace;
}

.pin-warning {
    font-size: 0.75rem !important;
    color: #b45309 !important; /* amber dark */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.small-icon {
    width: 0.9rem;
    height: 0.9rem;
}

/* Helpers */
.hidden {
    display: none !important;
}

.loading-state, .empty-state {
    text-align: center;
    padding: 3rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Footer Styling */
.app-footer {
    text-align: center;
    padding: 1.5rem 0;
    font-size: 0.8rem;
    color: var(--text-light);
    border-top: 1px solid var(--border-color);
}

/* Stats Bar below filters */
.tracker-stats-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.25rem;
    padding: 0 0.5rem;
}

.tracker-stats-right {
    display: flex;
    gap: 1.25rem;
    align-items: center;
}

.tracker-stats-right .stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.tracker-stats-right .stat-item.todo {
    color: #b45309; /* Amber dark */
}

.tracker-stats-right .stat-item.done {
    color: #047857; /* Emerald dark */
}

.stat-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 700;
}

.stat-item.todo .stat-count-badge {
    background-color: var(--warning-light);
    color: #b45309;
    border: 1px solid #fde68a;
}

.stat-item.done .stat-count-badge {
    background-color: var(--success-light);
    color: #047857;
    border: 1px solid #a7f3d0;
}

.stat-label {
    color: var(--text-muted);
}

/* Responsivité Mobile et Tablettes */
@media (max-width: 768px) {
    .main-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1.25rem;
        padding: 1.25rem;
    }
    
    .header-logo {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }
    
    .header-titles {
        text-align: center;
    }
    
    .header-actions {
        display: flex;
        justify-content: center;
        width: 100%;
    }
    
    .header-actions .btn {
        width: 100%;
    }
}

@media (max-width: 1024px) {
    .checkbox-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
}

/* Styles pour les demandes Urgentes */
.pub-card.urgent-card {
    border: 2px solid var(--danger);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.08), var(--shadow-sm);
    background-color: #fffafb;
}

.pub-card.urgent-card:hover {
    box-shadow: 0 8px 16px rgba(239, 68, 68, 0.12), var(--shadow-md);
    border-color: #f87171;
}

.urgent-badge-alert {
    background-color: var(--danger);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    animation: pulse-urgent 1.5s infinite;
}

@keyframes pulse-urgent {
    0% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { transform: scale(1.02); opacity: 0.9; box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.card-urgent-reason {
    background-color: var(--danger-light);
    border-left: 4px solid var(--danger);
    color: #991b1b;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-bottom: 0.5rem;
}
