:root {
    --kegel-sidebar-width: 264px;
    --kegel-sidebar-bg: #1e293b;
    --kegel-sidebar-border: rgba(226, 232, 240, 0.14);
    --kegel-text: #f8fafc;
    --kegel-muted: #b8c5d6;
    --kegel-accent: #34d399;
    --kegel-accent-dark: #0f766e;
    --kegel-bg: #f1f5f9;
    --kegel-card: #ffffff;
    --kegel-border: #e2e8f0;
    --kegel-topbar-height: 64px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body.kegel-app {
    min-height: 100vh;
    background: var(--kegel-bg);
    color: #0f172a;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

body.kegel-app a {
    color: var(--kegel-accent-dark);
    text-decoration: none;
}

body.kegel-app a:hover {
    text-decoration: underline;
}

/* Sidebar */
.kegel-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 5000;
    width: var(--kegel-sidebar-width);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    color: var(--kegel-text);
    background: linear-gradient(180deg, #334155 0%, var(--kegel-sidebar-bg) 100%);
    border-right: 1px solid var(--kegel-sidebar-border);
    transition: transform 0.25s ease;
}

.kegel-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 1.1rem 1rem;
    color: #fff;
    border-bottom: 1px solid var(--kegel-sidebar-border);
    text-decoration: none;
}

.kegel-brand:hover {
    text-decoration: none;
}

.kegel-brand-logo {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    padding: 4px;
    overflow: hidden;
    background: #fff;
    border-radius: 12px;
    flex: 0 0 auto;
}

.kegel-brand-logo img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

.kegel-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kegel-brand-text strong {
    font-size: 0.95rem;
    line-height: 1.2;
}

.kegel-brand-text small {
    margin-top: 0.15rem;
    color: #d1dae6;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.kegel-nav {
    flex: 1 1 auto;
    padding: 0.8rem 0.7rem 1rem;
}

.kegel-nav-section {
    margin-bottom: 1.15rem;
}

.kegel-nav-title {
    padding: 0.35rem 0.75rem;
    margin-bottom: 0.25rem;
    color: #d1dae6;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.kegel-nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.65rem 0.8rem;
    margin-bottom: 0.15rem;
    border-radius: 9px;
    color: #fff !important;
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none !important;
    transition: background 0.18s ease, color 0.18s ease;
}

.kegel-nav-link i {
    width: 1.1rem;
    color: #e8eef5;
    font-size: 0.92rem;
    text-align: center;
}

.kegel-nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.kegel-nav-link.is-active {
    background: rgba(16, 185, 129, 0.22);
    box-shadow: inset 3px 0 0 var(--kegel-accent);
}

.kegel-nav-link.is-active i {
    color: #a7f3d0;
}

.kegel-sidebar-footer {
    padding: 0.8rem 0.7rem 1rem;
    border-top: 1px solid var(--kegel-sidebar-border);
}

.kegel-user {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.3rem;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.05);
}

.kegel-user-icon {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    flex: 0 0 auto;
    border-radius: 999px;
    color: var(--kegel-accent);
    background: rgba(16, 185, 129, 0.18);
}

.kegel-user-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kegel-user-text strong {
    overflow: hidden;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kegel-user-text small {
    color: #e2e8f0;
    font-size: 0.7rem;
}

.kegel-logout,
.kegel-logout span,
.kegel-logout i {
    color: #fecaca !important;
}

.kegel-logout:hover {
    background: rgba(239, 68, 68, 0.12);
}

/* Main content */
.app-main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin-left: var(--kegel-sidebar-width);
    min-width: 0;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    min-height: var(--kegel-topbar-height);
    padding: 0 1.5rem;
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid var(--kegel-border);
    backdrop-filter: blur(8px);
}

.app-topbar-title {
    margin: 0;
    color: #0f172a;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.app-content {
    flex: 1 1 auto;
    width: 100%;
    max-width: 1500px;
    padding: 1.4rem 1.5rem 2.5rem;
}

.app-content h1,
.app-content h2 {
    color: #0f172a;
}

.app-content h1 {
    margin-top: 0;
    font-size: 1.4rem;
}

.app-content h2 {
    font-size: 1.15rem;
}

.app-content hr {
    margin: 1rem 0;
    border: 0;
    border-top: 1px solid var(--kegel-border);
}

/* Forms */
.app-content input[type="text"],
.app-content input[type="password"],
.app-content input[type="email"],
.app-content input[type="number"],
.app-content input[type="date"],
.app-content select,
.app-content textarea {
    max-width: 100%;
    padding: 0.5rem 0.6rem;
    color: #0f172a;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font: inherit;
}

.app-content input[type="text"]:focus,
.app-content input[type="password"]:focus,
.app-content input[type="email"]:focus,
.app-content input[type="number"]:focus,
.app-content input[type="date"]:focus,
.app-content select:focus,
.app-content textarea:focus {
    outline: 2px solid rgba(13, 148, 136, 0.25);
    border-color: #0d9488;
}

