:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface2: #1e2530;
    --border: #2a3444;
    --gold: #c8973a;
    --gold-light: #e8b85a;
    --gold-dim: rgba(200, 151, 58, 0.15);
    --green: #22c55e;
    --green-dim: rgba(34, 197, 94, 0.12);
    --green-border: rgba(34, 197, 94, 0.35);
    --red: #ef4444;
    --red-dim: rgba(239, 68, 68, 0.12);
    --red-border: rgba(239, 68, 68, 0.35);
    --text: #e2e8f0;
    --text-muted: #7a8899;
    --radius: 14px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Tajawal", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Background ornament ── */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(
            ellipse 60% 40% at 50% -10%,
            rgba(200, 151, 58, 0.18) 0%,
            transparent 70%
        ),
        radial-gradient(
            ellipse 40% 30% at 80% 80%,
            rgba(200, 151, 58, 0.07) 0%,
            transparent 60%
        );
    pointer-events: none;
    z-index: 0;
}

/* geometric pattern overlay */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            45deg,
            rgba(200, 151, 58, 0.03) 0,
            rgba(200, 151, 58, 0.03) 1px,
            transparent 0,
            transparent 50%
        ),
        repeating-linear-gradient(
            -45deg,
            rgba(200, 151, 58, 0.03) 0,
            rgba(200, 151, 58, 0.03) 1px,
            transparent 0,
            transparent 50%
        );
    background-size: 28px 28px;
    pointer-events: none;
    z-index: 0;
}

.wrap {
    position: relative;
    z-index: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

/* ── Header ── */
header {
    text-align: center;
    padding: 52px 0 36px;
}

.header-badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--gold-dim);
    border: 1px solid rgba(200, 151, 58, 0.4);
    border-radius: 50px;
    padding: 6px 18px;
    font-size: 13px;
    color: var(--gold-light);
    letter-spacing: 0.04em;
    animation: fadeDown 0.6s ease both;
}

.header-badge .dot {
    width: 7px;
    height: 7px;
    background: var(--gold);
    border-radius: 50%;
    animation: pulse-gold 2s infinite;
}

@keyframes pulse-gold {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.7);
    }
}

h1 {
    font-family: "Amiri", serif;
    font-size: clamp(2rem, 5vw, 3.4rem);
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
    animation: fadeDown 0.7s 0.1s ease both;
}

h1 span {
    background: linear-gradient(135deg, var(--gold-light), var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 15px;
    margin-top: 10px;
    animation: fadeDown 0.7s 0.2s ease both;
}

/* ── Controls ── */
.controls {
    display: flex;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 28px;
    animation: fadeDown 0.7s 0.3s ease both;
}

.search-box {
    flex: 1;
    min-width: 220px;
    position: relative;
}

.search-box input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 44px 12px 16px;
    color: var(--text);
    font-family: "Tajawal", sans-serif;
    font-size: 15px;
    outline: none;
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

.search-box input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(200, 151, 58, 0.15);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 17px;
    pointer-events: none;
}

.filter-btns {
    display: flex;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 5px;
}

.filter-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: "Tajawal", sans-serif;
    font-size: 14px;
    padding: 8px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.filter-btn.active {
    background: var(--gold-dim);
    color: var(--gold-light);
    font-weight: 600;
}

.filter-btn:hover:not(.active) {
    background: var(--surface2);
    color: var(--text);
}

.refresh-btn {
    background: var(--gold-dim);
    border: 1px solid rgba(200, 151, 58, 0.4);
    color: var(--gold-light);
    font-family: "Tajawal", sans-serif;
    font-size: 14px;
    padding: 10px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 7px;
}

.refresh-btn:hover {
    background: rgba(200, 151, 58, 0.25);
}

