﻿*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Cairo", "Segoe UI", "Tahoma", sans-serif;
  background-color: #f6f6f8;
  color: #1a1a1a;
  direction: rtl;
}

header {
  background: linear-gradient(135deg, #006bff, #00a3c4);
  color: #fff;
  padding: 2.5rem 1rem;
  text-align: right;
}

header h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.9rem, 2.6vw, 2.6rem);
}

.subtitle {
  margin: 0;
  font-size: clamp(0.95rem, 1.5vw, 1.1rem);
  opacity: 0.9;
}

.container {
  width: min(1180px, 92%);
  margin-inline: auto;
}

.summary {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  font-size: 1rem;
}

.summary div {
  background-color: rgba(255, 255, 255, 0.18);
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
}

main {
  margin-top: -1.8rem;
  margin-bottom: 3rem;
}

.card {
  background-color: #fff;
  border-radius: 16px;
  padding: clamp(1.2rem, 2.4vw, 1.8rem);
  margin-bottom: clamp(1.2rem, 2vw, 1.8rem);
  box-shadow: 0 15px 40px rgba(15, 55, 95, 0.1);
}

.card h2 {
  margin-top: 0;
  font-size: 1.4rem;
  color: #004f96;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.2rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field label {
  font-weight: 600;
  color: #333;
}

select,
input,
button {
  font-family: inherit;
}

select,
input[type="date"],
input[type="number"] {
  border: 1px solid #ccd7e6;
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  background-color: #fff;
}

select:focus,
input:focus {
  outline: none;
  border-color: #006bff;
  box-shadow: 0 0 0 2px rgba(0, 107, 255, 0.1);
}

.actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  justify-content: flex-start;
}

