:root {
  --bg: var(--tg-theme-bg-color, #f4f6fb);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-elevated: #ffffff;
  --text: var(--tg-theme-text-color, #0f172a);
  --hint: var(--tg-theme-hint-color, #64748b);
  --accent: var(--tg-theme-button-color, #2563eb);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2563eb);
  --border: rgba(148, 163, 184, 0.24);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --info: #3b82f6;
  --info-soft: rgba(59, 130, 246, 0.14);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #0f172a);
    --surface: var(--tg-theme-secondary-bg-color, #1e293b);
    --surface-elevated: #1e293b;
    --text: var(--tg-theme-text-color, #f8fafc);
    --hint: var(--tg-theme-hint-color, #94a3b8);
    --border: rgba(148, 163, 184, 0.18);
    --shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', Tahoma, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.65;
  direction: rtl;
  overflow-x: hidden;
}

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

a {
  color: var(--link);
  text-decoration: none;
}

.app-shell {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  backdrop-filter: blur(12px);
}

.topbar-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar-title h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sub {
  font-size: 11px;
  color: var(--hint);
}

.container {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.hero-card {
  background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 55%, #0ea5e9 100%);
  color: #ffffff;
  border: none;
  border-radius: 18px;
  padding: 18px 16px;
  box-shadow: 0 10px 26px rgba(37, 99, 235, 0.25);
}

.hero-card .muted-on-hero {
  color: rgba(255, 255, 255, 0.86);
  font-size: 12.5px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tile-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.15s ease;
  box-shadow: var(--shadow);
}

.tile-btn:active {
  transform: scale(0.97);
}

.tile-icon {
  font-size: 24px;
  line-height: 1;
}

.tile-title {
  font-weight: 700;
  font-size: 13px;
}

.tile-desc {
  font-size: 11px;
  color: var(--hint);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

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

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-sm {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: #059669; }
.badge-warning { background: var(--warning-soft); color: #d97706; }
.badge-danger { background: var(--danger-soft); color: #dc2626; }
.badge-info { background: var(--info-soft); color: #2563eb; }
.badge-neutral { background: rgba(148, 163, 184, 0.18); color: var(--hint); }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--hint);
}

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
}

.textarea {
  min-height: 82px;
  resize: vertical;
}

.pills-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.pills-row::-webkit-scrollbar {
  display: none;
}

.pill {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.pill.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.sticky-summary {
  position: sticky;
  top: 61px;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.course-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-right: 4px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.course-card.st-passed { border-right-color: var(--success); }
.course-card.st-current { border-right-color: var(--info); }
.course-card.st-next { border-right-color: var(--warning); }
.course-card.st-locked { opacity: 0.85; }

.seg-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.seg-btn {
  min-height: 34px;
  padding: 4px 6px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.seg-btn.active-passed {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.seg-btn.active-current {
  background: var(--info);
  color: #fff;
  border-color: var(--info);
}

.seg-btn.active-next {
  background: var(--warning);
  color: #111827;
  border-color: var(--warning);
}

.seg-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.22);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #10b981, #3b82f6);
  transition: width 0.25s ease;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  max-width: 680px;
  margin: 0 auto;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 10.5px;
  font-weight: 700;
  padding: 4px 2px;
  cursor: pointer;
  position: relative;
}

.nav-item.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 19px;
  line-height: 1.1;
}

.nav-dot {
  position: absolute;
  top: 2px;
  right: 26%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3);
  max-width: 90vw;
  text-align: center;
}

.toast.error {
  background: #dc2626;
}

.toast.success {
  background: #059669;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.muted {
  color: var(--hint);
  font-size: 12px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.qr-box {
  background: #ffffff;
  padding: 14px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  width: fit-content;
}

.checkbox-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
  cursor: pointer;
}

.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th, .data-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  text-align: right;
}

.data-table th {
  color: var(--hint);
  font-weight: 700;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.brand-logos {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.logo-uni-pill {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0f2744, #1d4ed8);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.logo-uni-pill img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-assoc-pill {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #ffffff;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  overflow: hidden;
}

.logo-assoc-pill img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
}

.hero-logos {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.hero-logo-uni {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  padding: 5px;
  object-fit: contain;
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.hero-logo-assoc {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: #ffffff;
  padding: 3px;
  object-fit: contain;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}
