/* MATRIX TABLE STYLES - RESPONSIVE UPGRADE */

/* Main Layout Grid - Mobile First: Single Column */
.matrix-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 40px;
}

@media (min-width: 1600px) {
    .matrix-layout { gap: 26px; margin-bottom: 55px; }
    .matrix-container { padding: 14px; }
    .matrix-header-title { padding: 18px; font-size: 1.05rem; }
    .legend-container { padding: 26px; }
    .troop-stats-card { padding: 14px; }
    .rc-value { font-size: 2.2rem; }
}

@media (min-width: 1920px) {
    .matrix-layout { gap: 30px; }
    .matrix-container { padding: 18px; }
    .matrix-header-title { padding: 20px; font-size: 1.1rem; }
    .legend-container { padding: 30px; }
}

/* Desktop: Sidebar on right */
@media (min-width: 992px) {
    .matrix-layout {
        flex-direction: row;
        align-items: flex-start;
    }
}

/* POINTS: Verlauf zwischen Header und Tabelle, Tabelle volle Breite */
.matrix-layout.matrix-layout--points {
    flex-direction: column;
}
@media (min-width: 992px) {
    .matrix-layout.matrix-layout--points {
        flex-direction: column;
    }
}

.matrix-sidebar.matrix-sidebar--history {
    max-height: 240px;
}
.matrix-sidebar.matrix-sidebar--history .archive-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-bottom: 0;
    border-left: 3px solid transparent;
    padding: 10px 12px;
    margin: 4px 6px 0 0;
    border-radius: 6px;
}
.matrix-sidebar.matrix-sidebar--history {
    overflow-y: auto;
}
@media (min-width: 992px) {
    .matrix-sidebar.matrix-sidebar--history {
        width: 100%;
        max-height: 180px;
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 0;
    }
    .matrix-sidebar.matrix-sidebar--history h4 {
        width: 100%;
        margin: 0 0 6px 0;
    }
}

.matrix-main {
    flex: 4;
    min-width: 0; /* Prevents flex items from overflowing container */
    width: 100%;
}

/* SIDEBAR */
.matrix-sidebar {
    width: 100%; /* Mobile full width */
    background: var(--card-bg);
    border: 1px solid #333;
    border-radius: var(--radius-medium);
    padding: 15px;
    max-height: 400px; /* Limit height on mobile */
    overflow-y: auto;
}

@media (min-width: 992px) {
    .matrix-sidebar {
        flex: 1;
        min-width: 250px;
        max-height: 80vh;
    }
}

.archive-link {
    display: block;
    padding: 12px; /* Bigger touch target */
    border-bottom: 1px solid #333;
    color: var(--text-gray);
    font-size: 14px; /* Readable text */
    text-decoration: none;
    transition: 0.2s;
    border-left: 3px solid transparent;
}
.archive-link:hover {
    background: rgba(255,255,255,0.05);
    color: white;
    padding-left: 15px;
}
.archive-link.active {
    color: var(--accent-glow);
    border-left-color: var(--accent-red);
    background: rgba(138, 12, 12, 0.1);
}

