:root {
    --bg: #0a0e1a;
    --bg-card: #111726;
    --bg-card-hover: #161d30;
    --border: #1f2940;
    --text: #e8edf7;
    --text-dim: #8b96ad;
    --accent: #00d99d;
    --accent-dim: #009d72;
    --gold: #f5b942;
    --red: #ff5a6e;
    --blue: #4a9eff;
    --radius: 16px;
    --font-display: 'Cairo', sans-serif;
    --font-body: 'IBM Plex Sans Arabic', sans-serif;
}

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

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    position: relative;
    overflow-x: hidden;
}

.bg-grid {
    position: fixed; inset: 0; z-index: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 60px 60px;
    opacity: 0.15;
    mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 40%, transparent 100%);
}
.bg-glow {
    position: fixed; top: -300px; left: 50%; transform: translateX(-50%);
    width: 800px; height: 800px; z-index: 0;
    background: radial-gradient(circle, rgba(0,217,157,0.12), transparent 60%);
    pointer-events: none;
}

.site-header {
    position: relative; z-index: 1;
    text-align: center; padding: 60px 20px 30px;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 14px; }
.brand-mark {
    display: grid; place-items: center;
    width: 52px; height: 52px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    border-radius: 14px; font-size: 28px; font-weight: 900; color: var(--bg);
    box-shadow: 0 8px 30px rgba(0,217,157,0.3);
}
.site-header h1 {
    font-family: var(--font-display); font-weight: 900;
    font-size: clamp(28px, 5vw, 44px);
    background: linear-gradient(135deg, #fff, var(--accent));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--text-dim); margin-top: 14px; font-size: 16px; }

.container { position: relative; z-index: 1; max-width: 1100px; margin: 0 auto; padding: 20px; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 22px;
    backdrop-filter: blur(10px);
}

/* منطقة الرفع */
.upload-zone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px; text-align: center; cursor: pointer;
    transition: all 0.3s; margin-bottom: 26px;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(0,217,157,0.04);
}
.upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-title { font-weight: 600; font-size: 17px; }
.upload-hint { color: var(--text-dim); font-size: 13px; margin-top: 6px; }
.preview { display: none; max-width: 220px; max-height: 220px; margin: 16px auto 0; border-radius: 12px; }
.preview.show { display: block; }

/* شبكة التكاليف */
.costs-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px; margin-bottom: 26px;
}
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 7px; font-weight: 500; }
.field input {
    width: 100%; padding: 13px 14px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 11px; color: var(--text); font-family: var(--font-body);
    font-size: 15px; transition: border-color 0.2s;
}
.field input:focus { outline: none; border-color: var(--accent); }

.btn-primary {
    width: 100%; padding: 16px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    color: var(--bg); border: none; border-radius: 12px;
    font-family: var(--font-display); font-weight: 700; font-size: 17px;
    cursor: pointer; transition: transform 0.15s, box-shadow 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 12px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(0,217,157,0.35); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-loader {
    width: 18px; height: 18px; border: 3px solid rgba(10,14,26,0.3);
    border-top-color: var(--bg); border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* النتائج */
.results { animation: fadeUp 0.5s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }

.market-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 22px; }
.market-card { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.market-label { font-size: 13px; color: var(--text-dim); }
.market-value { font-family: var(--font-display); font-size: 30px; font-weight: 900; }
.market-source { font-size: 12px; color: var(--text-dim); }
.market-card.lowest .market-value { color: var(--red); }
.market-card.highest .market-value { color: var(--gold); }
.market-card.suggested {
    border-color: var(--accent);
    box-shadow: 0 0 40px rgba(0,217,157,0.15);
    background: linear-gradient(180deg, rgba(0,217,157,0.06), var(--bg-card));
}
.market-card.suggested .market-value { color: var(--accent); }

.section-title { font-family: var(--font-display); font-weight: 700; font-size: 20px; margin-bottom: 20px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; text-align: right; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-dim); font-weight: 600; }
td a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; }
.price-cell { font-weight: 700; font-family: var(--font-display); }

/* التحليل المالي */
.breakdown { display: flex; flex-direction: column; gap: 0; }
.breakdown-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 0; border-bottom: 1px solid var(--border);
}
.breakdown-row .label { color: var(--text-dim); }
.breakdown-row .value { font-weight: 600; font-family: var(--font-display); }
.breakdown-row.op .label::before { content: '+ '; color: var(--accent); font-weight: 900; }
.formula-result {
    margin-top: 22px; padding: 22px;
    background: linear-gradient(135deg, rgba(0,217,157,0.08), transparent);
    border: 1px solid var(--accent); border-radius: 12px;
    display: flex; justify-content: space-between; align-items: center;
}
.formula-result .label { font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.formula-result .value { font-family: var(--font-display); font-weight: 900; font-size: 28px; color: var(--accent); }

.ai-card { border-color: var(--blue); }
.ai-card .section-title { color: var(--blue); }
.ai-note { margin-top: 14px; padding: 14px; background: var(--bg); border-radius: 10px; color: var(--text-dim); font-size: 14px; }

.error-box {
    background: rgba(255,90,110,0.1); border: 1px solid var(--red);
    color: var(--red); padding: 18px; border-radius: 12px; text-align: center;
}

.site-footer { text-align: center; padding: 40px 20px; color: var(--text-dim); font-size: 13px; position: relative; z-index: 1; }

@media (max-width: 640px) {
    .market-cards { grid-template-columns: 1fr; }
    .market-value { font-size: 26px; }
}

/* مؤشر الكاش */
.cache-badge {
    background: rgba(74,158,255,0.12);
    border: 1px solid var(--blue);
    color: var(--blue);
    padding: 12px 18px; border-radius: 12px;
    text-align: center; font-size: 14px; font-weight: 600;
    margin-bottom: 18px;
}
