/**
 * ZeitVW - Responsive Styles
 * Mobile-First Ansatz
 */

/* ============================================
   MOBILE (bis 768px)
   ============================================ */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
        --header-height: 56px;
    }

    /* Globale Overflow-Kontrolle */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }

    * {
        max-width: 100%;
    }

    /* Form Inputs mobil */
    .form-input,
    input[type="time"],
    input[type="date"],
    input[type="text"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    /* Sidebar mobil */
    .app-sidebar {
        transform: translateX(-100%);
        width: 80%;
        max-width: 300px;
    }

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

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        transition: all var(--transition);
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Main ohne Sidebar-Margin */
    .app-main {
        margin-left: 0;
    }

    /* Menu Toggle sichtbar */
    .menu-toggle {
        display: flex;
    }

    /* Header kompakter */
    .app-header {
        padding: 0 var(--spacing-md);
    }

    .page-title {
        font-size: var(--font-size-lg);
    }

    .user-name {
        display: none;
    }

    /* Content weniger Padding */
    .app-content {
        padding: var(--spacing-md);
    }

    /* Stats 2 Spalten */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-md);
    }

    .stat-card {
        padding: var(--spacing-md);
    }

    .stat-value {
        font-size: var(--font-size-xl);
    }

    /* Zeiteingabe kompakter */
    .time-entry-card {
        padding: var(--spacing-md);
    }

    .time-entry-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }

    .time-inputs {
        flex-direction: column;
        gap: var(--spacing-md);
        width: 100%;
    }

    .time-separator {
        display: none;
    }

    .time-input-group {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
    }

    .time-input-group input[type="time"] {
        font-size: var(--font-size-lg) !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        text-align: center;
        box-sizing: border-box !important;
        padding: var(--spacing-sm) var(--spacing-xs) !important;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    /* Time Input Wrapper für Placeholder */
    .time-input-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden;
    }

    /* Placeholder Text mobil kleiner */
    .time-placeholder {
        font-size: var(--font-size-sm);
    }

    /* Time Entry Card mobil */
    .time-entry-card {
        overflow: hidden;
    }

    /* Quick Actions vertikal */
    .quick-actions {
        flex-direction: column;
    }

    /* Tabellen scrollbar */
    .table-container {
        margin: 0 calc(-1 * var(--spacing-md));
        border-radius: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-container table {
        min-width: 500px;
    }

    th, td {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: var(--font-size-xs);
        white-space: nowrap;
    }

    /* Erste Spalte sichtbar - extra padding links */
    th:first-child,
    td:first-child {
        padding-left: var(--spacing-md);
    }

    /* Erste Spalte (Name) darf umbrechen */
    td:first-child {
        white-space: normal;
        min-width: 100px;
        max-width: 120px;
    }

    td:first-child strong {
        font-size: var(--font-size-sm);
    }

    td:first-child small {
        font-size: 10px;
    }

    /* Spalten auf Mobil kompakter */
    th:nth-child(3), td:nth-child(3),
    th:nth-child(4), td:nth-child(4) {
        min-width: 55px;
    }

    /* Actions Spalte kompakter */
    .table-actions {
        gap: 2px;
    }

    .table-actions .btn-sm {
        padding: var(--spacing-xs);
        min-height: 32px;
        min-width: 32px;
    }

    /* Badges kleiner */
    .badge {
        font-size: 10px;
        padding: 2px 6px;
    }

    /* Search Box mobil */
    .search-box {
        width: 100%;
        order: 1;
    }

    .search-box .form-input {
        max-width: 100% !important;
    }

    .card-header.flex {
        flex-direction: column;
        align-items: stretch;
    }

    .card-header .card-title {
        margin-bottom: var(--spacing-sm);
    }

    /* Monats-Navigation mobil */
    .card-body.flex.items-center.justify-between {
        flex-direction: row;
        flex-wrap: wrap;
        gap: var(--spacing-sm);
        text-align: center;
        justify-content: space-between;
    }

    .card-body.flex.items-center.justify-between .btn {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: var(--font-size-sm);
        min-width: auto;
        flex-shrink: 0;
    }

    .card-body.flex.items-center.justify-between h2 {
        font-size: var(--font-size-base);
        width: 100%;
        order: -1;
        margin-bottom: var(--spacing-sm);
    }

    .card-body.flex.items-center.justify-between .text-center {
        order: -1;
        width: 100%;
        margin-bottom: var(--spacing-sm);
    }

    .card-body.flex.items-center.justify-between .text-center h2 {
        margin-bottom: 0;
    }

    /* Buttons nebeneinander mit gleicher Breite */
    .card-body.flex.items-center.justify-between > a.btn,
    .card-body.flex.items-center.justify-between > span.btn {
        flex: 1;
        text-align: center;
    }

    /* Header PDF Button */
    .header-right .btn {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: var(--font-size-xs);
    }

    /* Overflow verhindern */
    .app-layout {
        overflow-x: hidden;
    }

    .app-main {
        overflow-x: hidden;
        max-width: 100vw;
    }

    .app-content {
        overflow-x: hidden;
    }

    /* Cards weniger Padding */
    .card-header,
    .card-body,
    .card-footer {
        padding: var(--spacing-md);
    }

    /* Modal volle Breite */
    .modal {
        max-width: calc(100vw - 2 * var(--spacing-md));
        margin: var(--spacing-md);
        border-radius: var(--radius-lg);
        width: 100%;
        box-sizing: border-box;
    }

    .modal-body {
        overflow-x: hidden;
    }

    /* Modal Form Inputs */
    .modal .form-input,
    .modal input[type="date"],
    .modal input[type="text"],
    .modal select,
    .modal textarea {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    .modal .form-group {
        width: 100%;
        max-width: 100%;
    }

    /* Login */
    .login-box {
        padding: var(--spacing-lg);
    }

    .login-title {
        font-size: var(--font-size-xl);
    }

    /* Buttons größer für Touch */
    .btn {
        min-height: 48px;
    }

    .btn-sm {
        min-height: 40px;
    }

    /* Formulare */
    .form-row {
        flex-direction: column;
    }

    .form-row > * {
        min-width: 100%;
    }

    /* Form Actions */
    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn {
        width: 100%;
    }
}

/* ============================================
   TABLET (769px - 1024px)
   ============================================ */
@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
    }

    .nav-item span {
        font-size: var(--font-size-sm);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   KLEINE MOBILE (bis 375px)
   ============================================ */
@media (max-width: 375px) {
    :root {
        --spacing-md: 0.75rem;
        --spacing-lg: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .language-bar {
        flex-wrap: wrap;
    }

    .lang-btn {
        width: 36px;
        height: 36px;
    }

    .flag-icon {
        width: 20px;
        height: 14px;
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .login-container {
        max-width: 450px;
    }

    .login-box {
        padding: var(--spacing-md);
    }

    .login-header {
        margin-bottom: var(--spacing-md);
    }

    .login-logo {
        max-height: 50px;
    }

    .form-group {
        margin-bottom: var(--spacing-md);
    }
}

/* ============================================
   DESKTOP (ab 1025px)
   ============================================ */
@media (min-width: 1025px) {
    /* Sidebar immer sichtbar */
    .sidebar-overlay {
        display: none !important;
    }

    .menu-toggle {
        display: none !important;
    }

    /* Hover-Effekte nur auf Desktop */
    .nav-item:hover {
        background: var(--gray-800);
    }

    table tr:hover {
        background: var(--gray-50);
    }
}

/* ============================================
   LARGE DESKTOP (ab 1440px)
   ============================================ */
@media (min-width: 1440px) {
    :root {
        --max-content-width: 1400px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   DRUCK STYLES
   ============================================ */
@media print {
    .app-sidebar,
    .app-header,
    .menu-toggle,
    .btn,
    .quick-actions,
    .modal-overlay {
        display: none !important;
    }

    .app-main {
        margin: 0 !important;
    }

    .app-content {
        padding: 0 !important;
        max-width: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }

    table {
        page-break-inside: avoid;
    }

    a {
        color: black !important;
        text-decoration: underline;
    }
}

/* ============================================
   DARK MODE (optional, für zukünftige Erweiterung)
   ============================================ */
@media (prefers-color-scheme: dark) {
    /* Aktivieren durch Klasse .dark-mode auf body */
    body.dark-mode {
        --white: #1e293b;
        --gray-50: #0f172a;
        --gray-100: #1e293b;
        --gray-200: #334155;
        --gray-300: #475569;
        --gray-400: #64748b;
        --gray-500: #94a3b8;
        --gray-600: #cbd5e1;
        --gray-700: #e2e8f0;
        --gray-800: #f1f5f9;
        --gray-900: #f8fafc;

        background-color: var(--gray-50);
        color: var(--gray-800);
    }
}

/* ============================================
   TOUCH-OPTIMIERUNGEN
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Größere Touch-Ziele */
    .btn {
        min-height: 48px;
    }

    .nav-item {
        padding: var(--spacing-md) var(--spacing-lg);
        min-height: 48px;
    }

    .form-input,
    .form-select {
        min-height: 48px;
    }

    /* Keine Hover-Effekte auf Touch */
    .nav-item:hover {
        background: transparent;
    }

    table tr:hover {
        background: transparent;
    }

    /* Ripple-Effekt für Buttons */
    .btn {
        position: relative;
        overflow: hidden;
    }

    .btn::after {
        content: '';
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        pointer-events: none;
        background-image: radial-gradient(circle, rgba(255,255,255,0.3) 10%, transparent 10%);
        background-repeat: no-repeat;
        background-position: 50%;
        transform: scale(10, 10);
        opacity: 0;
        transition: transform 0.3s, opacity 0.5s;
    }

    .btn:active::after {
        transform: scale(0, 0);
        opacity: 1;
        transition: 0s;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Fokus-Styles für Keyboard-Navigation */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn:focus-visible,
.form-input:focus-visible,
.form-select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --primary: #0000ee;
        --success: #008000;
        --danger: #cc0000;
        --warning: #cc6600;
    }

    .btn {
        border-width: 2px;
    }

    .form-input,
    .form-select {
        border-width: 2px;
    }

    .card {
        border: 2px solid var(--gray-800);
    }
}
