/* Mantis WebApp Stylesheet - Modern Telegram WebApp SaaS Theme */

:root {
  --bg-color: var(--tg-theme-bg-color, #0d1117);
  --secondary-bg-color: var(--tg-theme-secondary-bg-color, #161b22);
  --card-bg-color: var(--tg-theme-secondary-bg-color, #161b22);
  --card-border-color: rgba(255, 255, 255, 0.08);
  --text-color: var(--tg-theme-text-color, #f0f6fc);
  --text-muted: var(--tg-theme-hint-color, #8b949e);
  --link-color: var(--tg-theme-link-color, #58a6ff);
  --button-color: var(--tg-theme-button-color, #238636);
  --button-text-color: var(--tg-theme-button-text-color, #ffffff);

  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.5;
  font-size: 15px;
  min-height: 100vh;
  padding-bottom: calc(72px + var(--safe-bottom));
  overflow-x: hidden;
}

/* App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: rgba(13, 17, 23, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border-color);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(168, 85, 247, 0.25));
  border: 1px solid rgba(168, 85, 247, 0.4);
  border-radius: 9px;
  color: #c084fc;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-color);
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* Global Alert */
.global-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background-color: rgba(239, 68, 68, 0.15);
  border-bottom: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  font-size: 13px;
}

.alert-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 20px;
  cursor: pointer;
}

/* Main Content Area */
.app-content {
  padding: 16px;
  max-width: 680px;
  margin: 0 auto;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
  animation: fadeIn 0.2s ease-in-out;
}

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

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  gap: 12px;
}

.view-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.view-description {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

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

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

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

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-color);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.12);
}

.btn-danger-outline {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: var(--accent-danger);
  padding: 10px;
}

.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.1);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

textarea.form-input {
  min-height: 76px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.4;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-plan {
  background-color: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-success {
  background-color: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background-color: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background-color: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background-color: var(--card-bg-color);
  border: 1px solid var(--card-border-color);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  text-align: center;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-color);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.input-search {
  flex: 1;
  background-color: var(--card-bg-color);
  border: 1px solid var(--card-border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-color);
  font-size: 14px;
}

.input-search:focus, .form-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.select-filter {
  background-color: var(--card-bg-color);
  border: 1px solid var(--card-border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--text-color);
  font-size: 13px;
}

/* Cards & List */
.cards-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background-color: var(--card-bg-color);
  border: 1px solid var(--card-border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-size: 16px;
  font-weight: 600;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

/* Pair Card Specifics */
.pair-card {
  position: relative;
  transition: border-color 0.15s ease;
}

.pair-card:hover {
  border-color: rgba(255, 255, 255, 0.16);
}

.pair-flow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.channel-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #cbd5e1;
  max-width: 100%;
}

.channel-pill .pill-icon {
  font-size: 13px;
  opacity: 0.85;
  flex-shrink: 0;
}

.channel-pill .channel-info {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-pill .channel-name {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.2px;
}

.channel-pill .channel-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: var(--text-muted);
}

.flow-arrow {
  color: var(--accent-primary);
  font-weight: 700;
  flex-shrink: 0;
}

.pair-meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.meta-chip {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: var(--radius-full);
  background-color: rgba(255, 255, 255, 0.05);
  color: #94a3b8;
}

.meta-chip.active {
  background-color: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.pair-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--card-border-color);
  padding-top: 12px;
  margin-top: 4px;
}

/* Channels View */
.group-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.group-caption {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.cooldown-select {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--card-border-color);
  font-size: 13px;
}

/* Profile View */
.profile-card {
  margin-bottom: 16px;
}

.avatar-circle {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: rgba(59, 130, 246, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.profile-details-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
  border-top: 1px solid var(--card-border-color);
  padding-top: 12px;
}

.detail-item {
  display: flex;
  flex-direction: column;
}

.detail-label {
  font-size: 11px;
  color: var(--text-muted);
}

.detail-val {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-color);
}

.detail-val.copyable {
  cursor: pointer;
  text-decoration: underline dotted;
}

.text-accent {
  color: var(--accent-success);
}

/* Subscription & Limits */
.subscription-card {
  margin-bottom: 24px;
}

.sub-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.sub-caption {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.sub-plan-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-color);
}

.sub-expiry-box {
  margin-bottom: 16px;
}

.expiry-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}

.days-pill {
  font-weight: 700;
  color: var(--accent-primary);
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background-color: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-bg.small {
  height: 6px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.limits-box {
  border-top: 1px solid var(--card-border-color);
  padding-top: 14px;
}

.limits-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}

.limit-metric {
  margin-bottom: 10px;
}

.limit-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
  color: var(--text-muted);
}

/* Plans Catalog Grid */
.period-selector {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.btn-period {
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--card-border-color);
  background: var(--card-bg-color);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-period.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.plans-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.plan-item-card {
  background-color: var(--card-bg-color);
  border: 1px solid var(--card-border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plan-item-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.plan-item-name {
  font-size: 18px;
  font-weight: 700;
}

.plan-item-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-success);
}

.plan-features-list {
  list-style: none;
  font-size: 13px;
  color: var(--text-muted);
}

.plan-features-list li::before {
  content: "✓ ";
  color: var(--accent-success);
  font-weight: 700;
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background-color: rgba(22, 27, 34, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--card-border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 50;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 0;
  transition: all 0.15s ease;
}

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

.nav-icon {
  font-size: 20px;
  line-height: 1;
  margin-bottom: 2px;
}

.nav-label {
  font-size: 11px;
  font-weight: 600;
}

/* Modals & Bottom Sheets */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.15s ease-out;
}

.modal-backdrop.hidden {
  display: none !important;
}

.modal-sheet {
  background-color: var(--card-bg-color);
  border-top: 1px solid var(--card-border-color);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border-color);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--card-border-color);
  background-color: var(--bg-color);
}

.modal-footer .btn {
  flex: 1;
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-color);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.form-input {
  background-color: var(--bg-color);
  border: 1px solid var(--card-border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-color);
  font-size: 14px;
}

.cooldown-input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.cooldown-input-group .form-input {
  width: 100%;
  padding-right: 48px;
}

.input-suffix {
  position: absolute;
  right: 14px;
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

.switch-group {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.16);
  transition: 0.2s ease;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s ease;
}

input:checked + .slider {
  background-color: var(--accent-success);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.checkbox-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.checkbox-item input:disabled + span {
  opacity: 0.6;
}

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

.section-subtitle {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-color);
}

.pair-flow-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(255, 255, 255, 0.04);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 6px;
}

.flow-step {
  display: flex;
  flex-direction: column;
}

.flow-code {
  font-family: monospace;
  font-size: 13px;
  color: #60a5fa;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #1e293b;
  color: #f8fafc;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 200;
  pointer-events: none;
  animation: toastIn 0.2s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.skeleton-card {
  height: 90px;
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.03) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: var(--radius-lg);
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.hidden {
  display: none !important;
}