/* MATRIX CONTAINER (Card/Wrapper) */
.matrix-container {
    background: #111;
    border: 1px solid #333;
    border-radius: var(--radius-medium);
    padding: 10px; /* More padding */
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.matrix-header-title {
    background: #222;
    color: var(--accent-glow);
    padding: 15px; /* Comfortable padding */
    font-size: 1rem;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 10px;
}

/* TABELLE - Responsive Card View approach for very small screens or scroll */
.table-scroll-wrapper { 
    overflow-x: hidden; 
    -webkit-overflow-scrolling: touch;
    margin: 0;
    padding: 0;
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
    background: #0f1012; 
    font-size: 0.9rem; /* Bigger font for readability */
    font-family: 'Arial', sans-serif;
    color: #ccc;
    min-width: 100%;
    table-layout: fixed;

    /* Einheitliche Schriftgröße in den Mitglieder-Zeilen (wie die Zahlen-Inputs) */
    --matrix-cell-font-size: 11px;
}

@media (min-width: 1600px) {
    .matrix-table { font-size: 1rem; }
    .matrix-table td { height: 34px; }
}

/* Spaltenbreiten: so bleibt alles innerhalb des Viewports */
.matrix-table th.col-tiny,
.matrix-table td.col-tiny {
    width: 40px;
}

.matrix-table th.col-rank,
.matrix-table td.personal-rank-cell {
    width: 64px;
    text-align: left;
    color: #aaa;
    font-weight: bold;
    padding-left: 8px;
}

.matrix-table th.col-name,
.matrix-table td.personal-name-cell {
    width: 190px;
}

.matrix-table th {
    background: #1a1a1a;
    color: #eee;
    border: 1px solid #444;
    padding: 12px 10px; /* Touch friendly padding */
    font-weight: bold;
    text-align: left; /* Better readability */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* STATS GRID */
.stats-grid {
    display: none; /* Default hidden as per logic */
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* LEGEND & TABS (Moved from inline styles) */
.tab-container { display: flex; gap: 10px; margin-bottom: 20px; border-bottom: 1px solid #333; padding-bottom: 10px; }
.tab-btn { background: rgba(0,0,0,0.4); border: 1px solid #444; color: #888; padding: 10px 25px; cursor: pointer; font-size: 1rem; transition: all 0.3s; border-radius: 4px; }
.tab-btn:hover { background: rgba(255,255,255,0.05); color: white; }
.tab-btn.active { background: var(--accent-red-glow); border-color: var(--accent-red); color: white; box-shadow: 0 0 15px rgba(255,0,0,0.2); }

@media (max-width: 900px) {
    .tab-container { flex-wrap: wrap; }
    .tab-btn { flex: 1 1 auto; min-width: 120px; font-size: 0.85rem; padding: 8px 15px; }
}

.legend-container { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 30px; align-items: flex-start; }
.legend-group { background: rgba(255,255,255,0.03); border: 1px solid #333; border-radius: 5px; padding: 10px; min-width: 200px; }
.legend-item { display: flex; align-items: center; gap: 10px; padding: 5px; border-radius: 4px; cursor: pointer; transition: background 0.2s; }
.legend-item:hover { background: rgba(255,255,255,0.1); }
.legend-subgroup { margin-left: 20px; padding-left: 10px; border-left: 2px solid #444; margin-top: 5px; }
.color-badge { padding: 2px 8px; border-radius: 4px; text-align: center; font-weight: bold; color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.8); font-size: 0.75rem; min-width: 40px; border: 1px solid rgba(255,255,255,0.2); }

@media (max-width: 1200px) {
    .legend-container { flex-direction: column; }
    .legend-group { min-width: 100%; }
}

/* RECORD CARD (Counter - Troop Stats) */
.troop-stats-card {
    display: flex;
    justify-content: space-around;
    background: #111;
    border: 1px solid #333;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 30px;
}
.rc-content { display: flex; flex-direction: column; align-items: center; }
.rc-label { font-size: 0.8rem; color: #888; margin-bottom: 5px; }
.rc-value { font-size: 2rem; color: white; font-weight: bold; text-shadow: 0 0 10px rgba(255,255,255,0.2); }

@media (max-width: 600px) {
    .troop-stats-card { flex-direction: column; gap: 15px; padding: 15px; }
    .rc-value { font-size: 1.8rem; }
}

/* GRUPPEN HEADER (Dunkle Varianten der Farben) */
.group-fb { background: rgba(139, 0, 0, 0.2) !important; color: #ffcccc !important; } /* Fortbildung: Rotstich */
.group-tr { background: rgba(0, 0, 139, 0.2) !important; color: #ccccff !important; } /* Training: Blaustich */
.group-to { background: rgba(0, 100, 0, 0.2) !important; color: #ccffcc !important; } /* Tryouts: Grünstich */
.group-no { background: rgba(255, 140, 0, 0.15) !important; color: #ffe5cc !important; } /* Naval: Orange */
.group-result { background: #333 !important; border-bottom: 2px solid #555 !important; color: white !important; }

/* ZELLEN */
.matrix-table td {
    border: 1px solid #333;
    padding: 3px;
    text-align: center;
    vertical-align: middle;
    height: 30px;
    white-space: nowrap; /* Prevent wrapping cutting off text */
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Nur Body-Zellen: gleiche Schriftgröße für alle Inhalte (Name, Rang, etc.) */
.matrix-table tbody td {
    font-size: var(--matrix-cell-font-size);
}

/* PERSONAL: Rang + Name sauber im "Name"-Feld halten (ohne Überlaufen nach links) */
.matrix-table td.personal-name-cell {
    text-align: left;
    overflow: hidden;
}

.border-right { border-right: 2px solid #555 !important; }
.text-center { text-align: center; }
.font-bold { font-weight: bold; }
.font-orbitron { font-family: 'Orbitron', sans-serif; }
.text-gray { color: #888; }

/* INPUTS (Dunkles Theme) */
.num-calc, .input-tiny {
    width: clamp(22px, 1.8vw, 32px);
    height: 22px;
    border: 1px solid #444;
    background-color: #222;
    color: white;
    border-radius: 3px;
    text-align: center;
    font-size: var(--matrix-cell-font-size);
    padding: 0;
    -moz-appearance: textfield; 
}
.num-calc:focus, .input-tiny:focus { 
    border-color: var(--accent-red); 
    background-color: #333; 
    outline: none; 
}
input:disabled, select:disabled { 
    background-color: transparent !important; 
    color: inherit !important; /* Keep text color */
    opacity: 1 !important;
    border-color: transparent !important; /* No border for seamless look */
    -webkit-text-fill-color: inherit !important; /* Chrome fix */
    -webkit-appearance: none !important; /* Hide dropdown arrow */
    -moz-appearance: none !important;
    appearance: none !important;
    pointer-events: none; /* Prevent clicking */
}

/* Buttons */
.btn-action-green { background: #1b5e20; border: 1px solid #2e7d32; color: #a5d6a7; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 10px; transition: 0.2s; font-family: 'Orbitron'; }
.btn-action-green:hover { background: #2e7d32; color: white; box-shadow: 0 0 10px #2e7d32; }

.btn-action-blue { background: #0d47a1; border: 1px solid #1565c0; color: #bbdefb; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 10px; transition: 0.2s; font-family: 'Orbitron'; }
.btn-action-blue:hover { background: #1565c0; color: white; box-shadow: 0 0 10px #1565c0; }

/* ERGEBNIS FARBEN (Subtiler für Dark Mode) */
/* Erfolgreich: Dunkelgrün mit hellem Text */
.row-success td { background-color: rgba(0, 100, 0, 0.2); }
.row-success .result-sum { color: #4caf50; font-weight: bold; text-shadow: 0 0 5px rgba(76, 175, 80, 0.5); }

/* Fehlgeschlagen: Dunkelrot mit hellem Text */
.row-fail td { background-color: rgba(100, 0, 0, 0.15); }
.row-fail .result-sum { color: #f44336; font-weight: bold; text-shadow: 0 0 5px rgba(244, 67, 54, 0.5); }

.group-result-cell { background: #222; border-left: 2px solid #555 !important; }

/* LEGENDE */
.legend-container {
    background: var(--card-bg);
    border: 1px solid #333;
    border-radius: var(--radius-large);
    padding: 20px;
    margin-top: 40px;
}
.legend-header {
    font-family: 'Orbitron';
    color: white;
    margin-top: 0;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}
.legend-table {
    width: 100%; border-collapse: collapse; color: var(--text-gray); font-size: 13px;
}
.legend-table th { text-align: left; padding: 10px; border-bottom: 1px solid #444; color: white; font-family: 'Orbitron'; }
.legend-table td { padding: 8px 10px; border-bottom: 1px solid #222; }
.legend-table td.pts { font-weight: bold; color: var(--accent-glow); }

/* RESPONSIVE */
@media (max-width: 1200px) {
    .matrix-layout { flex-direction: column; }
    .matrix-sidebar { min-width: 100%; max-height: none; flex-direction: row; display: flex; flex-wrap: wrap; gap: 5px; }
    .matrix-sidebar h4 { width: 100%; }
    .archive-link { flex: 1 1 auto; min-width: 150px; text-align: center; border-bottom: none; border: 1px solid #333; border-radius: 4px; }
}

@media (max-width: 768px) {
    .matrix-table { font-size: 9px; }
    .matrix-table th, .matrix-table td { padding: 4px 2px; }
    .num-calc, .input-tiny { width: 28px; height: 20px; font-size: 9px; }
    .matrix-header-title { flex-direction: column; gap: 10px; text-align: center; }
    .legend-table { font-size: 11px; }
}
/* INPUT OVERRIDES */
.matrix-table input[disabled] {
    color: #ffffff !important;
    opacity: 1 !important; /* Prevent greying out in Safari/iOS */
    -webkit-text-fill-color: #ffffff !important; /* Force white color in Chrome/Safari */
    cursor: default;
}
