/* نظام إدارة مزارع الدواجن — RTL بلا أي مكتبات خارجية */
:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --brand: #0f766e;
    --brand-2: #115e59;
    --brand-soft: #ccfbf1;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --bad: #b91c1c;
    --bad-soft: #fee2e2;
    --good: #15803d;
    --good-soft: #dcfce7;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.65;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4rem; line-height: 1.35; font-weight: 700; }
h1 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
p { margin: .35rem 0; }
code { background: #f1f5f9; padding: .05rem .3rem; border-radius: 6px; font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.ok { color: var(--good); }
.bad { color: var(--bad); }
.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.space { justify-content: space-between; }
.num { text-align: left; font-variant-numeric: tabular-nums; direction: ltr; }

/* ---------- الهيكل ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex: 0 0 250px;
    background: #0b3b39;
    color: #e6fffb;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand { display: flex; gap: .6rem; align-items: center; padding: 1rem .9rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { font-size: 1.5rem; }
.brand strong { display: block; font-size: .98rem; }
.brand small { display: block; font-size: .72rem; opacity: .75; }

.nav { padding: .5rem .4rem 1rem; display: flex; flex-direction: column; gap: 1px; }
.nav-section { font-size: .7rem; letter-spacing: .03em; opacity: .55; padding: .7rem .7rem .25rem; }
.nav-link {
    display: flex; align-items: center; gap: .55rem;
    padding: .5rem .7rem; border-radius: 9px;
    color: #d7fbf6; font-size: .88rem; text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav-link.active { background: #ffffff; color: var(--brand-2); font-weight: 700; }
.sidebar-foot { margin-top: auto; padding: .8rem; font-size: .74rem; opacity: .7; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .small { font-size: .7rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem 1.1rem; background: var(--panel);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar-title h1 { margin: 0; font-size: 1.05rem; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .6rem; }
.user-chip { display: flex; flex-direction: column; font-size: .82rem; line-height: 1.2; }
.user-chip small { color: var(--muted); font-size: .7rem; }
.sync-pill { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: .15rem .55rem; font-size: .72rem; }
.icon-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 9px; padding: .25rem .5rem; font-size: 1.1rem; cursor: pointer; }

.content { padding: 1rem 1.1rem 2rem; display: flex; flex-direction: column; gap: .85rem; max-width: 1500px; width: 100%; }

/* ---------- البطاقات والمؤشرات ---------- */
.card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: .9rem 1rem; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .55rem; flex-wrap: wrap; }
.card-head h3 { margin: 0; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .7rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem; box-shadow: var(--shadow); }
.stat-label { font-size: .74rem; color: var(--muted); }
.stat-value { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.stat-hint { font-size: .7rem; color: var(--muted); }
.stat.good .stat-value { color: var(--good); }
.stat.bad .stat-value { color: var(--bad); }
.stat.warn .stat-value { color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: .85rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .6rem; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .6rem; }
.aging-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; }
.meta > div { display: flex; flex-direction: column; font-size: .85rem; }
.meta span { font-size: .72rem; color: var(--muted); }
.memo { background: #f8fafc; border-radius: 10px; padding: .45rem .6rem; }

.spark { width: 100%; height: 80px; display: block; margin-top: .4rem; }
.spark-labels { display: flex; justify-content: space-between; font-size: .68rem; color: var(--muted); }
.section-title { font-size: .9rem; color: var(--brand-2); border-bottom: 2px solid var(--brand-soft); padding-bottom: .2rem; margin-bottom: .4rem; }
.bullets { margin: .3rem 0 0; padding-inline-start: 1.1rem; font-size: .88rem; }
.bullets li { margin-bottom: .25rem; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .86rem; background: var(--panel); }
.tbl th, .tbl td { padding: .45rem .55rem; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
.tbl thead th { background: #f1f5f9; font-size: .78rem; color: #334155; font-weight: 700; white-space: nowrap; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl tfoot th { background: #f8fafc; }
.tbl .num { text-align: left; }
.tbl input, .tbl select { min-width: 90px; }
.empty { color: var(--muted); text-align: center; padding: 1rem; background: #f8fafc; border-radius: 10px; font-size: .88rem; }
.totals { display: flex; gap: 1rem; flex-wrap: wrap; padding-top: .55rem; border-top: 1px dashed var(--line); font-size: .86rem; }
.pager { display: flex; gap: .25rem; margin-top: .6rem; flex-wrap: wrap; }
.page { padding: .2rem .55rem; border: 1px solid var(--line); border-radius: 8px; font-size: .82rem; }
.page.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- النماذج ---------- */
.field { display: flex; flex-direction: column; gap: .2rem; font-size: .82rem; min-width: 0; }
.field > span { color: #334155; font-weight: 600; font-size: .78rem; }
.field small { color: var(--muted); font-size: .7rem; }
input, select, textarea {
    font: inherit; padding: .42rem .55rem; border: 1px solid #cbd5e1; border-radius: 9px;
    background: #fff; color: var(--ink); width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input.narrow { width: 6.5rem; }
.stack { display: flex; flex-direction: column; gap: .55rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .6rem; }
.filters .field { min-width: 140px; }
.check { display: inline-flex; gap: .35rem; align-items: center; font-size: .82rem; }
.check input { width: auto; }

/* ---------- الأزرار والشارات ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
    padding: .42rem .8rem; border-radius: 10px; border: 1px solid #cbd5e1;
    background: #fff; color: var(--ink); font-size: .84rem; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-sm { padding: .25rem .55rem; font-size: .78rem; }
.btn-block { width: 100%; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-muted { background: #e2e8f0; color: #475569; }

.alert { padding: .55rem .8rem; border-radius: 10px; font-size: .87rem; border: 1px solid transparent; }
.alert-success { background: var(--good-soft); border-color: #86efac; color: #14532d; }
.alert-error { background: var(--bad-soft); border-color: #fca5a5; color: #7f1d1d; }
.alert-info { background: #e0f2fe; border-color: #bae6fd; color: #075985; }

.result-box { margin-top: .6rem; padding: .7rem .9rem; border-radius: 12px; background: #f1f5f9; display: flex; flex-direction: column; gap: .1rem; }
.result-box b { font-size: 1.3rem; direction: ltr; text-align: right; }
.result-box.good { background: var(--good-soft); }
.result-box.bad { background: var(--bad-soft); }

/* ---------- المصادقة ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.2rem; background: linear-gradient(160deg, #0b3b39, #0f766e 55%, #115e59); }
.auth-card { background: #fff; border-radius: 18px; padding: 1.5rem; width: 100%; max-width: 470px; box-shadow: 0 20px 50px rgba(2, 44, 42, .35); }
.auth-card.center { text-align: center; }
.auth-brand { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.auth-brand small { display: block; color: var(--muted); font-size: .72rem; }
.auth-foot { margin-top: 1rem; font-size: .72rem; color: var(--muted); text-align: center; }
.checks { list-style: none; padding: 0; margin: .5rem 0; font-size: .84rem; }
.checks li { padding: .25rem .1rem; }
.checks li.ok { color: var(--good); }
.checks li.bad { color: var(--bad); }
.error-code { font-size: 3rem; font-weight: 800; color: var(--bad); }

/* ---------- الفاتورة ---------- */
.toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: .6rem; }
.invoice-print { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); max-width: 900px; }
.inv-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--brand); padding-bottom: .7rem; margin-bottom: .7rem; }
.inv-head h2 { color: var(--brand-2); }
.inv-meta { text-align: left; font-size: .85rem; }
.inv-title { font-weight: 800; color: var(--brand); font-size: 1.05rem; }
.inv-parties { display: flex; gap: 2rem; margin-bottom: .7rem; font-size: .88rem; }
.inv-parties > div { display: flex; flex-direction: column; }
.inv-lines { margin-bottom: .8rem; }
.inv-totals { margin-inline-start: auto; width: min(340px, 100%); display: flex; flex-direction: column; gap: .2rem; font-size: .88rem; }
.inv-totals > div { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--line); padding: .15rem 0; }
.inv-totals .grand { font-weight: 800; font-size: 1.05rem; color: var(--brand-2); border-bottom: 2px solid var(--brand); }
.inv-foot { margin-top: 1.2rem; border-top: 1px dashed var(--line); padding-top: .6rem; }
.signatures { display: flex; justify-content: space-between; margin-top: 1.6rem; font-size: .82rem; color: #334155; }

/* ---------- استجابة الشاشات ---------- */
@media (max-width: 980px) {
    .sidebar { position: fixed; inset-inline-start: 0; top: 0; z-index: 50; transform: translateX(100%); transition: transform .2s ease; }
    .sidebar.open { transform: translateX(0); }
    .icon-btn { display: inline-flex; }
    .content { padding: .8rem .7rem 2rem; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .topbar { padding: .6rem .7rem; }
    .inv-head { flex-direction: column; }
    .inv-meta { text-align: right; }
}

@media (max-width: 520px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .user-chip { display: none; }
}

/* ---------- الطباعة ---------- */
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .no-print, .toolbar, .alert { display: none !important; }
    .main { display: block; }
    .content { padding: 0; max-width: none; }
    .card, .invoice-print { box-shadow: none; border: none; padding: 0; }
    .invoice-print { max-width: none; }
    .tbl thead th { background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    a { color: #000; text-decoration: none; }
    @page { margin: 12mm; }
}