.refresh-btn.spinning svg {
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Stats bar ── */
.stats-bar {
    display: flex;
    gap: 14px;
    margin-bottom: 28px;
    flex-wrap: wrap;
    animation: fadeDown 0.7s 0.35s ease both;
}

.stat-card {
    flex: 1;
    min-width: 140px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-icon.total {
    background: var(--gold-dim);
}

.stat-icon.avail {
    background: var(--green-dim);
}

.stat-icon.unavail {
    background: var(--red-dim);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

.stat-num {
    font-size: 24px;
    font-weight: 800;
    margin-top: 1px;
}

.stat-num.gold {
    color: var(--gold-light);
}

.stat-num.green {
    color: var(--green);
}

.stat-num.red {
    color: var(--red);
}

/* ── Grid ── */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    animation: fadeUp 0.5s 0.4s ease both;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: default;
    transition:
        transform 0.18s,
        box-shadow 0.18s;
    position: relative;
    overflow: hidden;
    animation: cardIn 0.4s ease both;
}

.card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

.card:hover {
    transform: translateY(-3px);
}

.card.available {
    background: linear-gradient(
        135deg,
        var(--surface) 60%,
        rgba(34, 197, 94, 0.06)
    );
}

.card.available::before {
    border-color: var(--green-border);
}

.card.available:hover {
    box-shadow: 0 8px 32px rgba(34, 197, 94, 0.18);
}

.card.unavailable {
    background: linear-gradient(
        135deg,
        var(--surface) 60%,
        rgba(239, 68, 68, 0.04)
    );
    opacity: 0.75;
}

.card.unavailable::before {
    border-color: var(--red-border);
}

.card.unavailable:hover {
    box-shadow: 0 8px 32px rgba(239, 68, 68, 0.1);
    opacity: 0.9;
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.wilaya-code {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--surface2);
    border-radius: 6px;
    padding: 2px 7px;
    letter-spacing: 0.05em;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 3px;
}

.available .status-dot {
    background: var(--green);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

.unavailable .status-dot {
    background: var(--red);
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

.wilaya-name-ar {
    font-family: "Amiri", serif;
    font-size: 19px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}

.wilaya-name-fr {
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.status-label {
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
    padding: 3px 9px;
    border-radius: 6px;
    display: inline-block;
    width: fit-content;
}

.available .status-label {
    color: var(--green);
    background: var(--green-dim);
}

.unavailable .status-label {
    color: var(--red);
    background: var(--red-dim);
}

/* Shimmer skeleton */
.skeleton {
    animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
    0% {
        background-position: -600px 0;
    }

    100% {
        background-position: 600px 0;
    }
}

.sk-card {
    background: linear-gradient(
        90deg,
        var(--surface) 25%,
        var(--surface2) 50%,
        var(--surface) 75%
    );
    background-size: 600px 100%;
    border-radius: var(--radius);
    height: 112px;
    animation: shimmer 1.4s infinite;
    border: 1px solid var(--border);
}

/* Error / empty */
.message-box {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.message-box .icon {
    font-size: 42px;
    margin-bottom: 14px;
}

.message-box p {
    font-size: 16px;
}

.error-msg {
    color: var(--red);
    font-size: 13px;
}

/* Last update */
.last-update {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 28px;
}

/* Animations */
@keyframes fadeDown {
    from {
        opacity: 0;
        transform: translateY(-16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ── Live indicator ── */
.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 50px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
    transition: all 0.4s;
}

.live-indicator.ok {
    background: var(--green-dim);
    border-color: var(--green-border);
    color: var(--green);
}

.live-indicator.fetching {
    background: var(--gold-dim);
    border-color: rgba(200, 151, 58, 0.4);
    color: var(--gold-light);
}

.live-indicator.error {
    background: var(--red-dim);
    border-color: var(--red-border);
    color: var(--red);
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.live-indicator.ok .live-dot {
    background: var(--green);
    animation: pulse-live 1.2s infinite;
}

.live-indicator.fetching .live-dot {
    background: var(--gold);
    animation: pulse-live 0.6s infinite;
}

.live-indicator.error .live-dot {
    background: var(--red);
    animation: none;
}

@keyframes pulse-live {
    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(0.5);
        opacity: 0.4;
    }
}

/* Card status change flash */
.card.status-changing {
    opacity: 0.3;
    transform: scale(0.97);
    transition:
        opacity 0.2s,
        transform 0.2s;
}

.card.status-changed {
    animation: statusFlash 1.2s ease;
}

@keyframes statusFlash {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.3);
    }

    30% {
        box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.15);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

@media (max-width: 520px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-btns {
        justify-content: center;
    }
}
