@font-face {
  font-family: "Peyda";
  src: url("/static/fonts/PeydaWebFaNum-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Peyda";
  src: url("/static/fonts/PeydaWebFaNum-Medium.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Peyda";
  src: url("/static/fonts/PeydaWebFaNum-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Peyda";
  src: url("/static/fonts/PeydaWebFaNum-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --surface: #ffffff;
  --surface-card: #ffffff;
  --border: #d4d4d4;
  --muted: #f5f5f5;
  --text-primary: #171717;
  --text-secondary: #404040;
  --text-muted: #737373;
  --grid: #ececec;

  --series-1: #2463eb;
  --series-2: #21976b;
  --series-3: #a66c07;
  --series-4: #9d26d9;
  --series-5: #eb1414;
  --series-6: #096c9a;
  --series-7: #16a249;
  --series-other: var(--text-muted);

  --accent: #2463eb;
  --accent-hover: #1d4ed8;
  --accent-secondary: #9d26d9;
  --success: #16a249;
  --error: #eb1414;

  /* Unquoted on purpose: this value is also fed to Highcharts' chart.style.fontFamily,
     and the embedded quotes trip its config sanitizer (error #33). */
  --font-body: Peyda, Tahoma, Arial, system-ui, sans-serif;
  --font-heading: var(--font-body);
  --radius: 0.5rem;
  --radius-md: calc(var(--radius) - 2px);
  --radius-sm: calc(var(--radius) - 4px);
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --max-content-w: 1320px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  color-scheme: dark;
  --surface: #0a0a0a;
  --surface-card: #141414;
  --border: #262626;
  --muted: #262626;
  --text-primary: #fafafa;
  --text-secondary: #a3a3a3;
  --text-muted: #737373;
  --grid: #1f1f1f;

  --series-1: #447aee;
  --series-2: #239f71;
  --series-3: #c88208;
  --series-4: #b55ae2;
  --series-5: #ef4343;
  --series-6: #0b87c1;
  --series-7: #279b51;

  --accent: #447aee;
  --accent-hover: #5b8ef0;
  --accent-secondary: #b55ae2;
  --success: #279b51;
  --error: #ef4343;
}


* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  /* Page stays clipped; wide tables scroll inside .table-wrap instead. */
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  text-align: right;
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Login (standalone page) */
.login-page {
  /* Use dynamic viewport units when available (mobile address bar safe) */
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-box {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.login-box h1 {
  margin: 0 0 0.25rem;
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 600;
}

.login-box .subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-box label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.login-box input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  margin-bottom: 1rem;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1rem;
}

.login-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-box .error {
  color: var(--error);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.login-box button {
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}

.login-box button:hover {
  background: var(--accent-hover);
}

/* App — fixed max width for wide monitors */
#app {
  width: var(--max-content-w);
  max-width: calc(100% - 64px);
  margin: 0 auto;
  padding: var(--space-5) var(--space-5);
}
@media (max-width: 820px) {
  #app {
    max-width: calc(100% - 32px);
    padding: var(--space-4) var(--space-3);
    width: 100%;
  }
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.header h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.header .btn {
  font-family: var(--font-heading);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Visual left in RTL header (flex-end); keeps dark-mode control opposite the title. */
.header .theme-toggle {
  margin-inline-start: auto;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  flex-shrink: 0;
}

.theme-toggle .theme-icon {
  display: block;
  flex-shrink: 0;
}

.theme-toggle .theme-icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .theme-icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .theme-icon-sun {
  display: block;
}

.btn {
  padding: 0.55rem 1.1rem;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  /* Explicit: UA button styles do not inherit body font-family. */
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.btn:hover {
  background: var(--border);
}

/* KPIs */
.kpis-section {
  margin-bottom: 2rem;
}

.kpis-note {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0 0.25rem;
}

.kpis-note-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.info-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}

.info-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.25rem;
}

.kpis .card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18), 0 12px 30px rgba(0, 0, 0, 0.12);
}

.kpis .card:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.kpis .value {
  display: block;
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kpis #kpi-date-range {
  /* Date range is long; prevent overflow */
  font-size: 1.05rem;
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

.kpis .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Section headings */
.chart-wrap h2,
.topic-time-section h2,
.topic-time-card h3,
.table-section h2 {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Filter bar */
.filter-section {
  margin-bottom: 1.5rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-bar-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-inline-end: 0.25rem;
  align-self: center;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.filter-group label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.filter-bar input[type="date"],
.filter-bar input[type="month"],
.filter-bar input[type="text"],
.filter-bar select {
  padding: 0.4rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: var(--font-heading);
  font-weight: 600;
  min-width: 0;
}

.filter-bar input:focus,
.filter-bar select:focus {
  outline: none;
  border-color: var(--accent);
}

.native-date-hidden {
  /* Keep in DOM (for ISO value), hide from UI */
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.jalali-date-input {
  width: 140px;
  font-variant-numeric: tabular-nums;
}

.jalali-date-input[data-invalid="1"] {
  border-color: var(--error) !important;
  box-shadow: 0 0 0 2px rgba(248, 81, 73, 0.12);
}

.jalali-picker {
  position: absolute;
  z-index: 250;
  width: 320px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.jalali-picker.is-month .jalali-picker-grid {
  grid-template-columns: repeat(3, 1fr);
}

.jalali-picker.is-month .jalali-picker-day {
  padding: 10px 6px;
  font-size: 0.82rem;
}

.jalali-picker.is-month .jalali-picker-actions .jalali-picker-btn {
  min-width: 44px;
}

.jalali-picker[hidden] {
  display: none;
}

.jalali-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: nowrap;
}

.jalali-picker-mid {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  justify-content: center;
  flex-wrap: nowrap;
}

.jalali-picker-sr {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.jalali-picker-select,
.jalali-picker-year {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-family: var(--font-heading);
  font-weight: 800;
  line-height: 1.2;
}

.jalali-picker-select:focus,
.jalali-picker-year:focus {
  outline: none;
  border-color: var(--accent);
}

.jalali-picker-year {
  width: 90px;
  text-align: center;
  direction: ltr;
  unicode-bidi: plaintext;
}

.jalali-picker-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.jalali-picker-actions {
  display: inline-flex;
  gap: 6px;
}

.jalali-picker-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 6px 8px;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: 600;
  transition: background var(--transition), border-color var(--transition);
}

.jalali-picker-btn:hover {
  background: var(--border);
}

.jalali-picker-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.jalali-picker-dow {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 4px 0;
  font-weight: 700;
}

.jalali-picker-day {
  text-align: center;
  padding: 7px 0;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.jalali-picker-day:hover {
  border-color: rgba(88, 166, 255, 0.35);
  background: rgba(88, 166, 255, 0.10);
}

.jalali-picker-day.is-muted {
  color: rgba(139, 148, 158, 0.55);
  cursor: default;
}

.jalali-picker-day.is-selected {
  background: rgba(88, 166, 255, 0.18);
  border-color: rgba(88, 166, 255, 0.55);
}

.jalali-picker-day.is-today {
  border-color: rgba(63, 185, 80, 0.65);
}

.jalali-picker-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.jalali-picker-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.jalali-picker-clear {
  border-color: rgba(248, 81, 73, 0.55);
  color: var(--error);
  background: transparent;
}

.jalali-picker-clear:hover {
  background: rgba(248, 81, 73, 0.12);
  border-color: rgba(248, 81, 73, 0.75);
  color: #fff;
}

.filter-bar select {
  min-width: 120px;
  max-width: 180px;
  height: 2rem;
  cursor: pointer;
}

/* Multi-select checkbox dropdown (platforms) */
.multi-select {
  position: relative;
  min-width: 180px;
  max-width: 260px;
}

.multi-select > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.4rem 0.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: var(--font-heading);
  font-weight: 600;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  user-select: none;
}

.multi-select > summary::-webkit-details-marker {
  display: none;
}

.multi-select > summary::after {
  content: "▾";
  color: var(--text-muted);
  font-size: 0.85em;
}

.multi-select[open] > summary {
  border-color: rgba(88, 166, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.10);
}

.multi-select-box {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  width: 100%;
  max-height: 280px;
  overflow: auto;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  z-index: 250;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.multi-select-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.25rem 0.35rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.85rem;
  user-select: none;
}

.multi-select-item:hover {
  background: rgba(88, 166, 255, 0.08);
}

.multi-select-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.multi-select-item .muted {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.filter-bar .filter-clear {
  margin-inline-start: auto;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

/* Persian action buttons: match heading font/weight */
.filter-bar .filter-clear,
#empty-state-clear-btn,
.jalali-picker-clear,
.drawer-tab {
  font-family: var(--font-heading);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.btn-secondary {
  background: transparent;
  border-color: var(--text-muted);
  color: var(--text-muted);
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--text-primary);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0 0.25rem;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-primary);
}

.filter-chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  background: var(--border);
  border: none;
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}

.filter-chip button:hover {
  background: var(--error);
  color: #fff;
}

/* Charts */
.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
  min-height: 320px;
}
@media (max-width: 920px) {
  .charts { grid-template-columns: 1fr; }
}

.chart-span-2 {
  grid-column: 1 / -1;
}

.chart-wrap {
  position: relative;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-height: 300px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  transition: border-color var(--transition);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
}

.chart-wrap:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.chart-wrap h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
}

.chart-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.chart-head h2 {
  margin: 0;
}

.zoom-path {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: -0.5rem 0 0.75rem;
  padding: 0 0.25rem;
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.zoom-path .crumb {
  background: none;
  border: none;
  padding: 0.15rem 0.3rem;
  margin: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  border-radius: 4px;
}

.zoom-path .crumb:hover {
  background: var(--surface);
  text-decoration: underline;
}

.zoom-path .crumb.is-current {
  color: var(--text-primary);
  font-weight: 600;
  cursor: default;
  pointer-events: none;
}

.zoom-path .sep {
  color: var(--text-muted);
}

.topic-time-section {
  min-width: 0;
  width: 100%;
}

.topic-time-head {
  padding: 0 0.25rem;
}

.topic-time-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.topic-time-card {
  min-height: 360px;
}

.topic-time-card h3,
.chart-subhead h3 {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text-muted);
}

.chart-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.chart-subhead h3 {
  margin-bottom: 0;
}

.topic-race-toggle {
  flex: 0 0 auto;
  min-width: 4.5rem;
  padding-inline: 0.85rem;
}

.highcharts-container-wrap {
  direction: ltr;
}

.chart-message {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 260px;
  color: var(--text-muted);
  text-align: center;
}

.chart-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
  flex-wrap: wrap;
}

.chart-control {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.chart-control label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 650;
  /* Persian labels look cramped with extra tracking */
  letter-spacing: 0;
  font-family: var(--font-body);
}

.chart-control select {
  padding: 0.4rem 0.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-body);
  font-weight: 650;
  height: 2.25rem;
  cursor: pointer;
  max-width: 240px;
}

.chart-control select:focus {
  outline: none;
  border-color: var(--accent);
}

.chart-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  flex-wrap: wrap;
  margin-inline-start: auto;
}

.chart-export {
  position: relative;
  z-index: 20;
  flex: 0 0 auto;
}

.chart-export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-card);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.chart-export-button:hover,
.chart-export-button:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  outline: none;
}

