/* ========================================
   ROZPY STAROSWIATA - Styles
   Dark Warhammer Old World Theme
   ======================================== */

:root {
  --bg-dark: #0f0f1a;
  --bg-mid: #1a1a2e;
  --bg-card: #22223a;
  --bg-card-hover: #2a2a48;
  --bg-input: #16162a;
  --border: #333355;
  --border-light: #444466;
  --gold: #c9a55a;
  --gold-dim: #9a7a3a;
  --gold-bright: #e0c070;
  --red: #8b0000;
  --red-bright: #cc2200;
  --cream: #e8dcc8;
  --cream-dim: #b0a898;
  --white: #f0ece4;
  --green: #3a8a3a;
  --green-bright: #55bb55;
  --blue: #4488cc;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-heading: Georgia, "Times New Roman", serif;
  --radius: 4px;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --page-max: 1200px;
  --sidebar-w: 260px;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg-dark);
  color: var(--cream);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

a:hover {
  text-decoration: underline;
}

/* ======== HEADER ======== */

#site-header {
  background: linear-gradient(180deg, var(--bg-mid) 0%, var(--bg-dark) 100%);
  border-bottom: 2px solid var(--gold-dim);
  padding: 1.5rem 1rem 0.5rem;
  text-align: center;
}

.header-inner {
  max-width: var(--page-max);
  margin: 0 auto;
}

.site-title {
  font-family: var(--font-heading);
  font-size: 2.6rem;
  color: var(--gold);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6), 0 0 30px rgba(201,165,90,0.15);
  margin-bottom: 0.1rem;
}

.site-title a {
  color: inherit;
  text-decoration: none;
}

.site-title a:hover {
  text-decoration: none;
  opacity: 0.9;
}

.site-subtitle {
  font-size: 0.95rem;
  color: var(--cream-dim);
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.main-nav {
  display: flex;
  justify-content: center;
  gap: 0;
}

.nav-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--cream-dim);
  font-family: var(--font-heading);
  font-size: 1rem;
  padding: 0.6rem 1.5rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  letter-spacing: 0.04em;
}

.nav-btn:hover {
  color: var(--cream);
}

.nav-btn.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

/* ======== MAIN / VIEWS ======== */

#app {
  flex: 1;
  max-width: var(--page-max);
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
  position: relative;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* ======== LOADING ======== */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.3s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ======== FILTERS SIDEBAR ======== */

.lists-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.filters-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  position: sticky;
  top: 1rem;
}

.filters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.filters-header h2 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--gold);
}

.btn-reset {
  background: none;
  border: 1px solid var(--border);
  color: var(--cream-dim);
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-reset:hover {
  border-color: var(--red);
  color: var(--red-bright);
}

.filter-group {
  margin-bottom: 1rem;
}

.filter-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--cream-dim);
  margin-bottom: 0.3rem;
  letter-spacing: 0.03em;
}

.filter-group input,
.filter-group select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--cream);
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  outline: none;
  transition: border-color 0.2s;
}

.filter-group input:focus,
.filter-group select:focus {
  border-color: var(--gold-dim);
}

.filter-group select option {
  background: var(--bg-mid);
  color: var(--cream);
}

.range-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.range-inputs input {
  flex: 1;
  min-width: 0;
}

.range-sep {
  color: var(--cream-dim);
}

.btn-toggle-filters {
  display: none;
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 100;
  background: var(--gold-dim);
  color: var(--bg-dark);
  font-weight: 700;
  border: none;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
}

/* ======== LISTS MAIN ======== */

.lists-main {
  flex: 1;
  min-width: 0;
}

.results-bar {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--cream-dim);
}

.lists-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.75rem;
}

/* ======== LIST CARD ======== */

.list-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.list-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--gold-dim);
}

.list-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.4rem;
}

.list-card-faction {
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--gold);
  line-height: 1.3;
}

.list-card-pts {
  font-size: 0.85rem;
  color: var(--cream-dim);
  white-space: nowrap;
  margin-left: 0.5rem;
}

.list-card-meta {
  font-size: 0.82rem;
  color: var(--cream-dim);
  margin-bottom: 0.3rem;
}

