/* portal/assets/portal_style.css */
:root {
    --primary: #9C27B0;
    --primary-hover: #7B1FA2;
    --accent-red: #f44336;
    --bg-color: #f4f6f9;
    --bg-secondary: #ffffff;
    --text-color: #333;
    --text-muted: #777;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --radius: 8px;

    --nav-bg: #1e1e1e;
    --nav-dropdown-bg: #2d2d2d;
    --nav-text: #ffffff;

    --sidebar-width: 240px;
    --sidebar-width-collapsed: 70px;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --bg-secondary: #1e1e1e;
    --text-color: #e0e0e0;
    --text-muted: #999;
    --card-bg: #1e1e1e;
    --border-color: #3d3d3d;
    --nav-bg: #1a1a1a;
    --nav-dropdown-bg: #2d2d2d;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.2s, color 0.2s;
}

/* ============ Layout ============ */
.app-wrapper { display: flex; min-height: 100vh; }

/* ============ Sidebar ============ */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--nav-bg);
    color: var(--nav-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width 0.3s ease;
}
.sidebar-header {
    padding: 15px; height: 65px; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.05); white-space: nowrap; overflow: hidden;
}
.sidebar-header h1 { font-size: 1.2rem; margin: 0; color: #fff; display: flex; align-items: center; gap: 8px; }
.sidebar-header small { font-size: 0.5em; color: var(--text-muted); }
.sidebar-toggle { background: transparent; border: none; color: var(--nav-text); font-size: 1.5rem; cursor: pointer; padding: 0 5px; outline: none; }

.sidebar-nav { flex-grow: 1; overflow-y: auto; overflow-x: hidden; padding-top: 10px; }
.nav-item {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    color: #ccc;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.05); color: #fff; border-left-color: var(--primary); }
.nav-item .icon { font-size: 1.2rem; min-width: 30px; text-align: center; }
.nav-item .label { margin-left: 10px; }

/* ============ Sidebar Footer ============ */
.sidebar-footer { padding: 15px; border-top: 1px solid rgba(255,255,255,0.05); position: relative; }
.footer-expanded { display: flex; flex-direction: column; gap: 15px; width: 100%; }

.leg-switcher-single { color: #ccc; font-size: 13px; padding: 8px 10px; background: #2a2a2a; border-radius: 6px; border: 1px solid #444; }

.user-profile-row { display: flex; align-items: center; justify-content: space-between; }
.user-info { display: flex; align-items: center; gap: 10px; flex-grow: 1; padding: 4px 0; }
.user-name { color: #ccc; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.theme-icon-btn { background: none; border: none; color: #aaa; cursor: pointer; font-size: 16px; padding: 5px; transition: color 0.2s; border-radius: 50%; }
.theme-icon-btn:hover { color: var(--primary); background: rgba(255,255,255,0.05); }

/* Eingeklappter Avatar Trigger */
.avatar-btn {
    display: none;
    width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; border: none;
    font-weight: bold; cursor: pointer; align-items: center; justify-content: center; font-size: 14px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2); transition: transform 0.2s; margin: 0 auto;
}
.avatar-btn:hover { transform: scale(1.05); }

/* Avatar Flyout Menu */
.avatar-flyout {
    display: none; position: absolute; bottom: 60px; left: 15px; width: 240px; background: var(--nav-dropdown-bg);
    border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.4); flex-direction: column; padding: 15px; z-index: 200; border: 1px solid rgba(255,255,255,0.05);
}
.avatar-flyout.show { display: flex; animation: fadeIn 0.15s ease-in-out; }
.avatar-flyout-header { border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 10px; margin-bottom: 10px; }
.avatar-flyout a, .avatar-flyout button {
    display: block; color: #ccc; text-decoration: none; padding: 8px 0; background: none; border: none; text-align: left; cursor: pointer; width: 100%; font-size: 14px;
}
.avatar-flyout a:hover, .avatar-flyout button:hover { color: #fff; }

html:not([data-sidebar="collapsed"]) .flyout-theme-btn { display: none; }

/* ============ Collapsed Sidebar State ============ */
html[data-sidebar="collapsed"] .sidebar-nav { overflow: visible; }
html[data-sidebar="collapsed"] .sidebar { width: var(--sidebar-width-collapsed); }
html[data-sidebar="collapsed"] .sidebar-header h1 span { display: none; }
html[data-sidebar="collapsed"] .sidebar-header { justify-content: center; padding: 15px 0; }
html[data-sidebar="collapsed"] .nav-item .label { display: none; }
html[data-sidebar="collapsed"] .nav-item.active { border-left-color: transparent; background: var(--primary); }
html[data-sidebar="collapsed"] .footer-expanded { display: none; }
html[data-sidebar="collapsed"] .avatar-btn { display: flex; }

/* ============ Main content ============ */
.main-content { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
.content-scrollable { flex: 1; padding: 30px; width: 100%; max-width: 1100px; margin: 0 auto; }

/* --- Cards & Boxen --- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}
.card h2, .card h3 { color: var(--primary); margin-bottom: 15px; margin-top: 0; }

/* --- Formulare & Buttons --- */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.form-group input {
    width: 100%; padding: 12px 15px;
    border: 2px solid var(--border-color); border-radius: 6px;
    background: var(--bg-secondary); color: var(--text-color);
    font-size: 16px; transition: border-color 0.2s;
}
.form-group input:focus { outline: none; border-color: var(--primary); }
.form-group small { color: var(--text-muted); font-size: 12px; margin-top: 5px; display: block; }

.btn {
    display: inline-block; width: 100%; padding: 12px;
    background-color: var(--primary); color: white;
    border: none; border-radius: 6px; font-size: 16px; font-weight: bold;
    cursor: pointer; text-align: center; text-decoration: none;
    transition: background 0.2s;
}
.btn:hover { background-color: var(--primary-hover); }

/* --- Stat-Kacheln (wie im Hauptbereich) --- */
.stats { display: flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; justify-content: flex-start; }
.stat-box {
    background: var(--card-bg); padding: 15px 25px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); text-align: center;
    height: 110px; width: 160px; flex: 0 0 auto; display: flex; flex-direction: column; justify-content: center; align-items: center;
    overflow: hidden; box-sizing: border-box; transition: transform 0.2s;
}
.stat-box:hover { transform: translateY(-2px); }
.stat-unit { font-size: 12px; opacity: 0.8; margin-bottom: 2px; }
.stat-box .number { font-size: 28px; font-weight: bold; color: var(--primary); }
.stat-box .label { color: var(--text-muted); font-size: 14px; margin-top: 5px; }
.stat-box-muted .number { color: var(--text-muted); }
.stat-box-success .number { color: #2E7D32; }
.stat-box-danger .number { color: #C62828; }
.stat-box-warning .number { color: #F57F17; }

/* --- Footer --- */
.portal-footer {
    text-align: center; padding: 20px; color: var(--text-muted);
    font-size: 12px; border-top: 1px solid var(--border-color);
}
.portal-footer-docs {
    margin-bottom: 10px;
}
.portal-footer-docs a {
    color: var(--text-muted); text-decoration: underline; margin: 0 4px;
}
.portal-footer-docs a:hover { color: var(--primary); }

/* --- Messages --- */
.msg { padding: 15px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; font-weight: 500; }
.msg.error { background-color: #FFEBEE; color: #C62828; border-left: 4px solid #C62828; }
.msg.success { background-color: #E8F5E9; color: #2E7D32; border-left: 4px solid #2E7D32; }
[data-theme="dark"] .msg.error { background-color: #4a1515; color: #ef9a9a; }
[data-theme="dark"] .msg.success { background-color: #1b3d1e; color: #a5d6a7; }

/* --- Tabellen (Standardfarben ausserhalb Inline-Styles) --- */
table { color: var(--text-color); }

/* --- Sortierbare Tabellen --- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--primary); }
th.sortable .sort-arrow { display: inline-block; width: 10px; font-size: 10px; opacity: 0.5; transition: transform 0.15s; }
th.sortable.sort-asc .sort-arrow, th.sortable.sort-desc .sort-arrow { opacity: 1; }
th.sortable.sort-desc .sort-arrow { transform: rotate(180deg); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============ Responsive: Sidebar -> Top bar ============ */
@media (max-width: 800px) {
    .app-wrapper { flex-direction: column; }
    html[data-sidebar="collapsed"] .sidebar { width: 100%; }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }
    .sidebar-header { border-bottom: none; padding: 12px 15px; height: auto; }
    .sidebar-toggle { display: none; }
    html[data-sidebar="collapsed"] .sidebar-header h1 span { display: flex; }
    .sidebar-nav {
        flex-grow: 1;
        display: flex;
        overflow-x: auto;
        padding-top: 0;
    }
    .nav-item { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; padding: 12px 14px; }
    .nav-item.active { border-left-color: transparent; border-bottom-color: var(--primary); }
    html[data-sidebar="collapsed"] .nav-item .label { display: inline; }
    .sidebar-footer {
        border-top: 1px solid rgba(255,255,255,0.08);
        width: 100%;
        order: 3;
    }
    html[data-sidebar="collapsed"] .footer-expanded { display: flex; }
    .avatar-btn { display: none !important; }
    .content-scrollable { padding: 20px 15px; }
}