.chart-export-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  inset-inline-end: 0;
  inset-inline-start: auto;
  min-width: 10.5rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-card);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.16);
}

.chart-export-menu[hidden] {
  display: none;
}

.chart-export-menu button {
  display: block;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 650;
  text-align: right;
  cursor: pointer;
}

.chart-export-menu button:hover,
.chart-export-menu button:focus-visible {
  background: var(--muted);
  outline: none;
}

.chart-container {
  width: 100% !important;
  max-width: 100%;
  height: 300px !important;
  min-height: 280px;
  display: block;
  position: relative;
  overflow: hidden;
}

.chart-span-2 > .chart-container,
.topic-time-card > .chart-container {
  height: 420px !important;
  min-height: 360px;
}

/* Table */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  /* Allow .table-wrap horizontal scrollbar to show (was clipping it). */
  overflow: visible;
}

.table-section h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
}

.table-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.table-controls #table-info {
  font-family: var(--font-heading);
  font-weight: 650;
  color: var(--text-muted);
}

.table-controls input {
  flex: 1;
  max-width: 320px;
  padding: 0.55rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-heading);
  font-weight: 650;
  transition: border-color var(--transition);
}

.table-controls input::placeholder {
  color: rgba(139, 148, 158, 0.8);
  font-weight: 600;
}

