/* ===== Form Components ===== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-tertiary);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.form-group .hint {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--text-inverse);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-success {
    background: var(--color-success);
    color: var(--text-inverse);
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--color-danger);
    color: var(--text-inverse);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-full {
    width: 100%;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-icon {
    padding: 0.5rem;
    border-radius: var(--radius-md);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ===== Stats Cards ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

.stat-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-icon.blue {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.stat-icon.green {
    background: var(--color-success-light);
    color: var(--color-success);
}

.stat-icon.yellow {
    background: var(--color-warning-light);
    color: var(--color-warning);
}

.stat-icon.red {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ===== Tables ===== */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: var(--bg-secondary);
}

.data-table td {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.table-actions {
    display: flex;
    gap: 0.5rem;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-full);
}

.badge-success {
    background: var(--color-success-light);
    color: #065f46;
}

.badge-warning {
    background: var(--color-warning-light);
    color: #92400e;
}

.badge-danger {
    background: var(--color-danger-light);
    color: #991b1b;
}

.badge-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.badge-primary {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

/* ===== Modal ===== */
.modal-container {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal.modal-lg {
    max-width: 700px;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--color-primary);
    animation: toastIn 0.3s ease;
    max-width: 400px;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.toast-out {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.toast.success {
    border-left-color: var(--color-success);
}

.toast.error {
    border-left-color: var(--color-danger);
}

.toast.warning {
    border-left-color: var(--color-warning);
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    color: var(--color-success);
}

.toast.error .toast-icon {
    color: var(--color-danger);
}

.toast.warning .toast-icon {
    color: var(--color-warning);
}

.toast-message {
    font-size: 0.875rem;
    color: var(--text-primary);
}

/* ===== Error Message ===== */
.error-message {
    padding: 0.75rem 1rem;
    background: var(--color-danger-light);
    color: #991b1b;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

.empty-state > svg {
    width: 64px;
    height: 64px;
    color: var(--text-tertiary);
    margin-bottom: 1rem;
}

.empty-state .btn svg {
    width: 18px;
    height: 18px;
    color: currentColor;
    margin-bottom: 0;
}

.empty-state h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* ===== Loading ===== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-small {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 0.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header-left h2 {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-secondary);
}

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-bar .form-group {
    min-width: 180px;
}

.filter-bar input,
.filter-bar select {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.pagination-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.pagination-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.pagination-btn.active {
    background: var(--color-primary);
    color: var(--text-inverse);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== Checkbox ===== */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.checkbox-item:hover {
    border-color: var(--color-primary);
}

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
}

.checkbox-item span {
    font-size: 0.875rem;
    color: var(--text-primary);
}

/* ===== Confirm Dialog ===== */
.confirm-content {
    text-align: center;
}

.confirm-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confirm-icon.danger {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.confirm-icon svg {
    width: 32px;
    height: 32px;
}

.confirm-content h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.confirm-content p {
    color: var(--text-secondary);
}

/* ===== Detail View ===== */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.detail-item {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.detail-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.detail-value {
    font-size: 0.9375rem;
    color: var(--text-primary);
    word-break: break-word;
}

.detail-item.full-width {
    grid-column: span 2;
}

@media (max-width: 640px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
    
    .detail-item.full-width {
        grid-column: span 1;
    }
}

/* ===== Dashboard Charts Area ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

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

.chart-placeholder {
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    color: var(--text-tertiary);
}

/* ===== Responsive Components ===== */

/* Tablet Optimierungen (bis 1024px) */
@media (max-width: 1024px) {
    .modal {
        max-width: 90vw;
    }
    
    .modal.modal-lg {
        max-width: 95vw;
    }
    
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    
    .page-header-right {
        display: flex;
        justify-content: flex-end;
    }
}

/* Mobile Landscape (bis 768px) */
@media (max-width: 768px) {
    /* Buttons - größere Touch-Targets */
    .btn {
        padding: 0.75rem 1.25rem;
        min-height: 44px;
    }
    
    .btn-small {
        padding: 0.5rem 0.875rem;
        min-height: 36px;
    }
    
    /* Stats Cards */
    .stat-card {
        padding: 1rem;
    }
    
    .stat-icon {
        width: 40px;
        height: 40px;
    }
    
    .stat-icon svg {
        width: 20px;
        height: 20px;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    /* Cards */
    .card {
        border-radius: var(--radius-md);
    }
    
    .card-header,
    .card-body {
        padding: 1rem;
    }
    
    /* Modal */
    .modal {
        max-height: 85vh;
        margin: 0.5rem;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.875rem 1rem;
        flex-wrap: wrap;
    }
    
    .modal-footer .btn {
        flex: 1;
        min-width: 120px;
    }
    
    /* Tabellen */
    .data-table th,
    .data-table td {
        padding: 0.75rem 0.625rem;
        font-size: 0.8125rem;
    }
    
    /* Filter Bar */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-bar .form-group {
        min-width: 100%;
    }
    
    /* Toast */
    .toast-container {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }
    
    .toast {
        max-width: 100%;
    }
}

/* Mobile Portrait (bis 640px) */
@media (max-width: 640px) {
    /* Buttons in Reihen */
    .btn {
        font-size: 0.8125rem;
    }
    
    .btn-full-mobile {
        width: 100%;
    }
    
    /* Formular */
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 0.75rem;
        font-size: 16px; /* Verhindert Zoom auf iOS */
    }
    
    /* Page Header */
    .page-header-left h2 {
        font-size: 0.8125rem;
    }
    
    .page-header-right {
        width: 100%;
    }
    
    .page-header-right .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Stats Cards kompakter */
    .stat-card {
        padding: 0.875rem;
        gap: 0.75rem;
    }
    
    .stat-icon {
        width: 36px;
        height: 36px;
    }
    
    .stat-icon svg {
        width: 18px;
        height: 18px;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
    }
    
    /* Tabellen als Cards auf Mobile */
    .table-container {
        overflow-x: visible;
    }
    
    .data-table {
        display: block;
    }
    
    .data-table thead {
        display: none;
    }
    
    .data-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .data-table tbody tr {
        display: flex;
        flex-direction: column;
        background: var(--bg-primary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        padding: 0.875rem;
    }
    
    .data-table tbody tr:hover {
        background: var(--bg-primary);
    }
    
    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.375rem 0;
        border-bottom: none;
        gap: 0.5rem;
    }
    
    .data-table td:not(:last-child) {
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.5rem;
        margin-bottom: 0.375rem;
    }
    
    .data-table td::before {
        content: attr(data-label);
        font-weight: 500;
        font-size: 0.75rem;
        color: var(--text-secondary);
        text-transform: uppercase;
        flex-shrink: 0;
    }
    
    /* Action Buttons in Tabellen */
    .action-buttons,
    .table-actions {
        justify-content: flex-end;
        width: 100%;
        padding-top: 0.5rem;
    }
    
    /* Modal volle Breite */
    .modal-container {
        padding: 0;
        align-items: flex-end;
    }
    
    .modal {
        max-width: 100%;
        max-height: 90vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        margin: 0;
    }
    
    .modal.modal-lg {
        max-width: 100%;
    }
    
    /* Empty State */
    .empty-state {
        padding: 2rem 1rem;
    }
    
    .empty-state > svg {
        width: 48px;
        height: 48px;
    }
    
    /* Badges */
    .badge {
        font-size: 0.6875rem;
        padding: 0.1875rem 0.5rem;
    }
    
    /* Pagination */
    .pagination {
        flex-wrap: wrap;
    }
    
    .pagination-btn {
        width: 32px;
        height: 32px;
    }
    
    /* Dashboard Grid */
    .dashboard-grid {
        gap: 1rem;
    }
    
    /* Confirm Dialog */
    .confirm-icon {
        width: 48px;
        height: 48px;
    }
    
    .confirm-icon svg {
        width: 24px;
        height: 24px;
    }
    
    .confirm-content h3 {
        font-size: 1rem;
    }
    
    /* Detail View */
    .detail-item {
        padding: 0.625rem;
    }
    
    .detail-label {
        font-size: 0.6875rem;
    }
    
    .detail-value {
        font-size: 0.875rem;
    }
    
    /* Checkbox Group */
    .checkbox-group {
        flex-direction: column;
    }
    
    .checkbox-item {
        width: 100%;
    }
}

/* Extra kleine Geräte (bis 360px) */
@media (max-width: 360px) {
    html {
        font-size: 12px;
    }
    
    .stat-card {
        flex-direction: column;
        text-align: center;
    }
    
    .stat-icon {
        margin: 0 auto;
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
}

/* Touch Device Optimierungen */
@media (hover: none) and (pointer: coarse) {
    /* Größere klickbare Bereiche */
    .nav-item {
        padding: 1rem;
    }
    
    .btn-ghost.btn-small {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Kein Hover-Effekt auf Touch */
    .data-table tbody tr:hover {
        background: transparent;
    }
    
    .nav-item:hover {
        background: transparent;
    }
    
    .nav-item:active {
        background: rgba(255, 255, 255, 0.1);
    }
    
    /* Active States statt Hover */
    .btn:active {
        transform: scale(0.98);
    }
}

/* Landscape Modus auf Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .modal {
        max-height: 95vh;
    }
    
    .modal-body {
        max-height: 50vh;
        overflow-y: auto;
    }
    
    .login-container {
        padding: 1rem;
    }
    
    .login-header {
        margin-bottom: 1rem;
    }
    
    .login-form {
        gap: 0.75rem;
    }
}

/* Print Styles */
@media print {
    .sidebar,
    .main-header,
    .page-header-right,
    .filter-bar,
    .table-actions,
    .action-buttons,
    .pagination {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .data-table {
        display: table;
    }
    
    .data-table thead {
        display: table-header-group;
    }
    
    .data-table tbody {
        display: table-row-group;
    }
    
    .data-table tr {
        display: table-row;
    }
    
    .data-table td,
    .data-table th {
        display: table-cell;
    }
}
