/* Persian / RTL layout + typography overrides.
 * Loaded last when LANGUAGE_CODE is fa (or BIDI) so it wins over Inter-based stacks.
 */

html[lang="fa"],
html[dir="rtl"] {
  --linear-font-sans: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --dashboard-font-sans: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --linear-font-mono: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --dashboard-font-mono: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --font-mono: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --font-sans: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
}

html[lang="fa"] body,
html[lang="fa"] .app-shell-body,
html[lang="fa"] .app-header,
html[lang="fa"] .app-header-title,
html[lang="fa"] .app-header-copy,
html[lang="fa"] .app-bottom-nav,
html[lang="fa"] .dashboard-topbar,
html[lang="fa"] .dashboard-sidebar,
html[lang="fa"] .dashboard-container,
html[lang="fa"] .dashboard-bento,
html[lang="fa"] .dashboard-panel,
html[lang="fa"] .dashboard-metric-card,
html[lang="fa"] .device-tile,
html[lang="fa"] .linear-page-shell,
html[lang="fa"] .linear-panel,
html[lang="fa"] .linear-title,
html[lang="fa"] .linear-copy,
html[lang="fa"] .linear-label,
html[lang="fa"] .linear-button,
html[lang="fa"] .linear-input,
html[lang="fa"] .linear-select,
html[lang="fa"] .linear-sidebar-link,
html[lang="fa"] .linear-chip,
html[lang="fa"] button,
html[lang="fa"] input,
html[lang="fa"] select,
html[lang="fa"] textarea,
html[lang="fa"] .present-shell,
html[lang="fa"] .metering-shell {
  font-family: var(--dashboard-font-sans) !important;
}

/* Keep numerals LTR but use the same Persian UI font (Vazirmatn) so digits match labels */
html[lang="fa"] .linear-mono,
html[lang="fa"] .dashboard-mono,
html[lang="fa"] .linear-stat-value,
html[lang="fa"] .dashboard-metric-card__value,
html[lang="fa"] .dashboard-odometer,
html[lang="fa"] .dashboard-topbar-ops-value,
html[lang="fa"] .dashboard-topbar-clock,
html[lang="fa"] .linear-pagination-copy,
html[lang="fa"] .linear-table td.linear-mono,
html[lang="fa"] .mc-lcd__lines,
html[lang="fa"] .mc-lcd__value,
html[lang="fa"] .mc-lcd__page,
html[lang="fa"] .mc-bay__tag-code,
html[dir="rtl"] .dashboard-mono,
html[dir="rtl"] .linear-mono {
  font-family: var(--dashboard-font-sans) !important;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}

html[lang="fa"] .metering-page,
html[lang="fa"] .metering-main,
html[lang="fa"] .mc-lcd__label,
html[lang="fa"] .mc-panel__title,
html[lang="fa"] .mc-power__label {
  font-family: var(--dashboard-font-sans) !important;
}

html[lang="fa"] .mc-lcd__label {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  line-height: 1.25;
  letter-spacing: 0;
}

html[lang="fa"] .mc-lcd__value,
html[lang="fa"] .mc-lcd__page {
  letter-spacing: 0;
  text-align: end;
}

html[lang="fa"] .mc-lcd__row--stack .mc-lcd__value,
html[lang="fa"] .mc-lcd__datetime-block .mc-lcd__value {
  text-align: start;
}

/* Persian labels: drop Latin-style tracking / uppercase */
html[lang="fa"] .dashboard-sidebar-eyebrow,
html[lang="fa"] .dashboard-sidebar-footer-label,
html[lang="fa"] .dashboard-sidebar-status-label,
html[lang="fa"] .dashboard-section-kicker,
html[lang="fa"] .dashboard-panel-badge,
html[lang="fa"] .linear-kicker,
html[lang="fa"] .linear-sidebar-section,
html[lang="fa"] .app-header-page-badge,
html[lang="fa"] .dashboard-topbar-ops-label,
html[lang="fa"] .present-kicker {
  letter-spacing: 0 !important;
  text-transform: none !important;
}

/* -------------------------------------------------------------------------- */
/* Shell / sidebar                                                              */
/* -------------------------------------------------------------------------- */

