/* =========================================================
   TazaBazar BI — design tokens
   ========================================================= */
:root {
  color-scheme: light;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, Roboto, sans-serif;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-hover: #f2f5fa;
  --border: #e6e9ef;
  --border-strong: #d4d9e2;
  --text: #171a20;
  --text-2: #4b5260;
  --text-3: #808796;
  --primary: #2a78d6;
  --primary-hover: #1f68c2;
  --primary-soft: #e8f1fc;
  --grid: #eef0f4;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-crit: #e34948;
  --ok: #138a5e; --ok-soft: #e4f6ee;
  --warn: #b76e00; --warn-soft: #fdf3e0;
  --crit: #c93736; --crit-soft: #fdecec;
  --info-soft: #e8f1fc;
  --sidebar: #0d1726;
  --sidebar-text: #a9b3c4;
  --sidebar-active: #1c2c45;
  --tooltip-bg: #1d2129;
  --tooltip-text: #ffffff;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
  --radius: 12px;
  --radius-sm: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1015; --surface: #161920; --surface-2: #1b1f27; --surface-hover: #1f242e;
    --border: #262b35; --border-strong: #333a47;
    --text: #eceef2; --text-2: #b7bdc9; --text-3: #848c9b;
    --primary: #3987e5; --primary-hover: #5598e7; --primary-soft: #182a42;
    --grid: #232833;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-crit: #e66767;
    --ok: #3cc78f; --ok-soft: #12291f; --warn: #e5a53a; --warn-soft: #2b2110; --crit: #ff7b7a; --crit-soft: #301617; --info-soft: #182a42;
    --sidebar: #0a0d12; --sidebar-active: #1a2333;
    --tooltip-bg: #f0f1f4; --tooltip-text: #121418;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1015; --surface: #161920; --surface-2: #1b1f27; --surface-hover: #1f242e;
  --border: #262b35; --border-strong: #333a47;
  --text: #eceef2; --text-2: #b7bdc9; --text-3: #848c9b;
  --primary: #3987e5; --primary-hover: #5598e7; --primary-soft: #182a42;
  --grid: #232833;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-crit: #e66767;
  --ok: #3cc78f; --ok-soft: #12291f; --warn: #e5a53a; --warn-soft: #2b2110; --crit: #ff7b7a; --crit-soft: #301617; --info-soft: #182a42;
  --sidebar: #0a0d12; --sidebar-active: #1a2333;
  --tooltip-bg: #f0f1f4; --tooltip-text: #121418;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
}

/* =========================================================
   Base
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[dir="rtl"] body { font-size: 14.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--text); }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15.5px; font-weight: 620; }
h3 { font-size: 16px; font-weight: 620; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }
.muted { color: var(--text-3); }
.sm { font-size: 12px; }
.center { text-align: center; }
.ital { font-style: italic; }
.dot-sep { margin: 0 6px; color: var(--text-3); }
.no-scroll { overflow: hidden; }
::selection { background: var(--primary-soft); }

/* =========================================================
   Buttons & inputs
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:focus-visible, .icon-btn:focus-visible, .segmented button:focus-visible, .chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 0 rgba(5, 95, 255, .08); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); color: #fff; border-color: var(--crit); }
.btn-lg { height: 42px; font-size: 15px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid #fff; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn:not(.btn-primary):not(.btn-danger).loading::after { border-color: var(--primary); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn.bordered { border-color: var(--border-strong); background: var(--surface); }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; font-size: 12.5px; }
.link.danger { color: var(--crit); }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 550; color: var(--text-2); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap > svg { position: absolute; inset-inline-start: 12px; width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
.input-wrap input, .input-wrap select, .search, .pw-row input {
  width: 100%; height: 42px; padding: 0 12px; padding-inline-start: 40px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input-wrap.no-icon input, .input-wrap.no-icon select { padding-inline-start: 12px; height: 38px; }
.input-wrap input:hover, .input-wrap select:hover { border-color: var(--primary); }
.input-wrap input:focus, .input-wrap select:focus, .search:focus, .pw-row input:focus, .date-input input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.pw-toggle { position: absolute; inset-inline-end: 6px; width: 32px; height: 32px; display: grid; place-items: center; border: 0; background: none; color: var(--text-3); cursor: pointer; border-radius: 6px; }
.pw-toggle svg { width: 18px; height: 18px; }
.pw-toggle.on, .pw-toggle:hover { color: var(--primary); }
.input-wrap input[type=password] { padding-inline-end: 44px; }
.input-wrap.no-icon input[type=password] { padding-inline-end: 12px; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; border: 1px solid transparent; }
.alert-error { background: var(--crit-soft); color: var(--crit); border-color: color-mix(in srgb, var(--crit) 25%, transparent); }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--text-2); border-color: color-mix(in srgb, var(--primary) 20%, transparent); }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag-crit { background: var(--crit-soft); color: var(--crit); border-color: transparent; padding: 0 6px; }

/* Segmented control (Ant-style) */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 13px; font-weight: 550;
  height: 30px; padding: 0 12px; border-radius: 7px; cursor: pointer; transition: background .15s, color .15s, box-shadow .15s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.segmented.sm button { height: 26px; padding: 0 10px; font-size: 12.5px; }

