/* Tooltip styles for Reason/Stats columns */
.custom-tooltip {
    position: absolute;
    z-index: 9999;
    background: #222;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    max-width: 220px;
    pointer-events: none;
    white-space: pre-line;
    opacity: 0.97;
    transition: opacity 0.15s;
}
.tooltip-trigger {
    cursor: pointer;
}
.no-underline {
    text-decoration: none !important;
}
/* Torn Ranked War Tracker - Styles */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --success: #00d26a;
    --warning: #ffc107;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --border-color: #2a2a4a;
    --hospital-red: #ff4757;
    --hospital-yellow: #ffa502;
    --online-green: #2ed573;
    --idle-yellow: #ffa502;
    --offline-gray: #636e72;
    --claimed-purple: #a55eea;
    --traveling-blue: #54a0ff;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.4;
    font-size: 13px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 8px 12px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 8px;
}

header h1 {
    font-size: 1.3rem;
    color: var(--accent);
}

.header-stats {
    display: flex;
    gap: 15px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    align-items: center;
}

.btn-settings {
    padding: 3px 8px;
    font-size: 0.75rem;
    margin-left: auto;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-indicator.connected {
    color: var(--success);
}

.status-indicator.disconnected {
    color: var(--hospital-red);
}

/* Config Panel */
.config-panel {
    display: none;
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
}

.config-panel.visible {
    display: block;
}

.config-panel h3 {
    margin-bottom: 10px;
    color: var(--accent);
    font-size: 0.95rem;
}

.config-form {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.form-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.form-group input {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    width: 200px;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group .help-text {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.form-group .help-text a {
    color: var(--accent);
    text-decoration: none;
}

.form-group .help-text a:hover {
    text-decoration: underline;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    cursor: pointer;
}

.checkbox-label span {
    color: var(--text-primary);
}

/* User Status Bar */
.user-status-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--bg-secondary);
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.user-status-bar.hidden {
    display: none;
}

.user-status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-status-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 35px;
}

.bar-container {
    width: 100px;
    height: 16px;
    background: var(--bg-primary);
    border-radius: 3px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

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

.health-bar .bar-fill {
    background: linear-gradient(90deg, #ff4757, #ff6b81);
}

.energy-bar .bar-fill {
    background: linear-gradient(90deg, #ffa502, #ffbe3d);
}

.nerve-bar .bar-fill {
    background: linear-gradient(90deg, #3742fa, #5352ed);
}

.bar-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-primary);
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
}

.cooldown-item {
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 2px 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    min-width: 55px;
}

.cooldown-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.cooldown-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 60px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.cooldown-value.ready {
    color: var(--success);
}

.cooldown-value.active {
    color: var(--warning);
}

.status-item {
    padding: 4px 10px;
    border-radius: 4px;
    margin-left: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.status-state {
    font-size: 0.8rem;
    font-weight: 600;
}

.status-state.okay {
    color: var(--success);
}

.status-state.hospital {
    color: var(--hospital-red);
}

.status-state.jail {
    color: var(--warning);
}

.status-state.traveling {
    color: var(--traveling-blue);
}

/* Clickable stat items */
.clickable-stat {
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, background 0.15s ease;
}

.clickable-stat:hover {
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* Chain display */
.chain-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 12px;
    background: var(--bg-primary);
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.chain-item.active {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

.chain-item.warning {
    border-color: var(--warning);
    background: rgba(255, 193, 7, 0.15);
    animation: chain-pulse 1s ease-in-out infinite;
}

.chain-item.critical {
    border-color: var(--hospital-red);
    background: rgba(255, 71, 87, 0.2);
    animation: chain-pulse 0.5s ease-in-out infinite;
}

@keyframes chain-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.chain-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.chain-count {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.chain-count.bonus-close {
    color: var(--warning);
}

.chain-timer {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chain-timer.warning {
    color: var(--warning);
}

.chain-timer.critical {
    color: var(--hospital-red);
    font-weight: 600;
}

/* Chain bonus alert overlay */
.chain-alert-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(233, 69, 96, 0.95);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    animation: alert-flash 0.5s ease-in-out infinite;
}

.chain-alert-overlay.visible {
    display: flex;
}

@keyframes alert-flash {
    0%, 100% { background: rgba(233, 69, 96, 0.95); }
    50% { background: rgba(255, 107, 107, 0.95); }
}

.chain-alert-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.chain-alert-emoji {
    font-size: 5rem;
    animation: bounce 0.5s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.chain-alert-text {
    font-size: 2.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.chain-alert-count {
    font-size: 4rem;
    font-weight: 800;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* Buttons */
.btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

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

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 4px 8px;
}

.btn-secondary:hover {
    background: var(--bg-secondary);
}

.btn-claim {
    background: var(--success);
    color: white;
    padding: 3px 8px;
    font-size: 0.75rem;
}

.btn-claim:hover {
    background: #00b359;
}

.btn-claim.claimed {
    background: var(--claimed-purple);
    opacity: 0.7;
}

.btn-claim.claimed-by-me {
    background: var(--warning);
    color: #333;
}

.btn-claim:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-unclaim {
    background: var(--hospital-red);
    color: white;
    padding: 3px 8px;
    font-size: 0.75rem;
}

/* Settings Button Top */
.action-controls-top {
    display: none;
}

/* Controls */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.filter-section {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 3px;
}

.filter-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-right: 2px;
}

.filter-btn {
    padding: 3px 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.75rem;
}

.filter-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Range Filters */
.range-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
    width: 100%;
}

.range-filter {
    display: flex;
    align-items: center;
    gap: 4px;
}

.range-input {
    width: 55px;
    padding: 3px 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 3px;
    font-size: 0.75rem;
    text-align: center;
}

.range-input:focus {
    outline: none;
    border-color: var(--accent);
}

.range-select {
    padding: 3px 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 3px;
    font-size: 0.75rem;
    cursor: pointer;
}

.range-select:focus {
    outline: none;
    border-color: var(--accent);
}

.range-separator {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.btn-small {
    padding: 3px 6px;
    font-size: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-small:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-small.loading {
    opacity: 0.6;
    cursor: wait;
}

/* Stats column styling */
.stats-cell {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.stats-cell.has-stats {
    color: var(--text-primary);
}

.stats-cell .stats-value {
    font-weight: 500;
}

/* YATA ML estimates - highlighted styling */
.stats-cell .stats-value.yata {
    color: #00d26a;
    font-weight: 600;
    cursor: help;
}

/* FFScouter estimates - highlighted styling */
.stats-cell .stats-value.ffscouter {
    color: #4fc3f7;
    font-weight: 600;
    cursor: help;
}

/* Stats source badge */
.stats-source {
    display: inline-block;
    font-size: 0.55rem;
    font-weight: 700;
    padding: 1px 3px;
    border-radius: 3px;
    margin-left: 3px;
    vertical-align: super;
    line-height: 1;
    opacity: 0.8;
}

.stats-source.ff {
    background: rgba(79, 195, 247, 0.2);
    color: #4fc3f7;
}

.stats-source.ff-score {
    font-size: 0.6rem;
    padding: 1px 4px;
    font-weight: 700;
    border-radius: 3px;
    white-space: nowrap;
}
.stats-source.yata {
    background: rgba(0, 210, 106, 0.2);
    color: #00d26a;
}
.stats-cell .stats-age {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-left: 2px;
}
.action-controls {
    display: flex;
    gap: 6px;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: 0;
    padding: 0;
    background: var(--bg-secondary);
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 12px;
    border-right: 1px solid var(--border-color);
    min-width: 0;
    flex: 1;
}

.stat:last-child {
    border-right: none;
}

.stat.clickable {
    cursor: pointer;
    transition: background 0.15s ease;
}

.stat.clickable:hover {
    background: var(--bg-card);
}

.stat-value {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--accent);
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Target Table */
.target-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.target-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: 6px;
    overflow: hidden;
    min-width: 600px; /* Ensure table has minimum width */
}

.target-table thead {
    background: var(--bg-card);
}

.target-table th {
    padding: 8px 10px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    overflow: hidden;
        text-overflow: ellipsis;
}

.target-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.target-table th.sortable:hover {
    color: var(--text-primary);
}

.sort-icon {
    font-size: 0.65rem;
    margin-left: 3px;
    opacity: 0.5;
}

.target-table th.sorted .sort-icon {
    opacity: 1;
    color: var(--accent);
}

.target-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    overflow: hidden;
        text-overflow: ellipsis;
}

/* Column widths for consistent alignment */
.target-table th:nth-child(1),
.target-table td:nth-child(1) {
    width: 68px;
}

/* Timer */
.target-table th:nth-child(2),
.target-table td:nth-child(2) {
    width: 160px;
}

/* Name */
.target-table th:nth-child(3),
.target-table td:nth-child(3) {
    width: 36px;
    text-align: center;
}

/* Level */
.target-table th:nth-child(4),
.target-table td:nth-child(4) {
    width: 95px;
}

/* Stats */
.target-table th:nth-child(5),
.target-table td:nth-child(5) {
    width: 70px;
}

/* Status */
.target-table th:nth-child(6),
.target-table td:nth-child(6) {
    width: 170px;
}

/* Reason */
.target-table th:nth-child(7),
.target-table td:nth-child(7) {
    width: 72px;
}

/* Claimed */
.target-table th:nth-child(8),
.target-table td:nth-child(8) {
    width: 64px;
}

/* Action */
.target-table tbody tr {
    transition: background 0.1s ease;
}

.target-table tbody tr:hover {
    background: var(--bg-card);
}

.target-table tbody tr.traveling {
    opacity: 0.5;
}

.target-table tbody tr.claimed {
    opacity: 0.6;
}

.target-table tbody tr.claimed-by-me {
    opacity: 1;
    background: rgba(255, 193, 7, 0.1);
}

.target-table tbody tr.out {
    background: rgba(0, 210, 106, 0.05);
}

.target-table tbody tr.about-to-exit {
    background: rgba(255, 165, 2, 0.1);
    animation: pulse-row 1s infinite;
}

@keyframes pulse-row {
    0%, 100% { background: rgba(255, 165, 2, 0.1); }
    50% { background: rgba(255, 165, 2, 0.2); }
}

.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

/* Timer Display */
.timer-cell {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    font-weight: bold;
    min-width: 65px;
}

.timer-cell.critical {
    color: var(--hospital-red);
    animation: blink 0.5s infinite;
}

.timer-cell.warning {
    color: var(--hospital-yellow);
}

.timer-cell.safe {
    color: var(--text-secondary);
}

.timer-cell.out {
    color: var(--success);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Player Name Cell */
.name-cell {
    /* Do NOT use display:flex on <td> - it breaks table column alignment */
}

.player-links {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
    }
    
    .player-links-spacer {
        flex: 0 0 auto;
        width: 4px;
    }
    
    .profile-link {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 120px;
}

.profile-link, .attack-link {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
}

.profile-link:hover {
    color: var(--accent);
}

.attack-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: var(--hospital-red);
    border-radius: 3px;
    font-size: 0.7rem;
    color: white;
    text-decoration: none;
    opacity: 0.8;
}

.attack-link:hover {
    opacity: 1;
    transform: scale(1.1);
}

.copy-target-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: #2196F3;
    border: none;
    border-radius: 3px;
    font-size: 0.7rem;
    color: white;
    cursor: pointer;
    opacity: 0.7;
    transition: all 0.2s;
    padding: 0;
}

.copy-target-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.copy-target-btn:active {
    transform: scale(0.95);
}

.badge {
    padding: 1px 4px;
    border-radius: 2px;
    font-size: 0.6rem;
    font-weight: bold;
    text-transform: uppercase;
}

.badge.medding {
    background: var(--warning);
    color: #333;
}

.badge.traveling {
    background: var(--traveling-blue);
    color: white;
}

/* Online Status */
.online-cell {
    /* Do NOT use display:flex on <td> - it breaks table column alignment */
    }
    
    .online-content {
    display: flex;
    align-items: center;
    gap: 4px;
}

.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.online-dot.online {
    background: var(--online-green);
    box-shadow: 0 0 6px var(--online-green);
}

.online-dot.idle {
    background: var(--idle-yellow);
}

.online-dot.offline {
    background: var(--offline-gray);
}

.online-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Reason Cell */
.reason-cell {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: normal;
    word-break: break-word;
}

/* Claim Cell */
.claim-cell {
    font-size: 0.75rem;
    color: var(--claimed-purple);
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toast {
    padding: 8px 12px;
    border-radius: 4px;
    background: var(--bg-card);
    border-left: 3px solid var(--accent);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.2s ease;
    max-width: 280px;
    font-size: 0.8rem;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--hospital-red);
}

.toast.warning {
    border-left-color: var(--warning);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 900px) {
    /* On tablets, keep stats bar more readable */
    .stats-bar {
        flex-wrap: wrap;
        gap: 2px;
    }
    
    .stat {
        min-width: calc(33.33% - 2px);  /* 3 columns on tablet */
        border-right: none;
        border: 1px solid var(--border-color);
        border-radius: 4px;
    }
    
    /* Slightly reduce table font on tablets */
    .target-table th,
    .target-table td {
        padding: 6px 8px;
        font-size: 0.72rem;
    }
}

/* ============================================
   MOBILE: 600px breakpoint
   ============================================ */
@media (max-width: 600px) {
    body {
        font-size: 14px;
    }

    .container {
        padding: 6px;
    }

    header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 0;
    }

    header h1 {
        font-size: 1.3rem;
        width: 100%;
    }

    .header-stats {
        flex-wrap: wrap;
        gap: 10px;
        width: 100%;
        font-size: 0.8rem;
    }

    .settings-text {
        display: none;
    }

    .btn-settings {
        padding: 3px 6px;
    }

    /* Hide nerve bar on mobile */
    .nerve-item {
        display: none;
    }

    .user-status-bar {
        gap: 6px;
        padding: 6px;
        flex-wrap: wrap;
    }

    .user-status-item {
        flex-basis: calc(50% - 3px);
        gap: 4px;
        padding: 5px;
    }

    .user-status-label {
        font-size: 0.72rem;
        min-width: 28px;
    }

    .bar-container {
        width: 100%;
        min-width: 70px;
        height: 16px;
    }

    .bar-text {
        font-size: 0.72rem;
    }

    .cooldown-item {
        flex-basis: calc(33.33% - 4px);
        min-width: 65px;
        padding: 5px;
    }

    .cooldown-label {
        font-size: 0.68rem;
    }

    .cooldown-value {
        font-size: 0.8rem;
    }

    .chain-item {
        flex-basis: 100%;
        padding: 5px 10px;
    }

    .view-toggle-compact {
        flex-basis: 100%;
        justify-content: center;
        padding: 4px;
    }

    .status-item {
        flex-basis: 100%;
        margin-left: 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .toggle-btn-compact {
        flex: 1;
        padding: 6px 12px;
        font-size: 0.75rem;
    }

    .stats-bar {
        flex-wrap: wrap;
        gap: 4px;
        padding: 4px;
    }

    .stat {
        padding: 6px 10px;
        min-width: calc(33.33% - 3px);
        flex: 1;
        border-right: none;
        border: 1px solid var(--border-color);
        border-radius: 4px;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .stat-label {
        font-size: 0.65rem;
    }

    .config-panel {
        padding: 10px;
    }

    .config-form {
        flex-direction: column;
        gap: 10px;
    }

    .form-group {
        width: 100%;
    }

    .form-group input {
        width: 100%;
        font-size: 14px;
        padding: 8px;
    }

    .filter-section {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
    }

    .filter-group {
        flex-wrap: wrap;
        flex: 1 1 calc(50% - 2px);
        min-width: calc(50% - 2px);
        gap: 2px;
        justify-content: center;
    }

    .filter-btn {
        padding: 2px 4px;
        font-size: 0.62rem;
        flex: 1;
        min-width: 0;
        text-align: center;
        border-radius: 2px;
    }

    .range-filters {
        gap: 4px;
        padding-top: 4px;
        margin-top: 4px;
    }

    .range-filter {
        flex-wrap: wrap;
        width: 100%;
        gap: 4px;
    }

    .range-select {
        flex: 1;
        font-size: 0.78rem;
        padding: 6px;
    }

    .target-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -6px;
        padding: 0 6px;
    }

    .target-table {
        font-size: 0.72rem;
        min-width: 580px;
    }

    .target-table th,
    .target-table td {
        padding: 6px 5px;
        font-size: 0.72rem;
    }

    .target-table th:nth-child(1),
    .target-table td:nth-child(1) {
        width: 55px;
    }

    .target-table th:nth-child(3),
    .target-table td:nth-child(3) {
        width: 30px;
        text-align: center;
    }

    .target-table th:nth-child(4),
    .target-table td:nth-child(4) {
        width: 85px;
    }

    .target-table th:nth-child(5),
    .target-table td:nth-child(5) {
        width: 52px;
    }

    .target-table th:nth-child(6),
    .target-table td:nth-child(6) {
        width: 85px;
    }

    .target-table th:nth-child(7),
    .target-table td:nth-child(7) {
        width: 55px;
    }

    .target-table th:nth-child(8),
    .target-table td:nth-child(8) {
        width: 54px;
    }

    .profile-link {
        max-width: 90px;
    }

    .stats-cell {
        font-size: 0.7rem !important;
        white-space: nowrap !important;
        line-height: 1.3;
    }

    .stats-cell .stats-value {
        font-size: 0.72rem !important;
        font-weight: 600;
    }

    .stats-source {
        font-size: 0.5rem !important;
        padding: 0px 2px !important;
    }

    .stats-source.ff-score {
        font-size: 0.52rem !important;
        padding: 1px 3px !important;
    }

    .timer-cell {
        font-size: 0.72rem;
        min-width: 55px;
        font-weight: 600;
    }

    .name-cell {
        font-size: 0.72rem;
        min-width: 100px;
    }

    .player-links {
        gap: 3px;
    }

    .player-links a,
    .player-links button {
        font-size: 0.68rem;
        padding: 2px 5px;
    }

    .profile-link {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .online-cell {
        font-size: 0.72rem;
        min-width: 50px;
    }

    .online-content {
        gap: 3px;
    }

    .online-dot {
        width: 7px;
        height: 7px;
    }

    .online-text {
        display: inline !important;
        font-size: 0.68rem;
    }

    .reason-cell {
        max-width: 90px;
        font-size: 0.68rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .claim-cell {
        font-size: 0.68rem;
        min-width: 50px;
    }

    .btn-claim,
    .btn-unclaim {
        padding: 5px 8px;
        font-size: 0.72rem;
        min-height: 28px;
        touch-action: manipulation;
    }
}

/* ============================================
   MOBILE: 400px breakpoint
   ============================================ */
@media (max-width: 400px) {
    body {
        font-size: 13px;
    }

    .container {
        padding: 4px;
    }

    header h1 {
        font-size: 1.1rem;
    }

    .header-stats {
        font-size: 0.72rem;
        gap: 8px;
    }

    .stat {
        padding: 5px 8px;
        min-width: calc(33.33% - 3px);
    }

    .stat-value {
        font-size: 1rem;
    }

    .stat-label {
        font-size: 0.6rem;
    }

    .user-status-bar {
        gap: 4px;
        padding: 4px;
    }

    .user-status-item {
        gap: 3px;
        flex-basis: calc(50% - 2px);
        padding: 4px;
    }

    .user-status-label {
        font-size: 0.68rem;
        min-width: 26px;
    }

    .bar-container {
        min-width: 60px;
        height: 14px;
    }

    .bar-text {
        font-size: 0.68rem;
    }

    .cooldown-item {
        flex-basis: calc(33.33% - 3px);
        min-width: 60px;
        padding: 4px;
    }

    .cooldown-value,
    .status-state {
        font-size: 0.72rem;
    }

    .cooldown-label {
        font-size: 0.62rem;
    }

    .chain-item {
        flex-basis: 100%;
        padding: 4px 8px;
        gap: 2px;
    }

    .view-toggle-compact {
        flex-basis: 100%;
    }

    .status-item {
        flex-basis: 100%;
    }

    .chain-label {
        font-size: 0.62rem;
    }

    .chain-count {
        font-size: 0.85rem;
    }

    .chain-timer {
        font-size: 0.68rem;
    }

    .toggle-btn-compact {
        padding: 5px 10px;
        font-size: 0.68rem;
    }

    .filter-group {
        min-width: calc(50% - 2px);
        gap: 1px;
    }

    .filter-btn {
        padding: 2px 3px;
        font-size: 0.58rem;
        min-width: 0;
        border-radius: 2px;
    }

    .range-select {
        font-size: 0.72rem;
        padding: 5px;
    }

    .target-table {
        font-size: 0.68rem;
        min-width: 540px;
    }

    .target-table th,
    .target-table td {
        padding: 5px 4px;
        font-size: 0.68rem;
    }

    .target-table th:nth-child(1),
    .target-table td:nth-child(1) {
        width: 50px;
    }

    .target-table th:nth-child(3),
    .target-table td:nth-child(3) {
        width: 26px;
    }

    .target-table th:nth-child(4),
    .target-table td:nth-child(4) {
        width: 78px;
    }

    .target-table th:nth-child(5),
    .target-table td:nth-child(5) {
        width: 45px;
    }

    .target-table th:nth-child(6),
    .target-table td:nth-child(6) {
        width: 75px;
    }

    .target-table th:nth-child(7),
    .target-table td:nth-child(7) {
        width: 50px;
    }

    .target-table th:nth-child(8),
    .target-table td:nth-child(8) {
        width: 50px;
    }

    .profile-link {
        max-width: 75px;
    }

    .stats-cell {
        font-size: 0.65rem !important;
    }

    .stats-cell .stats-value {
        font-size: 0.68rem !important;
    }

    .stats-source.ff-score {
        font-size: 0.48rem !important;
    }

    .timer-cell {
        min-width: 50px;
        font-size: 0.68rem;
    }

    .name-cell {
        min-width: 90px;
        font-size: 0.68rem;
    }

    .player-links a,
    .player-links button {
        font-size: 0.62rem;
        padding: 2px 4px;
    }

    .online-cell {
        min-width: 45px;
        font-size: 0.68rem;
    }

    .online-text {
        font-size: 0.62rem;
    }

    .reason-cell {
        max-width: 80px;
        font-size: 0.62rem;
    }

    .claim-cell {
        font-size: 0.62rem;
        min-width: 48px;
    }

    .btn-claim,
    .btn-unclaim {
        padding: 4px 6px;
        font-size: 0.68rem;
        min-height: 26px;
    }

    .config-form {
        gap: 8px;
    }

    .form-group input {
        font-size: 13px;
        padding: 6px;
    }
}

/* Leaderboard Sidebar Styles */
.main-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 12px;
}

.sidebar {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 12px;
    height: fit-content;
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

.sidebar-section h3 {
    font-size: 0.95rem;
    color: var(--accent);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}

.lb-tab {
    flex: 1;
    padding: 4px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.lb-tab:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.lb-tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.leaderboard-content {
    font-size: 0.8rem;
}

.leaderboard-content.hidden {
    display: none;
}

.lb-entry {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    margin-bottom: 4px;
    background: var(--bg-card);
    border-radius: 4px;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.lb-entry:hover {
    background: var(--bg-primary);
    border-left-color: var(--accent);
}

.lb-entry.rank-1 {
    border-left-color: gold;
    background: rgba(255, 215, 0, 0.1);
}

.lb-entry.rank-2 {
    border-left-color: silver;
    background: rgba(192, 192, 192, 0.1);
}

.lb-entry.rank-3 {
    border-left-color: #cd7f32;
    background: rgba(205, 127, 50, 0.1);
}

.lb-rank {
    font-weight: bold;
    color: var(--text-secondary);
    min-width: 20px;
    margin-right: 8px;
}

.lb-entry.rank-1 .lb-rank {
    color: gold;
}

.lb-entry.rank-2 .lb-rank {
    color: silver;
}

.lb-entry.rank-3 .lb-rank {
    color: #cd7f32;
}

.lb-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.lb-value {
    font-weight: bold;
    color: var(--success);
    margin-left: 8px;
}

.lb-entry.empty {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    border: none;
    background: transparent;
}

.main-content {
    min-width: 0;
}

/* View Toggle */
.view-toggle {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 12px 0;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.toggle-btn {
    padding: 8px 20px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.toggle-btn:hover {
    background: var(--accent);
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--accent);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(233, 69, 96, 0.3);
}

/* Faction Overview Table */
.faction-overview-container {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.faction-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: 6px;
    overflow: hidden;
    min-width: 800px; /* Ensure minimum width for horizontal scroll */
}

.faction-table thead {
    background: var(--bg-card);
}

.faction-table th {
    padding: 8px 10px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
        text-transform: uppercase;
        border-bottom: 1px solid var(--border-color);
        white-space: nowrap;
}

.faction-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    white-space: nowrap;
    }
    
    /* Column sizing */
    .faction-table th:nth-child(2),
    .faction-table td:nth-child(2) {
        width: 40px;
        /* Level - very thin */
    }
    
    .faction-table th:nth-child(3),
    .faction-table td:nth-child(3) {
        width: 80px;
        /* Status */
    }
    
    .faction-table th:nth-child(4),
    .faction-table td:nth-child(4),
    .faction-table th:nth-child(5),
    .faction-table td:nth-child(5) {
        width: 120px;
        /* Life and Energy bars */
    }
    
    .faction-table tbody tr {
        transition: background 0.1s ease;
}

.faction-table tbody tr:hover {
    background: var(--bg-card);
}

.faction-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.faction-table th.sortable:hover {
    color: var(--text-primary);
}

.faction-table th.sorted .sort-icon {
    opacity: 1;
    color: var(--accent);
}
.faction-table a {
    color: var(--accent);
    text-decoration: none;
}

.faction-table a:hover {
    text-decoration: underline;
}

/* Status colors in faction table */
.status-okay {
    color: var(--success);
}

.status-hospital {
    color: var(--hospital-red);
    font-weight: 600;
}

.status-jail {
    color: var(--warning);
    font-weight: 600;
}

.status-traveling {
    color: var(--traveling-blue);
    font-weight: 500;
}

/* Mini bars for faction table */
.bar-mini {
    position: relative;
    width: 100px;
    height: 18px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
    display: inline-block;
}

.bar-fill-mini {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    transition: width 0.3s;
}

.life-bar-mini {
    background: linear-gradient(90deg, #ff4757, #ff6348);
}

.energy-bar-mini {
    background: linear-gradient(90deg, #00d26a, #2ed573);
}

.drug-bar-mini {
    background: linear-gradient(90deg, #a55eea, #8854d0);
}

.med-bar-mini {
    background: linear-gradient(90deg, #0abde3, #48dbfb);
}

.booster-bar-mini {
    background: linear-gradient(90deg, #ee5a6f, #f368e0);
}
.bar-text-mini {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.no-data,
.error {
    text-align: center;
    padding: 20px !important;
    color: var(--text-secondary);
}

.error {
    color: var(--hospital-red);
}
/* View Toggle Compact (in user status bar) */
.view-toggle-compact {
    display: flex;
    gap: 4px;
    padding: 2px;
    background: var(--bg-card);
    border-radius: 4px;
}

.toggle-btn-compact {
    padding: 4px 10px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    transition: all 0.2s;
}

.toggle-btn-compact:hover {
    background: rgba(233, 69, 96, 0.2);
    color: var(--text-primary);
}

.toggle-btn-compact.active {
    background: var(--accent);
    color: var(--text-primary);
}

/* Faction table sortable headers */
.faction-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.faction-table th.sortable:hover {
    color: var(--text-primary);
}

/* Energy stacked indicator */
.energy-stacked {
    font-size: 11px;
    color: var(--warning);
    margin-left: 4px;
}

/* Mobile responsive styles for faction table */
@media (max-width: 600px) {
    .faction-overview-container {
        padding: 8px;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            margin: 0 -8px;
        }
        
        .faction-table {
            font-size: 0.75rem;
            min-width: 100%;
        }
        
        .faction-table th,
        .faction-table td {
            padding: 6px 8px;
            font-size: 0.75rem;
        }
        
        .bar-mini {
            width: 80px;
            height: 16px;
        }
        
        .bar-text-mini {
            font-size: 0.7rem;
        }
        
        /* Keep all columns visible but adjust spacing */
        .faction-table td,
        .faction-table th {
            white-space: nowrap;
        }
        
        /* Name column */
        .faction-table td:first-child {
            min-width: 100px;
            font-size: 0.75rem;
        }
        
        /* Status icons and cooldowns */
        .faction-table td {
            font-size: 0.7rem;
        }
        }
        
        @media (max-width: 400px) {
            .faction-overview-container {
        padding: 6px;
    }
    
    .faction-table {
        font-size: 0.7rem;
    }
    
    .faction-table th,
    .faction-table td {
        padding: 5px 6px;
            font-size: 0.7rem;
    }
    
    .bar-mini {
        width: 70px;
        height: 14px;
    }
    
    .bar-text-mini {
        font-size: 0.65rem;
        }
        
        .faction-table td:first-child {
            min-width: 90px;
            font-size: 0.7rem;
    }
}

@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        display: none;
    }
}
