/* =========================================================================
   brand-ui.css — design tokens + component library (One UI inspired):
   rounded cards, pill buttons, soft shadows, calm surfaces, strong blue.
   ========================================================================= */
:root {
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, "IBM Plex Sans Arabic", sans-serif;
  --font-ar: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Inter", sans-serif;
  --mono: "Cascadia Mono", "SF Mono", Consolas, "Roboto Mono", monospace;

  --brand: #1428A0;
  --brand-2: #2189FF;
  --brand-3: #0B1A6E;
  --brand-soft: rgba(33, 137, 255, 0.12);
  --brand-grad: linear-gradient(135deg, #2189FF 0%, #1428A0 100%);

  --bg: #F2F4F7;
  --surface: #FFFFFF;
  --surface-2: #F7F8FA;
  --surface-3: #EEF1F5;
  --text: #0F1115;
  --text-2: #4A5160;
  --text-3: #8A919E;
  --border: #E4E8EE;
  --border-strong: #D2D8E1;

  --success: #0F9D58; --success-soft: rgba(15, 157, 88, 0.12);
  --danger: #E5383B;  --danger-soft: rgba(229, 56, 59, 0.12);
  --warning: #E08A00; --warning-soft: rgba(245, 158, 11, 0.16);
  --info: #2189FF;    --info-soft: rgba(33, 137, 255, 0.12);
  --orange: #EA580C;  --orange-soft: rgba(234, 88, 12, 0.12);

  --radius-xs: 8px; --radius-sm: 12px; --radius: 18px; --radius-lg: 24px; --radius-xl: 32px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.04), 0 6px 18px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, 0.18);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --sidebar-w: 268px;
  --topbar-h: 68px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0A0B0F;
  --surface: #14161C;
  --surface-2: #1A1D24;
  --surface-3: #22262F;
  --text: #F2F4F7;
  --text-2: #B6BDC9;
  --text-3: #7D8595;
  --border: #252933;
  --border-strong: #333845;
  --brand-soft: rgba(33, 137, 255, 0.18);
  --success: #34C77B; --success-soft: rgba(52, 199, 123, 0.16);
  --danger: #FF5A5F;  --danger-soft: rgba(255, 90, 95, 0.16);
  --warning: #FFB020; --warning-soft: rgba(255, 176, 32, 0.16);
  --info: #4DA3FF;    --info-soft: rgba(77, 163, 255, 0.16);
  --orange: #FB923C;  --orange-soft: rgba(251, 146, 60, 0.16);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; transition: background .25s var(--ease), color .25s var(--ease); }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
a { color: var(--brand-2); text-decoration: none; }
img { max-width: 100%; }
::selection { background: var(--brand-soft); }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.mono { font-family: var(--mono); font-size: .92em; }
.break { word-break: break-all; }
.d-block { display: block; }
.mt { margin-top: 14px; } .mt-sm { margin-top: 6px; } .mb { margin-bottom: 12px; }
.danger-text { color: var(--danger); } .ok-text { color: var(--success); }
.clamp-1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Icons ---------- */
.icon { width: 20px; height: 20px; flex: none; vertical-align: middle; }
.icon-xs { width: 14px; height: 14px; }

