/* ============ БАЗА ============ */

.dashboard {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ============ TOPBAR ============ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: nowrap;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-left { flex: 1; min-width: 0; }
.topbar-right { flex-shrink: 0; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; opacity: 0.85; }

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 12px var(--primary);
  flex-shrink: 0;
}

.crumb-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb-link:hover { color: var(--text); text-decoration: none; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 13px;
  min-height: 32px;
  min-width: 60px;
  max-width: 200px;
  overflow: hidden;
}
.user-chip img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.user-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip-loading {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-elev-3);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

/* ============ CONTENT ============ */

.content {
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.page-head p { margin: 0; font-size: 14px; }

/* ============ GUILD GRID ============ */

.guild-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

/* ============ GUILD CARD ============ */

.guild-card {
  position: relative;
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--bg-elev, #16181f);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  overflow: hidden;
  padding: 0 16px 16px;
  margin-top: 60px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.guild-card:hover {
  transform: translateY(-2px);
  border-color: rgba(88, 101, 242, 0.4);
}
.guild-card:active { transform: translateY(0); }
.guild-card.disabled { opacity: 0.85; cursor: default; }
.guild-card.disabled:hover { transform: none; }

/* ── Баннер ── */

.guild-banner {
  position: relative;
  height: 100px;
  margin: 0 -16px 0;
  background-size: cover;
  background-position: center;
  background-color: #262a36;
  background-repeat: no-repeat;
}

.guild-banner-empty {
  background: linear-gradient(135deg, rgba(88, 101, 242, 0.35), rgba(138, 149, 255, 0.15));
}

/* ── Иконка сервера (выезжает из баннера) ── */

.guild-card .guild-icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  overflow: hidden;
  border: 4px solid var(--bg-elev, #16181f);
  background: #5865F2;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  margin-top: -36px;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}
.guild-card .guild-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Инфо ── */

.guild-card .guild-info { min-width: 0; }

.guild-card .name {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guild-card .status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin-top: 4px;
}
.guild-card .status.bot-absent  { color: #ED4245; }
.guild-card .status.bot-present { color: var(--muted, #aaa); }

.guild-card .guild-arrow {
  position: absolute;
  top: 16px;
  right: 16px;
  color: var(--muted, #aaa);
}

.copy-btn { flex-shrink: 0; opacity: 0.6; }
.guild-card:hover .copy-btn { opacity: 1; }

.badge-premium {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  border-radius: 4px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1a1207;
}

/* ============ LAYOUT (guild.html) ============ */

.layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 57px);
  min-height: calc(100dvh - 57px);
}

.sidebar {
  width: 240px;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 16px 12px;
  flex-shrink: 0;
  position: sticky;
  top: 57px;
  height: calc(100vh - 57px);
  height: calc(100dvh - 57px);
  overflow-y: auto;
}

.guild-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 16px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.guild-mini-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary-a);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
  object-fit: cover;
}
.guild-mini-info { min-width: 0; flex: 1; }
.guild-mini-name {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.guild-mini-id {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  font-family: inherit;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}
.nav-item.active {
  background: var(--primary-a);
  color: var(--primary);
  border-color: rgba(88, 101, 242, 0.3);
}

.main {
  flex: 1;
  padding: 24px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}

.panel-header { margin-bottom: 20px; }
.panel-header h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
}
.panel-header p { margin: 0; font-size: 14px; }

/* ============ EMPTY ============ */

.empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 60px 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}
.empty h3 {
  margin: 12px 0 4px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}
.empty p { margin: 0 0 16px; font-size: 14px; }
.empty-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ============ SAVE BAR ============ */

.save-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px;
  margin-top: 8px;
  background: rgba(17, 17, 20, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: sticky;
  bottom: 16px;
  z-index: 5;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  flex-wrap: wrap;
}
.save-hint {
  font-size: 12px;
  color: var(--warning);
  margin-right: auto;
}

/* =============================================================
 * АДАПТИВ
 * ============================================================= */

/* ── Большие десктопы (1600+) ── */
@media (min-width: 1600px) {
  .content { max-width: 1280px; padding: 40px 32px; }
  .main { max-width: 1100px; padding: 32px; }
  .guild-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
}

/* ── Десктоп (1200–1599) ── */
@media (min-width: 1200px) and (max-width: 1599px) {
  .content { max-width: 1120px; }
  .main { max-width: 960px; }
}

/* ── Ноутбук (900–1199) ── */
@media (min-width: 900px) and (max-width: 1199px) {
  .content { padding: 24px 20px; }
  .guild-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .main { padding: 20px; }
}

/* ── Планшет (600–899) ── */
@media (max-width: 899px) {
  .content {
    padding: 20px 16px;
  }

  .page-head { margin-bottom: 20px; }
  .page-head h1 { font-size: 22px; }

  .guild-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
  }

  .guild-banner { height: 90px; }
  .guild-card .guild-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    font-size: 22px;
    margin-top: -32px;
    border-width: 3px;
  }
  .guild-card .name { font-size: 14px; }
}

