/**
 * ImmoGest - Main Stylesheet
 * Property Management Application
 */

/* ==========================================
   CSS Variables
   ========================================== */

:root {
    /* Colors - Light theme */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-input: #ffffff;
    
    --border: #e2e8f0;
    --border-light: #cbd5e1;
    --border-focus: #94a3b8;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-placeholder: #94a3b8;
    
    /* Accent colors */
    --accent-green: #16a34a;
    --accent-green-dim: #15803d;
    --accent-green-bg: rgba(22, 163, 74, 0.1);
    
    --accent-red: #dc2626;
    --accent-red-bg: rgba(220, 38, 38, 0.1);
    
    --accent-orange: #ea580c;
    --accent-orange-bg: rgba(234, 88, 12, 0.1);
    
    --accent-blue: #2563eb;
    --accent-blue-bg: rgba(37, 99, 235, 0.1);
    
    --accent-purple: #9333ea;
    --accent-purple-bg: rgba(147, 51, 234, 0.1);
    
    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 64px;
    
    /* Typography */
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    
    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* Shadows for light theme */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* ==========================================
   Reset & Base
   ========================================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    height: auto;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

/* ==========================================
   Layout
   ========================================== */

.app-layout {
    min-height: 100vh;
}

.main-content {
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-height: 100vh;
}

/* ==========================================
   Sidebar
   ========================================== */

.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

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

.logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent-green);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-icon svg {
    width: 20px;
    height: 20px;
    color: white;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo-text span {
    color: var(--accent-green);
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: 24px 0;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
    padding: 0 12px;
}

.nav-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 0 12px;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    position: relative;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: -12px;
    width: 3px;
    height: 24px;
    background: var(--accent-green);
    border-radius: 0 2px 2px 0;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    flex-shrink: 0;
}

