/* ==========================================
   MunaQasat.ma - Moroccan Tender Platform
   ========================================== */

:root {
    --primary: #1B4D3E;
    --primary-light: #2D7A5F;
    --primary-dark: #0F2E25;
    --accent: #C1272D;
    --accent-light: #E8434A;
    --gold: #D4A843;
    --gold-light: #F0C75E;
    --bg: #F0F2F5;
    --bg-card: #FFFFFF;
    --text: #1A1A2E;
    --text-secondary: #5A5A7A;
    --text-light: #8A8AAA;
    --border: #E0E0E8;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-hover: 0 8px 30px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== HEADER ===== */
.header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    color: white;
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

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

.logo-icon {
    width: 50px;
    height: 50px;
    background: rgba(255,255,255,0.15);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
}

.logo-text h1 {
    font-size: 1.6rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.logo-text h1 span {
    color: var(--gold-light);
}

.logo-text p {
    font-size: 0.8rem;
    opacity: 0.85;
    font-weight: 300;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(255,255,255,0.1);
    padding: 6px 14px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.pulse {
    width: 10px;
    height: 10px;
    background: #4ADE80;
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(74,222,128,0.7); }
    50% { opacity: 0.8; box-shadow: 0 0 0 8px rgba(74,222,128,0); }
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    transition: var(--transition);
}

.btn-refresh {
    background: rgba(255,255,255,0.15);
    color: white;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
}

.btn-refresh:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-1px);
}

.btn-refresh.spinning i {
    animation: spin 1s linear infinite;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
    padding: 10px 24px;
    text-decoration: none;
}

.btn-primary:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.last-update {
    font-size: 0.78rem;
    opacity: 0.7;
}

/* ===== STATS ===== */
.stats-section {
    max-width: 1400px;
    margin: -20px auto 0;
    padding: 0 24px;
    position: relative;
    z-index: 10;
}

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

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    transition: var(--transition);
    border-bottom: 3px solid transparent;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.stat-card.total { border-bottom-color: var(--primary); }
.stat-card.new { border-bottom-color: var(--gold); }
.stat-card.open { border-bottom-color: #4ADE80; }
.stat-card.closed { border-bottom-color: var(--accent); }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.stat-card.total .stat-icon { background: rgba(27,77,62,0.1); color: var(--primary); }
.stat-card.new .stat-icon { background: rgba(212,168,67,0.1); color: var(--gold); }
.stat-card.open .stat-icon { background: rgba(74,222,128,0.1); color: #22C55E; }
.stat-card.closed .stat-icon { background: rgba(193,39,45,0.1); color: var(--accent); }

.stat-number {
    font-size: 1.8rem;
    font-weight: 900;
    line-height: 1;
}

.stat-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 4px;
}

/* ===== CHARTS ===== */
.charts-section {
    max-width: 1400px;
    margin: 24px auto;
    padding: 0 24px;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.chart-card h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-card h3 i {
    color: var(--primary-light);
}

.chart-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bar-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bar-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    min-width: 120px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-track {
    flex: 1;
    height: 22px;
    background: var(--bg);
    border-radius: 11px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    border-radius: 11px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 24px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 8px;
}

.bar-fill span {
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
}

/* ===== SEARCH & FILTERS ===== */
.search-section {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px 16px;
}

.search-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px 16px;
    border: 2px solid transparent;
    transition: var(--transition);
    margin-bottom: 16px;
}

.search-box:focus-within {
    border-color: var(--primary-light);
    background: white;
    box-shadow: 0 0 0 4px rgba(45,122,95,0.1);
}

.search-box i {
    color: var(--text-light);
    font-size: 1.1rem;
    margin-left: 10px;
}

.search-box input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text);
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-light);
}

.search-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-light);
    padding: 8px;
    font-size: 1rem;
    transition: var(--transition);
}

.search-clear:hover {
    color: var(--accent);
}

.filters-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.filter-group {
    flex: 1;
    min-width: 160px;
}

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

.filter-group label i {
    margin-left: 4px;
    color: var(--primary-light);
}

.filter-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.88rem;
    color: var(--text);
    background: white;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='%235A5A7A'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    padding-left: 28px;
}