.list-card-record {
  display: flex;
  gap: 0.6rem;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.record-w { color: var(--green-bright); }
.record-l { color: var(--red-bright); }
.record-d { color: var(--cream-dim); }

.list-card-units {
  font-size: 0.78rem;
  color: var(--cream-dim);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ======== PAGINATION ======== */

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.page-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--cream-dim);
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.page-btn:hover {
  border-color: var(--gold-dim);
  color: var(--cream);
}

.page-btn.active {
  background: var(--gold-dim);
  color: var(--bg-dark);
  border-color: var(--gold-dim);
  font-weight: 700;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.page-ellipsis {
  color: var(--cream-dim);
  padding: 0.35rem 0.3rem;
  font-size: 0.85rem;
}

/* ======== DETAIL VIEW ======== */

.detail-container {
  max-width: 800px;
  margin: 0 auto;
}

.detail-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-back {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--cream);
}

.btn-back:hover {
  border-color: var(--gold-dim);
}

.btn-primary {
  background: var(--gold-dim);
  color: var(--bg-dark);
  font-weight: 600;
}

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

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--cream);
}

.btn-secondary:hover {
  border-color: var(--gold-dim);
}

.detail-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.detail-faction-title {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  color: var(--gold);
  margin-bottom: 0.3rem;
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem 1rem;
  margin-bottom: 1.2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.detail-meta-item {
  font-size: 0.88rem;
}

.detail-meta-label {
  color: var(--cream-dim);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.detail-meta-value {
  color: var(--cream);
}

.detail-section-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--gold);
  margin: 1.2rem 0 0.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}

.detail-rawlist {
  white-space: pre-wrap;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--cream);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.detail-units-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.detail-units-table th {
  text-align: left;
  color: var(--cream-dim);
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-units-table td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--bg-input);
  color: var(--cream);
}

.detail-units-table tr:hover td {
  background: var(--bg-card-hover);
}

.detail-items-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

.detail-item-tag {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  color: var(--gold-bright);
}

/* ======== STATS VIEW ======== */

.stats-container {
  max-width: var(--page-max);
}

.section-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--gold);
  margin-bottom: 1rem;
  letter-spacing: 0.05em;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
}

.stat-card h3 {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  color: var(--gold);
  margin-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

.stat-card-wide {
  grid-column: 1 / -1;
}

/* ======== CSS-ONLY CHARTS ======== */

.chart-bars {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
}

.chart-bar-label {
  width: 180px;
  flex-shrink: 0;
  text-align: right;
  color: var(--cream-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-bar-track {
  flex: 1;
  height: 18px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}

.chart-bar-fill-gold {
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
}

.chart-bar-fill-red {
  background: linear-gradient(90deg, var(--red), var(--red-bright));
}

.chart-bar-fill-blue {
  background: linear-gradient(90deg, #2255aa, var(--blue));
}

.chart-bar-value {
  width: 55px;
  flex-shrink: 0;
  text-align: right;
  color: var(--cream);
  font-size: 0.8rem;
}

/* Compact variant for win rates */
.chart-bars-compact { gap: 0.2rem; }
.chart-bars-compact .chart-bar-row { font-size: 0.75rem; }
.chart-bars-compact .chart-bar-label { width: 140px; font-size: 0.72rem; }
.chart-bars-compact .chart-bar-track { height: 14px; }
.chart-bars-compact .chart-bar-value { width: 45px; font-size: 0.72rem; }
.stat-card-compact { padding: 0.8rem; }
.stat-card-compact h3 { font-size: 0.95rem; margin-bottom: 0.5rem; }

/* ======== EXPANDABLE UNIT ROWS ======== */

.unit-row-main { cursor: pointer; }
.unit-row-main:hover td { background: rgba(201,165,90,0.08); }
.unit-row-detail { display: none; background: rgba(0,0,0,0.2); }
.unit-row-detail.open { display: table-row; }
.unit-row-detail td { padding: 0.5rem 0.6rem 0.5rem 1.2rem; }
.unit-options-list { list-style: none; padding-left: 0; margin: 0 0 0.4rem; }
.unit-options-list li { color: var(--cream-dim); font-size: 0.82rem; padding: 0.1rem 0; }
.unit-options-list li::before { content: "- "; color: var(--gold-dim); }
.unit-items-inline { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.unit-item-tag { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.15rem 0.5rem; font-size: 0.78rem; color: var(--gold-bright); }
.general-badge { background: var(--gold); color: var(--bg-dark); padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.75rem; font-weight: 600; margin-left: 0.4rem; vertical-align: middle; }

/* ======== POINTS PRESETS ======== */

.points-presets { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.4rem; }
.preset-btn { background: var(--bg-card); border: 1px solid var(--border); color: var(--cream-dim); padding: 0.2rem 0.5rem; border-radius: var(--radius); font-size: 0.8rem; cursor: pointer; transition: border-color 0.2s, color 0.2s; }
.preset-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ======== TOW LINKS ======== */

.unit-link { color: var(--cream); text-decoration: none; border-bottom: 1px dotted var(--gold-dim); }
.unit-link:hover { color: var(--gold); }
.item-link { color: var(--gold); text-decoration: none; }
.item-link:hover { text-decoration: underline; }

/* ======== STATS SELECTOR ======== */

.stats-selector {
  margin-bottom: 1rem;
}

.stats-selector select {
  width: 100%;
  max-width: 400px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--cream);
  font-size: 1rem;
  padding: 0.5rem 0.8rem;
  outline: none;
  font-family: var(--font-heading);
}
.stats-selector select:focus { border-color: var(--gold-dim); }
.stats-selector select option { background: var(--bg-mid); color: var(--cream); }

/* ======== FACTION STATS DETAIL ======== */

#faction-stats-detail { margin-bottom: 1rem; }
#faction-stats-detail .faction-stat-summary {
  display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem;
  font-size: 0.88rem;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.8rem 1rem;
}
#faction-stats-detail .faction-stat-summary span { color: var(--cream-dim); }
#faction-stats-detail .faction-stat-summary strong { color: var(--cream); }
#faction-stats-detail .faction-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}
#faction-stats-detail .faction-detail-grid .faction-detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
}
#faction-stats-detail .faction-detail-grid .faction-detail-card h4 {
  font-family: var(--font-heading); color: var(--gold); font-size: 0.95rem;
  margin: 0 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem;
}

/* ======== CAMERA ICON ======== */

.btn-img-search {
  display: inline-block;
  color: var(--cream-dim);
  font-size: 0.82rem;
  margin-left: 0.3rem;
  cursor: pointer;
  text-decoration: none;
  vertical-align: middle;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.btn-img-search:hover { opacity: 1; color: var(--gold); text-decoration: none; }

/* ======== STAT TABLE ======== */

.stat-table-wrap {
}

.stat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stat-table th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  text-align: left;
  color: var(--cream-dim);
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-table td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--bg-input);
  color: var(--cream);
}