.nav-item.active svg,
.nav-item:hover svg {
    opacity: 1;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-blue));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: white;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.btn-logout {
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.btn-logout:hover {
    background: var(--bg-hover);
    color: var(--accent-red);
}

/* ==========================================
   Page Header
   ========================================== */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.page-title h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.page-title p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.page-actions {
    display: flex;
    gap: 12px;
}

/* ==========================================
   Buttons
   ========================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    white-space: nowrap;
}

.btn svg {
    width: 18px;
    height: 18px;
}

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

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

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-danger {
    background: var(--accent-red-bg);
    color: var(--accent-red);
}

.btn-danger:hover {
    background: var(--accent-red);
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* ==========================================
   Cards
   ========================================== */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

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

.card-title {
    font-weight: 600;
    font-size: 1rem;
}

.card-action {
    font-size: 0.8rem;
    color: var(--accent-green);
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.card-action:hover {
    opacity: 0.8;
}

.card-body {
    padding: 24px;
}

/* ==========================================
   Stats Grid
   ========================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
}

.stat-card.green::before { background: var(--accent-green); }
.stat-card.blue::before { background: var(--accent-blue); }
.stat-card.orange::before { background: var(--accent-orange); }
.stat-card.red::before { background: var(--accent-red); }

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-card.green .stat-value { color: var(--accent-green); }
.stat-card.blue .stat-value { color: var(--accent-blue); }
.stat-card.orange .stat-value { color: var(--accent-orange); }
.stat-card.red .stat-value { color: var(--accent-red); }

.stat-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stat-detail strong {
    color: var(--text-secondary);
}

/* ==========================================
   Tables
   ========================================== */

.table-container {
    overflow-x: auto;
}

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

th {
    text-align: left;
    padding: 14px 24px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

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

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

tbody tr {
    transition: background var(--transition-fast);
}

tbody tr:hover {
    background: var(--bg-hover);
}

/* ==========================================
   Status Badges
   ========================================== */

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}

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

.status.paid, .status.success {
    background: var(--accent-green-bg);
    color: var(--accent-green);
}

.status.pending, .status.warning {
    background: var(--accent-orange-bg);
    color: var(--accent-orange);
}

.status.late, .status.danger {
    background: var(--accent-red-bg);
    color: var(--accent-red);
}

.status.info {
    background: var(--accent-blue-bg);
    color: var(--accent-blue);
}

/* ==========================================
   Amount formatting
   ========================================== */

.amount {
    font-family: var(--font-mono);
    font-weight: 500;
}

.amount.positive { color: var(--accent-green); }
.amount.negative { color: var(--accent-red); }

/* ==========================================
   Properties List
   ========================================== */

.properties-list {
    padding: 8px;
}

.property-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.property-item:hover {
    background: var(--bg-hover);
}

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

.property-icon svg {
    width: 24px;
    height: 24px;
}

.property-icon.immeuble {
    background: var(--accent-blue-bg);
    color: var(--accent-blue);
}

.property-icon.ppe {
    background: var(--accent-purple-bg);
    color: var(--accent-purple);
}

.property-icon.maison {
    background: var(--accent-green-bg);
    color: var(--accent-green);
}

.property-details {
    flex: 1;
    min-width: 0;
}

.property-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.property-address {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.property-stats {
    text-align: right;
}

.property-units {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.95rem;
}

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

/* ==========================================
   Alerts
   ========================================== */

.alert {
    display: flex;
    gap: 16px;
    padding: 16px;
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    border-left: 3px solid;
}

.alert.warning {
    background: var(--bg-hover);
    border-color: var(--accent-orange);
}

.alert.info {
    background: var(--bg-hover);
    border-color: var(--accent-blue);
}

.alert.success {
    background: var(--bg-hover);
    border-color: var(--accent-green);
}

.alert.danger {
    background: var(--bg-hover);
    border-color: var(--accent-red);
}

.alert-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.alert.warning .alert-icon { color: var(--accent-orange); }
.alert.info .alert-icon { color: var(--accent-blue); }
.alert.success .alert-icon { color: var(--accent-green); }
.alert.danger .alert-icon { color: var(--accent-red); }

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.alert-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ==========================================
   Flash Messages
   ========================================== */

.flash-message {
    padding: 16px 24px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.flash-message.success {
    background: var(--accent-green-bg);
    border: 1px solid var(--accent-green);
    color: var(--accent-green);
}

.flash-message.error {
    background: var(--accent-red-bg);
    border: 1px solid var(--accent-red);
    color: var(--accent-red);
}

/* ==========================================
   Content Grid
   ========================================== */

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

.content-grid .card + .card {
    margin-top: 24px;
}

/* ==========================================
   Expenses List
   ========================================== */

.expenses-list {
    padding: 16px 24px;
}

.expense-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.expense-item:last-child {
    border-bottom: none;
}

.expense-category {
    display: flex;
    align-items: center;
    gap: 12px;
}

.expense-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.expense-dot.mazout { background: var(--accent-orange); }
.expense-dot.electricite { background: var(--accent-blue); }
.expense-dot.eau { background: #06b6d4; }
.expense-dot.conciergerie { background: var(--accent-green); }
.expense-dot.assurance { background: var(--accent-purple); }
.expense-dot.travaux { background: var(--accent-red); }
.expense-dot.ppe_charges { background: #ec4899; }

.expense-label {
    font-size: 0.9rem;
}

.expense-amount {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ==========================================
   Mobile Header
   ========================================== */

.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    z-index: 90;
}

.mobile-menu-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

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

.mobile-logo .logo-text {
    font-size: 1.25rem;
    font-weight: 700;
}

.mobile-logo .logo-text span {
    color: var(--accent-green);
}

.sidebar-close-btn {
    display: none;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.sidebar-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 95;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.sidebar-overlay.active {
    opacity: 1;
}

/* ==========================================
   Responsive
   ========================================== */

@media (max-width: 1400px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .content-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1024px) {
    .mobile-header {
        display: flex;
    }
    
    .sidebar-close-btn {
        display: flex;
    }
    
    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }
    
    .sidebar-overlay.active {
        pointer-events: auto;
    }
    
    .app-layout {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        padding-top: 76px;
        max-height: none;
        overflow-y: visible;
    }
    
    body.sidebar-open {
        overflow: hidden;
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: 76px 16px 16px 16px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .stat-card {
        padding: 16px 20px;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .page-header {
        flex-direction: column;
        gap: 16px;
        margin-bottom: 20px;
    }
    
    .page-title h1 {
        font-size: 1.5rem;
    }
    
    .page-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .page-actions .btn {
        flex: 1;
        min-width: 140px;
    }
    
    /* Table responsive - proper horizontal scroll */
    .table-container {
        margin: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 500px;
    }
    
    .card {
        border-radius: var(--radius-md);
        overflow: hidden;
    }
    
    th, td {
        padding: 12px 14px;
        font-size: 0.85rem;
    }
    
    th:first-child, td:first-child {
        padding-left: 16px;
    }
    
    th:last-child, td:last-child {
        padding-right: 16px;
    }
    
    th {
        font-size: 0.65rem;
    }
    
    /* Cards */
    .card-header {
        padding: 16px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .card-body {
        padding: 16px;
    }
    
    /* Form responsive */
    .form-row {
        flex-direction: column;
    }
    
    .filters-form {
        flex-direction: column;
    }
    
    .filter-group {
        width: 100%;
    }
    
    /* Properties list */
    .property-item {
        padding: 12px;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .property-icon {
        width: 40px;
        height: 40px;
    }
    
    .property-icon svg {
        width: 20px;
        height: 20px;
    }
    
    .property-details {
        flex: 1;
        min-width: calc(100% - 60px);
    }
    
    .property-stats {
        width: 100%;
        display: flex;
        justify-content: space-between;
        padding-top: 8px;
        border-top: 1px solid var(--border);
    }
    
    /* Alerts */
    .alert {
        padding: 12px;
    }
    
    .alert-title {
        font-size: 0.85rem;
    }
    
    .alert-desc {
        font-size: 0.75rem;
    }
    
    /* Summary cards */
    .summary-cards {
        grid-template-columns: 1fr;
    }
    
    /* Info grid in detail views */
    .info-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    /* Modal responsive */
    .modal-content {
        margin: 16px;
        max-height: calc(100vh - 32px);
    }
    
    .modal-lg {
        width: calc(100% - 32px);
    }
    
    /* Buttons */
    .btn {
        padding: 10px 16px;
    }
    
    .btn-lg {
        padding: 12px 20px;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 68px 12px 12px 12px;
    }
    
    .mobile-header {
        padding: 0 12px;
    }
    
    .page-title h1 {
        font-size: 1.25rem;
    }
    
    .page-title p {
        font-size: 0.8rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    /* Tables on small screens */
    table {
        min-width: 400px;
    }
    
    th, td {
        padding: 10px 10px;
        font-size: 0.8rem;
    }
    
    th:first-child, td:first-child {
        padding-left: 12px;
    }
    
    th:last-child, td:last-child {
        padding-right: 12px;
    }
    
    /* Hide less important columns on very small screens */
    .hide-mobile {
        display: none;
    }
    
    /* Stack page actions */
    .page-actions {
        flex-direction: column;
    }
    
    .page-actions .btn {
        width: 100%;
    }
    
    /* Cards */
    .card-header {
        padding: 14px;
    }
    
    .card-body {
        padding: 14px;
    }
}
