/* =========================
   Base / Reset
========================= */

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* =========================
   Themes
========================= */

body.theme-dark {
  background: #050711;
  color: #f4f4f6;
}

body.theme-light {
  background: #f4f6fb;
  color: #111320;
}

body.theme-dark a {
  color: #74c0ff;
}
body.theme-light a {
  color: #1c7ed6;
}

/* Card / panel base colors per theme */

body.theme-dark .card {
  background: radial-gradient(circle at top left, #171a2b, #070918);
  color: #f5f5f7;
}

body.theme-light .card {
  background: #ffffff;
  color: #111320;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

/* =========================
   Layout
========================= */

#app-root {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.view {
  width: 100%;
}

#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.login-card {
  max-width: 380px;
  width: 100%;
  padding: 24px 20px;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

/* Main app */

#app-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
}

body.theme-light .topbar {
  border-bottom-color: rgba(15, 23, 42, 0.08);
}

.topbar-left h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.03em;
}

.topbar-subtitle {
  font-size: 12px;
  opacity: 0.75;
  margin-top: 4px;
}

.topbar-right {
  display: flex;
  gap: 8px;
}

/* Navbar */

.navbar {
  display: flex;
  gap: 8px;
  padding: 8px 20px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

body.theme-light .navbar {
  border-bottom-color: rgba(15, 23, 42, 0.08);
  background: #f8fafc;
}

/* Buttons */

button {
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}

button:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Nav buttons */

.nav-btn {
  background: transparent;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  border: 1px solid transparent;
  color: inherit;
  box-shadow: none;
}

body.theme-dark .nav-btn {
  color: #e5e7eb;
}

body.theme-light .nav-btn {
  color: #1f2933;
}

.nav-btn:hover {
  background: rgba(148, 163, 184, 0.14);
}

.nav-btn-active {
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #ffffff !important;
  border-color: rgba(191, 219, 254, 0.6);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.5);
}

/* =========================
   Main Content
========================= */

.main-content {
  flex: 1;
  padding: 16px 16px 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.inner-view {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

#dashboard-subtitle {
  margin: 0;
  font-size: 12px;
  opacity: 0.75;
}

/* =========================
   Cards & Forms
========================= */

.card {
  border-radius: 16px;
  padding: 16px 14px;
  margin-bottom: 16px;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.card h3 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 15px;
}

.form-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  gap: 4px;
}

.form-row label {
  font-size: 13px;
}

.form-row input,
.form-row select {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 6px 10px;
  font-size: 13px;
  background: rgba(15, 23, 42, 0.7);
  color: #e5e7eb;
}

body.theme-light .form-row input,
body.theme-light .form-row select {
  background: #f9fafb;
  color: #111827;
  border-color: rgba(148, 163, 184, 0.8);
}

.form-row input:focus,
.form-row select:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.form-actions {
  margin-top: 8px;
}

/* Text helpers */

.error-text {
  color: #f97373;
  font-size: 12px;
  margin-top: 8px;
}

.info-text {
  color: #22c55e;
  font-size: 12px;
  margin-top: 8px;
}

.small-text {
  font-size: 12px;
  opacity: 0.8;
}

.system-info-pre {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.85);
  color: #e5e7eb;
  font-size: 12px;
  overflow-x: auto;
}

body.theme-light .system-info-pre {
  background: #111827;
  color: #e5e7eb;
}

/* =========================
   Tables
========================= */

.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.data-table thead {
  background: linear-gradient(135deg, #111827, #020617);
}

body.theme-light .data-table thead {
  background: #e5e7eb;
}

.data-table th,
.data-table td {
  padding: 6px 8px;
  font-size: 12px;
  text-align: center;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  white-space: nowrap;
}

.data-table th {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #e5e7eb;
}

body.theme-light .data-table th {
  color: #111827;
}

.data-table tbody tr:nth-child(even) {
  background: rgba(15, 23, 42, 0.4);
}

body.theme-light .data-table tbody tr:nth-child(even) {
  background: #f9fafb;
}

.data-table tbody tr:nth-child(odd) {
  background: rgba(15, 23, 42, 0.7);
}

body.theme-light .data-table tbody tr:nth-child(odd) {
  background: #ffffff;
}

.data-table tbody tr:hover {
  background: rgba(37, 99, 235, 0.15);
}

/* Small table variant */

.small-table {
  min-width: 700px;
}

/* Empty row */

.empty-row {
  text-align: center;
  opacity: 0.7;
}

/* Dashboard specific */

.table-name-cell {
  text-align: left;
  font-weight: 500;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clickable {
  cursor: pointer;
}

.clickable:hover {
  text-decoration: underline;
}

/* Metric cells */

.metric-cell {
  font-variant-numeric: tabular-nums;
}

/* High / low percent coloring (base) */

.metric-high-1 {
  background: rgba(34, 197, 94, 0.12);
  color: #bbf7d0;
}

.metric-high-2 {
  background: rgba(22, 163, 74, 0.28);
  color: #bbf7d0;
}

.metric-low-1 {
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

.metric-low-2 {
  background: rgba(220, 38, 38, 0.28);
  color: #fee2e2;
}

body.theme-light .metric-high-1 {
  background: rgba(22, 163, 74, 0.16);
  color: #065f46;
}
body.theme-light .metric-high-2 {
  background: rgba(22, 163, 74, 0.24);
  color: #065f46;
}

body.theme-light .metric-low-1 {
  background: rgba(239, 68, 68, 0.16);
  color: #7f1d1d;
}
body.theme-light .metric-low-2 {
  background: rgba(220, 38, 38, 0.24);
  color: #7f1d1d;
}

/* =========================
   Rules section (local)
========================= */

.rules-form {
  margin: 12px 0;
}

.rules-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

.rules-form-row label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
}

.rules-form-row input,
.rules-form-row select {
  padding: 4px 6px;
  font-size: 13px;
}

.rules-form-row button {
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 13px;
}

.rules-table th,
.rules-table td {
  border: 1px solid rgba(148, 163, 184, 0.35);
  padding: 4px 6px;
  text-align: left;
}

.rules-table th {
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
}

body.theme-light .rules-table th {
  background: #e5e7eb;
  color: #111827;
}

/* Highlight by rules (applied on metric-cell) */

.chip-rule-warn {
  box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.9);
}

.chip-rule-danger {
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.9);
}