.app-content input[type="submit"],
.app-content button,
.app-content .button {
    padding: 0.55rem 0.9rem;
    color: #fff;
    background: var(--kegel-accent-dark);
    border: 0;
    border-radius: 7px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.app-content input[type="submit"]:hover,
.app-content button:hover,
.app-content .button:hover {
    background: #115e59;
}

/* Legacy tables */
.CSSTableGenerator,
.CSSTableGenerator1 {
    width: 100%;
    margin: 1rem 0;
    overflow-x: auto;
    background: var(--kegel-card);
    border: 1px solid var(--kegel-border);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

.CSSTableGenerator table,
.CSSTableGenerator1 table,
.app-content > table {
    width: 100%;
    min-width: 680px;
    margin: 0;
    border-collapse: collapse;
    border-spacing: 0;
    background: #fff;
}

.CSSTableGenerator th,
.CSSTableGenerator1 th,
.app-content table th {
    padding: 0.75rem 0.7rem;
    color: #334155;
    background: #f8fafc;
    border-bottom: 1px solid var(--kegel-border);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

.CSSTableGenerator td,
.CSSTableGenerator1 td,
.app-content table td {
    padding: 0.7rem;
    color: #1e293b;
    border-bottom: 1px solid #eef2f7;
    font-size: 0.85rem;
    vertical-align: middle;
}

.CSSTableGenerator tr:nth-child(even) td,
.CSSTableGenerator1 tr:nth-child(even) td,
.app-content table tr:nth-child(even) td {
    background: #f8fafc;
}

.CSSTableGenerator tr:hover td,
.CSSTableGenerator1 tr:hover td,
.app-content table tr:hover td {
    background: #f0fdfa;
}

.CSSTableGenerator tr:last-child td,
.CSSTableGenerator1 tr:last-child td {
    border-bottom: 0;
}

/* Tables without a wrapper */
.app-content > table {
    border: 1px solid var(--kegel-border);
    border-radius: 12px;
    overflow: hidden;
}

/* Attendance details on hover (statistik.php) */
span.popup {
    display: inline-block;
    cursor: help;
    vertical-align: top;
}

span.popup > span {
    display: none;
    width: max-content;
    max-width: min(340px, 78vw);
    margin-top: 0.45rem;
    padding: 0.55rem 0.65rem;
    color: #334155;
    background: #f8fafc;
    border: 1px solid var(--kegel-border);
    border-radius: 8px;
    box-shadow: 0 5px 16px rgba(15, 23, 42, 0.12);
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.55;
    text-align: left;
    white-space: normal;
}

span.popup:hover > span,
span.popup:focus-within > span {
    display: block;
}

span.popup b {
    color: var(--kegel-accent-dark);
}

/* Login */
body.kegel-login {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 1.25rem;
    color: #0f172a;
    background:
        radial-gradient(circle at 15% 15%, rgba(52, 211, 153, 0.22), transparent 38%),
        linear-gradient(145deg, #0f172a 0%, #1e293b 65%, #334155 100%);
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

.login-shell {
    width: min(100%, 430px);
}

.login-card {
    padding: 2rem;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    color: #0f172a;
    text-decoration: none;
}

.login-brand img {
    width: 58px;
    height: 58px;
    padding: 4px;
    object-fit: contain;
    background: #f8fafc;
    border: 1px solid var(--kegel-border);
    border-radius: 12px;
}

.login-brand span {
    display: flex;
    flex-direction: column;
}

.login-brand strong {
    font-size: 1.05rem;
}

.login-brand small {
    margin-top: 0.1rem;
    color: #64748b;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.login-card h1 {
    margin: 0 0 0.35rem;
    font-size: 1.55rem;
    letter-spacing: -0.02em;
}

.login-subtitle {
    margin: 0 0 1.4rem;
    color: #64748b;
}

.kegel-login-form {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.kegel-login-form label {
    margin-top: 0.55rem;
    color: #334155;
    font-size: 0.8rem;
    font-weight: 600;
}

.kegel-login-form input[type="text"],
.kegel-login-form input[type="password"] {
    width: 100%;
    padding: 0.7rem 0.8rem;
    color: #0f172a;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font: inherit;
}

.kegel-login-form input[type="text"]:focus,
.kegel-login-form input[type="password"]:focus {
    outline: 2px solid rgba(13, 148, 136, 0.25);
    border-color: #0d9488;
}

.kegel-login-form input[type="submit"] {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    color: #fff;
    background: #0f766e;
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.kegel-login-form input[type="submit"]:hover {
    background: #115e59;
}

/* Mobile */
.kegel-toggle {
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 6000;
    display: none;
    width: 2.55rem;
    height: 2.55rem;
    place-items: center;
    color: #fff;
    background: #0f172a;
    border: 0;
    border-radius: 9px;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.25);
    cursor: pointer;
}

.kegel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 4500;
    display: none;
    background: rgba(15, 23, 42, 0.45);
}

.kegel-backdrop.is-visible {
    display: block;
}

@media (max-width: 900px) {
    .kegel-sidebar {
        transform: translateX(-100%);
    }

    .kegel-sidebar.open {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0;
    }

    .kegel-toggle {
        display: grid;
    }

    .app-topbar {
        padding-left: 4rem;
    }

    .app-content {
        padding: 1rem 0.9rem 2rem;
    }

    .CSSTableGenerator table,
    .CSSTableGenerator1 table,
    .app-content > table {
        min-width: 620px;
    }
}

@media (max-width: 520px) {
    .login-card {
        padding: 1.4rem;
    }

    .app-content {
        font-size: 13px;
    }
}