.filter-group select:focus {
    border-color: var(--primary-light);
    outline: none;
    box-shadow: 0 0 0 3px rgba(45,122,95,0.1);
}

/* ===== RESULTS ===== */
.results-section {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px 40px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.results-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.results-count span {
    color: var(--primary);
    font-weight: 900;
    font-size: 1.1rem;
}

.tenders-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== TENDER CARD ===== */
.tender-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    transition: var(--transition);
    cursor: pointer;
    border-right: 4px solid transparent;
    position: relative;
}

.tender-card:hover {
    transform: translateX(-4px);
    box-shadow: var(--shadow-hover);
    border-right-color: var(--primary);
}

.tender-card.is-new {
    border-right-color: var(--gold);
}

.tender-card.is-new::before {
    content: 'جديد';
    position: absolute;
    top: 12px;
    left: 12px;
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 12px;
}

.tender-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 10px;
}

.tender-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.5;
    flex: 1;
}

.tender-ref {
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 700;
    background: rgba(27,77,62,0.08);
    padding: 3px 10px;
    border-radius: 6px;
    white-space: nowrap;
}

.tender-org {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tender-org i {
    color: var(--primary-light);
}

.tender-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.tender-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
}

.tag-source {
    background: rgba(27,77,62,0.08);
    color: var(--primary);
}

.tag-category {
    background: rgba(212,168,67,0.1);
    color: #B8941F;
}

.tag-region {
    background: rgba(100,100,200,0.08);
    color: #5555AA;
}

.tag-type-public {
    background: rgba(74,222,128,0.1);
    color: #16A34A;
}

.tag-type-prive {
    background: rgba(168,85,247,0.1);
    color: #9333EA;
}

.tag-type-bc {
    background: rgba(59,130,246,0.1);
    color: #2563EB;
}

.tender-dates {
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--text-light);
}

.tender-dates i {
    margin-left: 4px;
}

.deadline-urgent {
    color: var(--accent) !important;
    font-weight: 700;
}

.deadline-soon {
    color: #F59E0B !important;
    font-weight: 600;
}

/* ===== LOADING ===== */
.loading-spinner {
    text-align: center;
    padding: 60px;
    color: var(--text-light);
}

.loading-spinner i {
    font-size: 2.5rem;
    color: var(--primary-light);
    margin-bottom: 16px;
}

.loading-spinner p {
    font-size: 0.95rem;
}

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.page-btn {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid var(--border);
    background: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition);
}

.page-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary);
    background: rgba(45,122,95,0.05);
}

.page-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

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

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: modalIn 0.3s ease;
}

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

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

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.6;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px;
    transition: var(--transition);
    flex-shrink: 0;
}

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

.modal-body {
    padding: 24px;
}

.modal-detail {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--bg);
}

.modal-detail:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.modal-detail-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    background: rgba(45,122,95,0.08);
    color: var(--primary);
    flex-shrink: 0;
}

.modal-detail-label {
    font-size: 0.78rem;
    color: var(--text-light);
    font-weight: 600;
}

.modal-detail-value {
    font-size: 0.92rem;
    color: var(--text);
    font-weight: 500;
    margin-top: 2px;
}

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

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    top: 80px;
    left: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--primary-dark);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    animation: toastIn 0.4s ease, toastOut 0.4s ease 3.6s forwards;
    max-width: 360px;
}

.toast i {
    font-size: 1.1rem;
}

.toast.success { border-right: 3px solid #4ADE80; }
.toast.info { border-right: 3px solid #60A5FA; }
.toast.warning { border-right: 3px solid #FBBF24; }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateX(-30px); }
}

/* ===== FOOTER ===== */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--text-light);
    font-size: 0.82rem;
    border-top: 1px solid var(--border);
    margin-top: 20px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-light);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 1rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .header-content { flex-direction: column; text-align: center; }
    .header-actions { justify-content: center; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .filters-row { flex-direction: column; }
    .filter-group { min-width: 100%; }
    .tender-top { flex-direction: column; }
    .tender-meta { flex-direction: column; align-items: flex-start; }
    .tender-dates { margin-right: 0; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { padding: 14px 18px; }
    .stat-number { font-size: 1.4rem; }
}
