/* ===== Global reset & base ===== */
html, body {
  margin: 0;
  padding: 0;
  background-color: #1e1f1b;
}
body {
  font-family: Arial, sans-serif;
  color: #e6e6e6; /* near-white for readability */
  background-image:
    linear-gradient(rgba(0,0,0,0.1), rgba(0,0,0,0.1)),
    url('https://www.transparenttextures.com/patterns/asfalt-dark.png');
}

/* ===== Header ===== */
#header-bar {
  background-color: #191b15;
  border-bottom: 2px solid #4b5320;
  padding: 14px 20px;
}
#header-bar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 1px;
  color: #c7d7a5;
  text-transform: uppercase;
}

/* ===== 3-column layout ===== */
.container {
  display: grid;
  grid-template-columns: 240px 1fr 250px;
  gap: 16px;
  padding: 16px;
  align-items: start; /* keep top-aligned so nothing stacks vertically */
}

/* ===== Panels ===== */
.panel {
  border: 1px solid #3f4238;
  background-color: #2b2d26;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.45);
}

/* Left: Units */
#units-container {
  border: 1px solid #46493e;
  background-color: #2c2f27;
  padding: 10px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}
/* Group header rows */
#units-list li.group-header {
  font-size: 1.1em;
  font-weight: bold;
  /* same grey as the section titles – adjust if your colour differs */
  cursor: default;
  margin-top: 8px;
  list-style: none;
  pointer-events: none;
  /* kill any border / line */
  border: none !important;
  text-align: center;
  display: block;      /* make it a block so it fills the <ul> */
  width: 100%;
}
.group-header.group-general  { color: #27ae5f; }   /* green  */
.group-header.group-ground   { color: #a65317; }   /* brown  */
.group-header.group-naval    { color: #2549ac; }   /* dark blue */
.group-header.group-air      { color: #31a5d6; }   /* light blue */
.group-header.group-building { color: #e39612; }   /* orange-yellow */
.group-header.group-other    { color: #d73e3e; }   /* red */
#units-list img {
  width: 40px;
  height: 27px;
  object-fit: cover;
  display: block;
}
/* optional: tighten spacing above first header */
#units-list li.group-header:first-child {
  margin-top: 0;
}
/* header that sits above the unit list */
#units-list-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0 0.6rem;
  margin-bottom: 1rem;
}

#units-list-header #units-list-search {
  flex: 1 1 auto;
  padding: 0.25rem 0.5rem;
  font-size: 0.9rem;
  background: #2c2c2c;         /* dark input */
  color: #e0e0e0;
  border: 1px solid #555;
  border-radius: 4px;
}

#units-list-header #units-list-search::placeholder {
  color: #999;
}
#units-container ul { list-style: none; padding: 0; margin: 0; }
#units-container li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #3b3d35;
  cursor: grab;
}
#units-container li:hover { background-color: rgba(255,255,255,0.05); }
#units-container img { width: 40px; height: 40px; }

/* Middle: Stacks (scrollable) */
#stack-container {
  border: 1px solid #46493e;
  background-color: #2b2d26;
  padding: 10px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#stack-container .stack { order: 0; }       /* ensures button stays last */
#add-stack-button { order: 9999; }          /* always below the stacks */

/* Stack card */
.stack {
  border: 1px solid #56594c;
  background-color: #33352d;
  padding: 10px;
  position: relative;
}
.stack-title {
  font-weight: bold;
  color: #e0e0c6;
}
.stack table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}
.stack th, .stack td {
  border: 1px solid #444;
  padding: 6px;
  text-align: left;
}

/* Delete "X" — subtle enlarge (no spin) */
.stack-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  color: #ff6b6b;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.15s ease, color 0.15s ease;
}
.stack-delete:hover {
  transform: scale(1.25);
  color: #ff8989;
}

.defbonus-item img,
.stack .defbonus-cell img {
  width: 40px !important;
  height: 27px !important;
  object-fit: cover;
}

/* Add New Stack (inside middle panel) */
#add-stack-button {
  margin-top: 4px;
  align-self: center;
  background-color: #4b5320;
  border: 1px solid #6a7440;
  color: #e6e6e6;
  padding: 8px 14px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}
#add-stack-button:hover {
  transform: translateY(-1px);
  background-color: #5d6630;
  box-shadow: 0 2px 0 rgba(0,0,0,0.25);
}