/* ---------- Buttons (pill) ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 18px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; user-select: none; text-decoration: none;
  transition: background .18s var(--ease), color .18s, box-shadow .18s, transform .12s, border-color .18s; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn .icon { width: 18px; height: 18px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: none; }
.btn-primary:hover:not(:disabled) { background: var(--brand-3); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-ghost.danger, .btn-ghost.danger:hover { color: var(--danger); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(1.07); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.07); }
.btn-sm { height: 32px; padding: 0 13px; font-size: 13px; gap: 6px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-lg { height: 48px; padding: 0 26px; font-size: 15px; }
.btn-xl { height: 58px; padding: 0 34px; font-size: 17px; letter-spacing: .02em; }
.btn-xl .icon { width: 22px; height: 22px; }
.btn-block { width: 100%; }
.btn-icon-only { width: 36px; padding: 0; }
.btn-icon-only.btn-sm { width: 32px; }
.btn.busy { pointer-events: none; opacity: .75; }
.btn-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent; color: var(--text-2); cursor: pointer; transition: background .15s; }
.btn-icon:hover { background: var(--surface-3); color: var(--text); }
.link-btn { background: none; border: none; color: var(--brand-2); font: inherit; font-weight: 600; cursor: pointer; padding: 0 4px; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Inputs ---------- */
.input { width: 100%; height: 42px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea.input { height: auto; padding: 10px 14px; resize: vertical; line-height: 1.45; }
select.input { cursor: pointer; padding-inline-end: 34px; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238A919E' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
[dir="rtl"] select.input { background-position: left 12px center; }
.input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 4px var(--brand-soft); }
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.input:disabled { opacity: .6; cursor: not-allowed; background: var(--surface-2); }
.input-sm { height: 34px; font-size: 13px; padding: 0 10px; border-radius: 10px; }
select.input-sm { padding-inline-end: 28px; background-position: right 8px center; }
[dir="rtl"] select.input-sm { background-position: left 8px center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; }
.label { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.check-inline, .radio-inline { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check-inline input, .radio-inline input { width: 17px; height: 17px; accent-color: var(--brand-2); }

/* Toggle switch */
.toggle-field { flex-direction: row; align-items: center; gap: 12px; cursor: pointer; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.toggle { position: relative; width: 46px; height: 26px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background .2s; }
.toggle-track::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s var(--ease); }
.toggle input:checked + .toggle-track { background: var(--brand-2); }
.toggle input:checked + .toggle-track::after { transform: translateX(20px); }
[dir="rtl"] .toggle input:checked + .toggle-track::after { transform: translateX(-20px); }
.toggle input:disabled + .toggle-track { opacity: .5; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card > h3 { margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; gap: 16px; margin-bottom: 18px; }
.kpi-grid.kpi-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi-grid.kpi-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi-grid.kpi-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpi { display: flex; gap: 14px; align-items: center; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); min-width: 0; transition: transform .2s var(--ease), box-shadow .2s; }
.kpi:hover { transform: translateY(-2px); }
.kpi-icon { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; flex: none; }
.kpi-icon .icon { width: 23px; height: 23px; }
.kpi-body { min-width: 0; }
.kpi-label { font-size: 12px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.kpi-money { font-size: 19px; }
.kpi-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-lg .kpi { padding: 22px; }
.kpi-lg .kpi-value { font-size: 30px; }
.kpi-blue .kpi-icon { background: rgba(33,137,255,.13); color: #2189FF; }
.kpi-indigo .kpi-icon { background: rgba(20,40,160,.12); color: #3651E0; }
.kpi-green .kpi-icon { background: var(--success-soft); color: var(--success); }
.kpi-red .kpi-icon { background: var(--danger-soft); color: var(--danger); }
.kpi-amber .kpi-icon { background: var(--warning-soft); color: var(--warning); }
.kpi-indigo2 .kpi-icon { background: rgba(20,40,160,.12); color: #3651E0; }
.kpi-teal .kpi-icon { background: rgba(20,184,166,.14); color: #14B8A6; }
.kpi-sky .kpi-icon { background: rgba(14,165,233,.14); color: #0EA5E9; }
.kpi-slate .kpi-icon { background: rgba(100,116,139,.14); color: #64748B; }

/* ring (percentage) */
.ring { --p: 0; width: 52px; height: 52px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: radial-gradient(closest-side, var(--surface) 76%, transparent 78% 100%), conic-gradient(#3651E0 calc(var(--p) * 1%), var(--surface-3) 0); }
.ring span { font-size: 12px; font-weight: 800; }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1; }
.chip .icon { width: 13px; height: 13px; }
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.chip-warning { background: var(--warning-soft); color: var(--warning); }
.chip-info { background: var(--info-soft); color: var(--info); }
.chip-orange { background: var(--orange-soft); color: var(--orange); }
.chip-neutral { background: var(--surface-3); color: var(--text-2); }
.chip-dark { background: #1F2937; color: #fff; }
[data-theme="dark"] .chip-dark { background: #E5E7EB; color: #111; }

/* ---------- Notices ---------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13.5px; border: 1px solid transparent; }
.notice .icon { margin-top: 1px; }
.notice-info { background: var(--info-soft); color: var(--text); border-color: rgba(33,137,255,.18); }
.notice-info .icon { color: var(--info); }
.notice-warning { background: var(--warning-soft); color: var(--text); border-color: rgba(245,158,11,.25); }
.notice-warning .icon { color: var(--warning); }
.result-banner { display: flex; gap: 14px; align-items: center; padding: 16px 18px; border-radius: var(--radius); }
.result-banner .icon { width: 28px; height: 28px; flex: none; }
.result-banner.success { background: var(--success-soft); } .result-banner.success .icon { color: var(--success); }
.result-banner.danger { background: var(--danger-soft); } .result-banner.danger .icon { color: var(--danger); }
.result-banner.warning { background: var(--warning-soft); } .result-banner.warning .icon { color: var(--warning); }

/* ---------- Modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; opacity: 0; transition: opacity .2s var(--ease); }
.modal-wrap.show { opacity: 1; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 12, 24, .5); backdrop-filter: blur(4px); }
.modal { position: relative; background: var(--surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  transform: translateY(14px) scale(.98); transition: transform .25s var(--ease); border: 1px solid var(--border); }
.modal-wrap.show .modal { transform: none; }
.modal-sm { max-width: 460px; } .modal-md { max-width: 620px; } .modal-lg { max-width: 860px; } .modal-xl { max-width: 1240px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 26px 8px; gap: 10px; }
.modal-head h3 { font-size: 19px; font-weight: 800; }
.modal-body { padding: 12px 26px 18px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 26px 22px; flex-wrap: wrap; }
.modal-error { margin: 0 26px; padding: 10px 14px; background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; }
.confirm-body { text-align: center; }
.confirm-body p { font-size: 15px; }
.confirm-icon { width: 60px; height: 60px; border-radius: 20px; margin: 4px auto 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-2); }
.confirm-icon .icon { width: 30px; height: 30px; }
.confirm-icon.danger { background: var(--danger-soft); color: var(--danger); }
.confirm-person { display: flex; align-items: center; gap: 12px; text-align: start; background: var(--surface-2); padding: 12px; border-radius: var(--radius); margin-top: 12px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 22px; inset-inline-end: 22px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
.toast { display: flex; align-items: center; gap: 12px; padding: 13px 14px 13px 16px; border-radius: var(--radius); background: #111827; color: #fff; box-shadow: var(--shadow-lg);
  transform: translateY(12px); opacity: 0; transition: all .25s var(--ease); font-size: 13.5px; font-weight: 500; }
.toast.show { transform: none; opacity: 1; }
.toast-success .icon:first-child { color: #34D399; } .toast-error .icon:first-child { color: #F87171; } .toast-warning .icon:first-child { color: #FBBF24; } .toast-info .icon:first-child { color: #60A5FA; }
.toast-msg { flex: 1; }
.toast-x { background: none; border: none; color: rgba(255,255,255,.6); cursor: pointer; display: grid; place-items: center; padding: 2px; }
.toast-x .icon { width: 16px; height: 16px; }

/* ---------- Dropdown ---------- */
.dropdown { position: absolute; z-index: 1500; min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; animation: pop .16s var(--ease); }
.dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: none; background: none; color: var(--text); font: inherit; font-size: 13.5px; border-radius: 10px; cursor: pointer; text-align: start; }
.dropdown-item:hover { background: var(--surface-3); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ---------- Segmented tabs ---------- */
.seg-tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-3); border-radius: 999px; margin-bottom: 16px; flex-wrap: wrap; }
.seg { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 16px; border-radius: 999px; border: none; background: transparent; color: var(--text-2); font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; transition: all .18s var(--ease); }
.seg .icon { width: 17px; height: 17px; }
.seg:hover { color: var(--text); }
.seg.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 2px 8px rgba(0,0,0,.06); }
.seg-tabs.sm .seg { height: 30px; padding: 0 12px; font-size: 12.5px; }

/* ---------- Avatars ---------- */
.avatar { object-fit: cover; border-radius: 50%; background: var(--surface-3); flex: none; display: inline-block; vertical-align: middle; }
.avatar-sm { width: 36px; height: 36px; }
.avatar-md { width: 48px; height: 48px; border-radius: 14px; }
.avatar-lg { width: 88px; height: 88px; border-radius: 22px; }
.avatar-xl { width: 180px; height: 180px; border-radius: 30px; }
.avatar.no-photo { opacity: .85; }
.photo-btn { border: none; background: none; padding: 0; cursor: zoom-in; border-radius: 50%; }

/* ---------- Progress ---------- */
.progress { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--brand-grad); border-radius: 999px; transition: width .25s var(--ease); }
.progress-dialog { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 14px; }
.mini-progress { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.mini-progress-bar { flex: 1; height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; min-width: 50px; }
.mini-progress-bar span { display: block; height: 100%; background: var(--brand-grad); border-radius: 999px; transition: width .4s var(--ease); }
.mini-progress-bar.lg { height: 10px; margin: 8px 0 6px; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 42px 20px; color: var(--text-2); }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 22px; background: var(--surface-3); display: grid; place-items: center; color: var(--text-3); }
.empty-icon .icon { width: 30px; height: 30px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }
.empty-state p { max-width: 460px; margin: 0 auto 14px; }

/* ---------- Key/value grid ---------- */
.kv-grid { display: grid; grid-template-columns: minmax(150px, 34%) 1fr; gap: 10px 18px; font-size: 13.5px; }
.kv-grid > div:nth-child(odd) { color: var(--text-3); font-weight: 500; }
.kv-grid.wide { grid-template-columns: minmax(190px, 30%) 1fr; }
.code-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; font-family: var(--mono); font-size: 12px; max-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }

/* ---------- Stepper ---------- */
.stepper { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-weight: 600; font-size: 13px; }
.step-n { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); font-size: 13px; }
.step-n .icon { width: 15px; height: 15px; }
.step.active { color: var(--text); } .step.active .step-n { background: var(--brand-grad); color: #fff; }
.step.done { color: var(--success); } .step.done .step-n { background: var(--success-soft); color: var(--success); }
.step-line { flex: 1; min-width: 20px; height: 2px; background: var(--border); border-radius: 2px; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
