/* === Brand palette (from logo: neon blue-purple on dark) === */
:root {
  --brand-primary: #6366f1;
  --brand-accent: #818cf8;
  --brand-glow: #4f46e5;
  --brand-purple: #7c3aed;
  --brand-blue: #3b82f6;
  --brand-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #3b82f6 100%);
  --brand-gradient-soft: linear-gradient(135deg, rgba(79,70,229,.15) 0%, rgba(124,58,237,.15) 100%);
  --brand-surface: rgba(99,102,241,.08);
  --brand-on: rgba(99,102,241,.2);
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--tg-theme-bg-color, #0f0f1a);
  color: var(--tg-theme-text-color, #e8e8f0);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0);
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  max-width: 100vw;
}

/* === Loader === */
.loader-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(99,102,241,.3);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Typography === */
.page-title {
  font-size: 22px; font-weight: 700;
  padding: 16px 16px 8px;
}
.section-title {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase;
  color: var(--tg-theme-hint-color, #8888aa);
  padding: 20px 16px 8px;
  letter-spacing: 0.5px;
}
.hint-text {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #8888aa);
  padding: 4px 16px 12px;
}

/* === Logo header === */
.logo-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 8px;
}
.logo-header img {
  width: 80px; height: 80px;
  border-radius: 20px;
  margin-bottom: 10px;
}
.logo-header .app-name {
  font-size: 24px;
  font-weight: 800;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-header .app-subtitle {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #8888aa);
  margin-top: 2px;
}

/* === Cards === */
.card {
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: 12px;
  margin: 8px 16px;
  overflow: hidden;
}
.card-body { padding: 14px 16px; }

/* === List cells (iOS settings style) === */
.cell-group {
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: 12px;
  margin: 8px 16px;
  overflow: hidden;
}
.cell {
  display: flex; align-items: center;
  padding: 12px 16px;
  min-height: 44px;
  gap: 12px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.cell:active { background: rgba(99,102,241,.1); }
.cell + .cell {
  border-top: 0.5px solid rgba(99,102,241,.15);
  margin-left: 16px;
  padding-left: 0;
}
.cell-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.cell-content { flex: 1; min-width: 0; }
.cell-title {
  font-size: 16px; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cell-subtitle {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #8888aa);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Компании — полное название, контейнер растёт */
.company-result .cell-content,
.ob-company-result .cell-content { min-width: auto; }
.company-result .cell-title,
.company-result .cell-subtitle,
.ob-company-result .cell-title {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.cell-value {
  font-size: 15px;
  color: var(--tg-theme-hint-color, #8888aa);
  flex-shrink: 0;
}
.cell-chevron::after {
  content: '›'; font-size: 20px; font-weight: 300;
  color: var(--brand-accent);
  margin-left: 4px;
}

/* === Toggle switch === */
.toggle {
  position: relative;
  width: 51px; height: 31px; flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: rgba(120,120,128,.16);
  border-radius: 16px;
  transition: background .25s;
  cursor: pointer;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 27px; height: 27px;
  left: 2px; top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform .25s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.toggle input:checked + .toggle-slider {
  background: var(--brand-primary);
  box-shadow: 0 0 12px rgba(99,102,241,.4);
}
.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* === Buttons === */
.btn {
  display: block; width: calc(100% - 32px);
  margin: 12px 16px;
  padding: 14px;
  border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:active { opacity: .7; }
.btn-primary {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: 0 4px 16px rgba(99,102,241,.3);
}
.btn-danger {
  background: transparent;
  color: #ef4444;
}
.btn-secondary {
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  color: var(--tg-theme-text-color, #e8e8f0);
}

/* === Chips / Tags === */
.chips {
  display: flex; flex-wrap: wrap;
  gap: 8px; padding: 8px 16px;
  overflow: visible;
}
.chip {
  display: inline-flex; align-items: center;
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
  border: 1.5px solid rgba(99,102,241,.3);
  background: transparent;
  color: var(--tg-theme-text-color, #e8e8f0);
}
/* Выбранные компании — краткое + полное название */
.selected-companies-list {
  padding: 8px 16px;
}
.selected-company-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: 12px;
  border-left: 3px solid var(--brand-primary);
  cursor: pointer;
  transition: background .15s;
}
.selected-company-item:active {
  background: rgba(99,102,241,.15);
}
.selected-company-content {
  flex: 1;
  min-width: 0;
  overflow: visible;
}
.selected-company-quoted {
  font-size: 15px;
  color: var(--brand-accent);
  font-weight: 600;
  margin-bottom: 4px;
}
/* Полное название — без обрезки, контейнер растёт по содержимому */
.selected-company-full {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #8888aa);
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}
.selected-company-remove {
  flex-shrink: 0;
  color: var(--brand-accent);
  font-size: 16px;
}
.chip.active {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
  box-shadow: 0 0 10px rgba(99,102,241,.3);
}

/* === Search input === */
.search-wrap {
  padding: 8px 16px;
}
.search-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(99,102,241,.2);
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  color: var(--tg-theme-text-color, #e8e8f0);
  font-size: 16px;
  outline: none;
  transition: border-color .2s;
}
.search-input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 8px rgba(99,102,241,.2);
}
.search-input::placeholder {
  color: var(--tg-theme-hint-color, #8888aa);
}

/* === Record cards === */
.record-card {
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: 12px;
  margin: 8px 16px;
  padding: 14px 16px;
  border-left: 3px solid var(--brand-primary);
  position: relative;
}
.record-index {
  position: absolute;
  top: 8px; right: 12px;
  font-size: 11px; font-weight: 600;
  color: var(--brand-accent);
  opacity: .6;
}
.record-status {
  font-size: 15px; font-weight: 600;
  margin-bottom: 6px;
  color: var(--brand-accent);
}
.record-row {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 14px;
  padding: 2px 0;
  color: var(--tg-theme-text-color, #e8e8f0);
}
.record-row-company {
  align-items: flex-start;
}
.record-row-company .record-company {
  flex: 1;
  min-width: 0;
  word-wrap: break-word;
  white-space: normal;
  line-height: 1.4;
}
.record-label {
  color: var(--tg-theme-hint-color, #8888aa);
  flex-shrink: 0;
}
.record-date {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #8888aa);
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(99,102,241,.1);
}

/* === Tabs === */
.tabs {
  display: flex;
  padding: 4px;
  gap: 0;
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: 10px;
  margin: 8px 16px;
}
.tab {
  flex: 1;
  padding: 8px 12px;
  text-align: center;
  font-size: 14px; font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  border: none;
  background: transparent;
  color: var(--tg-theme-hint-color, #8888aa);
}
.tab.active {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}

/* === Source card on dashboard === */
.source-card {
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: 16px;
  margin: 8px 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: transform .1s, box-shadow .2s;
  border: 1px solid rgba(99,102,241,.1);
}
.source-card:active {
  transform: scale(.98);
  box-shadow: 0 0 16px rgba(99,102,241,.15);
}
.source-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.source-icon.ks2 { background: rgba(99,102,241,.15); }
.source-icon.claims { background: rgba(124,58,237,.15); }
.source-icon.psd { background: rgba(59,130,246,.15); }
.source-info { flex: 1; }
.source-name { font-size: 17px; font-weight: 600; }
.source-desc { font-size: 13px; color: var(--tg-theme-hint-color, #8888aa); }
.source-toggle {
  width: 51px; height: 31px;
  border-radius: 16px;
  flex-shrink: 0;
  position: relative;
  cursor: pointer;
  transition: background .25s;
}
.source-toggle.on {
  background: var(--brand-primary);
  box-shadow: 0 0 12px rgba(99,102,241,.4);
}
.source-toggle.off {
  background: rgba(120,120,128,.16);
}
.source-toggle::after {
  content: '';
  position: absolute;
  width: 27px; height: 27px;
  top: 2px; left: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform .25s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.source-toggle.on::after {
  transform: translateX(20px);
}
.source-toggle.soon {
  background: rgba(120,120,128,.08);
  cursor: default;
  opacity: .5;
}
.source-toggle.soon::after {
  background: rgba(255,255,255,.5);
}

/* === Subscription banner === */
.sub-banner {
  background: var(--brand-gradient);
  border-radius: 16px;
  margin: 12px 16px;
  padding: 20px;
  color: #fff;
  box-shadow: 0 4px 24px rgba(79,70,229,.3);
  position: relative;
  overflow: hidden;
}
.sub-banner::before {
  content: '';
  position: absolute;
  top: -40%; right: -20%;
  width: 200px; height: 200px;
  background: rgba(255,255,255,.08);
  border-radius: 50%;
}
.sub-banner-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; position: relative; }
.sub-banner-desc { font-size: 14px; opacity: .85; margin-bottom: 12px; position: relative; }
.sub-banner .btn {
  background: rgba(255,255,255,.2);
  backdrop-filter: blur(4px);
  color: #fff;
  margin: 0; width: 100%;
  position: relative;
  box-shadow: none;
}

/* === Pagination === */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; padding: 12px 16px;
}
.pagination-btn {
  padding: 8px 18px; border-radius: 10px;
  border: none;
  background: var(--brand-gradient);
  color: #fff;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(99,102,241,.2);
}
.pagination-btn:disabled {
  opacity: .3; cursor: default;
  box-shadow: none;
}
.pagination-info {
  font-size: 14px;
  color: var(--tg-theme-hint-color, #8888aa);
}

/* === Stat grid (admin) === */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px 16px;
}
.stat-box {
  background: var(--tg-theme-secondary-bg-color, #1a1a2e);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  border: 1px solid rgba(99,102,241,.1);
}
.stat-value {
  font-size: 24px; font-weight: 700;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat-label { font-size: 12px; color: var(--tg-theme-hint-color, #8888aa); margin-top: 2px; }

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: 48px 32px;
  color: var(--tg-theme-hint-color, #8888aa);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; }

/* === Back button simulation (for non-Telegram testing) === */
.back-header {
  display: flex; align-items: center;
  padding: 8px 8px 0;
  gap: 4px;
  cursor: pointer;
  color: var(--brand-accent);
  font-size: 16px;
}

/* === Animations === */
.page-enter {
  animation: slideIn .2s ease-out;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* === Info banner === */
.info-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 8px 16px;
  padding: 12px 14px;
  background: rgba(59, 130, 246, .12);
  border: 1px solid rgba(59, 130, 246, .25);
  border-radius: 12px;
}
.info-banner-icon {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1.4;
}
.info-banner-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.45;
  color: var(--tg-theme-text-color, #e8e8f0);
}
.info-banner-close {
  flex-shrink: 0;
  font-size: 14px;
  color: var(--tg-theme-hint-color, #8888aa);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1.4;
}

/* === Subscription status on dashboard === */
.sub-status {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px 14px;
  margin: 0 16px 4px;
  background: var(--brand-surface);
  border-radius: 12px;
  border: 1px solid rgba(99,102,241,.15);
}
.sub-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  flex-shrink: 0;
}
.sub-text {
  font-size: 14px;
  color: var(--tg-theme-text-color, #e8e8f0);
}
.sub-date {
  font-weight: 700;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