/* Right side: controls + results in a column */
#right-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0; /* prevents overflow in grid */
}
#right-controls {
  border: 1px solid #46493e;
  background-color: #2b2d26;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
#battle-results {
  border: 1px solid #46493e;
  background-color: #2b2d26;
  padding: 10px;
  white-space: pre-wrap;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
  box-shadow: inset 0 0 8px rgba(0,0,0,0.45);
}

/* ===== Unified control styling (inputs, selects, checkboxes) ===== */
input[type="number"],
input[type="text"],
input[type="url"], 
select {
  background-color: #1e1f1b;
  border: 1px solid #595c50;
  color: #e6e6e6;
  padding: 6px 8px;
  border-radius: 6px;
  outline: none;
  min-height: 16px;
}
input[type="number"]:focus,
input[type="text"]:focus,
input[type="url"]:focus, 
select:focus {
  border-color: #7f8f4a;
  box-shadow: 0 0 0 2px rgba(127,143,74,0.25);
}

/* Native select dropdown arrow (for any non-Select2 selects) */
select {
  appearance: none;
  padding-right: 28px;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='%23e6e6e6'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

/* Custom checkboxes (dark theme) */
input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid #6a6d5f;
  background-color: #1e1f1b;
  border-radius: 3px;
  margin-right: 6px;
  position: relative;
  vertical-align: middle;
  cursor: pointer;
}
input[type="checkbox"]:hover {
  border-color: #8b9560;
}
input[type="checkbox"]:checked {
  background-color: #4b5320;
  border-color: #8b9560;
  box-shadow: 0 0 0 1px #8b9560 inset;
}
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: 2px solid #e6e6e6;
  border-left: 0;
  border-top: 0;
  transform: rotate(45deg);
}

