/* ============================================================
   WARCAL — Unit Power Table
   Styles for the VT323 mainframe console + dot-matrix paper table
   + military-form popover.
   ============================================================ */

/* ── Page layout override ────────────────────────────────────────────── */

body.page-warcal {
  --binder-image: url("../src/empty.png");
  overflow-y: auto;
  overflow-x: auto;
}

.warcal-main {
  margin-top: 0;
  padding: 56px 20px 60px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-family: 'VT323', monospace;
  text-transform: uppercase;
}

/* ── Metric color palette ──────────────────────────────────────────────
   Matches the warcalfilter.html color coding.                          */
:root {
  --c-S:     #1a1aff;
  --c-Lhard: #b71c1c;
  --c-Lsoft: #e6a71e;
  --c-Lair:  #1b5e20;
  --c-I:     #4e1c8b;

  --green-bar:    #e1ede2;
  --paper-white:  #fdfdfb;
  --ink-black:    #2b2b2b;
  --panel-grey:   #a0a0a0;
  --panel-border: #808080;
  --panel-shadow: #606060;
  --metal-shine:  rgba(255, 255, 255, 0.2);
}

/* ============================================================
   Mainframe Console Panel (filter menu)
   ============================================================ */

.warcal-console {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  font-family: 'Public Sans', Arial, sans-serif;
  background-color: var(--panel-grey);
  background-image: linear-gradient(to bottom, var(--panel-grey), #8e8e8e);
  border: 4px solid var(--panel-border);
  border-bottom-color: var(--panel-shadow);
  box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.5),
              inset 0 0 10px rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 20px;
  box-sizing: border-box;
  position: relative;
  z-index: 10;
}

/* Corner screw details */
.warcal-console::before,
.warcal-console::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #444;
  box-shadow: inset 1px 1px 2px rgba(255, 255, 255, 0.3),
              1px 1px 1px rgba(0, 0, 0, 0.5);
}
.warcal-console::before { top: 10px; left: 10px; }
.warcal-console::after  { top: 10px; right: 10px; }

.console-header {
  font-size: 1.4rem;
  color: #333;
  border-bottom: 2px solid #777;
  padding-bottom: 10px;
  margin-bottom: 20px;
  letter-spacing: 2px;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.2);
}

#warcal-filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ── Push Buttons ─────────────────────────────────────────────────────── */

.push-button {
  height: 36px;
  background-color: #e0e0e0;
  border: 2px solid #888;
  border-bottom-color: #666;
  border-right-color: #666;
  color: #444;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  position: relative;
  font-family: 'Public Sans', Arial, sans-serif;
  font-size: 1.1rem;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.3);
  box-sizing: border-box;
  white-space: nowrap;
}

.push-button:active {
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  border-top-color:    #666;
  border-left-color:   #666;
  border-bottom-color: #ccc;
  border-right-color:  #ccc;
  transform: translateY(1px);
}

.push-button::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px; right: 2px; bottom: 2px;
  background: linear-gradient(135deg, var(--metal-shine), transparent);
  pointer-events: none;
}

/* Active/filtered state */
.push-button.filter-active {
  background-color: #cce0ff;
  border-color: #4488cc;
  border-bottom-color: #2266aa;
  border-right-color:  #2266aa;
  color: #003;
}

/* Red "clear locks" button */
.push-button-red {
  background-color: #ff3333;
  border-color:        #b30000;
  border-bottom-color: #900;
  border-right-color:  #900;
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
}
.push-button-red:active {
  background-color: #b30000;
  border-top-color:  #900;
  border-left-color: #900;
}

/* Secondary "load examples" button */
.push-button-sec {
  background-color: #4a6741;
  border-color:        #2d4229;
  border-bottom-color: #1e2f1c;
  border-right-color:  #1e2f1c;
  color: #b6ffb6;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
}
.push-button-sec:active {
  background-color: #2d4229;
  border-top-color:  #1e2f1c;
  border-left-color: #1e2f1c;
}

/* ── Search Input ─────────────────────────────────────────────────────── */

.console-search {
  width: 200px;
  height: 36px;
  background-color: #fff;
  color: #333;
  border: 2px solid #aaa;
  border-top-color:  #888;
  border-left-color: #888;
  padding: 0 10px;
  font-family: 'Public Sans', Arial, sans-serif;
  font-size: 1.1rem;
  text-transform: uppercase;
  cursor: text;
  box-sizing: border-box;
}

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

/* ── Dropdown ─────────────────────────────────────────────────────────── */

.console-dropdown-wrap {
  position: relative;
}

.console-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  background: #e4e4e4;
  border: 2px solid #888;
  border-top-color: #aaa;
  box-shadow: 3px 3px 8px rgba(0, 0, 0, 0.4);
  min-width: 160px;
  padding: 4px 0;
  max-height: 280px;
  overflow-y: auto;
}

.console-dropdown.hidden { display: none; }

.console-dropdown .dropdown-header {
  display: flex;
  gap: 6px;
  padding: 5px 12px;
  border-bottom: 1px solid #aaa;
  font-size: 0.85rem;
  color: #555;
}

.console-dropdown .dropdown-header a {
  color: #3060b0;
  cursor: pointer;
  text-decoration: none;
}
.console-dropdown .dropdown-header a:hover { text-decoration: underline; }

.console-dropdown label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-family: 'Public Sans', Arial, sans-serif;
  font-size: 1rem;
  color: #333;
  text-transform: uppercase;
}
.console-dropdown label:hover { background: #d0d0d0; }

.console-dropdown input[type="checkbox"] {
  cursor: pointer;
  width: 14px;
  height: 14px;
  margin: 0;
  flex-shrink: 0;
}

/* ── Toggle Switch ────────────────────────────────────────────────────── */

.console-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.console-toggle-wrap label {
  color: #444;
  font-size: 1rem;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

.toggle-switch {
  width: 36px;
  height: 36px;
  border: 2px solid #888;
  background-color: #dcdcdc;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: #666;
  box-shadow: inset 1px 1px 2px rgba(255, 255, 255, 0.2);
  transition: background-color 0.2s, box-shadow 0.2s;
}

.toggle-switch.on::after {
  background-color: #00cc00;
  box-shadow: inset 1px 1px 2px rgba(255, 255, 255, 0.2),
              0 0 5px rgba(0, 255, 0, 0.8);
}

/* ── Unit Count Display ───────────────────────────────────────────────── */

.unit-count-display {
  background-color: #333;
  border: 2px solid #aaa;
  border-top-color:  #888;
  border-left-color: #888;
  color: #e0e0e0;
  padding: 5px 12px;
  border-radius: 4px;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
  font-family: 'Public Sans', Arial, sans-serif;
  font-size: 1rem;
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

/* ============================================================
   Dot-Matrix Paper Table
   ============================================================ */

.paper-outer {
  width: 100%;
  min-width: 1080px;  /* match paper-container so ::after hole stays at paper's true right edge */
  max-width: 1280px;
  margin: 0 auto;
  position: relative;
  margin-top: -10px;  /* slight overlap with console */
}

.paper-container {
  width: 100%;
  min-width: 1080px;  /* colgroup total (960) + side padding (2×60) */
  background-color: transparent;
  background-image: linear-gradient(
    to right,
    transparent 45px,
    var(--paper-white) 45px,
    var(--paper-white) calc(100% - 45px),
    transparent calc(100% - 45px)
  );
  box-shadow: 15px 15px 30px rgba(0, 0, 0, 0.5);
  padding: 20px 60px 40px;
  box-sizing: border-box;
  position: relative;
  z-index: 1;
}

/* Tractor-feed holes on left and right margins */
.paper-outer::before,
.paper-outer::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 45px;
  background-image: radial-gradient(circle, transparent 30%, var(--paper-white) 35%);
  background-size: 35px 35px;
  background-position: center;
  z-index: 2;
  pointer-events: none;
}
.paper-outer::before { left: 0; }
.paper-outer::after  { right: 0; }

/* ── Table ────────────────────────────────────────────────────────────── */

.warcal-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--ink-black);
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
  table-layout: fixed;
}

