/**
 * Design-Optimierungen & Ergänzungen
 * Polished UI-Komponenten für moderne Benutzeroberfläche
 */

/* ============================================================
   GLOBAL JS TOAST HELPER
   ============================================================ */

/* ============================================================
   1. SELECT-STYLING (Custom Arrow)
   ============================================================ */
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px !important;
    cursor: pointer;
}

select.form-control:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300d9ff' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

[data-theme="light"] select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a5568' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* ============================================================
   2. CUSTOM CHECKBOX & RADIO
   ============================================================ */
input[type="checkbox"],
input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-elevated);
    cursor: pointer;
    position: relative;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    vertical-align: middle;
}

input[type="radio"] { border-radius: 50%; }

input[type="checkbox"]:hover,
input[type="radio"]:hover {
    border-color: var(--primary-color);
    background: rgba(0, 217, 255, 0.05);
}

input[type="checkbox"]:checked {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 5px;
    width: 5px;
    height: 9px;
    border: 2px solid #000;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}

input[type="radio"]:checked {
    border-color: var(--primary-color);
    background: var(--bg-elevated);
}

input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ============================================================
   3. TEXTAREA STYLING
   ============================================================ */
textarea.form-control {
    resize: vertical;
    min-height: 100px;
    line-height: var(--line-height-relaxed);
}

/* ============================================================
   4. INPUT GROUP (Icon + Input)
   ============================================================ */
.input-group {
    position: relative;
    display: flex;
    align-items: stretch;
}

.input-group .input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    width: 16px;
    height: 16px;
    z-index: 1;
    transition: color var(--transition-fast);
}

.input-group .form-control {
    padding-left: 40px;
}

.input-group .form-control:focus ~ .input-icon,
.input-group:focus-within .input-icon {
    color: var(--primary-color);
}

.input-group-append {
    display: flex;
    align-items: center;
}

.input-group .form-control:not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group .btn:last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* ============================================================
   5. CARD VARIANTS
   ============================================================ */
.card-compact {
    padding: var(--spacing-4);
}

.card-flush {
    padding: 0;
    overflow: hidden;
}

.card-flush .card-header {
    padding: var(--spacing-4) var(--spacing-5);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-flush .card-body {
    padding: var(--spacing-5);
}

.card-flush .card-footer {
    padding: var(--spacing-4) var(--spacing-5);
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .card-flush .card-footer {
    background: rgba(0, 0, 0, 0.02);
}

/* Colored top border cards */
.card-primary { border-top: 2px solid var(--primary-color); }
.card-success  { border-top: 2px solid var(--success-color); }
.card-danger   { border-top: 2px solid var(--danger-color); }
.card-warning  { border-top: 2px solid var(--warning-color); }
.card-purple   { border-top: 2px solid var(--secondary-color); }

/* ============================================================
   6. TABLE IMPROVEMENTS
   ============================================================ */
.table-wrapper {
    position: relative;
}

/* Sticky action column */
.data-table td:last-child,
.data-table th:last-child {
    position: sticky;
    right: 0;
    background: inherit;
}

.data-table .table-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
    white-space: nowrap;
}

/* Sortable headers */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th.sortable:hover {
    color: var(--primary-color);
}

.data-table th.sortable::after {
    content: ' ↕';
    opacity: 0.3;
    font-size: 0.7em;
}

.data-table th.sort-asc::after { content: ' ↑'; opacity: 0.8; color: var(--primary-color); }
.data-table th.sort-desc::after { content: ' ↓'; opacity: 0.8; color: var(--primary-color); }

/* ============================================================
   7. FILTER BAR
   ============================================================ */
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: var(--spacing-5);
    flex-wrap: wrap;
    padding: var(--spacing-4);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.filter-bar .form-control {
    flex: 1;
    min-width: 180px;
    max-width: 280px;
}

.filter-bar .btn {
    white-space: nowrap;
}

.filter-label {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ============================================================
   8. PAGE HEADER IMPROVEMENTS
   ============================================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-6);
    gap: var(--spacing-4);
}

.page-header-left {}

.page-header h1 {
    color: var(--text-color);
    font-size: var(--font-size-2xl);
    font-weight: 700;
    margin-bottom: var(--spacing-1);
    line-height: var(--line-height-tight);
}

.page-subtitle {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    margin-top: var(--spacing-1);
}

.page-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* ============================================================
   9. BUTTON GROUP
   ============================================================ */
.btn-group {
    display: inline-flex;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.btn-group .btn {
    border-radius: 0;
    border: none;
    border-right: 1px solid var(--border-color);
    flex: 1;
}

.btn-group .btn:last-child {
    border-right: none;
}

.btn-group .btn.active {
    background: rgba(0, 217, 255, 0.15);
    color: var(--primary-color);
}

/* ============================================================
   10. LOADING OVERLAY
   ============================================================ */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 15, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    z-index: 100;
}

[data-theme="light"] .loading-overlay {
    background: rgba(248, 249, 250, 0.7);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(0, 217, 255, 0.2);
    border-top-color: var(--primary-color);
    border-radius: var(--radius-full);
    animation: spin 0.7s linear infinite;
}

.spinner-sm { width: 20px; height: 20px; border-width: 2px; }
.spinner-lg { width: 48px; height: 48px; border-width: 4px; }

/* ============================================================
   11. SCROLL AREA (für lange Listen)
   ============================================================ */
.scroll-area {
    overflow-y: auto;
    max-height: 400px;
    padding-right: 4px;
}

.scroll-area::-webkit-scrollbar { width: 4px; }
.scroll-area::-webkit-scrollbar-track { background: transparent; }
.scroll-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}
.scroll-area::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* ============================================================
   12. KEYBOARD SHORTCUT BADGE
   ============================================================ */
.kbd {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-bottom-width: 2px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-family: 'Orbitron', monospace;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ============================================================
   13. GRID UTILITIES
   ============================================================ */
.grid-2  { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--spacing-5); }
.grid-3  { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--spacing-5); }
.grid-4  { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--spacing-5); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--spacing-5); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--spacing-4); }

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ============================================================
   14. ANIMATION UTILITIES
   ============================================================ */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.9); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 10px rgba(0, 217, 255, 0.2); }
    50%       { box-shadow: 0 0 25px rgba(0, 217, 255, 0.5); }
}

.animate-fade-up   { animation: fadeInUp   var(--transition-base) ease-out both; }
.animate-fade-down { animation: fadeInDown var(--transition-base) ease-out both; }
.animate-scale     { animation: scaleIn    var(--transition-base) ease-out both; }
.animate-pulse-glow { animation: pulse-glow 2s ease-in-out infinite; }

.delay-100 { animation-delay: 100ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-400 { animation-delay: 400ms; }

/* ============================================================
   15. TEXT UTILITIES
   ============================================================ */
.text-gradient {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-wrap { white-space: normal; }

/* ============================================================
   16. RESPONSIVE UTILITIES
   ============================================================ */
@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .page-header { flex-direction: column; }
    .page-header-actions { width: 100%; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .form-control { max-width: 100%; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 769px) {
    .hide-desktop { display: none !important; }
}

/* ============================================================
   17. PRINT STYLES
   ============================================================ */
@media print {
    .navbar, .btn, .filters, .filter-bar, .toast-container,
    .mobile-menu-toggle, .theme-toggle, .btn-icon { display: none !important; }

    .card {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    body {
        background: white !important;
        color: black !important;
    }

    a { color: black !important; text-decoration: underline; }
}
