/* ========== Base Reset & Theme ========== */
* { box-sizing: border-box; }
:root {
  --bg: #0d1117;
  --panel: #111827;
  --panel-2: #0f172a;
  --card: #0b1220;
  --text: #cbd5e1;
  --muted: #94a3b8;
  --brand: #eab308;
  --accent: #38bdf8;
  --danger: #ef4444;
  --border: #1f2937;
  --border-soft: #1b2636;
  --green: #48d597;
  --amber: #ffcd4f;
  --grey: #7d8ea3;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

/* ========== Header ========== */
.app-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}
.app-header .brand { grid-column: 2; }

.app-header-2 {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 0 16px 12px 16px;
}
.app-header-2 .war-toggle { grid-column: 1; display: inline-flex; align-items: center; gap: 8px; }
.app-header-2 .key-panel { grid-column: 3; }
.war-label { color: #cde4ff; font-weight: 600; }
#warModeMeta.badge { margin-left: 4px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 20px; }
.brand h1 { font-size: 16px; margin: 0; color: var(--text); }

.key-panel { display: flex; gap: 8px; align-items: center; }
.key-panel input {
  width: 170px; max-width: 52vw;
  background: #0b1628;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}
.key-panel input::placeholder { color: #5b6b83; }
.key-panel .btn { white-space: nowrap; }

/* ========== TABS ========== */
.main-tabs {
    display: flex;
    justify-content: center;
    gap: 2px;
    background: var(--border);
    padding-top: 1px;
}
.main-tab {
    flex: 1;
    max-width: 200px;
    background: var(--panel);
    color: var(--muted);
    border: none;
    padding: 12px;
    cursor: pointer;
    font-weight: 600;
    border-top: 2px solid transparent;
}
.main-tab:hover { background: var(--panel-2); color: var(--text); }
.main-tab.active {
    background: var(--bg);
    color: var(--accent);
    border-top-color: var(--accent);
}

.sub-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.sub-tab {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 2px solid transparent;
}
.sub-tab.active {
    color: var(--text);
    border-bottom-color: var(--green);
}

/* ========== Buttons & Badges ========== */
.btn {
  background: #142033;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.btn:hover { background: #172640; }
.btn.primary { background: #173153; border-color: #204166; color: #dbeafe; }
.btn.primary:hover { background: #1b3b66; }
.btn.tiny { padding: 6px 10px; border-radius: 6px; font-size: 12px; }
.btn.outline { background: transparent; }
.btn.danger { background: #3b0f12; border-color: #5b1a1f; color: #fecaca; }
.btn.danger:hover { background: #4a1418; }

.badge {
  background: #182235;
  color: #e2e8f0;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
}

/* ========== Content Layout ========== */
.content {
  display: grid;
  grid-template-columns: 1.0fr 1.0fr;
  gap: 16px;
  padding: 16px;
}

.panel .card {
  background: linear-gradient(180deg, var(--panel), var(--card));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.card.stretch { height: calc(100% - 0px); display: flex; flex-direction: column; }

.card-head.roster-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.card-head.roster-head h2 {
  margin: 0;
  font-size: 16px;
}

/* ========== Intel Tables ========== */
.intel-card {
    height: 80vh; /* Fixed height for scrolling */
    display: flex;
    flex-direction: column;
}
.table-wrapper {
    flex: 1;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.intel-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
}
.intel-table th, .intel-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    white-space: nowrap;
}
/* Sticky Headers */
.intel-table thead th {
    position: sticky;
    top: 0;
    background: var(--panel-2);
    z-index: 10;
    font-weight: 600;
    color: var(--muted);
}
.intel-table thead tr:nth-child(2) th {
    top: 29px; /* Height of first header row */
}

/* Sortable Headers */
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--accent); background-color: var(--panel-2); }
.sort-asc::after { content: " ▲"; color: var(--accent); }
.sort-desc::after { content: " ▼"; color: var(--accent); }

/* Sticky Columns (Name & Level) */
.intel-sticky-col {
    position: sticky;
    left: 0;
    background: var(--panel);
    z-index: 20;
    border-right: 2px solid var(--border);
}
.intel-sticky-col-2 {
    position: sticky;
    left: 120px; /* Adjust based on name width */
    background: var(--panel);
    z-index: 20;
    border-right: 2px solid var(--border);
}
/* Sticky Corners */
.sticky-corner-1 {
    position: sticky;
    top: 0; left: 0;
    z-index: 30 !important;
    background: var(--panel-2) !important;
}
.sticky-corner-2 {
    position: sticky;
    top: 29px; left: 0;
    z-index: 30 !important;
    background: var(--panel-2) !important;
}

/* Activity Cells */
.intel-cell { text-align: center; font-weight: bold; width: 30px; }
.status-A { background: #14532d; color: #86efac; } /* Green */
.status-I { background: #713f12; color: #fde047; } /* Amber */
.status-O { background: #450a0a; color: #fca5a5; } /* Red */
.status-M { background: #1f2937; color: #4b5563; } /* Missing */

/* Drug Cells */
.drug-table th { text-align: center; }
.intel-pos { color: var(--green); font-weight: bold; }
.intel-zero { color: var(--muted); opacity: 0.3; }
.text-center { text-align: center; }
.text-sm { font-size: 12px; }

.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.dot-A { background: #22c55e; }
.dot-I { background: #eab308; }
.dot-O { background: #ef4444; }

/* ========== Other CSS (Retained) ========== */
.switch { position: relative; display: inline-block; width: 50px; height: 28px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; cursor: pointer; background: #344256; border-radius: 999px; transition: .2s ease; }
.slider::before { content: ""; position: absolute; height: 20px; width: 20px; left: 4px; top: 4px; background: #e2e8f0; border-radius: 999px; transition: .2s ease; }
.switch input:checked + .slider { background: #275d37; }
.switch input:checked + .slider::before { transform: translateX(22px); }
#warModeToggle.readOnly { pointer-events: none; opacity: .6; }

.enemy-row, .mine-row { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "left right" "mid mid"; gap: 8px; align-items: start; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: #0b1220; }
.enemy-row .left, .mine-row .left { grid-area: left; display: flex; align-items: center; gap: 8px; min-width: 0; }
.enemy-row .mid, .mine-row .mid { grid-area: mid; min-width: 0; }
.enemy-row .right, .mine-row .right { grid-area: right; display: flex; gap: 8px; justify-content: flex-end; align-items: start; }

a.name { color: #dbeafe; text-decoration: none; }
a.name:hover { text-decoration: underline; }

.PABS-status-dot { height: 10px; width: 10px; border-radius: 50%; display: inline-block; }
.dot-green { background-color: var(--green); }
.dot-goldenrod { background-color: var(--amber); }
.dot-gray { background-color: var(--grey); }

.status-green { color: #a7f3d0; }
.status-red   { color: #fecaca; }
.status-blue  { color: #bfdbfe; }
.status-yellow{ color: #fde68a; }

.PABS-selections-display { display: none !important; }
.PABS-selections-presence { font-size: 13px; color: #e5eefc; padding-left: 18px; margin-top: 2px; }
.tw-picker-link { display: inline-flex; gap: 6px; align-items: center; text-decoration: none; color: #4ea1ff; }
.tw-picker-link:hover { text-decoration: underline; }
.tw-picker-plain { color: inherit; }
.tw-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tw-presence-green { background: #48d597; }
.tw-presence-amber { background: #ffcd4f; }
.tw-presence-grey  { background: #7d8ea3; }
.tw-state { font-size: 11px; opacity: .85; padding: 0 6px; border-radius: 10px; border: 1px solid rgba(255,255,255,.08); }
.tw-state-green { color:#aaf2d0; background:#081a12; border-color:#134b30; }
.tw-state-blue  { color:#bfe1ff; background:#071420; border-color:#153953; }
.tw-state-red   { color:#ffb6b6; background:#140808; border-color:#4a141c; }

.PABS-ff-container { padding: 2px 0 4px 0; font-size: 0.7em; }
.PABS-ff-score { font-weight: 600; padding: 1px 5px; border-radius: 4px; display: inline-block; line-height: 1.1; }
.PABS-ff-stats { font-size: 1.2em; font-weight: 600; margin-left: 8px; vertical-align: middle; color: #e8ecf5; font-style: italic; }

.ff-range-wrap { background: #0b1626; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.ff-range-head { font-weight: 600; color: #cde4ff; margin-bottom: 6px; }
.ff-range-rows { display: grid; gap: 8px; }
.ff-row { display: grid; grid-template-columns: 42px 1fr 50px; align-items: center; gap: 8px; }
.ff-row label { color: #9fb6d4; font-size: 13px; }
.ff-range-val { font-variant-numeric: tabular-nums; color: #eaeef5; }
.ff-range-hint { margin-top: 6px; color: #93a6bf; font-size: 12px; }
.ff-row input[type="number"] { width: 100%; background: #0b1628; color: #eaeef5; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; outline: none; }
.ff-row input[type="number"]::-webkit-outer-spin-button, .ff-row input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ff-row input[type="number"] { -moz-appearance: textfield; }

.app-footer { display: grid; padding: 10px 16px; border-top: 1px solid var(--border); grid-template-columns: auto 1fr auto; color: var(--muted); }
.app-footer .footerMsg{ grid-column: 1; }
.app-footer .poll{ grid-column: 3; }
.poll-h { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.poll-b { font-size: 14px; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.75); backdrop-filter: blur(2px); z-index: 9999; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-content { background: var(--panel); border: 1px solid var(--border); width: 90%; max-width: 500px; height: 65vh; display: flex; flex-direction: column; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,0.5); overflow: hidden; }
.modal-header { padding: 12px 16px; background: var(--panel-2); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 16px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.chat-history { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.chat-msg { max-width: 85%; padding: 8px 12px; border-radius: 8px; font-size: 13px; position: relative; word-wrap: break-word; }
.my-msg { align-self: flex-end; background: #1e3a8a; border: 1px solid #2563eb; color: #dbeafe; border-bottom-right-radius: 2px; }
.other-msg { align-self: flex-start; background: var(--card); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 2px; }
.msg-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; opacity: 0.6; margin-bottom: 4px; }
.msg-user { font-weight: 600; color: var(--accent); }
.my-msg .msg-user { color: #93c5fd; }
.chat-form { padding: 12px; background: var(--panel-2); border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-form input { flex: 1; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; outline: none; font-size: 14px; }
.chat-form input:focus { border-color: var(--accent); }
.btn.chat-btn { color: var(--green); border-color: rgba(72, 213, 151, 0.3); }
.btn.chat-btn:hover { background: rgba(72, 213, 151, 0.1); }
.chat-link { color: var(--accent); text-decoration: underline; }

/* New Unread Styles (Badge) */
.btn.relative { position: relative; }
.chat-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: #ef4444; /* red */
    color: white;
    font-size: 10px;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid white;
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
    z-index: 10;
    pointer-events: none; /* Let clicks pass through to button */
}

/* Floating New Message Button */
.new-msg-btn { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.5); border: 1px solid var(--accent); }

/* Mobile Intel Cards */
.mobile-intel-cards { display: none; flex-direction: column; gap: 10px; max-height: 80vh; overflow-y: auto; }
.intel-card-mobile { background: var(--card); border: 1px solid var(--border); padding: 12px; border-radius: 8px; }
.intel-card-mobile h3 { margin: 0 0 8px 0; font-size: 16px; color: var(--text); display:flex; justify-content:space-between; }
.intel-card-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 13px; }
.stat-row { display: flex; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,0.05); padding: 4px 0; }
.val-pos { color: var(--green); font-weight: bold; }
.val-zero { color: var(--muted); opacity: 0.5; }

/* Mobile Intel Filter Control */
.mobile-intel-controls {
    display: none; /* Hidden on desktop */
    margin-bottom: 12px;
}
.mobile-intel-controls select {
    width: 100%;
    background: #0b1628;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
}

@media (max-width: 1100px) {
  .content { grid-template-columns: 1fr; }
  .enemy-row, .mine-row { grid-template-columns: 1fr; grid-template-areas: "left" "mid" "right"; }
  .enemy-row .right, .mine-row .right { justify-content: flex-start; }
  .ov-top { grid-template-columns: 1fr 1fr; }
  #enemyPanel.enemy-collapsed { display: none !important; }
  
  /* Mobile Intel View */
  .mobile-intel-controls { display: block; }
  .hidden-mobile { display: none !important; }
}
@media (min-width: 1101px) {
  #toggleEnemyMobile { display: none !important; }
  .mobile-intel-cards { display: none !important; } /* Force hide cards on desktop */
  .hidden-desktop { display: none !important; }
}
.overview { padding: 12px 16px 0 16px; }
.ov-row { display: grid; gap: 12px; margin-bottom: 12px; }
.ov-top { grid-template-columns: repeat(3, 1fr); }
.tile { background: linear-gradient(180deg, var(--panel), var(--card)); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.tile-h { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tile-b { font-size: 14px; }
.ov-filters { grid-template-columns: 1fr; }
.filters label { margin-left: 8px; }
.mid .status-text { display: inline-block; margin-bottom: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }