/* /css/serverlogs.css */

/* =========
   Grundlayout
   ========= */
:root {
    --card-bg: #0f1523;
    --card-border: #2a3245;
    --text: #e8ecf4;
    --muted: #a7b0c2;
    --accent: #6aa7ff;
    --input-bg: #0b0f17;
    --input-border: #2b3550;
    --input-focus: #7db2ff;
    --row-alt: rgba(255, 255, 255, 0.025);
    --row-hover: rgba(125, 178, 255, 0.10);
    --shadow: 0 12px 30px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: light) {
    :root {
        --card-bg: #ffffff;
        --card-border: #dfe5ef;
        --text: #0e1726;
        --muted: #5c6883;
        --accent: #2f6df6;
        --input-bg: #f7f9fc;
        --input-border: #ccd7ea;
        --input-focus: #2f6df6;
        --row-alt: rgba(0, 0, 0, 0.03);
        --row-hover: rgba(47, 109, 246, 0.08);
        --shadow: 0 10px 24px rgba(15, 23, 36, .08);
    }
}

.decent-box.logs-server-box {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: clamp(14px, 2vw, 20px);
    box-shadow: var(--shadow);
    color: var(--text);
}

.logs-server-box h2 {
    margin: 0 0 12px;
    font-size: clamp(1.1rem, 2vw, 1.35rem);
    letter-spacing: .2px;
}

/* =========
   Filterleiste
   ========= */
.logs-controls {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin: 6px 0 14px;
}

.logs-controls .form-group {
    display: grid;
    gap: 6px;
}

.logs-controls label {
    font-size: .85rem;
    color: var(--muted);
}

.logs-controls input[type="text"],
.logs-controls input[type="datetime-local"] {
    appearance: none;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text);
    height: 38px;
    padding: 0 10px;
    border-radius: 10px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    width: 100%;
}

.logs-controls input::placeholder {
    color: color-mix(in oklab, var(--muted) 70%, transparent);
}

.logs-controls input:focus {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--input-focus) 25%, transparent);
}

/* Breakpoints für Filter */
@media (max-width: 1100px) {
    .logs-controls {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .logs-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 480px) {
    .logs-controls {
        grid-template-columns: 1fr;
    }
}

/* =========
   Tabelle (Desktop)
   ========= */
.logs-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border: 1px solid var(--card-border);
    border-radius: 12px;
}

.logs-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    text-align: left;
    font-weight: 600;
    font-size: .88rem;
    padding: 12px 12px;
    background: linear-gradient(0deg, var(--card-bg), color-mix(in oklab, var(--card-bg) 85%, black));
    color: var(--muted);
    border-bottom: 1px solid var(--card-border);
    backdrop-filter: blur(4px);
}

.logs-table tbody td {
    padding: 12px 12px;
    font-size: .95rem;
    line-height: 1.35;
    vertical-align: top;
    border-bottom: 1px solid color-mix(in oklab, var(--card-border) 85%, transparent);
    word-break: break-word;
}

.logs-table tbody tr:nth-child(even) td {
    background: var(--row-alt);
}

.logs-table tbody tr:hover td {
    background: var(--row-hover);
}

