:root {
  --ink: #16211D;
  --muted: #5B6661;
  --ground: #F4F5F2;
  --card: #FFFFFF;
  --line: #E1E5E2;
  --line-soft: #EEF1EF;
  --accent: #0F6E5C;
  --accent-dark: #0A4F42;
  --accent-soft: #F0F7F4;
  --accent-line: #D3E8DF;
  --ok-bg: #E3F3EC;
  --ok-ink: #0B5A4A;
  --warn-bg: #FDF0DC;
  --warn-ink: #8A5200;
  --err-bg: #FBE9E7;
  --err-ink: #9B2C1C;
  --side: #16211D;
  --side-2: #1E2C27;
  --side-active: #24342E;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "IBM Plex Sans Arabic", system-ui, sans-serif; color: var(--ink); background: var(--ground); font-size: 15px; line-height: 1.6; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #4CC79A; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- الهيكل ---------- */
.shell { display: flex; flex-wrap: wrap; min-height: 100vh; }
.side { flex: 1 1 232px; background: var(--side); color: #E8ECE9; padding: 24px 16px; display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 19px; }
.brand strong { display: block; font-size: 18px; color: #fff; }
.brand span { font-size: 12px; color: #A9B5AF; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; text-decoration: none; color: #C9D3CE; min-height: 44px; }
.nav-link:hover { color: #fff; background: var(--side-2); }
.nav-link[aria-current="page"] { color: #fff; background: var(--side-active); font-weight: 600; }
.nav-badge { margin-inline-start: auto; background: #F2B544; color: #2A1D00; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 0 8px; }
.side-status { margin-top: auto; padding: 14px; border-radius: 12px; background: var(--side-2); font-size: 13px; color: #C9D3CE; display: flex; flex-direction: column; gap: 6px; }
.side-status b { color: #fff; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4CC79A; flex: 0 0 8px; }
.dot.bad { background: #F07A5F; }
.dot.off { background: #6B7A74; }
.svc { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.svc li { display: flex; align-items: center; gap: 8px; }
.side-status button { background: none; border: 1px solid #3A4A44; color: #C9D3CE; border-radius: 8px; min-height: 36px; cursor: pointer; }
main { flex: 999 1 560px; min-width: 0; padding: 32px; display: flex; flex-direction: column; gap: 24px; }
.demo-bar { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid #F0DDB8; padding: 10px 16px; border-radius: 12px; font-size: 14px; }

/* ---------- عناصر عامة ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.page-head h1 { margin: 0; font-size: 28px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.cols { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.col-wide { flex: 3 1 480px; min-width: 0; }
.col-narrow { flex: 2 1 320px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.card h2 { margin: 0; font-size: 19px; }
.card h3 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid #CBD2CE; background: #fff; color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--ink); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn[disabled] { opacity: .6; cursor: wait; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--ok-bg); color: var(--ok-ink); white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.err { background: var(--err-bg); color: var(--err-ink); }
.badge.neutral { background: #EEF1EF; color: var(--muted); }
.box-accent { padding: 16px 18px; border-radius: 12px; background: var(--accent-soft); border: 1px solid var(--accent-line); display: flex; flex-direction: column; gap: 6px; }
.box-accent > span:first-child { font-size: 13px; font-weight: 600; color: var(--ok-ink); }
.box-warn { padding: 12px 16px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-ink); font-size: 14px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.loading { color: var(--muted); }
.error { padding: 16px; border-radius: 12px; background: var(--err-bg); color: var(--err-ink); }

/* ---------- الأرقام ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--ink); }
a.kpi:hover { border-color: var(--accent); color: var(--ink); }
.kpi span { font-size: 14px; color: var(--muted); }
.kpi strong { font-size: 32px; line-height: 1.2; }
.kpi em { font-style: normal; font-size: 13px; color: var(--accent); }
.kpi em.warn { color: #9A5B00; }

/* ---------- الموافقات ---------- */
.approval { padding: 16px; border-radius: 12px; border: 1px solid #E8ECE9; background: #FAFBFA; display: flex; flex-direction: column; gap: 12px; }
.approval-top { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.approval-info { display: flex; flex-direction: column; gap: 2px; flex: 1 1 260px; min-width: 0; }
.approval-kind { font-size: 12px; font-weight: 600; color: var(--accent); }
.approval-info strong { font-size: 16px; }
.approval-note { font-size: 14px; color: var(--muted); }
.edit-panel { display: grid; gap: 12px; padding-top: 4px; border-top: 1px solid var(--line-soft); }
.edit-panel[hidden] { display: none; }

/* ---------- النماذج ---------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea { min-height: 44px; padding: 8px 12px; border: 1px solid #CBD2CE; border-radius: 10px; background: #fff; width: 100%; }
.field textarea { min-height: 120px; resize: vertical; line-height: 1.7; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px #CFE6DC; }
.fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ltr { direction: ltr; text-align: right; }

/* ---------- القوائم ---------- */
.list { display: flex; flex-direction: column; gap: 4px; }
.list-item { display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: right; padding: 14px 16px; border-radius: 12px; border: 1px solid transparent; background: #fff; cursor: pointer; }
.list-item:hover { background: #FAFBFA; }
.list-item[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.list-item .top { display: flex; justify-content: space-between; gap: 8px; }
.tabs { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.tab { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 200px; padding: 12px 16px; border-radius: 12px; border: 2px solid var(--line); background: #fff; text-align: right; cursor: pointer; }
.tab[aria-selected="true"] { border-color: var(--accent); }
.feed-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.feed-row time { flex: 0 0 48px; color: var(--muted); font-size: 13px; }

/* ---------- المكالمات ---------- */
.transcript { white-space: pre-wrap; background: #F6F7F5; border-radius: 12px; padding: 16px; max-height: 320px; overflow-y: auto; font-size: 14px; line-height: 1.9; margin: 0; }

/* ---------- المستندات ---------- */
.preview { position: relative; height: 560px; border-radius: 12px; background: #F1F2F0; border: 1px dashed #B9C2BD; display: grid; place-items: center; overflow: hidden; }
.preview iframe, .preview img { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.preview img { object-fit: contain; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; padding: 10px 14px; font-weight: 600; background: #F6F7F5; white-space: nowrap; }
td { padding: 12px 14px; border-top: 1px solid var(--line-soft); vertical-align: middle; }
tr.selected td { background: var(--accent-soft); }
.radio { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.radio input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- عروض الأسعار ---------- */
.rfq-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.rfq-card { background: #fff; border: 2px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 6px; text-align: right; cursor: pointer; }
.rfq-card[aria-pressed="true"] { border-color: var(--accent); }
.supplier-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; }

/* ---------- التقرير ---------- */
.report-frame { width: 100%; height: 1100px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---------- الدخول ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(420px, 100%); }

/* ---------- الإشعارات ---------- */
#toast { position: fixed; bottom: 24px; left: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.toast-msg { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 360px; font-size: 14px; }
.toast-msg.err { background: var(--err-ink); }

@media (max-width: 760px) {
  main { padding: 20px 16px; }
  .kpis, .rfq-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fields-grid { grid-template-columns: minmax(0, 1fr); }
  .supplier-row { grid-template-columns: minmax(0, 1fr); }
  .side { flex-basis: 100%; }
  .side-status { display: none; }
  .preview { height: 380px; }
}
@media print {
  .side, .demo-bar, .page-head .row { display: none; }
}

/* النظام المحاسبي */
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.acc-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #fff; }
.acc-card .badge { align-self: flex-start; }
.acc-card label.btn:focus-within { outline: 3px solid var(--accent, #0F6E5C); outline-offset: 2px; }

/* الربط */
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.conn-list { display: flex; flex-direction: column; gap: 12px; }
.conn summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; list-style: none; }
.conn summary::-webkit-details-marker { display: none; }
.conn summary:focus-visible { outline: 3px solid var(--accent, #0F6E5C); outline-offset: 4px; border-radius: 8px; }
.conn-title { display: flex; flex-direction: column; gap: 2px; }
.conn[open] summary { margin-bottom: 12px; }
.conn-steps { margin: 0; padding-right: 22px; display: flex; flex-direction: column; gap: 10px; line-height: 1.8; }
.copy-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.copy-row code { background: #F2F5F3; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 13px; unicode-bidi: isolate; word-break: break-all; }

/* واتساب */
.wa-layout { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .wa-layout { grid-template-columns: 1fr; } }
.wa-list { display: flex; flex-direction: column; gap: 8px; max-height: 640px; overflow: auto; }
.wa-list .list-item { flex-direction: column; align-items: stretch; gap: 4px; }
.wa-thread { display: flex; flex-direction: column; gap: 12px; min-height: 420px; }
.wa-msgs { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow: auto; padding: 12px; background: #EFEAE2; border-radius: 12px; }
.wa-msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.wa-msg p { margin: 0; white-space: pre-line; line-height: 1.7; }
.wa-msg span { display: block; font-size: 11px; color: var(--muted, #5B6661); margin-top: 2px; text-align: left; }
.wa-msg.in { align-self: flex-start; background: #fff; }
.wa-msg.out { align-self: flex-end; background: #D9FDD3; }
.wa-composer { display: flex; gap: 8px; align-items: flex-end; }
.wa-composer textarea { flex: 1; min-height: 48px; }
.wa-draft { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.wa-draft.sent { opacity: .7; }
.wa-draft textarea { min-height: 70px; }

/* الموظفون */
.staff-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.staff-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }

/* الفوترة الإلكترونية */
.zatca { border-radius: 12px; padding: 12px 14px; border: 1px solid; display: flex; flex-direction: column; gap: 6px; }
.zatca ul { margin: 0; padding-right: 18px; line-height: 1.8; }
.zatca.ok { background: #EAF6F1; border-color: #A9D8C6; color: #0B5A4A; }
.zatca.warn { background: #FFF7E6; border-color: #F2D49B; color: #7A4B00; }
.zatca.bad { background: #FDECEA; border-color: #F4B6AE; color: #8A1C12; }

/* تبديل اللغة */
.lang-toggle { margin: 10px 0 0; align-self: flex-start; background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.35); border-radius: 999px; padding: 4px 14px; font: inherit; font-size: 13px; cursor: pointer; }
.login-card .lang-toggle, main .lang-toggle { border-color: var(--line); }
.lang-toggle:focus-visible { outline: 3px solid var(--accent, #0F6E5C); outline-offset: 2px; }
html[dir="ltr"] body { font-family: system-ui, -apple-system, "Segoe UI", "IBM Plex Sans Arabic", sans-serif; }