/* Language + theme switch */
.prefs { display: flex; align-items: center; gap: 6px; }
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.lang-switch button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 12.5px; font-weight: 600; padding: 0 10px; height: 30px; cursor: pointer; min-width: 36px; }
.lang-switch button + button { border-inline-start: 1px solid var(--border); }
.lang-switch button.active { background: var(--primary-soft); color: var(--primary); }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}

/* Brand */
.brand-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; color: var(--text); letter-spacing: -.01em; }
.brand-mark b { color: var(--primary); font-weight: 750; }
.brand-mark .logo { flex: none; }
.brand-mark.lg { font-size: 20px; color: #fff; }
.brand-mark.lg .logo { width: 40px; height: 40px; }
.brand-mark.lg b { color: #8fc0ff; }

/* =========================================================
   Auth page
   ========================================================= */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-brand {
  position: relative; overflow: hidden; color: #dbe6f5;
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(57, 135, 229, .35), transparent 60%),
    radial-gradient(700px 500px at 90% 90%, rgba(27, 175, 122, .18), transparent 60%),
    linear-gradient(160deg, #0b1424 0%, #0f1d33 55%, #0b1424 100%);
  display: flex; align-items: center; padding: 56px;
}
.auth-brand::before {
  content: ""; position: absolute; inset: 0; opacity: .35;
  background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 40px 40px; mask-image: radial-gradient(ellipse at 30% 40%, #000 30%, transparent 75%);
}
.auth-brand-inner { position: relative; max-width: 480px; }
.auth-brand h1 { color: #fff; font-size: 34px; line-height: 1.15; margin: 44px 0 14px; font-weight: 700; letter-spacing: -.02em; }
.auth-brand p { font-size: 15.5px; color: #a8b8cf; max-width: 420px; }
.auth-preview { margin-top: 40px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ap-card, .ap-spark { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: 12px; padding: 14px 16px; backdrop-filter: blur(6px); }
.ap-card span { display: block; font-size: 12px; color: #93a4bd; }
.ap-card b { display: block; font-size: 20px; color: #fff; margin: 2px 0 10px; }
.ap-bar { display: block; height: 6px; border-radius: 6px; background: rgba(255,255,255,.08); position: relative; overflow: hidden; }
.ap-bar::after { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: var(--w); background: #3987e5; border-radius: 6px; }
.ap-bar.alt::after { background: #e66767; }
.ap-spark { grid-column: span 2; color: #6da7ec; height: 92px; }
.ap-spark svg { width: 100%; height: 100%; }

.auth-form-wrap { position: relative; display: flex; align-items: center; justify-content: center; padding: 72px 24px 40px; background: var(--surface); }
.auth-top { position: absolute; top: 20px; inset-inline-end: 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 28px; }
.auth-card .btn-lg { margin-top: 8px; }
.auth-foot { margin-top: 32px; font-size: 12px; text-align: center; }
.sm-only { display: none !important; }

@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .sm-only { display: inline-flex !important; margin-bottom: 28px; }
}

/* Error / setup */
.error-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px; }
.error-code { font-size: 88px; font-weight: 800; line-height: 1; letter-spacing: -.04em; background: linear-gradient(135deg, var(--primary), var(--series-3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.error-page .btn { margin-top: 12px; }
.debug { max-width: 720px; white-space: pre-wrap; text-align: start; background: var(--surface); border: 1px solid var(--border); padding: 12px; border-radius: 8px; font-size: 12px; }

.setup-page { min-height: 100vh; }
.setup-narrow { max-width: 440px; margin: 0 auto; padding: 64px 20px; }
.setup-narrow .brand-mark { margin-bottom: 20px; }
.setup-narrow .card h2 { margin-bottom: 12px; }
.setup-narrow .card .muted { margin-bottom: 18px; }
.setup-wide { max-width: 1280px; margin: 0 auto; padding: 32px 20px 48px; }
.setup-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.setup-grid { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 20px; align-items: start; margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
.form-grid .field { margin-bottom: 12px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span-2 { grid-column: span 2; }
.pw-row { display: flex; gap: 6px; min-width: 230px; }
.pw-row input { height: 30px; padding: 0 10px; font-size: 13px; }
.search { height: 34px; padding: 0 12px; max-width: 220px; }
form.inline { display: inline; margin-inline-start: 6px; }
.table-wrap.tall { max-height: 640px; overflow: auto; }
@media (max-width: 1000px) { .setup-grid { grid-template-columns: 1fr; } }

/* =========================================================
   App shell
   ========================================================= */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px; z-index: 40;
}
.sidebar .brand-mark { color: #fff; padding: 4px 10px 22px; }
.sidebar .brand-mark b { color: #8fc0ff; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64718a; padding: 14px 12px 6px; font-weight: 600; }
[dir="rtl"] .nav-label { letter-spacing: 0; text-transform: none; font-size: 12px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--sidebar-text); font-weight: 520; transition: background .15s, color .15s; }
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #3987e5; }
[dir="rtl"] .nav-item.active { box-shadow: inset -3px 0 0 #3987e5; }
.nav-item.disabled { opacity: .45; cursor: default; }
.nav-item.disabled:hover { background: none; color: var(--sidebar-text); }
.sidebar-foot { font-size: 11.5px; padding: 8px 12px; color: #5c6880; }
.sidebar-backdrop { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 60px; display: flex; align-items: center; gap: 12px;
  padding: 0 28px; background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; }
.crumbs { color: var(--text-3); font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.crumbs b { color: var(--text); font-weight: 600; }
.topbar-right { margin-inline-start: auto; display: flex; align-items: center; gap: 12px; }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 8px 0 4px; border: 1px solid transparent; border-radius: 999px; background: none; color: var(--text); font: inherit; cursor: pointer; }
[dir="rtl"] .user-btn { padding: 0 4px 0 8px; }
.user-btn:hover { background: var(--surface-hover); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #3987e5, #6250d6); }
.user-name { font-weight: 550; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown { position: absolute; inset-inline-end: 0; top: calc(100% + 8px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 50; animation: pop .14s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.dd-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; display: flex; flex-direction: column; }
.dd-head .muted { font-size: 12px; }
.dd-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none; color: var(--text); font: inherit; border-radius: 6px; cursor: pointer; text-align: start; }
.dd-item:hover { background: var(--surface-hover); }
.dd-item.danger { color: var(--crit); }

.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1600px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head p { margin-top: 4px; }
.page-head b { color: var(--text-2); font-weight: 600; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head p { margin-top: 3px; font-size: 13px; max-width: 720px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; flex-wrap: wrap; }
.range-picker { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-input { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 4px 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
[dir="rtl"] .date-input { padding: 0 10px 0 4px; }
.date-input:focus-within { border-color: var(--primary); }
.date-input span { font-size: 12px; color: var(--text-3); font-weight: 550; }
.date-input input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; height: 30px; }
.range-arrow { color: var(--text-3); }
[dir="rtl"] .range-arrow { transform: scaleX(-1); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { display: flex; gap: 14px; align-items: flex-start; padding: 18px 20px; transition: transform .15s, box-shadow .15s; }
.kpi:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.kpi-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-icon.blue { background: color-mix(in srgb, var(--series-1) 13%, transparent); color: var(--series-1); }
.kpi-icon.red { background: color-mix(in srgb, var(--series-crit) 13%, transparent); color: var(--series-crit); }
.kpi-icon.amber { background: color-mix(in srgb, #eda100 15%, transparent); color: #c98500; }
.kpi-icon.green { background: color-mix(in srgb, var(--series-3) 14%, transparent); color: var(--series-3); }
.kpi-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.kpi-label { font-size: 13px; color: var(--text-3); font-weight: 550; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin: 4px 0 4px; font-variant-numeric: tabular-nums; color: var(--text); }
.kpi-sub { font-size: 12.5px; color: var(--text-3); min-height: 19px; display: flex; align-items: center; }
.meter { display: block; width: 100%; height: 6px; border-radius: 6px; background: var(--grid); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--series-crit); border-radius: 6px; transition: width .6s ease; }

/* Skeleton */
.sk { display: inline-block; width: 90px; height: 1em; border-radius: 6px; background: linear-gradient(90deg, var(--grid) 25%, var(--surface-2) 50%, var(--grid) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; vertical-align: middle; }
.sk.w-100 { width: 100%; }
@keyframes shimmer { to { background-position: -200% 0; } }
.is-loading .chart-box, .is-loading .table-wrap, .is-loading .kpi-value { opacity: .55; transition: opacity .2s; }

/* Charts */
.chart-box { position: relative; width: 100%; min-height: 160px; }
.chart-box.h-280 { height: 280px; }
.chart-box canvas { display: block; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); font-size: 14px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; }
.lg-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.lg-item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th { text-align: start; font-size: 12px; font-weight: 600; color: var(--text-3); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table thead th:first-child { border-start-start-radius: 8px; }
.table thead th:last-child { border-start-end-radius: 8px; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tfoot th { background: transparent; color: var(--text); font-size: 13px; border-bottom: 0; border-top: 1px solid var(--border-strong); }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-hover); }
.table.clickable tbody tr[data-reason] { cursor: pointer; }
.table.compact td { padding: 9px 10px; }
.table .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .id { font-size: 11.5px; }
.table td.wrap { max-width: 280px; white-space: normal; overflow-wrap: anywhere; }
.bar-col { width: 22%; min-width: 100px; }
.bar { display: block; height: 8px; border-radius: 8px; background: var(--grid); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 8px; background: var(--series-1); }
.bar.crit i { background: var(--series-crit); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 8px; vertical-align: middle; flex: none; }
.status-pill { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; white-space: nowrap; }
.status-pill .status-dot { margin-inline-end: 6px; }

/* Chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; transition: border-color .15s, background .15s; }
.chip:hover { border-color: var(--primary); }
.chip i { width: 10px; height: 10px; border-radius: 3px; }
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip.strong { background: var(--crit-soft); border-color: transparent; color: var(--crit); }
.chip.strong b { color: var(--crit); }

/* Free text list */
.free-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.free-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(80px, 30%) 48px; gap: 14px; align-items: center; }
.free-list .free-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.free-list b { text-align: end; font-variant-numeric: tabular-nums; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); z-index: 60; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(820px, 100vw); z-index: 70;
  background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); visibility: hidden;
}
[dir="rtl"] .drawer { transform: translateX(-105%); }
.drawer.open { transform: none !important; visibility: visible; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 24px 14px; border-bottom: 1px solid var(--border); }
.drawer-head .muted { margin-top: 4px; font-size: 13px; }
.drawer-filters { margin: 14px 24px 0; align-self: flex-start; }
.drawer-body { flex: 1; overflow: auto; padding: 12px 24px; }
.drawer-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-top: 1px solid var(--border); }
.pager { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }

/* Toasts */
.toast-host { position: fixed; bottom: 20px; inset-inline-end: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 90; }
.toast { padding: 10px 16px; border-radius: 10px; background: var(--tooltip-bg); color: var(--tooltip-text); box-shadow: var(--shadow-lg); font-size: 13.5px; animation: pop .2s; transition: opacity .4s; }
.toast.error { background: var(--crit); color: #fff; }
.toast.out { opacity: 0; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 260px; transform: translateX(-100%); transition: transform .25s; }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar-open .sidebar { transform: none !important; }
  .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(10,14,22,.45); z-index: 35; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px 16px 40px; }
  .user-name, .crumbs span, .crumbs .sep { display: none; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr; }
  .kpi-value { font-size: 24px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .range-picker { justify-content: stretch; }
  .date-input { flex: 1; }
  .range-arrow { display: none; }
  .lang-switch button { min-width: 30px; padding: 0 6px; }
  .card { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .free-list li { grid-template-columns: minmax(0, 1fr) 40px; }
  .free-list .bar { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