html[dir="rtl"] .dashboard-sidebar {
  inset-inline-end: 0;
  inset-inline-start: auto;
  border-inline-start: 1px solid color-mix(in srgb, var(--dashboard-border-soft, #E6E9F2) 80%, transparent);
  border-left: none;
  border-right: none;
  box-shadow: 4px 0 24px var(--dashboard-shadow-sm, rgba(21, 36, 71, 0.1));
}

html[dir="rtl"] .dashboard-sidebar[data-state="closed"] {
  transform: translateX(-100%);
}

html[dir="rtl"] .dashboard-sidebar[data-state="open"] {
  transform: translateX(0);
}

html[dir="rtl"] .dashboard-sidebar-link.is-active {
  border-inline-start: 3px solid var(--dashboard-blue, #204098);
  border-left: none;
  border-right: none;
}

html[dir="rtl"] .dashboard-sidebar-header,
html[dir="rtl"] .dashboard-sidebar-user-card,
html[dir="rtl"] .dashboard-sidebar-link,
html[dir="rtl"] .dashboard-sidebar-link-body {
  text-align: start;
}

html[dir="rtl"] .dashboard-sidebar-link {
  flex-direction: row;
}

/* -------------------------------------------------------------------------- */
/* Keep designed grid maps; restore RTL only for content                       */
/* -------------------------------------------------------------------------- */

html[dir="rtl"] .dashboard-bento,
html[dir="rtl"] .dashboard-metric-card__body,
html[dir="rtl"] .device-tile-main,
html[dir="rtl"] .dashboard-record-panel {
  direction: ltr;
}

html[dir="rtl"] .dashboard-bento > *,
html[dir="rtl"] .dashboard-metric-card__body > *,
html[dir="rtl"] .device-tile-main > *,
html[dir="rtl"] .dashboard-record-panel > *,
html[dir="rtl"] .app-header-brand,
html[dir="rtl"] .app-header-copy,
html[dir="rtl"] .app-header-toolbar,
html[dir="rtl"] .dashboard-topbar-brand,
html[dir="rtl"] .dashboard-topbar-main-actions,
html[dir="rtl"] .dashboard-panel,
html[dir="rtl"] .dashboard-metric-card,
html[dir="rtl"] .device-tile,
html[dir="rtl"] .dashboard-status-card,
html[dir="rtl"] .dashboard-alarm-card {
  direction: rtl;
  text-align: start;
}

/* -------------------------------------------------------------------------- */
/* Topbar / chips / menus                                                       */
/* -------------------------------------------------------------------------- */

html[dir="rtl"] .app-header-shell,
html[dir="rtl"] .dashboard-topbar-shell,
html[dir="rtl"] .dashboard-topbar--ops .dashboard-topbar-shell {
  /* Natural RTL: brand on the right, actions on the left */
  direction: rtl;
}

html[dir="rtl"] .dashboard-topbar-menu,
html[dir="rtl"] .app-header-menu,
html[dir="rtl"] .chart-export-menu {
  inset-inline-end: 0;
  inset-inline-start: auto;
  right: auto;
  left: auto;
}

html[dir="rtl"] .dashboard-topbar-ops {
  /* Keep metric chip order stable (do not mirror the strip) */
  direction: ltr;
}

html[dir="rtl"] .dashboard-panel-header,
html[dir="rtl"] .dashboard-metric-card__header,
html[dir="rtl"] .device-tile header,
html[dir="rtl"] .dashboard-notification-item-head {
  direction: rtl;
}

html[dir="rtl"] .dashboard-topbar-ops-chip,
html[dir="rtl"] .dashboard-breakdown-chip,
html[dir="rtl"] .dashboard-compare-chip,
html[dir="rtl"] .dashboard-panel-badge,
html[dir="rtl"] .linear-chip {
  direction: rtl;
  text-align: start;
}

html[lang="fa"] .dashboard-topbar-ops-label,
html[lang="fa"] .dashboard-topbar-ops-chip--time .dashboard-topbar-date {
  letter-spacing: 0 !important;
  text-transform: none !important;
}

html[lang="fa"] .dashboard-topbar-ops-chip {
  min-width: 5.75rem;
}

html[lang="fa"] .dashboard-topbar-ops-chip--time.dashboard-topbar-datetime {
  min-width: 7.25rem;
}

html[dir="rtl"] .dashboard-connection-status,
html[dir="rtl"] .dashboard-topbar-ops-chip--stream {
  flex-direction: row;
}

/* -------------------------------------------------------------------------- */
/* Cards / tiles / notifications — logical edges                               */
/* -------------------------------------------------------------------------- */

html[dir="rtl"] .device-tile,
html[dir="rtl"] .dashboard-status-card,
html[dir="rtl"] .dashboard-alarm-card,
html[dir="rtl"] .dashboard-ai-brief,
html[dir="rtl"] .dashboard-notification-item {
  text-align: start;
}

html[dir="rtl"] .dashboard-notification-item,
html[dir="rtl"] .dashboard-ai-brief,
html[dir="rtl"] .dashboard-alarm-card--critical,
html[dir="rtl"] .dashboard-alarm-card--warning,
html[dir="rtl"] .dashboard-alarm-card--info {
  border-left: none;
  border-right: none;
  border-inline-start-width: 3px;
  border-inline-start-style: solid;
  padding-inline-start: 0.85rem;
  padding-left: 0;
  padding-right: 0;
}

html[dir="rtl"] .dashboard-alarm-card--critical,
html[dir="rtl"] .dashboard-notification-item[data-severity="critical"] {
  border-inline-start-color: #e11d48;
}

html[dir="rtl"] .dashboard-alarm-card--warning,
html[dir="rtl"] .dashboard-notification-item[data-severity="warning"] {
  border-inline-start-color: #FF7F50;
}

html[dir="rtl"] .dashboard-alarm-card--info,
html[dir="rtl"] .dashboard-notification-item[data-severity="info"] {
  border-inline-start-color: var(--primary, #204098);
}

/* Switches / toggles: mirror thumb travel in RTL */
html[dir="rtl"] .linear-toggle-track .linear-toggle-thumb,
html[dir="rtl"] .dashboard-plc-switch-thumb,
html[dir="rtl"] [data-switch-thumb] {
  left: auto;
  right: 2px;
  inset-inline-start: auto;
  inset-inline-end: 2px;
}

html[dir="rtl"] .linear-toggle.is-on .linear-toggle-thumb,
html[dir="rtl"] .dashboard-plc-switch.is-on .dashboard-plc-switch-thumb,
html[dir="rtl"] [data-switch].is-on [data-switch-thumb] {
  transform: translateX(-1.25rem);
}

/* -------------------------------------------------------------------------- */
/* Settings / linear shell                                                      */
/* -------------------------------------------------------------------------- */

html[dir="rtl"] .linear-settings-layout,
html[dir="rtl"] .linear-page-grid--sidebar,
html[dir="rtl"] .linear-form-stack,
html[dir="rtl"] .linear-field,
html[dir="rtl"] .linear-table,
html[dir="rtl"] .linear-sidebar-nav {
  direction: rtl;
  text-align: start;
}

html[dir="rtl"] .linear-settings-hub-card__chevron,
html[dir="rtl"] .linear-sidebar-link-icon svg {
  transform: scaleX(-1);
}

html[dir="rtl"] .linear-input,
html[dir="rtl"] .linear-select,
html[dir="rtl"] .linear-textarea {
  text-align: start;
}

html[dir="rtl"] .linear-actions {
  justify-content: flex-start;
}

/* -------------------------------------------------------------------------- */
/* Bottom nav / mobile                                                          */
/* -------------------------------------------------------------------------- */

html[dir="rtl"] .app-bottom-nav,
html[dir="rtl"] .app-bottom-nav__glass {
  direction: rtl;
}

html[dir="rtl"] body.app-mobile-shell .app-header-toolbar,
html[dir="rtl"] body.app-mobile-shell .dashboard-topbar-main-actions {
  margin-inline-start: 0;
  margin-left: 0;
  margin-right: 0;
  justify-content: flex-end;
}

/* -------------------------------------------------------------------------- */
/* Charts / metering / present                                                  */
/* -------------------------------------------------------------------------- */

html[dir="rtl"] .chart-export-btn--menu {
  flex-direction: row-reverse;
}

html[dir="rtl"] .metering-page,
html[dir="rtl"] .metering-main,
html[dir="rtl"] .present-shell {
  direction: rtl;
  text-align: start;
  font-family: var(--dashboard-font-sans);
}

html[dir="rtl"] .metering-page .dashboard-mono,
html[dir="rtl"] .present-shell .dashboard-mono,
html[dir="rtl"] .present-odometer__value,
html[dir="rtl"] .mc-lcd__value,
html[dir="rtl"] .mc-lcd__page {
  direction: ltr;
  unicode-bidi: isolate;
}

/* Datepicker already has some RTL; reinforce text direction */
html[dir="rtl"] .suniar-datepicker-popup,
html[dir="rtl"] .suniar-datepicker-range {
  direction: rtl;
}

/* -------------------------------------------------------------------------- */
/* Device modals (inverter / meter / substation) — Vazirmatn + no Latin casing */
/* -------------------------------------------------------------------------- */

html[lang="fa"] .dashboard-device-modal,
html[lang="fa"] .dashboard-device-modal-panel,
html[lang="fa"] .device-modal-header__title,
html[lang="fa"] .device-modal-header__kicker,
html[lang="fa"] .device-modal-header__copy,
html[lang="fa"] .device-modal-header__meta,
html[lang="fa"] .device-modal-tab,
html[lang="fa"] .device-modal-tab span,
html[lang="fa"] .device-modal-kpi__label,
html[lang="fa"] .device-modal-extra__title,
html[lang="fa"] .device-modal-extra__subtitle,
html[lang="fa"] .device-modal-extra__kicker,
html[lang="fa"] .device-modal-strings__subtitle,
html[lang="fa"] .device-modal-smart__kicker,
html[lang="fa"] .device-modal-smart__title,
html[lang="fa"] .device-modal-smart__subtitle,
html[lang="fa"] .device-modal-smart-card__headline,
html[lang="fa"] .device-modal-smart-card__detail,
html[lang="fa"] .device-modal-smart-summary__label,
html[lang="fa"] .dashboard-device-modal-section-title,
html[lang="fa"] .dashboard-device-modal-detail__label,
html[lang="fa"] .inverter-threshold-card__title,
html[lang="fa"] .inverter-threshold-empty,
html[lang="fa"] .inverter-string-card__title,
html[lang="fa"] .dashboard-substation-modal-gauge-label,
html[lang="fa"] .dashboard-modal-loading-text {
  font-family: var(--dashboard-font-sans) !important;
}

html[lang="fa"] .device-modal-header__kicker,
html[lang="fa"] .device-modal-kpi__label,
html[lang="fa"] .device-modal-phase-chip p,
html[lang="fa"] .device-modal-smart__kicker,
html[lang="fa"] .device-modal-smart-summary__label,
html[lang="fa"] .dashboard-device-modal-section-title,
html[lang="fa"] .dashboard-device-modal-detail__label,
html[lang="fa"] .device-modal-extra__kicker,
html[lang="fa"] .dashboard-substation-modal-gauge-label,
html[lang="fa"] .dashboard-device-modal-panel .uppercase,
html[lang="fa"] .dashboard-device-modal-panel .tracking-wide {
  letter-spacing: 0 !important;
  text-transform: none !important;
}

html[dir="rtl"] .dashboard-device-modal-detail {
  direction: rtl;
}

html[dir="rtl"] .dashboard-device-modal-detail__value {
  text-align: start;
}

html[dir="rtl"] .device-modal-header__meta,
html[dir="rtl"] .device-modal-tab-list,
html[dir="rtl"] .device-modal-kpi-strip {
  direction: rtl;
}

/* Keep numeric / code values LTR with the same Persian UI font */
html[lang="fa"] .dashboard-device-modal-detail__value,
html[lang="fa"] .device-modal-kpi__value,
html[lang="fa"] .device-modal-phase-chip strong,
html[lang="fa"] .device-modal-extra-stat strong,
html[lang="fa"] .device-modal-extra-card__key,
html[lang="fa"] .inverter-threshold-metric-card__live,
html[lang="fa"] .inverter-threshold-metric-card__bounds,
html[lang="fa"] .inverter-string-metrics dd,
html[lang="fa"] .dashboard-substation-modal-gauge-value,
html[lang="fa"] .dashboard-device-modal-panel .dashboard-mono {
  font-family: var(--dashboard-font-sans) !important;
  direction: ltr;
  unicode-bidi: isolate;
}
