/*
Theme Name: Water Association Manager - التسيير المالي للجمعيات
Theme URI: https://example.com/water-manager
Author: Water Manager Dev
Description: نظام متكامل لتسيير جمعيات الماء الصالح للشرب - إدارة المستفيدين، الفوترة، الاستخلاص، والتقارير المالية. A comprehensive water association management system for Moroccan drinking water associations.
Version: 1.0.0
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 8.0
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: water-manager
Domain Path: /languages
Tags: rtl-language-support, custom-menu, translation-ready
*/

/* ===== CSS Variables ===== */
:root {
    --wm-primary: #0369a1;
    --wm-primary-dark: #075985;
    --wm-primary-light: #38bdf8;
    --wm-accent: #f59e0b;
    --wm-accent-dark: #d97706;
    --wm-success: #16a34a;
    --wm-danger: #dc2626;
    --wm-warning: #ea580c;
    --wm-bg: #f0f9ff;
    --wm-surface: #ffffff;
    --wm-surface-alt: #f8fafc;
    --wm-border: #e2e8f0;
    --wm-text: #1e293b;
    --wm-text-light: #64748b;
    --wm-text-muted: #94a3b8;
    --wm-sidebar-width: 280px;
    --wm-header-height: 64px;
    --wm-radius: 12px;
    --wm-radius-sm: 8px;
    --wm-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --wm-shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
    --wm-font-ar: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
    --wm-font-num: 'Tabular Nums', 'Noto Sans Arabic', sans-serif;
    --wm-transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--wm-font-ar);
    background: var(--wm-bg);
    color: var(--wm-text);
    direction: rtl;
    line-height: 1.7;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--wm-primary); text-decoration: none; }
a:hover { color: var(--wm-primary-dark); }

/* ===== Login Page ===== */
.wm-login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0c4a6e 0%, #0369a1 50%, #0ea5e9 100%);
    position: relative;
    overflow: hidden;
}

.wm-login-wrapper::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -25%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(56,189,248,0.15) 0%, transparent 70%);
    border-radius: 50%;
}

.wm-login-wrapper::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -15%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(245,158,11,0.1) 0%, transparent 70%);
    border-radius: 50%;
}

.wm-login-card {
    background: var(--wm-surface);
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.2);
    position: relative;
    z-index: 1;
    text-align: center;
}

.wm-login-card .wm-logo-icon {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--wm-primary), var(--wm-primary-light));
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 32px;
    color: #fff;
}

.wm-login-card h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--wm-text);
}

.wm-login-card .wm-subtitle {
    color: var(--wm-text-light);
    font-size: 14px;
    margin-bottom: 32px;
}

.wm-login-card .wm-form-group {
    margin-bottom: 20px;
    text-align: right;
}

.wm-login-card label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--wm-text);
    margin-bottom: 6px;
}

.wm-login-card input[type="text"],
.wm-login-card input[type="password"],
.wm-login-card input[type="email"],
.wm-login-card input[type="tel"],
.wm-login-card input[type="number"],
.wm-login-card select {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0;
    box-sizing: border-box;
    padding: 12px 16px;
    border: 2px solid var(--wm-border);
    border-radius: var(--wm-radius-sm);
    font-family: var(--wm-font-ar);
    font-size: 15px;
    line-height: 1.5;
    transition: border-color var(--wm-transition);
    direction: rtl;
    background: #fff;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    margin: 0;
}

.wm-login-card select {
    appearance: auto;
    -webkit-appearance: auto;
    -moz-appearance: auto;
    cursor: pointer;
    height: auto;
}

.wm-login-card input:focus,
.wm-login-card select:focus {
    outline: none;
    border-color: var(--wm-primary);
    box-shadow: 0 0 0 3px rgba(3,105,161,0.1);
}

.wm-login-card .wm-btn-login {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--wm-primary), var(--wm-primary-dark));
    color: #fff;
    border: none;
    border-radius: var(--wm-radius-sm);
    font-family: var(--wm-font-ar);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--wm-transition);
    margin-top: 8px;
}

.wm-login-card .wm-btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(3,105,161,0.3);
}

/* ===== Dashboard Layout ===== */
.wm-app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.wm-sidebar {
    width: var(--wm-sidebar-width);
    background: linear-gradient(180deg, #0c4a6e 0%, #075985 100%);
    color: #fff;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform var(--wm-transition);
    overflow-y: auto;
}

.wm-sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 14px;
}

.wm-sidebar-header .wm-logo-sm {
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.wm-sidebar-header .wm-brand {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
}

.wm-sidebar-header .wm-brand small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    opacity: 0.7;
}

/* Association Selector */
.wm-assoc-selector {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.wm-assoc-selector label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
    display: block;
    margin-bottom: 8px;
}