.stat-table tr:hover td {
  background: var(--bg-card-hover);
}

.stat-table .rank-col {
  color: var(--cream-dim);
  width: 2rem;
}

.stat-table .count-col {
  text-align: right;
  color: var(--gold);
}

/* ======== ABOUT ======== */

.about-container {
  max-width: 700px;
  margin: 0 auto;
}

.about-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  line-height: 1.7;
}

.about-content p {
  margin-bottom: 0.8rem;
}

.about-content h3 {
  font-family: var(--font-heading);
  color: var(--gold);
  margin: 1.2rem 0 0.5rem;
  font-size: 1.1rem;
}

.about-content ul {
  margin-left: 1.5rem;
  margin-bottom: 0.8rem;
}

.about-content li {
  margin-bottom: 0.3rem;
}

/* ======== TOAST ======== */

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  background: var(--bg-card);
  border: 1px solid var(--gold-dim);
  color: var(--cream);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ======== FOOTER ======== */

#site-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.8rem;
  color: var(--cream-dim);
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* ======== RESPONSIVE ======== */

@media (max-width: 768px) {
  .site-title {
    font-size: 1.6rem;
  }

  .nav-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }

  .lists-layout {
    flex-direction: column;
  }

  .filters-sidebar {
    width: 100%;
    position: static;
  }

  .filters-sidebar .filter-group,
  .filters-sidebar .filters-header {
    display: none;
  }

  .filters-sidebar.open .filter-group,
  .filters-sidebar.open .filters-header {
    display: block;
  }

  .btn-toggle-filters {
    display: block;
  }

  .lists-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .chart-bar-label {
    width: 100px;
    font-size: 0.72rem;
  }

  .chart-bar-value {
    width: 45px;
    font-size: 0.72rem;
  }

  .detail-top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .detail-meta-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .site-title {
    font-size: 1.3rem;
    letter-spacing: 0.08em;
  }

  #app {
    padding: 0.5rem;
  }

  .detail-content {
    padding: 1rem;
  }

  .stat-card {
    padding: 0.8rem;
  }
}