.logs-table tbody td:nth-child(1) {
    /* Zeit */
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.logs-table tbody td:nth-child(2) {
    /* User */
    color: var(--muted);
}

.logs-table tbody td:nth-child(3) {
    /* Aktion */
    font-weight: 600;
}

.logs-table tbody td:nth-child(4) {
    /* Zeile / Produkt */
    max-width: 0;
    /* lässt den Cell shrinken */
}

/* Wenn Details sehr lang sind, schön umbrechen */
@supports (overflow-wrap: anywhere) {
    .logs-table tbody td:nth-child(4) {
        overflow-wrap: anywhere;
    }
}

/* =========
   Mobile – übersichtliche, scrollbare Tabelle
   ========= */
@media (max-width: 720px) {

    /* Wrapper: sanftes horizontales Scrollen mit Sticky-Header */
    .logs-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px;
        position: relative;
        box-shadow: inset 0 0 0 1px var(--card-border);
    }

    .logs-table {
        border: 0;
        min-width: 820px;
        /* sinnvolle Mindestbreite, damit Spalten nicht kollabieren */
        table-layout: fixed;
        border-radius: 0;
    }

    .logs-table thead th,
    .logs-table tbody td {
        padding: 10px 12px;
        font-size: 15px;
        line-height: 1.4;
    }

    /* Spaltenbreiten klar definieren */
    .logs-table thead th:nth-child(1),
    .logs-table tbody td:nth-child(1) {
        min-width: 170px;
        white-space: nowrap;
    }

    .logs-table thead th:nth-child(2),
    .logs-table tbody td:nth-child(2) {
        min-width: 120px;
        white-space: nowrap;
    }

    .logs-table thead th:nth-child(3),
    .logs-table tbody td:nth-child(3) {
        min-width: 150px;
        white-space: nowrap;
    }

    /* Textspalten: dürfen umbrechen und breit werden */
    .logs-table thead th:nth-child(4),
    .logs-table tbody td:nth-child(4) {
        min-width: 220px;
        white-space: normal;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .logs-table thead th:nth-child(5),
    .logs-table tbody td:nth-child(5) {
        min-width: 160px;
        white-space: normal;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .logs-table thead th:nth-child(6),
    .logs-table tbody td:nth-child(6),
    .logs-table thead th:nth-child(7),
    .logs-table tbody td:nth-child(7) {
        min-width: 240px;
        white-space: normal;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    /* Optik: klarere Zeilentrennung für Finger-Scan */
    .logs-table tbody tr td {
        border-bottom: 1px solid color-mix(in oklab, var(--card-border) 90%, transparent);
    }

    .logs-table tbody tr:nth-child(even) td {
        background: transparent;
        /* Zebra auf Mobile oft störend */
    }

    /* Kleiner Schatten-Hinweis rechts, dass gescrollt werden kann */
    .logs-table-wrapper::after {
        content: "";
        position: sticky;
        right: 0;
        top: 0;
        bottom: 0;
        width: 24px;
        pointer-events: none;
        background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .18));
        mix-blend-mode: multiply;
    }

    /* Timestamp etwas prägnanter, aber einzeilig */
    .logs-table tbody td:nth-child(1) {
        font-weight: 600;
        font-variant-numeric: tabular-nums;
    }
}

/* =========
   Utility: leichte Scrollbar (Desktop)
   ========= */
@media (min-width: 721px) {
    .logs-table-wrapper {
        max-height: 65vh;
        overflow: auto;
        border-radius: 12px;
    }

    .logs-table-wrapper::-webkit-scrollbar {
        height: 10px;
        width: 10px;
    }

    .logs-table-wrapper::-webkit-scrollbar-thumb {
        background: color-mix(in oklab, var(--muted) 35%, transparent);
        border-radius: 8px;
    }
}

/* =========
   Kleinere Optik-Details
   ========= */
.logs-server-box .empty,
.logs-server-box .error {
    padding: 12px 14px;
    border: 1px dashed var(--card-border);
    border-radius: 10px;
    color: var(--muted);
}

/* ===== Serverlog: sinnvolle Spaltenbreiten (Desktop) ===== */
@media (min-width: 721px) {
    .logs-table {
        table-layout: auto !important;
        width: 100%;
    }

    /* 1–3 kompakt & ohne Umbruch */
    .logs-table thead th:nth-child(1) {
        width: 180px;
    }

    /* Zeit */
    .logs-table thead th:nth-child(2) {
        width: 140px;
    }

    /* Benutzer */
    .logs-table thead th:nth-child(3) {
        width: 160px;
    }

    /* Aktion */

    .logs-table tbody td:nth-child(1),
    .logs-table tbody td:nth-child(2),
    .logs-table tbody td:nth-child(3) {
        white-space: nowrap;
    }

    /* 4 = Zeile/Produkt: darf wachsen & umbrechen */
    .logs-table thead th:nth-child(4) {
        width: auto;
    }

    .logs-table tbody td:nth-child(4) {
        max-width: none !important;
        white-space: normal !important;
        word-break: break-word !important;
        overflow-wrap: anywhere;
    }
}

/* Safety: falls irgendwo Breiten hart gesetzt wurden */
.logs-table th,
.logs-table td {
    width: auto !important;
}

/* Die Karte selbst soll die ganze Content-Höhe nutzen */
.decent-box.logs-server-box {
    display: flex;
    flex-direction: column;
    /* Falls deine Content-Area nicht schon 100% hoch ist:
     gib der Box eine Mindesthöhe relativ zur Viewport-Höhe.
     Passe den Abzug (Paddings/Abstände/Header) bei Bedarf an. */
    min-height: calc(100vh - 140px);
}

/* Filterleiste bleibt oben, nimmt nur so viel Platz wie nötig */
.logs-controls {
    flex: 0 0 auto;
}

/* Der Tabellen-Wrapper füllt den Rest und scrollt intern */
.logs-table-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    /* wichtig, damit overflow in Flex-Child greift */
    overflow: auto;
    border-radius: 12px;
}

/* Desktop: ggf. die alte 65vh-Begrenzung neutralisieren */
@media (min-width: 721px) {
    .logs-table-wrapper {
        max-height: none !important;
    }
}

/* Sticky-Header funktioniert im scrollenden Wrapper weiterhin */
.logs-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}