.warcal-table thead th {
  text-align: left;
  border-bottom: 2px solid #aaa;
  padding: 8px 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.warcal-table thead th:first-child { cursor: default; }
.warcal-table thead th:last-child  { cursor: default; }

/* Sort indicators — use ink-black to stay on paper */
.warcal-table thead th.sorted-asc::after  { content: ' ▲'; color: #333; }
.warcal-table thead th.sorted-desc::after { content: ' ▼'; color: #333; }

/* Green-bar striping — 5 rows per band */
.warcal-table tbody tr { height: 48px; }

.warcal-table tbody tr:nth-child(10n+1),
.warcal-table tbody tr:nth-child(10n+2),
.warcal-table tbody tr:nth-child(10n+3),
.warcal-table tbody tr:nth-child(10n+4),
.warcal-table tbody tr:nth-child(10n+5) {
  background-color: var(--green-bar);
}

.warcal-table td {
  padding: 4px 10px;
  border-left: 1px solid rgba(0, 0, 0, 0.05);
  white-space: nowrap;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Lock column */
.warcal-table td.td-lock { text-align: center; }

.unit-lock-checkbox {
  cursor: pointer;
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

/* ── Unit Identification Cell ─────────────────────────────────────────── */

.unit-name-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.unit-id-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.unit-img {
  width: 64px;
  height: 36px;
  object-fit: cover;
  filter: sepia(0.3) contrast(1.1) grayscale(0.2);
  border: 1px solid #777;
  flex-shrink: 0;
}

.unit-id-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.unit-name {
  font-size: 1.2rem;
  font-weight: bold;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-sub {
  font-size: 0.85rem;
  opacity: 0.75;
  line-height: 1;
  display: block;
}

/* Info / popover trigger button */
.unit-pop-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 4px;
  color: #555;
  flex-shrink: 0;
  transition: color 0.15s;
  line-height: 1;
}
.unit-pop-btn:hover { color: #000; }

/* ── Data Columns ─────────────────────────────────────────────────────── */

.td-cost {
  font-weight: bold;
  font-size: 1.2rem;
  color: #111;
}

/* Metric value columns — right-aligned, colored */
.td-S,
.td-Lhard,
.td-Lsoft,
.td-Lair,
.td-I {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* Coalition / country badges */
.badge-nato {
  color: #1a3a7a;
  font-weight: bold;
}
.badge-pact {
  color: #8b0000;
  font-weight: bold;
}

/* ── Sparkline Bar Chart ──────────────────────────────────────────────── */

.spark-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 0;
}

.spark-row {
  display: flex;
  align-items: center;
  height: 10px;
}

.spark-track {
  flex: 1;
  height: 7px;
  background: rgba(0, 0, 0, 0.10);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.spark-fill {
  height: 100%;
  min-width: 2px;
  transition: width 0.3s ease;
  background-image: radial-gradient(currentColor 1px, transparent 1px);
  background-size: 3px 3px;
  background-position: center;
}

/* ── Empty State ──────────────────────────────────────────────────────── */

.warcal-empty {
  text-align: center;
  padding: 60px;
  color: #888;
  font-size: 1.2rem;
}

/* ============================================================
   Military-Form Popover
   Adapted from webapp-dev unitpower popover design.
   ============================================================ */

.warcal-popover {
  position: fixed;
  z-index: 500;
  background-color: #e8e6e1;     /* aged paper */
  border: 1px solid #999;
  box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);
  width: min(550px, calc(100vw - 20px));
  padding: 15px;
  color: #1a1a1a;
  text-transform: uppercase;
  transform: rotate(-0.5deg);    /* slight physical lean */
  overflow: hidden;
  font-family: 'VT323', monospace;
}

.warcal-popover.hidden { display: none; }

/* Paper-grain texture overlay */
.warcal-popover::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url('https://www.transparenttextures.com/patterns/paper-fibers.png');
  opacity: 0.3;
  pointer-events: none;
}

.warcal-popover .watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-30deg);
  font-size: 80px;
  font-weight: 900;
  color: rgba(0, 0, 0, 0.05);
  pointer-events: none;
  z-index: 0;
  white-space: nowrap;
}

/* Grid helpers */
.warcal-popover .grid-row {
  display: flex;
  border-left:  2px solid #1a1a1a;
  border-right: 2px solid #1a1a1a;
}

.warcal-popover .b-top         { border-top:    2px solid #1a1a1a; }
.warcal-popover .b-bottom      { border-bottom: 2px solid #1a1a1a; }
.warcal-popover .b-thin-bottom { border-bottom: 1px solid #1a1a1a; }

.warcal-popover .box {
  padding: 4px 8px;
  border-right: 1px solid #1a1a1a;
  position: relative;
  z-index: 1;
}

.warcal-popover .box:last-child { border-right: none; }

.warcal-popover .label {
  font-size: 10px;
  font-weight: bold;
  display: block;
  line-height: 1;
}

.warcal-popover .data {
  font-family: "Courier New", Courier, monospace;
  font-weight: bold;
  font-size: 16px;
  color: #111;
}

.warcal-popover .header-title {
  flex-grow: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
  padding: 10px;
  position: relative;
  z-index: 1;
}

/* Weapon table */
.warcal-popover table {
  width: 100%;
  border-collapse: collapse;
  margin-top: -1px;
  position: relative;
  z-index: 1;
}

.warcal-popover th,
.warcal-popover td {
  border: 1px solid #1a1a1a;
  padding: 4px;
  text-align: left;
  font-size: 11px;
}

.warcal-popover th { background: rgba(0, 0, 0, 0.05); }

.warcal-popover .weapon-data {
  font-family: "Courier New", Courier, monospace;
  font-size: 13px;
  font-weight: bold;
}

/* Override global striping inside popover */
.warcal-popover table tr:nth-child(even) td,
.warcal-popover table tr:nth-child(odd)  td { background: transparent !important; }
.warcal-popover table tr:hover td           { background: rgba(0,0,0,0.03) !important; }

.warcal-popover .remarks-section {
  height: 60px;
  padding: 5px;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  position: relative;
  z-index: 1;
  flex: 1;
}

.warcal-popover .reference-image {
  width: 100%;
  transform: rotate(1deg);
  border: 5px solid #fff;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
}

/* ── Pagination ────────────────────────────────────────────────────────── */

.warcal-pagination {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px 6px;
  font-family: 'VT323', monospace;
  text-transform: uppercase;
  color: var(--ink-black);
}

.pg-info {
  font-size: 14px;
  color: var(--panel-shadow);
  letter-spacing: 0.04em;
}

.pg-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.pg-btn {
  font-family: 'VT323', monospace;
  font-size: 18px;
  line-height: 1;
  padding: 2px 10px;
  background: var(--panel-grey);
  background-image: linear-gradient(to bottom, var(--panel-grey), #8e8e8e);
  border: 2px solid var(--panel-border);
  border-bottom-color: var(--panel-shadow);
  border-right-color:  var(--panel-shadow);
  color: var(--ink-black);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-width: 32px;
  text-align: center;
}

.pg-btn:hover:not(:disabled) {
  background: #b8b8b8;
  border-color: var(--ink-black);
}

.pg-btn:active:not(:disabled) {
  border-top-color:  var(--panel-shadow);
  border-left-color: var(--panel-shadow);
  border-bottom-color: var(--panel-border);
  border-right-color:  var(--panel-border);
}

.pg-btn.pg-active {
  background: var(--ink-black);
  color: var(--green-bar);
  border-color: var(--ink-black);
  cursor: default;
}

.pg-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.pg-ellipsis {
  font-size: 18px;
  padding: 0 4px;
  color: var(--panel-shadow);
}
