/* رفيق السحابي — نفس ألوان برنامج الحاسوب */
:root {
  --primary: #2563eb; --primary-dark: #1d4ed8; --primary-soft: #dbeafe;
  --success: #16a34a; --success-soft: #dcfce7;
  --danger: #dc2626; --danger-soft: #fee2e2;
  --warning: #d97706; --warning-soft: #fef3c7;
  --purple: #7c3aed; --info: #0891b2;
  --bg: #f1f5f9; --surface: #ffffff; --surface-alt: #f8fafc; --border: #e2e8f0;
  --sidebar: #0f172a; --sidebar-hover: #1e293b; --sidebar-text: #cbd5e1;
  --text: #0f172a; --text-2: #475569; --muted: #94a3b8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif; font-size: 15px;
  background: var(--bg); color: var(--text); line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.3; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.mono { font-family: Consolas, "Courier New", monospace; }
.text-success { color: var(--success); } .text-danger { color: var(--danger); } .text-warning { color: var(--warning); }
.nowrap { white-space: nowrap; }

/* ===== الهيكل ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; background: var(--sidebar); color: #fff; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.brand { padding: 22px 20px 16px; text-align: center; border-bottom: 1px solid var(--sidebar-hover); }
.brand .logo { font-size: 1.8rem; font-weight: 800; }
.brand .store { color: var(--sidebar-text); font-size: .9rem; }
.nav { padding: 10px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px;
  color: var(--sidebar-text); font-weight: 600; margin-bottom: 3px;
}
.nav a:hover { background: var(--sidebar-hover); text-decoration: none; color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav .icon { width: 22px; text-align: center; }
.user-box { padding: 14px 16px; border-top: 1px solid var(--sidebar-hover); font-size: .9rem; }
.user-box .name { font-weight: 700; }
.user-box form { margin-top: 8px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 28px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.content { padding: 24px 28px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== البطاقات ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 1.1rem; }
.card.narrow { max-width: 460px; width: 100%; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-2e { grid-template-columns: 1fr 1fr; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; border-inline-start: 5px solid var(--accent, var(--primary)); box-shadow: var(--shadow); }
.stat .label { color: var(--text-2); font-weight: 700; font-size: .92rem; }
.stat .value { font-size: 1.6rem; font-weight: 800; color: var(--accent, var(--primary)); margin: 4px 0 2px; }
.stat .hint { color: var(--muted); font-size: .82rem; }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: start; font-size: .82rem; color: var(--text-2); background: var(--surface-alt); padding: 10px 12px; font-weight: 700; white-space: nowrap; }
td { padding: 10px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: #fafcff; }
td.num, th.num { text-align: end; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 30px; }

/* ===== الشارات ===== */
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.yellow { background: var(--warning-soft); color: var(--warning); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.gray { background: var(--border); color: var(--text-2); }

/* ===== النماذج والأزرار ===== */
label { display: block; font-weight: 700; font-size: .88rem; color: var(--text-2); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-alt);
  font: inherit; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: #fff; }
.field { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 18px; border-radius: 9px; border: 1px solid transparent;
  background: var(--primary); color: #fff; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { border-color: var(--primary); }
.btn.success { background: var(--success); } .btn.danger { background: var(--danger); } .btn.warning { background: var(--warning); }
.btn.sm { padding: 5px 12px; font-size: .85rem; }
.btn.block { width: 100%; padding: 12px; font-size: 1.05rem; }
.btn.link { background: none; color: var(--sidebar-text); padding: 0; font-weight: 600; }
.inline { display: inline; margin: 0; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.alert.success { background: var(--success-soft); color: var(--success); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warning { background: var(--warning-soft); color: #92400e; }
.alert.info { background: var(--primary-soft); color: var(--primary-dark); }
.validation-summary-errors ul { margin: 0; padding-inline-start: 18px; }
.field-validation-error { color: var(--danger); font-size: .82rem; }

.token-box { background: var(--sidebar); color: #a5f3fc; padding: 14px 16px; border-radius: 10px; direction: ltr; text-align: left; font-family: Consolas, monospace; word-break: break-all; }
.steps { padding-inline-start: 20px; } .steps li { margin-bottom: 6px; }

/* ===== صفحات الدخول والموقع ===== */
.center-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(135deg, #1d4ed8 0%, #0f172a 100%); }
.auth-card { max-width: 420px; width: 100%; }
.auth-card .logo { font-size: 2.2rem; font-weight: 800; color: var(--primary); text-align: center; }

.site-nav { display: flex; justify-content: space-between; align-items: center; padding: 18px 6vw; background: var(--surface); border-bottom: 1px solid var(--border); }
.site-nav .logo { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.hero { padding: 70px 6vw 50px; background: linear-gradient(135deg, #1d4ed8 0%, #0f172a 100%); color: #fff; text-align: center; }
.hero h1 { font-size: 2.5rem; } .hero p { font-size: 1.15rem; color: #dbeafe; max-width: 720px; margin: 10px auto 26px; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; padding: 40px 6vw; }
.feature .icon { font-size: 1.8rem; }
.site-section { padding: 0 6vw 50px; }
.domain-input { display: flex; direction: ltr; align-items: stretch; }
.domain-input input { border-radius: 9px 0 0 9px; text-align: left; }
.domain-input span { background: var(--border); padding: 10px 12px; border-radius: 0 9px 9px 0; color: var(--text-2); white-space: nowrap; }

.chart-box { position: relative; height: 280px; }
.bar-list .row { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; font-size: .9rem; }
.bar { height: 7px; background: var(--primary-soft); border-radius: 9px; margin-bottom: 12px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 9px; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { display: flex; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; }
  .grid-2, .grid-2e { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}

/* ترقيم الصفحات */
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.pager .muted { padding: 0 6px; }

/* ===== الصفحات الكاملة (إدارة من المنصة) ===== */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs a { padding: 9px 16px; border-radius: 9px 9px 0 0; font-weight: 700; color: var(--text-2); border: 1px solid transparent; border-bottom: none; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--primary); }
.tabs a.active { background: var(--surface); border-color: var(--border); color: var(--primary); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 18px; }
.kv div { border-bottom: 1px dashed var(--border); padding-bottom: 6px; }
.kv .k { color: var(--muted); font-size: .82rem; font-weight: 700; display: block; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); margin: 6px 0 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 3px; }
.error-text { color: var(--danger); font-size: .82rem; margin-top: 3px; }
.btn.ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn.ghost:hover { background: var(--surface-alt); color: var(--danger); }
.text-end { text-align: end; }
.row-muted td { color: var(--muted); }
details.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 0 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
details.panel > summary { cursor: pointer; padding: 14px 0; font-weight: 800; color: var(--primary); list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 14px; }

/* إدخال المشتريات: أسطر الفاتورة */
table.lines input, table.lines select { padding: 7px 8px; min-width: 70px; }
table.lines td { padding: 6px 6px; }
table.lines .name { min-width: 180px; font-weight: 700; }
.lookup { position: relative; }
.lookup-list { position: absolute; z-index: 20; inset-inline: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .15); max-height: 320px; overflow-y: auto; display: none; }
.lookup-list.open { display: block; }
.lookup-list button { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: start; padding: 9px 12px; border: 0;
  background: none; font: inherit; cursor: pointer; border-bottom: 1px solid var(--surface-alt); }
.lookup-list button:hover, .lookup-list button.active { background: var(--primary-soft); }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.totals .big { font-size: 1.5rem; font-weight: 800; color: var(--primary); }

/* ===== المساعد الذكي (لوحة المعلومات) ===== */
.ai-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.ai-head { display: flex; align-items: center; gap: 18px; padding: 16px 20px; color: #fff; background: linear-gradient(120deg, #1e3a8a, #2563eb 55%, #7c3aed); }
.ai-ring { position: relative; width: 86px; height: 86px; flex: none; }
.ai-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ai-ring circle { fill: none; stroke-width: 9; }
.ai-ring .track { stroke: rgba(255, 255, 255, .22); }
.ai-ring .value { stroke-linecap: round; filter: drop-shadow(0 0 4px rgba(255, 255, 255, .5)); }
.ai-ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ai-ring-text b { font-size: 1.6rem; } .ai-ring-text span { font-size: .75rem; opacity: .8; }
.ai-title { flex: 1; min-width: 0; }
.ai-name { font-size: 1.25rem; font-weight: 800; }
.ai-health { opacity: .95; } .ai-forecast { font-size: .88rem; opacity: .9; margin-top: 2px; }
.ai-refresh { color: #fff; border: 1px solid rgba(255, 255, 255, .45); border-radius: 9px; padding: 7px 12px; font-weight: 700; white-space: nowrap; }
.ai-refresh:hover { background: rgba(255, 255, 255, .14); text-decoration: none; }
.ai-body { display: grid; grid-template-columns: 1fr 1.25fr; gap: 16px; padding: 16px 20px; }
.ai-list { display: flex; flex-direction: column; gap: 8px; max-height: 330px; overflow-y: auto; padding-inline-end: 4px; }
.ai-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-alt); border-inline-start: 4px solid var(--info); }
.ai-item.danger { border-color: var(--danger); background: var(--danger-soft); }
.ai-item.warning { border-color: var(--warning); background: var(--warning-soft); }
.ai-item.good { border-color: var(--success); background: var(--success-soft); }
.ai-icon { font-size: 1.4rem; flex: none; }
.ai-text { flex: 1; min-width: 0; }
.ai-item-title { font-weight: 800; }
.ai-kind { font-size: .72rem; font-weight: 700; color: var(--text-2); background: rgba(255, 255, 255, .7); border-radius: 6px; padding: 1px 6px; margin-inline-start: 4px; }
.small-btn { padding: 6px 12px; font-size: .85rem; }
.smart-filter { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
@media (max-width: 900px) {
  .ai-body { grid-template-columns: 1fr; }
  .ai-head { flex-wrap: wrap; }
  .ai-title { flex-basis: calc(100% - 110px); }
  .ai-refresh { margin-inline-start: auto; }
}

/* شعار رفيق */
.brand .logo { display: flex; align-items: center; justify-content: center; gap: 8px; }
.brand .logo img { width: 34px; height: 34px; border-radius: 9px; }
.powered { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 10px; font-size: .78rem; font-weight: 700; }
.powered img { width: 18px; height: 18px; border-radius: 4px; }
.logo { display: inline-flex; align-items: center; gap: 8px; }
.logo img { width: 34px; height: 34px; border-radius: 9px; }
