/* ProExcel Business Systems — نظام تحليل الفواتير */
@font-face {
    font-family: 'Cairo';
    src: url('../fonts/Cairo-Variable.ttf') format('truetype');
    font-weight: 200 900;
    font-style: normal;
    font-display: swap;
}

:root {
    --primary: #123A63;
    --primary-dark: #0D2B4A;
    --primary-light: #1D5A96;
    --green: #21A366;
    --green-dark: #178450;
    --bg: #F2F5F9;
    --panel: #FFFFFF;
    --border: #D7DEE8;
    --text: #1E2A38;
    --muted: #5C6B7C;
    --danger: #C0392B;
    --warn: #B7791F;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.7;
}

/* شريط الديمو */
.demo-banner {
    background: #FDF3D7;
    border-bottom: 2px solid #E4C65B;
    color: #6B4E00;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 18px;
    flex-wrap: wrap;
}
.demo-banner .demo-tag {
    background: #B7791F;
    color: #FFFFFF;
    font-weight: 800;
    font-size: 17px;
    padding: 2px 18px;
    border-radius: 6px;
    letter-spacing: 1px;
}
.demo-banner .demo-note { font-weight: 600; }
.demo-banner .demo-exit {
    margin-inline-start: auto;
    color: #6B4E00;
    font-weight: 700;
    text-decoration: underline;
}
body.is-demo .topbar { border-top: 3px solid #B7791F; }
.demo-badge { background: #B7791F; }

/* الترويسة */
.topbar {
    background: var(--primary);
    color: #FFFFFF;
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    flex-wrap: wrap;
    gap: 8px;
}
.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand-en { font-size: 18px; font-weight: 300; letter-spacing: .3px; }
.brand-en b { font-weight: 800; color: #7FD8AC; }
.brand-sep { width: 1px; height: 22px; background: rgba(255,255,255,.35); }
.brand-ar { font-size: 14px; opacity: .92; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 700; }
.badge, .role-badge {
    font-size: 12px;
    padding: 2px 12px;
    border-radius: 20px;
    background: var(--green);
    color: #FFFFFF;
    font-weight: 700;
}
.role-badge { background: rgba(255,255,255,.16); }

/* الهيكل */
.shell { display: flex; min-height: calc(100vh - 130px); }
.sidebar {
    width: 265px;
    flex-shrink: 0;
    background: var(--primary-dark);
    color: #DCE6F2;
    padding: 14px 10px;
}
.content {
    flex: 1;
    padding: 22px 26px;
    min-width: 0;
}

/* القائمة الجانبية */
.menu { list-style: none; margin: 0; padding: 0; }
.menu-section { margin-bottom: 4px; }
.menu-section-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 0;
    color: #B9C8DC;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 700;
    padding: 9px 10px;
    cursor: pointer;
    border-radius: 6px;
    text-align: right;
}
.menu-section-btn:hover { background: rgba(255,255,255,.07); color: #FFFFFF; }
.menu-section-btn.active-parent { background: rgba(33,163,102,.18); color: #FFFFFF; }
.menu-arrow {
    width: 0; height: 0;
    border-inline-start: 6px solid transparent;
    border-inline-end: 6px solid transparent;
    border-top: 7px solid currentColor;
    transition: transform .15s ease;
    flex-shrink: 0;
}
.menu-section.open > .menu-section-btn .menu-arrow { transform: rotate(180deg); }
.menu-items {
    list-style: none;
    margin: 0;
    padding: 0;
    display: none;
}
.menu-section.open > .menu-items { display: block; }
.menu-link {
    display: block;
    color: #D4DEEA;
    text-decoration: none;
    padding: 7px 26px 7px 10px;
    border-radius: 6px;
    font-size: 13.8px;
}
.menu-link:hover { background: rgba(255,255,255,.08); color: #FFFFFF; }
.menu-link.active {
    background: var(--green);
    color: #FFFFFF;
    font-weight: 700;
}

/* البطاقات */
.stat-card-link { text-decoration: none; color: inherit; }
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-inline-start: 5px solid var(--primary);
    border-radius: 8px;
    padding: 14px 16px;
}
.stat-card:hover { box-shadow: 0 2px 8px rgba(18,58,99,.12); }
.stat-value { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat-label { color: var(--muted); font-size: 13.5px; font-weight: 600; }
.stat-card.c-green { border-inline-start-color: var(--green); }
.stat-card.c-green .stat-value { color: var(--green-dark); }
.stat-card.c-red { border-inline-start-color: var(--danger); }
.stat-card.c-red .stat-value { color: var(--danger); }
.stat-card.c-warn { border-inline-start-color: var(--warn); }
.stat-card.c-warn .stat-value { color: var(--warn); }

/* اللوحات */
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 22px;
    overflow: hidden;
}
.panel-head {
    background: #F7F9FC;
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.panel-head h2, .panel-head h3 { margin: 0; font-size: 16px; color: var(--primary); }
.panel-body { padding: 16px; }

.page-title { color: var(--primary); font-size: 21px; margin: 0 0 16px; font-weight: 800; }
.page-sub { color: var(--muted); margin: -8px 0 18px; font-size: 13.5px; }

/* الجداول */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    background: #FFFFFF;
    font-size: 13.6px;
}
table.data th, table.data td {
    border: 1px solid var(--border);
    padding: 8px 10px;
    text-align: right;
    vertical-align: middle;
}
table.data th {
    background: var(--primary);
    color: #FFFFFF;
    font-weight: 700;
    white-space: nowrap;
}
table.data tbody tr:nth-child(even) { background: #F7F9FC; }
table.data tbody tr:hover { background: #EEF4FB; }
table.data td.num, table.data th.num { text-align: left; direction: ltr; }
table.data .actions { white-space: nowrap; }
table.data tfoot td { background: #EDF2F8; font-weight: 800; }

/* حالات الملفات */
.st { display: inline-block; padding: 1px 10px; border-radius: 12px; font-size: 12.2px; font-weight: 700; white-space: nowrap; }
.st-pending     { background: #E8ECF1; color: #44515F; }
.st-processing  { background: #DCEBFA; color: #175A94; }
.st-extracted   { background: #DFF3E8; color: #178450; }
.st-review      { background: #FCF0D8; color: #92610A; }
.st-failed      { background: #F9E0DC; color: #A93226; }
.st-approved    { background: #21A366; color: #FFFFFF; }
.st-error       { background: #E5E0F5; color: #5B3FA8; }

/* الأزرار */
.btn {
    display: inline-block;
    background: var(--primary);
    color: #FFFFFF;
    border: 0;
    border-radius: 6px;
    padding: 8px 18px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.6;
}
.btn:hover { background: var(--primary-light); }
.btn-green { background: var(--green); }
.btn-green:hover { background: var(--green-dark); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: #EDF2F8; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #922B21; }
.btn-sm { padding: 4px 12px; font-size: 12.8px; border-radius: 5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-link { background: none; border: 0; color: var(--primary-light); text-decoration: underline; cursor: pointer; font-family: inherit; font-size: 13px; padding: 0; }

/* النماذج */
form .field { margin-bottom: 14px; }
form label { display: block; font-weight: 700; margin-bottom: 4px; font-size: 13.5px; }
form .hint { color: var(--muted); font-size: 12.3px; margin-top: 3px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    background: #FFFFFF;
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(33,163,102,.35); border-color: var(--green); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; min-width: 150px; }

/* التنبيهات */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-weight: 600; }
.alert-ok { background: #DFF3E8; color: #178450; border: 1px solid #B5E3C9; }
.alert-error { background: #F9E0DC; color: #A93226; border: 1px solid #F0B9B2; }
.alert-warn { background: #FCF0D8; color: #92610A; border: 1px solid #EFD9A7; }
.alert-info { background: #DCEBFA; color: #175A94; border: 1px solid #B9D8F0; }

/* الرسوم البيانية البسيطة */
.chart {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    height: 190px;
    padding: 10px 6px 0;
}
.chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart .bar {
    width: 70%;
    max-width: 58px;
    background: linear-gradient(180deg, var(--primary-light), var(--primary));
    border-radius: 5px 5px 0 0;
    min-height: 3px;
}
.chart .bar-val { font-size: 11.6px; font-weight: 700; color: var(--primary); margin-bottom: 3px; direction: ltr; }
.chart .bar-label { font-size: 12px; color: var(--muted); margin-top: 6px; white-space: nowrap; }

/* شاشة المراجعة */
.review-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.viewer-panel { position: sticky; top: 12px; }
.viewer-box {
    background: #525659;
    border-radius: 8px;
    min-height: 420px;
    max-height: 70vh;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 10px;
}
.viewer-box img { max-width: 100%; height: auto; transform-origin: top center; transition: transform .12s ease; }
.viewer-box embed, .viewer-box iframe { width: 100%; height: 65vh; border: 0; background: #FFFFFF; }
.viewer-tools { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.extracted-hint { color: var(--muted); font-size: 11.8px; margin-top: 2px; }
.extracted-hint b { color: var(--primary-light); }

/* جدول الأصناف في المراجعة */
.items-editor table.data td, .items-editor table.data th { padding: 5px 6px; }
.items-editor input { padding: 5px 6px; font-size: 13px; }
.totals-summary { background: #F0F5FA; border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; margin-top: 12px; font-size: 13.6px; }
.totals-summary div { display: flex; justify-content: space-between; padding: 2px 0; }
.totals-summary .diff-warn { color: var(--danger); font-weight: 800; }
.totals-summary .diff-ok { color: var(--green-dark); font-weight: 800; }

/* شريط تقدم المعالجة */
.progress-outer { background: #E3EAF2; border-radius: 10px; height: 22px; overflow: hidden; }
.progress-inner { background: var(--green); height: 100%; width: 0; transition: width .3s ease; }
.file-row-pending { border: 1px dashed var(--border); border-radius: 6px; padding: 8px 12px; margin-bottom: 8px; background: #FFFFFF; }

/* صفحة الدخول والهبوط */
.auth-wrap { max-width: 420px; margin: 50px auto; }
.auth-wrap .panel { padding: 6px; }
.landing-hero {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #FFFFFF;
    padding: 55px 25px;
    text-align: center;
}
.landing-hero h1 { margin: 0 0 8px; font-size: 30px; }
.landing-hero p { margin: 0 auto 22px; max-width: 720px; opacity: .93; }
.landing-features { max-width: 980px; margin: 30px auto; padding: 0 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.feature-card { background: #FFFFFF; border: 1px solid var(--border); border-radius: 8px; padding: 18px; }
.feature-card h3 { margin: 0 0 6px; color: var(--primary); font-size: 15.5px; }
.feature-card p { margin: 0; color: var(--muted); font-size: 13.4px; }

/* سجل عمليات */
.log-lines { font-size: 13px; }
.mono { direction: ltr; text-align: left; font-family: Consolas, Monaco, monospace; font-size: 12.5px; }

/* الطباعة */
@media print {
    .topbar, .sidebar, .footer, .no-print, .demo-banner, .btn, .filters { display: none !important; }
    body { background: #FFFFFF; font-size: 12.5px; }
    .shell { display: block; }
    .content { padding: 0; }
    .panel { border: 1px solid #999; break-inside: avoid; }
    table.data th { background: #EEE !important; color: #000 !important; }
    .print-only { display: block !important; }
}
.print-only { display: none; }

/* التجاوب */
@media (max-width: 980px) {
    .review-layout { grid-template-columns: 1fr; }
    .viewer-panel { position: static; }
}
@media (max-width: 820px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; padding: 6px; }
    .content { padding: 14px; }
    .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ---------- القراءة الضوئية داخل المتصفح (OCR) ---------- */
.ocr-filled { border-color: #1E9E6A !important; background: #F0FAF5 !important; box-shadow: 0 0 0 2px rgba(30, 158, 106, .12); }
.ocr-inline { display: inline-block; margin-top: 6px; }
.ocr-batch-row { padding: 5px 0; border-bottom: 1px dashed #E3EAF2; }
.ocr-row-status { color: #5B6B7E; font-size: 13px; }
