@font-face {
  font-family: 'Vazirmatn';
  src: url('/assets/Vazirmatn.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --primary-border: #bfdbfe;
  
  --teal: #0d9488;
  --teal-subtle: #f0fdfa;
  
  --success: #16a34a;
  --success-subtle: #f0fdf4;
  --warning: #d97706;
  --warning-subtle: #fffbeb;
  --danger: #dc2626;
  --danger-subtle: #fef2f2;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

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

html {
  font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover {
  color: var(--primary-hover);
}

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

.skip {
  position: absolute;
  top: -100px;
  right: 16px;
  background: var(--primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  z-index: 9999;
  transition: top 0.2s ease;
}
.skip:focus {
  top: 16px;
}

/* ================= PORTAL STYLES ================= */
body.portal {
  background: radial-gradient(circle at top, #ffffff 0%, #f8fafc 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.portal-header {
  padding: 24px 36px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.15rem;
}
.brand small {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.25rem;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.portal-main {
  max-width: 980px;
  margin: 0 auto;
  padding: 60px 24px;
  text-align: center;
}

.portal-main h1 {
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1.25;
  margin: 16px 0 20px;
  color: var(--text-primary);
}
.portal-main h1 span {
  color: var(--primary);
}

.portal-intro {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 640px;
  margin: 0 auto 48px;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 28px;
  text-align: right;
  margin-bottom: 40px;
}

.portal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  color: inherit;
  position: relative;
  overflow: hidden;
}
.portal-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-border);
}
.portal-card.featured {
  border: 2px solid var(--primary);
  background: linear-gradient(to bottom, #ffffff 0%, #f8faff 100%);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.portal-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--primary-subtle);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}
.portal-icon.teal {
  background: var(--teal-subtle);
  color: var(--teal);
}

.portal-card h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.portal-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 24px;
  flex-grow: 1;
}

.card-link {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  font-weight: 600;
  font-size: 1rem;
}
.portal-card small {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 6px;
}

.portal-note {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.portal-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-light);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ================= DASHBOARD APP SHELL ================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.workspace {
  background: var(--bg-subtle);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.workspace small {
  display: block;
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

#navigation {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-grow: 1;
}

#navigation button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-weight: 500;
  cursor: pointer;
  text-align: right;
  transition: all 0.15s ease;
  width: 100%;
}
#navigation button span {
  font-size: 1.1rem;
  opacity: 0.7;
}
#navigation button:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}
#navigation button.active {
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 600;
}
#navigation button.active span {
  opacity: 1;
}

.baseline-side {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 16px;
  font-size: 0.8rem;
}
.baseline-side strong {
  display: block;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.baseline-side bdi {
  color: var(--primary);
  direction: ltr;
  display: block;
  margin: 2px 0 6px;
}
.baseline-side p {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.back-link {
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  display: inline-block;
}
.back-link:hover {
  color: var(--primary);
  background: var(--bg-subtle);
}

.main-shell {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.snapshot {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.snapshot small {
  color: var(--text-muted);
  margin-right: 4px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
}

main#main {
  padding: 32px;
  flex-grow: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 16px;
}

.page-heading h1 {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.page-heading p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  font-weight: 700;
  display: block;
}

.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--primary-subtle);
  color: var(--primary);
}
.pill.neutral {
  background: var(--bg-hover);
  color: var(--text-secondary);
}
.pill.success {
  background: var(--success-subtle);
  color: var(--success);
}
.pill.warning {
  background: var(--warning-subtle);
  color: var(--warning);
}
.pill.danger {
  background: var(--danger-subtle);
  color: var(--danger);
}

.button {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.button.primary {
  background: var(--primary);
  color: #fff;
}
.button.primary:hover {
  background: var(--primary-hover);
}
.button.secondary {
  background: var(--bg-surface);
  border-color: var(--border);
  color: var(--text-secondary);
}
.button.secondary:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

/* ================= METRIC CARDS & BANDS ================= */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.kpi-card .kpi-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}
.kpi-card .kpi-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: 8px;
}
.kpi-card .kpi-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 28px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.panel-head h2, .panel-head h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}
.panel-head p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
  gap: 24px;
  margin-bottom: 28px;
}

/* ================= TABLES ================= */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.9rem;
}

thead th {
  background: var(--bg-subtle);
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}
tbody tr:hover {
  background: #f8fafc;
}

tbody td {
  padding: 12px 16px;
  color: var(--text-secondary);
}

.table-filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  flex-grow: 1;
  min-width: 240px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
}
.search-input:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.pagination .buttons {
  display: flex;
  gap: 8px;
}

/* ================= NOTICE / WARNING BANNER ================= */
.alert-banner {
  background: var(--warning-subtle);
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 24px;
  color: #92400e;
  font-size: 0.88rem;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.alert-banner.info {
  background: var(--primary-subtle);
  border-color: var(--primary-border);
  color: #1e40af;
}

/* ================= MODAL DIALOG ================= */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 0;
  max-width: 720px;
  width: 90%;
  margin: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
  background: var(--bg-surface);
  color: var(--text-primary);
}
dialog::backdrop {
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
}

.dialog-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dialog-head h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

#dialog-body {
  padding: 24px;
  max-height: 75vh;
  overflow-y: auto;
}

.detail-row {
  display: flex;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg-subtle);
}
.detail-row:last-child {
  border-bottom: none;
}
.detail-key {
  width: 180px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  flex-shrink: 0;
}
.detail-val {
  flex-grow: 1;
  color: var(--text-primary);
  font-size: 0.9rem;
  word-break: break-word;
}

.loading {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
  display: block;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.dashboard-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-light);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-left: none;
    border-bottom: 1px solid var(--border);
  }
  #navigation {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 8px;
  }
  #navigation button {
    white-space: nowrap;
  }
  main#main {
    padding: 20px 16px;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
}