.wm-assoc-selector select {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--wm-radius-sm);
    color: #fff;
    font-family: var(--wm-font-ar);
    font-size: 14px;
    cursor: pointer;
    direction: rtl;
}

.wm-assoc-selector select option {
    background: #0c4a6e;
    color: #fff;
}

.wm-assoc-num {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 13px;
    opacity: 0.8;
}

.wm-assoc-num strong {
    color: var(--wm-accent);
    font-size: 22px;
}

/* Nav */
.wm-sidebar-nav {
    padding: 16px 12px;
    flex: 1;
}

.wm-sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: rgba(255,255,255,0.75);
    border-radius: var(--wm-radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--wm-transition);
    margin-bottom: 2px;
}

.wm-sidebar-nav a:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.wm-sidebar-nav a.active {
    background: var(--wm-accent);
    color: #000;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(245,158,11,0.3);
}

.wm-sidebar-nav a .nav-icon {
    width: 22px;
    text-align: center;
    font-size: 16px;
}

.wm-sidebar-nav .nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.4;
    padding: 16px 16px 8px;
}

.wm-sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 13px;
}

.wm-sidebar-footer .wm-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.wm-sidebar-footer .wm-user-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* Main Content */
.wm-main {
    flex: 1;
    margin-right: var(--wm-sidebar-width);
    min-height: 100vh;
}

.wm-topbar {
    height: var(--wm-header-height);
    background: var(--wm-surface);
    border-bottom: 1px solid var(--wm-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.wm-topbar h2 {
    font-size: 18px;
    font-weight: 700;
}

.wm-topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wm-content {
    padding: 28px;
}

/* ===== Cards ===== */
.wm-card {
    background: var(--wm-surface);
    border-radius: var(--wm-radius);
    border: 1px solid var(--wm-border);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--wm-shadow);
}

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

.wm-card-header h3 {
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ===== Stat Cards ===== */
.wm-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.wm-stat-card {
    background: var(--wm-surface);
    border-radius: var(--wm-radius);
    border: 1px solid var(--wm-border);
    padding: 20px 24px;
    box-shadow: var(--wm-shadow);
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.wm-stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.wm-stat-icon.blue { background: #dbeafe; color: #2563eb; }
.wm-stat-icon.green { background: #dcfce7; color: #16a34a; }
.wm-stat-icon.amber { background: #fef3c7; color: #d97706; }
.wm-stat-icon.red { background: #fee2e2; color: #dc2626; }

.wm-stat-content .wm-stat-value {
    font-size: 26px;
    font-weight: 800;
    line-height: 1.2;
    color: var(--wm-text);
}

.wm-stat-content .wm-stat-label {
    font-size: 13px;
    color: var(--wm-text-light);
    margin-top: 2px;
}

/* ===== Tables ===== */
.wm-table-wrapper {
    overflow-x: auto;
    border-radius: var(--wm-radius-sm);
    border: 1px solid var(--wm-border);
}

.wm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.wm-table thead {
    background: var(--wm-surface-alt);
}

.wm-table th {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 13px;
    color: var(--wm-text-light);
    text-align: right;
    border-bottom: 2px solid var(--wm-border);
    white-space: nowrap;
}

.wm-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--wm-border);
    vertical-align: middle;
}

.wm-table tbody tr:hover {
    background: #f0f9ff;
}

.wm-table tbody tr:last-child td {
    border-bottom: none;
}

/* ===== Buttons ===== */
.wm-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--wm-radius-sm);
    font-family: var(--wm-font-ar);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--wm-transition);
    line-height: 1.4;
}

.wm-btn-primary {
    background: var(--wm-primary);
    color: #fff;
}
.wm-btn-primary:hover {
    background: var(--wm-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(3,105,161,0.25);
}

.wm-btn-accent {
    background: var(--wm-accent);
    color: #000;
}
.wm-btn-accent:hover {
    background: var(--wm-accent-dark);
}

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

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

.wm-btn-outline {
    background: transparent;
    border: 2px solid var(--wm-border);
    color: var(--wm-text);
}
.wm-btn-outline:hover {
    border-color: var(--wm-primary);
    color: var(--wm-primary);
}

.wm-btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.wm-btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--wm-radius-sm);
}

/* ===== Forms ===== */
.wm-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.wm-form-group {
    margin-bottom: 16px;
}

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

.wm-input,
.wm-select,
.wm-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--wm-border);
    border-radius: var(--wm-radius-sm);
    font-family: var(--wm-font-ar);
    font-size: 14px;
    color: var(--wm-text);
    transition: border-color var(--wm-transition);
    direction: rtl;
    background: var(--wm-surface);
}

.wm-input:focus,
.wm-select:focus,
.wm-textarea:focus {
    outline: none;
    border-color: var(--wm-primary);
    box-shadow: 0 0 0 3px rgba(3,105,161,0.1);
}

.wm-textarea {
    min-height: 100px;
    resize: vertical;
}