/* Select2 dark theme overrides */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
  background-color: #1e1f1b !important;
  border: 1px solid #595c50 !important;
  color: #e6e6e6 !important;
  min-height: 32px;
  border-radius: 6px !important;
}
.select2-container--default .select2-selection--single .select2-selection__rendered,
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
  color: #e6e6e6 !important;
}
.select2-container--default .select2-selection--single .select2-selection__arrow b {
  border-color: #e6e6e6 transparent transparent transparent !important;
}
.select2-dropdown {
  background-color: #2b2d26 !important;
  border: 1px solid #595c50 !important;
}
.select2-results__option { color: #e6e6e6 !important; }
.select2-results__option--highlighted { background-color: #4b5320 !important; }

/* already-selected item: darker green */
.select2-container--default .select2-results__option--selected {
    background-color: #2d3a10 !important;   /* darker than #4b5320 */
    color: #e6e6e6 !important;
}

/* keep the lighter green for hover/focus */
.select2-container--default .select2-results__option--highlighted {
    background-color: #4b5320 !important;
    color: #e6e6e6 !important;
}

.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple,
.select2-allies + .select2-container--default .select2-selection--multiple,   /* allies multi-select */
.select2-allies + .select2-container--default .select2-selection--single {
  background-color: #1e1f1b !important;
  border: 1px solid #595c50 !important;
  color: #e6e6e6 !important;
  border-radius: 6px !important;
  min-height: 32px;
}

/* choices (pills) */
.select2-container--default .select2-selection__choice,
.select2-allies + .select2-container--default .select2-selection__choice {
  background-color: #4b5320 !important;
  color: #e6e6e6 !important;
  border: 1px solid #6a7440 !important;
}

/* drop-down list */
.select2-dropdown,
.select2-allies + .select2-container--default .select2-dropdown {
  background-color: #2b2d26 !important;
  border: 1px solid #595c50 !important;
}

.select2-results__option {
  color: #e6e6e6 !important;
}
.select2-results__option--highlighted {
  background-color: #4b5320 !important;
}
.select2-results__option--selected {
  background-color: #2d3a10 !important;
}

.select2-container--default * {
  color: #e6e6e6 !important;
}

/* Buttons (right controls) */
#submit-button {
  background-color: #4b5320;
  border: 1px solid #6a7440;
  color: #e6e6e6;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
#submit-button:hover { background-color: #5d6630; transform: translateY(-1px); }

.control-label {
  font-size: 12px;
  opacity: 0.9;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background-color: #4b5320; border-radius: 4px; }
::-webkit-scrollbar-track { background-color: #1e1f1b; }

/* Colors helpers used by sim.js output */
.green { color: #a8c686; }
.lightred { color: #ff6666; }
.dark.mini { font-size: 0.8em; color: #bdbdbd; }

.stack-options-top .gear-icon,
.stack-options-top .upgrade-count-label {
    display: inline-flex;           /* keeps them on the same line */
    align-items: center;            /* vertically centers both */
}

.stack-options-bottom label {
  display: block;
  margin-bottom: 4px;
}

input[type="checkbox"]:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stack-options-bottom {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.stack-options-bottom label {
  flex: 1 1 45%;
  min-width: 140px;
}

.stack table th,
.stack table td {
  text-align: center;
  vertical-align: middle;
  padding: 6px 4px;
}

/* left-aligned columns */
.stack table th:nth-child(2),
.stack table td:nth-child(2),
.stack table th:nth-child(7),
.stack table td:nth-child(7) {
  text-align: left;
  vertical-align: middle;
}

.stack tbody tr {
  line-height: 40px;   /* 40 px ≈ icon height; adjust to your actual img height */
}

.stack td:nth-child(2),
.stack td:nth-child(7) {
  vertical-align: middle;
  padding: 0 6px;      /* keep horizontal padding, kill vertical padding */
}

.stack td:nth-child(2) img,
.stack td:nth-child(7) img {
  vertical-align: middle;
width: 40px;
  height: 27px;
}

.stack .quantity-cell {
  width: 45px;
  text-align: center;
}

#loading-icon img {
  width: 22px;
  height: 22px;
  margin-left: 8px;
  vertical-align: middle;
}

/* Modal backdrop */
.upgrade-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}

/* Modal card */
.modal-card {
    width: 420px;
    max-height: 70vh;
    background: #2b2d26;
    border: 1px solid #46493e;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
}

/* Modal header */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid #3f4238;
    font-weight: 600;
}

/* Close button */
.modal-close {
    background: none;
    border: none;
    color: #ff6b6b;
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.15s;
}
.modal-close:hover {
    transform: scale(1.2);
}

/* Modal body */
.modal-body {
    flex: 1 1 auto;
    padding: 12px;
    overflow-y: auto;
}

/* Modal footer */
.modal-footer {
    padding: 12px;
    text-align: center;
}

/* Apply button */
.btn-apply {
    background: #4b5320;
    border: 1px solid #6a7440;
    color: #e6e6e6;
    padding: 8px 18px;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.15s;
}
.btn-apply:hover {
    transform: translateY(-1px);
    background: #5d6630;
}

.gear-icon,
.gear-icon img,
.upgrade-desc-toggle {
  cursor: pointer;
}

.upgrade-item {
  display: flex;                /* overall column */
  flex-direction: column;
  border-bottom: 1px solid #3f4238;
  padding-bottom: 6px;
  margin-bottom: 6px;
}

.upgrade-row {                 /* the single line with image / name / checkbox / info */
  display: flex;
  align-items: center;
  gap: 8px;
}

.upgrade-row img {
  width: 40px;
  height: 27px;
  object-fit: cover;
}

.upgrade-desc {
  margin-top: 4px;
  font-size: 0.9em;
  color: #999;
  display: none;               /* hidden by default */
}

.upgrade-desc.show {
  display: block;              /* toggled by JS */
}

/* settings overlay */
.settings-modal {
  position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}

/* ===== NAVBAR (solid dark-olive) ===== */
#top-nav {
  position: sticky;
  top: 0;
  z-index: 999;

  background: #23251f;              /* same tone as panels, no gradient */
  border-bottom: 2px solid #4b5320;

  padding: 8px 14px;
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Search box */
#units-list-search {
  flex: 1 1 240px;
  padding: 6px 8px;
  font-size: 0.9rem;

  background: #1e1f1b;
  color: #e6e6e6;
  border: 1px solid #595c50;
  border-radius: 4px;
  outline: none;
}

#units-list-search::placeholder { color: #999; }
#units-list-search:focus {
  border-color: #7f8f4a;
  box-shadow: 0 0 0 2px rgba(127, 143, 74, 0.25);
}

/* Settings button */
#settings-button {
  background: #4b5320;
  border: 1px solid #6a7440;
  color: #e6e6e6;
  padding: 6px 12px;
  font-size: 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
}

#settings-button:hover {
  background-color: #5d6630;
  transform: translateY(-1px);
}

/* ---- select2-unit-sets (identical to select2-strategies overrides) ---- */
.select2-unit-sets + .select2-container--default .select2-selection--single {
  background-color: #1e1f1b !important;
  border: 1px solid #595c50 !important;
  color: #e6e6e6 !important;
  min-height: 32px;
  border-radius: 6px !important;
}

.select2-unit-sets + .select2-container--default
.select2-selection--single .select2-selection__rendered {
  color: #e6e6e6 !important;
}

.select2-unit-sets + .select2-container--default
.select2-selection--single .select2-selection__arrow b {
  border-color: #e6e6e6 transparent transparent transparent !important;
}

/* dropdown background */
.select2-unit-sets-dropdown {
  background-color: #2b2d26 !important;
  border: 1px solid #595c50 !important;
}

/* option text colour */
.select2-unit-sets-dropdown .select2-results__option {
  color: #e6e6e6 !important;
}

/* lighter olive on hover */
.select2-unit-sets-dropdown .select2-results__option--highlighted {
  background-color: #4b5320 !important;
  color: #e6e6e6 !important;
}

/* darker olive for already-selected */
.select2-unit-sets-dropdown .select2-results__option--selected {
  background-color: #2d3a10 !important;
  color: #e6e6e6 !important;
}

/* ‑- force light-green hover on the selected item ‑- */
.select2-container--default
  .select2-results__option--selected:hover,
.select2-container--default
  .select2-results__option--selected.select2-results__option--highlighted {
  background-color: #4b5320 !important;
}

/* search box inside strategies & unit-sets */
.select2-container--default .select2-search--dropdown .select2-search__field,
.select2-strategies .select2-search__field,
.select2-unit-sets .select2-search__field {
  background-color: #1e1f1b !important;
  border: 1px solid #595c50 !important;
  color: #e6e6e6 !important;
}

.error-bar {
    position: absolute;
    top: 0;
    right: calc(250px);
    display: flex;
    flex-direction: row-reverse;
    gap: 2px;
    pointer-events: auto;
    z-index: 1000;
    align-items: center;
    padding: 2px 0;
}

.error-bar .fa-icon {
    font-size: 1.5em;
    cursor: pointer;
    margin: 0 4px;
}

.error-bar .fa-icon[data-tooltip] { position: relative; }

.error-bar .fa-icon[data-label]:hover::after {
  content: attr(data-label) "\A" attr(data-msg); /* line break */
  white-space: pre-line;
  position: absolute;
  top: 100%;
  right: 0;
  background: #2b2d26;
  border: 1px solid #595c50;
  color: #f5f5f5;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
  transform: translateY(6px);
  max-width: 300px;
  line-height: 1.4;
}

/* color the first line depending on severity */
.error-bar .fa-icon[level="error"]:hover::after {
  color: #e74c3c;
}
.error-bar .fa-icon[level="warning"]:hover::after {
  color: #f39c12;
}
.error-bar .fa-icon[level="info"]:hover::after {
  color: #3498db;
}

.tooltip-wrapper {
  position: relative;
  display: inline-block;
}

.tooltip {
  position: absolute;
  top: 120%;
  right: 0;
  background: #2b2d26;
  border: 1px solid #595c50;
  color: #f5f5f5;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
  line-height: 1.4;
  max-width: 600px;
  width: max-content;
  min-width: 150px;
  white-space: normal;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.tooltip-title {
  font-weight: 600;       /* slightly bolder */
  font-size: 14px;        /* a bit bigger than description */
  display: block;
  color: #f1c40f;         /* can change based on error level if needed */
}

.tooltip-description {
  font-size: 13px;
  line-height: 1.4;
  color: #f5f5f5;
}

.tooltip strong {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

/* Show on hover */
.tooltip-wrapper:hover .tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* Severity accent (label color) */
.tooltip-error strong { color: #e74c3c; }
.tooltip-warning strong { color: #f39c12; }
.tooltip-info strong { color: #3498db; }

/* upgrade counter next to the gear icon */
.upgrade-count-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #c7d7a5;
    background: #1e1f1b;
    border: 1px solid #595c50;
    border-radius: 4px;
    padding: 2px 6px;
    margin-left: 6px;
    line-height: 1;
     transform: translateY(-2px); 
}