/* ============================================================
   THEME COLORS & DESIGN SYSTEM — v2 (навбар 3 секции, липкий подвал,
   выпадающее меню профиля, чат-виджет на всех страницах)
   ============================================================ */

/* ========== VARIABLES: фракции (themes) ========== */
:root {
  /* Caldari (default) */
  --bg: #0a0e1a;
  --panel: #1a2236;
  --panel-2: #242e42;
  --line: #404d66;
  --text: #cad5e2;
  --muted: #8a96ac;
  --accent: #4a9eff;
  --accent-2: #6bb3ff;
  --accent-soft: rgba(74, 158, 255, 0.08);
  --ok: #22c55e;
  --danger: #ef4444;

  --race: "caldari";
  --race-color: #4a9eff;
}

html[data-theme="gallente"] {
  --bg: #0a1a10;
  --panel: #1a2f24;
  --panel-2: #243a2e;
  --line: #405554;
  --text: #cae2d5;
  --muted: #8aaca0;
  --accent: #4aff8a;
  --accent-2: #6bffb3;
  --accent-soft: rgba(74, 255, 138, 0.08);
  --ok: #22c55e;
  --danger: #ef4444;

  --race: "gallente";
  --race-color: #4aff8a;
}

html[data-theme="minmatar"] {
  --bg: #1a0a04;
  --panel: #2f1a12;
  --panel-2: #3a2418;
  --line: #554028;
  --text: #e2cec5;
  --muted: #aca890;
  --accent: #ff8a4a;
  --accent-2: #ffb36b;
  --accent-soft: rgba(255, 138, 74, 0.08);
  --ok: #22c55e;
  --danger: #ef4444;

  --race: "minmatar";
  --race-color: #ff8a4a;
}

html[data-theme="amarr"] {
  --bg: #1a1504;
  --panel: #2f2812;
  --panel-2: #3a341a;
  --line: #55502a;
  --text: #e2dcc5;
  --muted: #aca898;
  --accent: #ffd74a;
  --accent-2: #ffe26b;
  --accent-soft: rgba(255, 215, 74, 0.08);
  --ok: #22c55e;
  --danger: #ef4444;

  --race: "amarr";
  --race-color: #ffd74a;
}

/* ========== ФОНОВЫЕ ИЗОБРАЖЕНИЯ ПО ФРАКЦИЯМ + ПЛАВНАЯ АНИМАЦИЯ СМЕНЫ ========== */
body {
  background-size: cover;
  background-attachment: fixed;
  background-position: center;
  position: relative;
}

/* Два слоя фона: старый и новый, анимация clip-path по диагонали */
body::before,
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-size: cover;
  background-attachment: fixed;
  background-position: center;
  z-index: -1;
  pointer-events: none;
}

body::before {
  /* Старый фон (под низом) */
  background-image: var(--old-bg, url("/static/img/caldari.7eb55b0e5699.jpg"));
}