button {
  border: none;
  border-radius: 12px;
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

button.primary {
  background: linear-gradient(135deg, #006bff, #0057d8);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 91, 220, 0.22);
}

button.primary:hover {
  transform: translateY(-1px);
}

button.light {
  background-color: #f0f4fa;
  color: #1a1a1a;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.status {
  color: #555;
  font-size: 0.95rem;
}

.table-wrapper {
  overflow-x: auto;
  margin-top: 1.2rem;
  border-radius: 16px;
  border: 1px solid #e2e6f0;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 100%;
}

th,
td {
  padding: 0.9rem 0.8rem;
  text-align: right;
  border-bottom: 1px solid #eef1f6;
  font-size: 0.95rem;
}

thead th {
  background-color: #f7f9fc;
  font-weight: 700;
  color: #0f3569;
  position: sticky;
  top: 0;
}

tbody tr:nth-child(even) {
  background-color: #fbfcff;
}

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

.pagination button {
  background-color: #fff;
  border: 1px solid #ccd7e6;
  box-shadow: 0 5px 12px rgba(12, 42, 73, 0.08);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.price-cell {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.6rem;
}

.price-cell .price-value {
  font-weight: 700;
  color: #004f96;
  font-size: 1.05rem;
}

.row-toggle {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
  border: 1px solid #c8d6ea;
  background-color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #0c3a6b;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.row-toggle::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

.row-toggle[aria-expanded="true"]::before {
  transform: rotate(135deg);
}

@media (hover: hover) {
  .row-toggle:hover {
    background-color: #e9f2ff;
    color: #0b5fd8;
  }
}

.row-toggle:focus-visible {
  outline: 2px solid #5aa4ff;
  outline-offset: 2px;
}

.data-row.is-expanded {
  background-color: rgba(0, 107, 255, 0.06);
}

.mobile-detail-row td {
  padding: 0;
  border-bottom: none;
  background-color: transparent;
}

.detail-container {
  padding: 0.8rem 1rem 1rem;
  background-color: #f3f7ff;
  border: 1px solid #d8e3f7;
  border-radius: 14px;
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  direction: rtl;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: #1c3358;
}

.detail-label {
  font-weight: 600;
  color: #0f3569;
  white-space: nowrap;
}

.detail-value {
  font-weight: 500;
  text-align: right;
  direction: rtl;
  overflow-wrap: anywhere;
}

@media (min-width: 769px) {
  .row-toggle {
    display: none;
  }
  .mobile-detail-row {
    display: none !important;
  }
}

footer {
  background-color: #102238;
  color: #c8d4e5;
  padding: 1.4rem 1rem;
  text-align: center;
}

.spinner {
  position: fixed;
  inset: 0;
  backdrop-filter: blur(2px);
  background-color: rgba(16, 35, 56, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: #fff;
  z-index: 1000;
}

.spinner.hidden {
  display: none;
}

.loader {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}


.dashboard-card {
  display: grid;
  gap: 1.5rem;
}

.dashboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 1rem;
}

.dashboard-header h2 {
  margin-bottom: 0.3rem;
}

.dashboard-range {
  margin: 0;
  color: #5a6c85;
  font-size: 0.95rem;
}

.metrics-grid {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.8rem, 1.8vw, 1.4rem);
  justify-content: flex-start;
  align-items: stretch;
}

.metric-card {
  background: linear-gradient(135deg, #0d4d91, #0c2a49);
  color: #fff;
  padding: 1.2rem;
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(13, 77, 145, 0.22);
  display: grid;
  gap: 0.55rem;
  min-height: 150px;
  flex: 1 1 clamp(240px, 32%, 320px);
  min-width: 220px;
  max-width: 320px;
}

.category-card {
  background-color: #fff;
  color: #103b74;
  padding: 1.2rem;
  border-radius: 16px;
  border: 1px solid #e2eaf5;
  box-shadow: 0 12px 26px rgba(16, 59, 116, 0.12);
  display: grid;
  gap: 0.65rem;
  min-height: 150px;
  flex: 1 1 clamp(240px, 32%, 320px);
  min-width: 220px;
  max-width: 320px;
}

.category-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0c2a49;
}

.category-row {
  display: flex;
  justify-content: flex-start;
  align-items: baseline;
  gap: 0.5rem;
}

.category-row-label {
  font-size: 0.96rem;
  color: #325178;
}

.category-row-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: #0b5fd8;
}

.category-footnote {
  font-size: 0.9rem;
  color: #4a6287;
  font-weight: 600;
}


.focus-card {
  background: linear-gradient(135deg, #f6f9ff, #eef3ff);
  color: #0b3565;
  padding: 1.2rem;
  border-radius: 16px;
  border: 1px solid #d6e2fb;
  box-shadow: 0 12px 30px rgba(13, 77, 145, 0.15);
  display: grid;
  gap: 0.65rem;
  min-height: 150px;
  flex: 1 1 clamp(240px, 32%, 320px);
  min-width: 220px;
  max-width: 320px;
}
@media (max-width: 1200px) {
  .metrics-grid {
    justify-content: center;
  }
}

.focus-name {
  font-size: 1.18rem;
  font-weight: 700;
  color: #0a2c57;
  margin: 0;
}

.focus-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.focus-row-label {
  font-size: 0.86rem;
  color: #325178;
  white-space: nowrap;
}

.focus-row-value {
  font-size: 1rem;
  font-weight: 700;
  color: #0b5fd8;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.focus-footnote {
  font-size: 0.85rem;
  color: #4a6287;
  font-weight: 600;
}

.metric-label {
  font-size: 0.95rem;
  opacity: 0.85;
  white-space: normal;
}

.metric-value {
  font-size: 1.55rem;
  font-weight: 700;
  white-space: normal;
}

.metric-hint {
  font-size: 0.85rem;
  opacity: 0.75;
  white-space: normal;
}

.empty-state {
  background-color: #f0f4fa;
  border-radius: 16px;
  padding: 1.2rem;
  text-align: center;
  color: #60708a;
  font-size: 0.95rem;
}

.dashboard-note {
  font-size: 0.9rem;
  color: #5c6c82;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.2rem;
}

.dashboard-card.is-hidden {
  display: none !important;
}

.chart-card {
  background-color: #f9fbff;
  border-radius: 16px;
  padding: 1.2rem;
  box-shadow: inset 0 0 0 1px #e3ebf5;
  display: grid;
  gap: 0.8rem;
}

.chart-card-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: #103b74;
}

.chart-wrapper {
  position: relative;
  height: 220px;
}

.focus-trend-card {
  margin-top: 1.4rem;
}

.focus-trend-wrapper {
  height: 280px;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

.entity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.entity-list li {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 18px rgba(15, 42, 78, 0.08);
}

.entity-list.is-scrollable {
  max-height: 320px;
  overflow-y: auto;
}

.entity-list .empty {
  justify-content: center;
  color: #60708a;
  box-shadow: none;
  background-color: transparent;
  padding: 0;
}

.entity-name {
  font-weight: 600;
  color: #103b74;
}

.entity-stats {
  color: #4a5d76;
  font-size: 0.9rem;
}

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }

  .chart-wrapper {
    height: 220px;
  }

  .focus-trend-wrapper {
    height: 240px;
  }
}

@media (max-width: 768px) {
  header {
    text-align: center;
    padding: 2.2rem 1.4rem;
  }

  .container {
    width: min(720px, 94%);
  }

  .summary {
    justify-content: center;
  }

  .card {
    padding: clamp(1rem, 3.2vw, 1.4rem);
  }

  .metrics-grid {
    justify-content: center;
  }

  .metric-card,
  .category-card,
  .focus-card {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
  }

  .actions {
    justify-content: center;
  }

  table {
    table-layout: fixed;
    border-spacing: 0;
  }

  th,
  td {
    padding: 0.6rem 0.55rem;
    font-size: 0.88rem;
  }

  thead th {
    font-size: 0.92rem;
  }

  .optional-mobile {
    display: none !important;
  }

  .price-cell {
    justify-content: space-between;
  }

  .price-cell .price-value {
    font-size: 1.1rem;
  }

  tbody tr.data-row {
    border-bottom: 1px solid #dbe5f5;
    cursor: pointer;
    transition: background-color 0.15s ease;
  }

  tbody tr.data-row:active {
    background-color: rgba(0, 107, 255, 0.08);
  }

  .detail-container {
    padding: 0.9rem 1rem;
    gap: 0.5rem;
    margin-top: -0.2rem;
  }

  .detail-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .detail-label {
    white-space: normal;
  }
}

@media (max-width: 600px) {
  .container {
    width: min(520px, 94%);
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .summary div {
    width: 100%;
    text-align: center;
  }

  .table-header {
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
  }

  th,
  td {
    font-size: 0.82rem;
    padding: 0.5rem 0.55rem;
  }

  .optional-tablet {
    display: none !important;
  }
}

@media (max-width: 420px) {
  header {
    padding: 2rem 1rem;
  }

  .card {
    padding: 1rem;
  }

  .row-toggle {
    width: 2rem;
    height: 2rem;
  }

  .price-cell .price-value {
    font-size: 1rem;
  }
}

/* === AI Chat Widget Styles === */

.chat-toggle {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #006bff, #0057d8);
  color: #fff;
  border: none;
  box-shadow: 0 8px 24px rgba(0, 91, 220, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 1100;
}

.chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 32px rgba(0, 91, 220, 0.45);
}

.chat-toggle svg {
  width: 28px;
  height: 28px;
}

.chat-panel {
  position: fixed;
  bottom: 100px;
  left: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  max-height: 500px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(15, 42, 78, 0.25);
  display: flex;
  flex-direction: column;
  z-index: 1100;
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-panel.hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
}

.chat-header {
  background: linear-gradient(135deg, #006bff, #0057d8);
  color: #fff;
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.chat-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.15s ease;
}

.chat-close:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  background-color: #f7f9fc;
  min-height: 280px;
  max-height: 320px;
}

.chat-message {
  max-width: 85%;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.user {
  align-self: flex-start;
}

.chat-message.ai {
  align-self: flex-end;
}

.chat-message .message-content {
  padding: 0.8rem 1rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  direction: rtl;
  text-align: right;
}

.chat-message.user .message-content {
  background: linear-gradient(135deg, #006bff, #0057d8);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-message.ai .message-content {
  background-color: #fff;
  color: #1a1a1a;
  border: 1px solid #e2e6f0;
  border-bottom-left-radius: 4px;
}

.chat-message.error .message-content {
  background-color: #fff0f0;
  color: #c41e3a;
  border: 1px solid #ffcdd2;
}

.chat-input-form {
  display: flex;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  background-color: #fff;
  border-top: 1px solid #e2e6f0;
}

.chat-input-form input {
  flex: 1;
  border: 1px solid #ccd7e6;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  direction: rtl;
  text-align: right;
}

.chat-input-form input:focus {
  outline: none;
  border-color: #006bff;
  box-shadow: 0 0 0 2px rgba(0, 107, 255, 0.1);
}

.chat-input-form button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #006bff, #0057d8);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}

.chat-input-form button:hover {
  transform: scale(1.05);
}

.chat-input-form button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.chat-typing {
  display: flex;
  gap: 4px;
  padding: 0.8rem 1rem;
}

.chat-typing span {
  width: 8px;
  height: 8px;
  background-color: #006bff;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.chat-typing span:nth-child(1) { animation-delay: -0.32s; }
.chat-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

@media (max-width: 480px) {
  .chat-toggle {
    bottom: 16px;
    left: 16px;
    width: 54px;
    height: 54px;
  }
  
  .chat-panel {
    bottom: 86px;
    left: 12px;
    width: calc(100vw - 24px);
    max-height: 60vh;
  }
  
  .chat-messages {
    min-height: 200px;
    max-height: 40vh;
  }
}
