/* ================================================================
   WC3 OBJECT EDITOR – STYLESHEET
   ================================================================
   Colour palette:
     Background     #1a1a2e  (deep navy)
     Surface        #16213e  (dark blue-grey)
     Accent         #e94560  (coral red)
     Border         #0f3460  (royal blue)
     Text           #e0e0e0  (off-white)
     Muted text     #888 / #777 / #555
   ================================================================ */

/* ----------------------------------------------------------------
   RESET & BASE
   ---------------------------------------------------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  font-size: 13px;
}

/* ----------------------------------------------------------------
   HEADER BAR
   ---------------------------------------------------------------- */
.hdr {
  background: #16213e;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 2px solid #0f3460;
  flex-wrap: wrap;
}

.hdr h1 {
  font-size: 17px;
  color: #e94560;
  white-space: nowrap;
}

/* ----------------------------------------------------------------
   BUTTONS
   ---------------------------------------------------------------- */
.btn {
  padding: 5px 12px;
  border: 1px solid #0f3460;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: 0.12s;
}

.b-load { background: #0f3460; color: #fff; }
.b-load:hover { background: #1a5276; }

.b-exp { background: #1b6b3a; color: #fff; border-color: #1b6b3a; }
.b-exp:hover { background: #27ae60; }

.b-imp { background: #6b3a1b; color: #fff; border-color: #6b3a1b; }
.b-imp:hover { background: #ae6027; }

.b-add { background: #7d6608; color: #fff; border-color: #7d6608; }
.b-add:hover { background: #b7950b; }

.b-del { background: #922b21; color: #fff; border-color: #922b21; }
.b-del:hover { background: #c0392b; }

.b-demo { background: #3ab6ff; color: #fff; }

.b-sm { padding: 2px 6px; font-size: 11px; }

/* ----------------------------------------------------------------
   TABS
   ---------------------------------------------------------------- */
.tabs {
  display: flex;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  padding: 0 14px;
}

.tab {
  padding: 7px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: #888;
}

.tab:hover { color: #ccc; }

.tab.active {
  color: #e94560;
  border-bottom-color: #e94560;
}

/* ----------------------------------------------------------------
   TOOLBAR  (search, toggles, stats bar)
   ---------------------------------------------------------------- */
.toolbar {
  padding: 6px 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.search {
  padding: 4px 8px;
  background: #252550;
  border: 1px solid #0f3460;
  color: #e0e0e0;
  border-radius: 3px;
  font-size: 12px;
  width: 180px;
}

.search:focus {
  border-color: #e94560;
  outline: none;
}

/* -- Toggle switch (show all columns) -- */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}

.toggle-label {
  font-size: 11px;
  color: #888;
  white-space: nowrap;
}

.toggle {
  position: relative;
  width: 36px;
  height: 18px;
  cursor: pointer;
  display: inline-block;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle .slider {
  position: absolute;
  inset: 0;
  background: #333;
  border-radius: 9px;
  transition: 0.2s;
}

.toggle .slider::before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background: #777;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .slider {
  background: #0f3460;
}

.toggle input:checked + .slider::before {
  transform: translateX(18px);
  background: #e94560;
}

.stats {
  color: #777;
  font-size: 11px;
  margin-left: auto;
}

/* ----------------------------------------------------------------
   DATA TABLE  –  Outer wrapper & base table styles
   ---------------------------------------------------------------- */
.tw {
  overflow: auto;
  max-height: calc(100vh - 140px);
  margin: 0 14px 14px;
  border: 1px solid #0f3460;
  border-radius: 3px;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

/* -- Column headers -- */
th {
  background: #0f3460;
  color: #ddd;
  padding: 4px 6px;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 10;
  font-size: 11px;
  white-space: nowrap;
  border-right: 1px solid #1a2a4e;
  cursor: default;
  min-width: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
}

th .sub {
  font-size: 9px;
  color: #7799bb;
  display: block;
  font-weight: normal;
}

/* -- Column resize handle -- */
th .col-resize {
  position: absolute;
  right: 0;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 11;
}

th .col-resize:hover {
  background: rgba(233, 69, 96, 0.5);
}

/* -- Data cells -- */
td {
  padding: 1px 2px;
  border-bottom: 1px solid #252550;
  border-right: 1px solid #1e1e3e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

td input {
  width: 100%;
  background: transparent;
  color: #e0e0e0;
  border: 1px solid transparent;
  padding: 1px 3px;
  font: 12px Consolas, monospace;
  border-radius: 2px;
}

td input:focus {
  border-color: #e94560;
  background: #25255a;
  outline: none;
}

td select {
  width: 100%;
  background: #1a1a30;
  color: #e0e0e0;
  border: 1px solid transparent;
  padding: 1px 3px;
  font: 12px Consolas, monospace;
  border-radius: 2px;
  cursor: pointer;
}

td select:focus {
  border-color: #e94560;
  background: #25255a;
  outline: none;
}

/* Active resize cursor */
.resizing {
  cursor: col-resize !important;
  user-select: none !important;
}

/* ----------------------------------------------------------------
   ROW COLOURING
   r0 = original table  |  r1 = custom table
   ga = alternating group shading
   ---------------------------------------------------------------- */
.r0       { background: #1a1a30; }
.r1       { background: #1a2a1a; }
.r0:hover { background: #222248; }
.r1:hover { background: #223a22; }

.ga.r0       { background: #1e1e38; }
.ga.r1       { background: #1e301e; }
.ga.r0:hover { background: #282850; }
.ga.r1:hover { background: #284028; }

/* -- Building-override highlight (ubdg = "Is a Building") -- */
tr.ubdg-override       { background: rgba(233, 166, 69, 0.10) !important; }
tr.ubdg-override:hover { background: rgba(233, 166, 69, 0.18) !important; }
tr.ubdg-override > td:first-child {
  border-left: 3px solid #e9a645;
}

/* ----------------------------------------------------------------
   UNIT TYPE SECTION HEADERS  (Heroes / Buildings / Units)
   ---------------------------------------------------------------- */
.unit-section-header {
  background: #0d1a35;
  color: #8ab4e0;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #0f3460;
  border-top: 2px solid #0f3460;
  user-select: none;
}

.unit-section-header:first-child {
  border-top: none;
}

.unit-section-empty {
  color: #555;
  padding: 6px 14px;
  font-size: 11px;
  font-style: italic;
  background: #0a0a1a;
  border-bottom: 1px solid #0f3460;
}

/* -- ID column (Base ID / Custom ID) -- */
.idc {
  font: 12px Consolas, monospace;
  color: #7fb3d8;
  padding: 2px 4px;
}

/* -- Delete / action column -- */
.del-c {
  text-align: center;
  padding: 0;
}

/* -- Sub-row styling -- */
.sub-row td { border-bottom: 1px solid #1a1a30; }
.sub-row .sr-pad { border-right: none; }
.sub-row .sr-lvl {
  color: #6a6a9a;
  font-size: 11px;
  text-align: center;
  padding-left: 4px;
}

/* -- Group head separator -- */
.grp-head {
  border-top: 2px solid #2a2a5a;
}

/* -- Read-only cells (main-row-only fields in sub-rows) -- */
.ro-cell {
  color: #555;
  font: 12px Consolas, monospace;
  padding: 1px 4px;
  background: black;
}

/* ----------------------------------------------------------------
   NESTED LEVEL SUB-TABLE  (abilities, upgrades, doodads)
   ---------------------------------------------------------------- */
.sub-table-row > td {
  padding: 0 0 4px 30px !important;
  border-bottom: 2px solid #2a2a5a;
  background: rgba(0, 0, 0, 0.25);
}

.level-table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: auto;
  margin: 0;
  opacity: 0.72;
}

.level-table th {
  background: #08162e;
  color: #667788;
  padding: 2px 5px;
  text-align: left;
  font-size: 9px;
  white-space: nowrap;
  border-right: 1px solid #152030;
  position: sticky;
  top: 0;
  z-index: 5;
  min-width: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: normal;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.level-table th .sub {
  font-size: 8px;
  color: #3a4a5a;
  display: block;
  font-weight: normal;
}

.level-table th .col-resize {
  position: absolute;
  right: 0;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 6;
}

.level-table th .col-resize:hover {
  background: rgba(233, 69, 96, 0.4);
}

.level-table td {
  padding: 1px 2px;
  border-bottom: 1px solid #151528;
  border-right: 1px solid #151520;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-table td input {
  width: 100%;
  background: transparent;
  color: #aab0b8;
  border: 1px solid transparent;
  padding: 1px 3px;
  font: 11px Consolas, monospace;
  border-radius: 2px;
}

.level-table td input:focus {
  border-color: #e94560;
  background: #1e1e40;
  outline: none;
  color: #e0e0e0;
}

.level-table td select {
  width: 100%;
  background: #12121e;
  color: #aab0b8;
  border: 1px solid transparent;
  padding: 1px 3px;
  font: 11px Consolas, monospace;
  border-radius: 2px;
  cursor: pointer;
}

.level-table td select:focus {
  border-color: #e94560;
  background: #1e1e40;
  outline: none;
  color: #e0e0e0;
}

.level-table .sr-lvl {
  color: #4a4a6a;
  font-size: 10px;
  text-align: center;
  padding: 1px 4px;
  font-family: Consolas, monospace;
}

.level-table tr:hover { opacity: 1; }
.level-table tr:hover td input,
.level-table tr:hover td select { color: #e0e0e0; }

/* ----------------------------------------------------------------
   COLUMN CATEGORY HEADERS
   ---------------------------------------------------------------- */
.cat-head-row th {
  background: #09122a;
  border-right: 1px solid #1a2a4e;
  border-bottom: 1px solid #0f3460;
}

.cat-spacer {
  background: #09122a;
  border-right: none !important;
}

.cat-head {
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #6899bb;
  cursor: pointer;
  padding: 2px 8px;
  user-select: none;
  font-weight: 600;
  transition: 0.1s;
}

.cat-head:hover {
  background: #102048;
  color: #cce0ff;
}

.cat-head.cat-expanded {
  border-left: 2px solid #1a3a6e;
  border-right: 2px solid #1a3a6e;
}

.cat-head.cat-collapsed {
  min-width: 28px !important;
  max-width: 120px !important;
  color: #6899bb;
  padding: 2px 4px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cat-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: #1a3a6e;
  color: #8ab4e0;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  vertical-align: middle;
  flex-shrink: 0;
}

.cat-stub {
  background: #07101e !important;
  width: 28px !important;
  min-width: 28px !important;
  max-width: 28px !important;
  padding: 0 !important;
  border-right: 1px solid #1a2a4e !important;
}

/* ----------------------------------------------------------------
   UTILITY
   ---------------------------------------------------------------- */
.hidden {
  display: none !important;
}

/* ----------------------------------------------------------------
   POPUP OVERLAY (Add Row dialog)
   ---------------------------------------------------------------- */
.ov {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pop {
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 16px;
  min-width: 320px;
  max-width: 460px;
  max-height: 80vh;
  overflow-y: auto;
}

.pop h3 {
  margin-bottom: 10px;
  color: #e94560;
  font-size: 14px;
}

.pop label {
  display: block;
  margin: 5px 0 2px;
  font-size: 11px;
  color: #999;
}

.pop input,
.pop select {
  width: 100%;
  padding: 5px 7px;
  background: #252550;
  border: 1px solid #0f3460;
  color: #e0e0e0;
  border-radius: 3px;
  font-size: 12px;
}

.pop .pb {
  margin-top: 12px;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ----------------------------------------------------------------
   STATISTICS BUTTON
   ---------------------------------------------------------------- */
.b-stats {
  background: linear-gradient(135deg, #6c3483, #8e44ad);
  color: #fff;
  border-color: #8e44ad;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.b-stats:hover {
  background: linear-gradient(135deg, #8e44ad, #a569bd);
  box-shadow: 0 0 12px rgba(142, 68, 173, 0.5);
}

/* ----------------------------------------------------------------
   STATISTICS MODAL  –  Presentation-quality overlay
   ---------------------------------------------------------------- */
.stats-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: statsOverlayIn 0.25s ease-out;
}

@keyframes statsOverlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.stats-modal {
  background: linear-gradient(165deg, #141428 0%, #0e1a30 50%, #0c0c1e 100%);
  border: 1px solid #1a3a6e;
  border-radius: 16px;
  width: 92vw;
  max-width: 1200px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(233, 69, 96, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  animation: statsModalIn 0.3s ease-out;
}

@keyframes statsModalIn {
  from { opacity: 0; transform: translateY(30px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* -- Header -- */
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid rgba(15, 52, 96, 0.6);
  flex-shrink: 0;
}

.stats-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, #e94560, #ff7eb3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stats-close {
  width: 34px;
  height: 34px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: #aaa;
  font-size: 18px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
}

.stats-close:hover {
  background: #e94560;
  color: #fff;
  transform: scale(1.08);
}

/* -- Scrollable body -- */
.stats-body {
  overflow-y: auto;
  padding: 24px 28px 32px;
  flex: 1;
}

.stats-body::-webkit-scrollbar {
  width: 6px;
}

.stats-body::-webkit-scrollbar-track {
  background: transparent;
}

.stats-body::-webkit-scrollbar-thumb {
  background: rgba(233, 69, 96, 0.3);
  border-radius: 3px;
}

.stats-body::-webkit-scrollbar-thumb:hover {
  background: rgba(233, 69, 96, 0.5);
}

/* -- Summary cards -- */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stats-card {
  background: linear-gradient(145deg, rgba(15, 52, 96, 0.4), rgba(10, 25, 50, 0.6));
  border: 1px solid rgba(15, 52, 96, 0.5);
  border-radius: 12px;
  padding: 18px 16px;
  text-align: center;
  transition: 0.2s;
  position: relative;
  overflow: hidden;
}

.stats-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(233, 69, 96, 0.06) 0%, transparent 70%);
  pointer-events: none;
}

.stats-card:hover {
  border-color: rgba(233, 69, 96, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.stats-card-icon {
  font-size: 26px;
  margin-bottom: 6px;
}

.stats-card-value {
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.stats-card-label {
  font-size: 11px;
  color: #778;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

/* -- Chart grid -- */
.stats-chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
}

.stats-chart-wrap {
  background: #12122a;
  border: 1px solid rgba(15, 52, 96, 0.4);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: 0.2s;
  position: relative;
  overflow: hidden;
}

.stats-chart-wrap::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(233, 69, 96, 0.3), transparent);
}

.stats-chart-wrap:hover {
  border-color: rgba(58, 182, 255, 0.3);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.stats-chart-wrap canvas {
  max-width: 100%;
  height: auto;
}

.stats-chart-subtitle {
  color: #556;
  font-size: 10px;
  text-align: center;
  margin-top: 10px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

/* -- Responsive -- */
@media (max-width: 700px) {
  .stats-modal {
    width: 98vw;
    border-radius: 10px;
  }
  .stats-chart-grid {
    grid-template-columns: 1fr;
  }
  .stats-body {
    padding: 14px;
  }
}