body::after {
  /* Новый фон (сверху, с анимацией clip-path) */
  background-image: var(--new-bg, url("/static/img/caldari.7eb55b0e5699.jpg"));
  clip-path: polygon(0 0, 0 0, 0 100%);
  transition: clip-path 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body.theme-transitioning::after {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

html[data-theme="caldari"] body::after {
  --new-bg: url("/static/img/caldari.7eb55b0e5699.jpg");
}

html[data-theme="gallente"] body::after {
  --new-bg: url("/static/img/gallente.8e57da16dfd7.jpg");
}

html[data-theme="minmatar"] body::after {
  --new-bg: url("/static/img/minmatar.e071715d9b23.jpg");
}

html[data-theme="amarr"] body::after {
  --new-bg: url("/static/img/amarr.89f439b5bcf5.jpg");
}

/* ========== КЛАССИЧЕСКИЙ ВИД (кнопка в меню профиля) ========== */
body.classic-design {
  background-image: none !important;
  background-color: var(--bg);
}

/* ============================================================
   LAYOUT & STRUCTURE
   ============================================================ */

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

/* ========== ГЛОБАЛЬНЫЕ ССЫЛКИ: подчёркивание в цвет активной темы вместо синего браузера ========== */
a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

a:hover,
a:focus-visible {
  color: var(--accent-2);
  border-bottom-color: var(--accent-2);
}

a:visited {
  color: var(--accent);
}

/* ========== СТРОКИ КИЛЛБОРДА: своя подсветка при наведении, без общего подчёркивания ========== */
.killmail-row:hover {
  background: var(--accent-soft);
  border-bottom-color: transparent !important;
}

html {
  scroll-behavior: smooth;
  --font-head: Cinzel, Rajdhani, "Exo 2", Oswald, sans-serif;
  --font-body: Inter, sans-serif;
  --radius: 8px;
  font-size: 16px;
  height: 100%;
}

/* ========== ЛИПКИЙ ПОДВАЛ: html/body растягиваются на весь экран ========== */
body {
  font-family: var(--font-body);
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

/* ========== ПОЛУПРОЗРАЧНЫЙ ФОН ДЛЯ ТОПБАРА ========== */
.topbar {
  background: rgba(10, 14, 26, 0.85);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

/* ========== НАВБАР: 3 СЕКЦИИ, ОДНА СТРОКА ВСЕГДА ========== */
.navbar-grid {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  min-height: 58px;
}

.nav-left {
  justify-self: start;
  min-width: 0;
  overflow: hidden;
}

.nav-center {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  max-width: 100%;
}

.nav-center::-webkit-scrollbar {
  display: none;
}

.nav-center a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-center a:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.6px;
  min-width: 0;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: cover;
}

.brand-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ========== THEME SWITCHER ========== */
.theme-switch {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.theme-switch a {
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0;
  text-indent: -9999px;
  flex-shrink: 0;
}

.theme-switch a.caldari { background: #4a9eff; }
.theme-switch a.gallente { background: #4aff8a; }
.theme-switch a.minmatar { background: #ff8a4a; }
.theme-switch a.amarr { background: #ffd74a; }

.theme-switch a:hover,
.theme-switch a[data-active="1"] {
  border-color: #fff;
  box-shadow: 0 0 8px currentColor;
  transform: scale(1.1);
}

/* ========== КНОПКА ВХОДА (тёмная, не засвечена) ========== */
.btn-auth {
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 8px 16px;
  font-size: 0.88rem;
}

.btn-auth:hover {
  background: var(--accent-soft);
  color: var(--accent-2);
  transform: none;
  box-shadow: none;
}

/* ========== МЕНЮ ПРОФИЛЯ (клик по нику -> дропдаун) ========== */
.user-menu {
  position: relative;
  flex-shrink: 0;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 10px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: all 0.2s ease;
}

.user-menu-trigger:hover {
  border-color: var(--accent);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.user-nick {
  font-weight: 600;
  font-size: 0.88rem;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-caret {
  font-size: 0.65rem;
  color: var(--muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.user-menu.open .user-caret {
  transform: rotate(180deg);
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 200;
}

.user-menu.open .user-menu-dropdown {
  display: flex;
}

.user-menu-dropdown a,
.user-menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.87rem;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.user-menu-dropdown form {
  margin: 0;
}

/* ========== ОСНОВНОЙ КОНТЕНТ: растягивается, подвал прижат к низу ========== */
.main-content {
  flex: 1 0 auto;
  padding-top: 28px;
  padding-bottom: 60px;
  background: rgba(10, 14, 26, 0.65);
  backdrop-filter: blur(5px);
}

/* ========== ЦЕНТРАЛЬНЫЙ БОКС (карточки) — увеличен книзу ========== */
.card {
  background: rgba(26, 34, 54, 0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 30px;
  margin: 0;
  backdrop-filter: blur(8px);
}

.card:hover {
  background: rgba(26, 34, 54, 0.85);
  border-color: var(--accent);
}

/* ========== СЕТКА ========== */
.grid {
  display: grid;
  gap: 20px;
  margin-top: 18px;
}

.grid.cols-2 {
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* ========== ТИПОГРАФИЯ ========== */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-head);
  font-weight: 600;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

h1 {
  font-size: 2.2rem;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(74, 158, 255, 0.3);
}

h2 {
  font-size: 1.6rem;
  color: var(--accent);
  margin-top: 20px;
}

h3 {
  font-size: 1.2rem;
  color: var(--accent);
}

p {
  margin-bottom: 10px;
}

p.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ========== КНОПКИ & ФОРМЫ ========== */
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 10px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #05080c;
  border: none;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-head);
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--accent-2);
  color: #05080c;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(74, 158, 255, 0.3);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

.btn.ghost:hover {
  background: var(--accent-soft);
  color: var(--accent-2);
}

/* ========== ТАБЛИЦЫ ========== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.6px;
}

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ========== СТАРЫЙ ЧАТ-БЛОК (оставлен для HTMX-фолбэка, больше не используется на главной) ========== */
.chat-box {
  height: 340px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.chat-msg {
  margin-bottom: 10px;
}

.chat-msg .who {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
}

/* ========== СТАТИСТИКА ========== */
.progress {
  height: 8px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress > i {
  display: block;
  height: 100%;
  background: var(--accent);
}

.stat {
  font-family: var(--font-head);
  font-size: 1.6rem;
  color: var(--accent);
}

.profit-pos {
  color: var(--ok);
}

.profit-neg {
  color: var(--danger);
}

/* ========== БЕЙДЖИ ========== */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-right: 8px;
  margin-bottom: 8px;
}

.badge.ok {
  background: rgba(34, 197, 94, 0.2);
  color: var(--ok);
  border: 1px solid rgba(34, 197, 94, 0.4);
}

/* ========== ЛИПКИЙ ПОДВАЛ ========== */
.site-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: rgba(10, 14, 26, 0.9);
  backdrop-filter: blur(10px);
  margin-top: auto;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 18px 20px;
}

.footer-signature {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.footer-trademark {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

/* ========== REF-CHIPS (плашки фитов/производств) ========== */
.ref-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 0.92em;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.ref-chip:hover,
.ref-chip:focus {
  background: var(--accent);
  color: #fff;
  outline: none;
  transform: scale(1.05);
}

.ref-chip-missing {
  opacity: 0.55;
  cursor: default;
  border-style: dashed;
}

.ref-chip-missing:hover {
  background: none;
  color: inherit;
  transform: none;
}

/* ========== POPUP (рефы) ========== */
.ref-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.ref-popup-box {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 20px;
  min-width: 280px;
  max-width: 420px;
  backdrop-filter: blur(10px);
  position: relative;
}

.ref-popup-box h3 {
  margin: 0 0 12px;
  font-size: 1.05em;
}

.ref-popup-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.ref-popup-actions form {
  margin: 0;
}

.ref-popup-rename-row {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.ref-popup-rename-row input {
  flex: 1;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: transparent;
  color: inherit;
}

.ref-popup-close {
  position: absolute;
  top: 10px;
  right: 14px;
  cursor: pointer;
  font-size: 1.2em;
  opacity: 0.7;
  background: none;
  border: none;
  color: inherit;
  transition: opacity 0.2s ease;
}

.ref-popup-close:hover {
  opacity: 1;
}

/* ========== ПЛАВАЮЩИЙ ЧАТ-ВИДЖЕТ (справа снизу, на всех страницах) ========== */
.chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 320px;
  max-height: min(500px, calc(100vh - 40px));
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  z-index: 999;
  backdrop-filter: blur(10px);
  transition: max-height 0.3s ease;
  overflow: hidden;
}

.chat-widget-header {
  background: linear-gradient(135deg, var(--accent-soft), rgba(255, 255, 255, 0.02));
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: move;
  user-select: none;
  border-radius: 10px 10px 0 0;
}

.chat-widget-title {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.92rem;
}

.chat-widget-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.chat-widget-btn:hover {
  color: var(--accent-2);
  transform: scale(1.2);
}

.chat-widget-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 0;
}

.chat-widget.collapsed .chat-widget-body {
  display: none;
}

.chat-widget.collapsed {
  max-height: 44px;
}

.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  min-height: 200px;
  max-height: 380px;
  font-size: 0.85rem;
}

.chat-widget-msg {
  margin-bottom: 8px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.04);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
}

.chat-widget-msg-author {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.8rem;
  margin-bottom: 2px;
}

.chat-widget-msg-text {
  color: var(--text);
  word-wrap: break-word;
  line-height: 1.3;
}

#chat-widget-form {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  display: flex;
  gap: 6px;
}

#chat-widget-form input {
  flex: 1;
  margin: 0;
}

#chat-widget-form button {
  margin: 0;
  padding: 8px 14px;
  flex-shrink: 0;
}

/* ========== МЕДИА-ЗАПРОСЫ: навбар и чат-виджет ========== */
@media (max-width: 1100px) {
  .nav-center {
    gap: 8px;
  }

  .nav-center a {
    font-size: 0.85rem;
    padding: 6px 8px;
  }

  .brand-text {
    max-width: 220px;
  }
}

@media (max-width: 900px) {
  .navbar-grid {
    gap: 8px;
    padding: 8px 14px;
  }

  .nav-center {
    gap: 4px;
  }

  .nav-center a {
    font-size: 0.78rem;
    padding: 5px 7px;
  }

  .brand-text {
    max-width: 140px;
    font-size: 0.9rem;
  }

  .brand-logo {
    width: 26px;
    height: 26px;
  }

  .theme-switch a {
    width: 22px;
    height: 22px;
  }

  .user-nick {
    max-width: 80px;
  }
}

@media (max-width: 680px) {
  .navbar-grid {
    grid-template-columns: auto auto auto;
    gap: 4px;
  }

  .nav-center a {
    font-size: 0.7rem;
    padding: 4px 5px;
  }

  .user-nick {
    display: none;
  }

  .brand-text {
    max-width: 90px;
  }
}

@media (max-width: 600px) {
  .grid.cols-2 {
    grid-template-columns: 1fr;
  }

  .grid.cols-3 {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }

  h1 {
    font-size: 1.8rem;
  }

  .chat-widget {
    width: calc(100% - 20px);
    right: 10px;
    left: 10px;
    max-height: 60vh;
  }

  .chat-widget-messages {
    min-height: 150px;
    max-height: calc(60vh - 120px);
  }

  .footer-inner {
    flex-direction: column;
    text-align: center;
    gap: 6px;
  }

  .footer-trademark {
    text-align: center;
  }
}