.table-controls input:focus {
  outline: none;
  border-color: var(--accent);
}

.table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 70vh;
  overflow-x: scroll;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#episodes-table {
  /* Explicit width forces overflow inside .table-wrap (not squeezed to 100%). */
  width: 1980px;
  max-width: none;
  border-collapse: collapse;
  font-size: 0.85rem;
  table-layout: fixed;
}

#episodes-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-card);
}

#episodes-table th,
#episodes-table td {
  padding: 0.6rem 0.85rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  /* Prevent RTL/LTR mixing from messing up glyph shaping/ordering. */
  unicode-bidi: plaintext;
}

code {
  direction: ltr;
  unicode-bidi: plaintext;
  font-variant-numeric: tabular-nums;
}

#episodes-table th {
  color: var(--text-muted);
  font-weight: 750;
  font-size: 0.78rem;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}

/* Column widths (table-layout: fixed) — sum ≈ min-width on #episodes-table */
#episodes-table th:nth-child(1) { width: 160px; } /* مکالمه */
#episodes-table th:nth-child(2) { width: 70px; }  /* اپیزود */
#episodes-table th:nth-child(3) { width: 90px; }  /* پلتفرم */
#episodes-table th:nth-child(4) { width: 90px; }  /* ماه */
#episodes-table th:nth-child(5) { width: 140px; } /* موضوع اصلی */
#episodes-table th:nth-child(6) { width: 160px; } /* موضوع ریز */
#episodes-table th:nth-child(7) { width: 80px; }  /* اطمینان */
#episodes-table th:nth-child(8) { width: 150px; } /* موضوعات کاری/غیرکاری */
#episodes-table th:nth-child(9) { width: 170px; } /* اطمینان موضوعات کاری/غیرکاری */
#episodes-table th:nth-child(10) { width: 120px; } /* نیت کاربر */
#episodes-table th:nth-child(11) { width: 140px; } /* اطمینان نیت کاربر */
#episodes-table th:nth-child(12) { width: 70px; }  /* پیام */
#episodes-table th:nth-child(13) { width: 150px; } /* شروع */
#episodes-table th:nth-child(14) { width: 280px; } /* خلاصه */