/* ── Планшет / узкий (600–768) — сайдбар сжимается ── */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
    min-height: auto;
  }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: none;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px;
  }

  .guild-mini {
    padding-bottom: 12px;
    margin-bottom: 10px;
  }

  .side-nav {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .side-nav::-webkit-scrollbar { display: none; }

  .nav-item {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 14px;
    font-size: 13px;
  }

  .main {
    padding: 16px;
    max-width: none;
  }

  .panel-header h1 { font-size: 20px; }

  .save-bar {
    bottom: 8px;
    padding: 12px;
    gap: 8px;
  }
}

/* ── Телефон (480–599) ── */
@media (max-width: 599px) {
  .topbar {
    padding: 8px 12px;
    gap: 8px;
  }

  .crumb-link span:not([data-icon]) { display: none; }
  .crumb-link { gap: 0; }

  .user-chip {
    max-width: 130px;
    padding: 3px 8px 3px 3px;
  }
  .user-chip span {
    font-size: 12px;
  }

  .content { padding: 16px 12px; }

  .page-head h1 { font-size: 20px; }
  .page-head p  { font-size: 13px; }

  .guild-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .guild-card {
    padding: 0 14px 14px;
    margin-top: 56px;
  }

  .guild-banner {
    height: 84px;
    margin: 0 -14px 0;
  }

  .guild-card .guild-icon {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    font-size: 20px;
    margin-top: -30px;
    border-width: 3px;
  }

  .guild-card .name { font-size: 14px; }
  .guild-card .status { font-size: 11px; }

  .main { padding: 14px 12px; }
  .panel-header h1 { font-size: 18px; }

  .save-bar {
    flex-direction: column-reverse;
    align-items: stretch;
    bottom: 4px;
    padding: 10px;
  }
  .save-bar .btn { width: 100%; }
  .save-hint { text-align: center; margin-right: 0; }
}

/* ── Узкий телефон (≤ 479) ── */
@media (max-width: 479px) {
  .topbar {
    flex-wrap: wrap;
    padding: 8px 10px;
  }

  .topbar-left { width: 100%; }
  .topbar-right { width: 100%; justify-content: flex-end; }

  .brand span:not(.brand-dot) { font-size: 13px; }

  .user-chip { max-width: 100px; }
  .user-chip img { width: 20px; height: 20px; }
  .user-chip span { display: none; }

  .guild-card .guild-arrow { display: none; }

  .guild-card .status .badge-premium { font-size: 9px; }
}

/* ── Очень узкий телефон (≤ 360) ── */
@media (max-width: 360px) {
  .content,
  .main { padding: 12px 8px; }

  .guild-card {
    margin-top: 48px;
    padding: 0 12px 12px;
  }

  .guild-banner {
    height: 72px;
    margin: 0 -12px 0;
  }

  .guild-card .guild-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    font-size: 18px;
    margin-top: -26px;
    border-width: 3px;
  }

  .guild-card .name { font-size: 13px; }

  .guild-mini-icon { width: 32px; height: 32px; }
  .guild-mini-name { font-size: 13px; }
}

/* ── Ландшафтный режим телефона (max-height 500) ── */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .sidebar {
    max-height: 200px;
    overflow-y: auto;
  }
  .guild-banner { height: 70px; }
  .guild-card { margin-top: 50px; }
  .guild-card .guild-icon {
    width: 56px;
    height: 56px;
    margin-top: -28px;
  }
}

/* ── ТВ / очень большие экраны (2000+) ── */
@media (min-width: 2000px) {
  .content {
    max-width: 1500px;
    padding: 48px 40px;
  }
  .main { max-width: 1300px; padding: 40px; }
  .guild-grid {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
  }
  .guild-banner { height: 130px; }
  .guild-card .guild-icon {
    width: 88px;
    height: 88px;
    font-size: 28px;
    margin-top: -44px;
  }
  .guild-card .name { font-size: 17px; }
}

/* ============ ПРЕДПОЧТЕНИЯ ПРИ ПОЛЬЗОВАТЕЛЕ ============ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ ТАЧ-УСТРОЙСТВА ============ */

@media (hover: none) and (pointer: coarse) {
  .guild-card:hover {
    transform: none;
    border-color: rgba(255, 255, 255, 0.06);
  }
  .guild-card:active {
    transform: scale(0.98);
    border-color: rgba(88, 101, 242, 0.4);
  }
  .nav-item:hover { background: transparent; }
  .nav-item:active { background: var(--bg-elev-2); }
}