/* ===== Tabs ===== */
.wm-tabs {
    display: flex;
    gap: 4px;
    background: var(--wm-surface-alt);
    padding: 4px;
    border-radius: var(--wm-radius-sm);
    margin-bottom: 24px;
    overflow-x: auto;
}

.wm-tab {
    padding: 10px 20px;
    border: none;
    background: transparent;
    font-family: var(--wm-font-ar);
    font-size: 14px;
    font-weight: 600;
    color: var(--wm-text-light);
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--wm-transition);
    white-space: nowrap;
}

.wm-tab:hover {
    color: var(--wm-text);
    background: rgba(0,0,0,0.04);
}

.wm-tab.active {
    background: var(--wm-surface);
    color: var(--wm-primary);
    box-shadow: var(--wm-shadow);
}

.wm-tab-panel {
    display: none;
}

.wm-tab-panel.active {
    display: block;
}

/* ===== Badges & Tags ===== */
.wm-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.wm-badge-success { background: #dcfce7; color: #15803d; }
.wm-badge-danger { background: #fee2e2; color: #b91c1c; }
.wm-badge-warning { background: #fef3c7; color: #92400e; }
.wm-badge-info { background: #dbeafe; color: #1e40af; }

/* ===== Checkbox ===== */
.wm-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.wm-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--wm-primary);
    cursor: pointer;
}

/* ===== Toggle Switch ===== */
.wm-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

.wm-toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
}

.wm-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.wm-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--wm-border);
    border-radius: 26px;
    transition: var(--wm-transition);
}

.wm-toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    right: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: var(--wm-transition);
}

.wm-toggle-switch input:checked + .wm-toggle-slider {
    background: var(--wm-primary);
}

.wm-toggle-switch input:checked + .wm-toggle-slider::before {
    transform: translateX(-22px);
}

/* ===== Modal ===== */
.wm-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.wm-modal-overlay.active {
    display: flex;
}

.wm-modal {
    background: var(--wm-surface);
    border-radius: var(--wm-radius);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 60px rgba(0,0,0,0.2);
}

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

.wm-modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.wm-modal-body {
    padding: 24px;
}

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

/* ===== Alert / Notice ===== */
.wm-alert {
    padding: 14px 20px;
    border-radius: var(--wm-radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.wm-alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.wm-alert-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.wm-alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.wm-alert-danger { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }

/* ===== Empty State ===== */
.wm-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--wm-text-light);
}

.wm-empty-icon {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 16px;
}

.wm-empty h4 {
    font-size: 16px;
    margin-bottom: 8px;
    color: var(--wm-text);
}

/* ===== Responsive ===== */
.wm-mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--wm-text);
    cursor: pointer;
}

@media (max-width: 1024px) {
    .wm-sidebar {
        transform: translateX(100%);
    }
    .wm-sidebar.open {
        transform: translateX(0);
    }
    .wm-main {
        margin-right: 0;
    }
    .wm-mobile-toggle {
        display: block;
    }
}

@media (max-width: 640px) {
    .wm-content {
        padding: 16px;
    }
    .wm-stats-grid {
        grid-template-columns: 1fr;
    }
    .wm-form-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Global Loader ===== */
.wm-loader-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.wm-loader-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.wm-loader-box {
    background: #fff;
    border-radius: 16px;
    padding: 28px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.wm-loader-spinner {
    width: 40px;
    height: 40px;
    border: 3.5px solid #e2e8f0;
    border-top-color: #0369a1;
    border-radius: 50%;
    animation: wm-spin 0.7s linear infinite;
}
@keyframes wm-spin {
    to { transform: rotate(360deg); }
}
.wm-loader-text {
    font-size: 14px;
    font-weight: 600;
    color: #334155;
}

/* Button loader state */
.wm-btn.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
}
.wm-btn.loading .btn-text {
    visibility: hidden;
}
.wm-btn.loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    top: 50%;
    left: 50%;
    margin-top: -9px;
    margin-left: -9px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: wm-spin 0.6s linear infinite;
}

/* Table skeleton loader */
.wm-skeleton-row td {
    position: relative;
    overflow: hidden;
}
.wm-skeleton-row td::after {
    content: '';
    display: block;
    height: 12px;
    width: 70%;
    margin: 4px auto;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: wm-shimmer 1.2s ease-in-out infinite;
    border-radius: 4px;
}
@keyframes wm-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Content loading placeholder */
.wm-loading-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #94a3b8;
    gap: 12px;
}
.wm-loading-placeholder .wm-loader-spinner {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

/* ===== Print Styles ===== */
@media print {
    .wm-sidebar, .wm-topbar, .wm-btn, .wm-tabs { display: none !important; }
    .wm-main { margin: 0 !important; }
    .wm-card { box-shadow: none; border: 1px solid #ccc; }
    .wm-loader-overlay { display: none !important; }
}