.chip-rule-success {
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.9);
}

.chip-rule-info {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.9);
}

/* =========================
   Login specific
========================= */

.login-card h1 {
  margin-top: 0;
  margin-bottom: 16px;
  font-size: 20px;
  text-align: center;
}

.login-card .form-row {
  margin-bottom: 12px;
}

/* =========================
   Responsive
========================= */

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .topbar-right {
    align-self: stretch;
    justify-content: flex-end;
  }

  .navbar {
    flex-wrap: wrap;
  }

  .main-content {
    padding: 12px 10px 18px;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  #back-to-dashboard-btn {
    align-self: flex-end;
  }
}

@media (max-width: 600px) {
  .login-card {
    padding: 20px 16px;
  }

  .data-table {
    min-width: 700px;
  }

  .small-table {
    min-width: 600px;
  }
}

/* ----- Row hover ONLY for non-colored cells ----- */

/* ترنزیشن برای همه سلول‌ها */
.data-table tbody tr td {
  transition: background-color 0.15s ease;
}

/* هاور فقط برای سلول‌هایی که کلاس رنگی ندارند */
body.theme-dark .data-table tbody tr:hover td:not(.metric-high-1):not(.metric-high-2):not(.metric-low-1):not(.metric-low-2):not(.chip-rule-danger):not(.chip-rule-success):not(.chip-rule-info):not(.chip-rule-warn) {
  background-color: rgba(255, 255, 255, 0.08) !important;
  cursor: pointer;
}

body.theme-light .data-table tbody tr:hover td:not(.metric-high-1):not(.metric-high-2):not(.metric-low-1):not(.metric-low-2):not(.chip-rule-danger):not(.chip-rule-success):not(.chip-rule-info):not(.chip-rule-warn) {
  background-color: rgba(0, 0, 0, 0.06) !important;
  cursor: pointer;
}

/* --------------------------------------------- */
/*   STRONG COLUMN SEPARATORS IN DASHBOARD       */
/*   TABLE, TOTAL, LAST, RED, BLACK, ZERO, ...   */
/* --------------------------------------------- */

#dashboard-table th,
#dashboard-table td {
  border-color: rgba(255,255,255,0.35);
}

/* LIGHT THEME OVERRIDE */
body.theme-light #dashboard-table th,
body.theme-light #dashboard-table td {
  border-color: rgba(0,0,0,0.35);
}

/* 1) Between TOTAL (2) and LAST (3) */
#dashboard-table th:nth-child(2),
#dashboard-table td:nth-child(2) {
  border-right: 2px solid rgba(255,255,255,0.35);
}
body.theme-light #dashboard-table th:nth-child(2),
body.theme-light #dashboard-table td:nth-child(2) {
  border-right: 2px solid rgba(0,0,0,0.35);
}

/* 2) After LAST (3) → before RED */
#dashboard-table th:nth-child(3),
#dashboard-table td:nth-child(3) {
  border-right: 2px solid rgba(255,255,255,0.35);
}
body.theme-light #dashboard-table th:nth-child(3),
body.theme-light #dashboard-table td:nth-child(3) {
  border-right: 2px solid rgba(0,0,0,0.35);
}

/* 3) After BLACK (5) */
#dashboard-table th:nth-child(5),
#dashboard-table td:nth-child(5) {
  border-right: 2px solid rgba(255,255,255,0.35);
}
body.theme-light #dashboard-table th:nth-child(5),
body.theme-light #dashboard-table td:nth-child(5) {
  border-right: 2px solid rgba(0,0,0,0.35);
}

/* 4) After ZERO (6) */
#dashboard-table th:nth-child(6),
#dashboard-table td:nth-child(6) {
  border-right: 2px solid rgba(255,255,255,0.35);
}
body.theme-light #dashboard-table th:nth-child(6),
body.theme-light #dashboard-table td:nth-child(6) {
  border-right: 2px solid rgba(0,0,0,0.35);
}

/* 5) After ODD (8) */
#dashboard-table th:nth-child(8),
#dashboard-table td:nth-child(8) {
  border-right: 2px solid rgba(255,255,255,0.35);
}
body.theme-light #dashboard-table th:nth-child(8),
body.theme-light #dashboard-table td:nth-child(8) {
  border-right: 2px solid rgba(0,0,0,0.35);
}

/* 6) After 19–36 (10) */
#dashboard-table th:nth-child(10),
#dashboard-table td:nth-child(10) {
  border-right: 2px solid rgba(255,255,255,0.35);
}
body.theme-light #dashboard-table th:nth-child(10),
body.theme-light #dashboard-table td:nth-child(10) {
  border-right: 2px solid rgba(0,0,0,0.35);
}

/* 7) After D3 (13) */
#dashboard-table th:nth-child(13),
#dashboard-table td:nth-child(13) {
  border-right: 2px solid rgba(255,255,255,0.35);
}
body.theme-light #dashboard-table th:nth-child(13),
body.theme-light #dashboard-table td:nth-child(13) {
  border-right: 2px solid rgba(0,0,0,0.35);
}