/* All headers/cells are centered; keep this file's rule for clarity. */

#episodes-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}

#episodes-table th[data-sort]:hover {
  color: var(--text-primary);
}

#episodes-table th.is-sorted {
  color: var(--text-primary);
}

#episodes-table th.sort-asc::after,
#episodes-table th.sort-desc::after {
  display: inline-block;
  margin-inline-start: 0.35rem;
  color: rgba(139, 148, 158, 0.9);
  font-size: 0.8em;
  transform: translateY(-0.5px);
}
#episodes-table th.sort-asc::after { content: "▲"; }
#episodes-table th.sort-desc::after { content: "▼"; }

#episodes-table tbody tr {
  transition: background var(--transition);
}

#episodes-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.12);
}

#episodes-table tbody tr.episode-row {
  cursor: pointer;
}
#episodes-table tbody tr:hover {
  background: rgba(88, 166, 255, 0.08);
}

/* Column sizing + truncation (widths come from th; clamp long text in-cell) */
#episodes-table td { overflow: hidden; }

.cell-episode { text-align: center; }
.cell-conf,
.cell-work-related-conf,
.cell-work-classification-conf,
.cell-count {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.cell-work-related,
.cell-work-classification {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-work-related-conf,
.cell-work-classification-conf {
  white-space: nowrap;
}
.cell-start { font-variant-numeric: tabular-nums; }

.cell-summary {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.55;
}

/* Rubika viewer: remove "خلاصه" from table + drawer */
html.viewer-rubika #episodes-table th[data-sort="objective_summary"],
html.viewer-rubika #episodes-table td.cell-summary {
  display: none;
}

html.viewer-rubika #episodes-table {
  width: 1700px;
}

.cell-main,
.cell-fine {
  white-space: nowrap;
  line-height: 1.55;
}

/* Clamp long text WITHOUT changing td display (keeps columns aligned) */
.cell-clamp-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

/* Force a single-line row (ellipsis). */
.cell-clamp-1 {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-platform,
.cell-month,
.cell-start {
  white-space: nowrap;
}

.cell-main,
.cell-fine,
.cell-summary {
  /* prevent very long tokens from blowing layout */
  word-break: break-word;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.pagination #page-info {
  font-family: var(--font-heading);
  font-weight: 650;
  color: var(--text-muted);
}

.pagination button {
  padding: 0.55rem 1.1rem;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  font-family: var(--font-heading);
  font-weight: 700;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination button:not(:disabled):hover {
  background: var(--border);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 2.5rem 2rem;
  margin-bottom: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

.empty-state p {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.empty-state .btn {
  margin-top: 0.25rem;
}

.reload-error {
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  color: var(--error);
  font-size: 0.9rem;
}

/* Messages drawer (right-side in RTL) */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  transition: opacity var(--transition);
}
.drawer-overlay[hidden] { display: none; }

.messages-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(980px, 96vw);
  max-width: 100%;
  height: 100vh;
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  z-index: 101;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  transition: transform var(--transition);
}
.messages-drawer[hidden] { display: none; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 0.75rem;
}
.drawer-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer-title-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-cid {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.drawer-cid code {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

/* Conversation id cell + copy button (table) */
.cid-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.cid-short {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.72rem;
  line-height: 1.4;
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: 700;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: rgba(88, 166, 255, 0.10);
  border-color: rgba(88, 166, 255, 0.55);
  color: var(--text-primary);
}

.icon-btn.is-copied {
  background: rgba(63, 185, 80, 0.12);
  border-color: rgba(63, 185, 80, 0.55);
  color: var(--success);
}
.drawer-close {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  line-height: 1;
}

.drawer-tabs {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-inline-start: auto;
}

.drawer-tab {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 999px;
  white-space: nowrap;
}

.drawer-tab[aria-selected="true"] {
  color: var(--text-primary);
  border-color: rgba(88, 166, 255, 0.6);
  background: rgba(88, 166, 255, 0.12);
}
.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.drawer-split {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 0.42fr) minmax(0, 0.58fr);
  gap: 0;
  overflow: hidden;
}

html.viewer-rubika .drawer-split {
  grid-template-columns: 1fr;
}

.drawer-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-panel-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--font-heading);
  letter-spacing: -0.01em;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-summary {
  border-inline-end: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.08);
}

html.viewer-rubika .drawer-summary {
  display: none;
}

.drawer-summary-meta {
  padding: 0.85rem 1rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.drawer-summary-meta .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.75rem;
  margin-inline-end: 6px;
  margin-bottom: 6px;
  white-space: nowrap;
}

.drawer-summary-text {
  padding: 0.85rem 1rem 1.2rem;
  overflow-y: auto;
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-bubble.is-in-episode {
  border: 1px solid rgba(88, 166, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.08);
}

.msg-bubble.is-outside-episode {
  opacity: 0.72;
}

@media (max-width: 900px) {
  .messages-drawer { width: 100vw; }
  .drawer-split { grid-template-columns: 1fr; }
  .drawer-summary { border-inline-end: 0; border-bottom: 1px solid var(--border); }
  .drawer-summary-text { max-height: 34vh; }
}
.msg-bubble {
  max-width: 90%;
  padding: 0.65rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}
.msg-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}
.msg-bubble.assistant, .msg-bubble.other {
  align-self: flex-start;
  background: var(--surface-card);
  border: 1px solid var(--border);
}
.msg-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.msg-bubble.user .msg-meta {
  /* Metadata inside user bubbles sits on accent-blue background. */
  color: rgba(255, 255, 255, 0.88);
}
.drawer-loading, .drawer-error {
  color: var(--text-muted);
  padding: 1rem;
  text-align: center;
}
.drawer-error { color: var(--error); }

/* Sampling-method dialog (opened from the ⓘ button above the KPI cards) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(680px, calc(100vw - 2rem));
  max-height: min(80vh, 46rem);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  z-index: 101;
}
.modal[hidden] { display: none; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.9;
}

.modal-body h3 {
  margin: 1.5rem 0 0.6rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-body h3:first-of-type { margin-top: 1.25rem; }

.modal-lead {
  margin: 0;
  padding: 0.75rem 0.9rem;
  background: var(--muted);
  border-radius: var(--radius-md);
  border-inline-start: 3px solid var(--accent);
  color: var(--text-primary);
}

.modal-list {
  margin: 0;
  padding-inline-start: 1.25rem;
}

.modal-list li { margin-bottom: 0.5rem; }
.modal-list li:last-child { margin-bottom: 0; }
.modal-list b { color: var(--text-primary); font-weight: 700; }

/* Segmented control (chart view / stack / share toggles) */
.seg {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--muted);
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.seg-btn:hover {
  color: var(--text-primary);
}

.seg-btn.is-active {
  background: var(--surface-card);
  color: var(--text-primary);
  box-shadow: 0 0 0 1px var(--border);
}

.chart-head h2 {
  color: var(--text-secondary);
}
