/**
 * Responsive UI Optimizations
 * Modern, scalable design for all screen sizes
 */

/* ═══════════════════════════════════════════════════════
   CSS Variables for consistent theming
   ═══════════════════════════════════════════════════════ */
:root {
    /* Spacing scale */
    --spacing-xs: 0.25rem;   /* 4px */
    --spacing-sm: 0.5rem;    /* 8px */
    --spacing-md: 1rem;      /* 16px */
    --spacing-lg: 1.5rem;    /* 24px */
    --spacing-xl: 2rem;      /* 32px */
    --spacing-2xl: 3rem;     /* 48px */

    /* Typography scale */
    --font-xs: 0.75rem;      /* 12px */
    --font-sm: 0.875rem;     /* 14px */
    --font-md: 1rem;         /* 16px */
    --font-lg: 1.125rem;     /* 18px */
    --font-xl: 1.25rem;      /* 20px */
    --font-2xl: 1.5rem;      /* 24px */

    /* Card/section styling */
    --card-border-radius: 12px;
    --card-shadow: 0 2px 8px var(--evoi-shadow);
    --card-hover-shadow: 0 4px 16px var(--evoi-shadow);

    /* Touch targets */
    --min-touch-target: 44px;
}

/* ═══════════════════════════════════════════════════════
   Layout improvements
   ═══════════════════════════════════════════════════════ */
.page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Main content area - responsive padding */
main .content {
    padding: var(--spacing-md);
    width: 100%;
    max-width: 2000px;
    margin: 0 auto;
}

@media (min-width: 641px) {
    /* Chain flex-fill from article.content down through page containers */
    article.content {
        display: flex;
        flex-direction: column;
    }

    /* List pages: page-container fills remaining height after PageHeader */
    .page-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    /* Grid wrapper inside page-container fills the container */
    .grid-container {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .grid-container > .e-grid,
    .grid-container > .sf-grid-wrapper {
        flex: 1;
        min-height: 0;
    }

    /* Timer layout: two-column row fills available height */
    .timer-layout {
        flex: 1;
        min-height: 0;
        align-items: stretch;
    }

    .timer-layout .card {
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .timer-layout .card > .card-body {
        flex: 1;
        min-height: 0;
        overflow: auto;
        padding-bottom: 0;
    }
}

/* Zeiterfassung: Höhenkette bis in die Spalten hinein.
   Erst ab 768px, denn dort stehen die beiden Karten nebeneinander (col-md-6). Darunter
   stapeln sie sich — dann ist eine scrollende Seite richtig, und ein Zwang auf Fensterhöhe
   würde beide zusammenquetschen.

   Ohne diese Regeln endete die Kette bei .timer-layout: Die Bootstrap-Spalte blieb auf der
   natürlichen Höhe der Stoppuhr-Karte stehen (gemessen 609px) und schob die Seite über den
   Rand — links scrollte die ganze Seite, rechts nur das Gitter. Der Grund ist, dass ein
   Flex-Element ohne min-height:0 nicht unter seine Inhaltsgröße schrumpfen kann; und
   height:100% an der Karte bezog sich dann auf ebendiese 609px statt auf den Platz. */
@media (min-width: 768px) {
    /* Kein Umbruch: In einem umbrechenden Flex-Container ergibt sich die Zeilenhöhe aus dem
       Inhalt, und ein Element kann NICHT darunter schrumpfen — min-height:0 hilft dort nichts.
       Erst ohne Umbruch bekommen die Spalten die Höhe des Containers. Ab 768px stehen ohnehin
       genau zwei Spalten nebeneinander (col-md-6), es gibt also nichts umzubrechen. */
    .timer-layout {
        flex-wrap: nowrap;
    }

    .timer-layout > [class*="col-"] {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .timer-layout .card {
        flex: 1;
        min-height: 0;
        height: auto;
    }
}

@media (min-width: 1200px) {
    main .content {
        padding: var(--spacing-xl);
    }
}

@media (max-width: 768px) {
    main .content {
        padding: var(--spacing-sm);
        padding-bottom: var(--spacing-lg); /* Extra space for mobile navigation */
    }
}

/* ═══════════════════════════════════════════════════════
   Section/Card Styling - consistent modern look
   ═══════════════════════════════════════════════════════ */
.section {
    padding: var(--spacing-md);
    background: var(--sf-grid-header-bg-color, var(--evoi-surface-sunken));
    border-radius: var(--card-border-radius);
    margin-bottom: var(--spacing-md);
    box-shadow: var(--card-shadow);
    transition: box-shadow 0.2s ease;
}

.section:hover {
    box-shadow: var(--card-hover-shadow);
}

@media (max-width: 768px) {
    .section {
        padding: var(--spacing-sm);
        border-radius: 8px;
    }
}

.section h5 {
    font-size: var(--font-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--bs-body-color);
}

@media (max-width: 768px) {
    .section h5 {
        font-size: var(--font-md);
        margin-bottom: var(--spacing-sm);
    }
}

/* ═══════════════════════════════════════════════════════
   Responsive Grid System
   ═══════════════════════════════════════════════════════ */
/* Better spacing for form grids */
.row.g-3 {
    --bs-gutter-x: 1rem;
}

@media (max-width: 768px) {
    .row.g-3 {
        --bs-gutter-x: 0.75rem;
    }

    /* Stack form elements on mobile */
    .col-md-3, .col-md-4, .col-md-6 {
        margin-bottom: var(--spacing-sm);
    }
}

/* ═══════════════════════════════════════════════════════
   Form Elements - adaptive sizing
   ═══════════════════════════════════════════════════════ */
/* Make all inputs/touch targets accessible */
.form-control,
.form-select,
.SfTextBox,
.SfNumericTextBox,
.SfDatePicker,
.SfDateTimePicker,
.SfDropDownList {
    min-height: var(--min-touch-target);
    font-size: var(--font-md);
}

@media (max-width: 768px) {
    .form-control,
    .form-select,
    .SfTextBox,
    .SfNumericTextBox,
    .SfDatePicker,
    .SfDateTimePicker,
    .SfDropDownList {
        font-size: var(--font-md); /* Slightly larger for mobile */
        width: 100% !important; /* Full width on mobile */
    }
}

/* Numeric inputs - compact but accessible */
.SfNumericTextBox.e-small,
.SfTextBox.e-small {
    min-height: 40px;
}

@media (max-width: 768px) {
    .SfNumericTextBox.e-small,
    .SfTextBox.e-small {
        min-height: 44px;
    }
}

/* ═══════════════════════════════════════════════════════
   Buttons - responsive sizing
   ═══════════════════════════════════════════════════════ */
.btn,
.SfButton {
    min-height: var(--min-touch-target);
    padding: 0.5rem 1rem;
    font-size: var(--font-md);
    border-radius: 8px;
    transition: all 0.2s ease;
}

@media (max-width: 768px) {
    .btn,
    .SfButton {
        width: 100%; /* Full width buttons on mobile */
        margin-bottom: var(--spacing-sm);
    }

    /* Stacked button layouts on mobile */
    .btn-group .btn,
    .button-group .button {
        width: 100%;
        margin: 0;
    }
}

/* Button icons - ensure proper sizing */
.btn i,
.SfButton .e-icon {
    font-size: 1rem;
    margin-right: 8px;
}

@media (max-width: 768px) {
    .btn i,
    .SfButton .e-icon {
        margin-right: 6px;
    }

    /* Only icon on very small screens if text overflows */
    .btn span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* ═══════════════════════════════════════════════════════
   Tables & Lists - responsive behavior
   ═══════════════════════════════════════════════════════ */
/* Make tables scrollable on small screens */
.table-responsive {
    border-radius: var(--card-border-radius);
    box-shadow: var(--card-shadow);
}

@media (max-width: 768px) {
    .table-responsive {
        border-radius: 8px;
        box-shadow: var(--card-shadow);
    }

    /* Compact table layout on mobile */
    .table td, .table th {
        padding: 0.75rem 0.5rem;
        font-size: var(--font-sm);
    }
}

/* Time entry groups - adaptive layout */
.time-entry-group {
    border: 1px solid var(--bs-border-color);
    border-radius: var(--card-border-radius);
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--evoi-surface);
    transition: box-shadow 0.2s ease;
}

.time-entry-group:hover {
    box-shadow: var(--card-hover-shadow);
}

@media (max-width: 768px) {
    .time-entry-group {
        padding: var(--spacing-sm);
        border-radius: 8px;
    }

    /* Stack group items vertically on mobile */
    .time-entry-group .row {
        flex-direction: column;
    }

    .time-entry-group .col-auto,
    .time-entry-group .col-md-auto {
        width: 100%;
        margin-bottom: var(--spacing-xs);
    }

    /* Group header: let the right-side rate/amount block wrap under the project + description
       instead of squeezing everything onto one line. */
    .time-entry-group > .d-flex.align-items-center {
        flex-wrap: wrap;
    }

    .time-entry-group > .d-flex.align-items-center > .text-end {
        width: 100%;
        text-align: left !important;
        margin-top: var(--spacing-xs);
    }

    .time-entry-group > .d-flex.align-items-center > .text-end .d-flex {
        justify-content: flex-start !important;
    }

    /* Detail rows: the two date-time pickers have fixed 180px widths that overflow a phone.
       Stack them full-width instead of running off-screen. */
    .time-entries-detail .time-entry-row {
        flex-wrap: wrap;
    }

    .time-entries-detail .time-entry-row > .d-flex {
        flex: 1 1 100%;
    }

    .time-entries-detail .time-entry-row .e-datetime-wrapper,
    .time-entries-detail .time-entry-row .e-control-wrapper {
        width: 100% !important;
    }

    /* The "–" range separator is meaningless once the pickers stack vertically. */
    .time-entries-detail .time-entry-row > span.text-muted {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════
   Modals & Dialogs - adaptive sizing
   ═══════════════════════════════════════════════════════ */
.SfDialog,
.modal-dialog {
    width: 90vw !important;
    max-width: 600px !important;
    margin: 1rem auto !important;
}

@media (max-width: 768px) {
    .SfDialog,
    .modal-dialog {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 0.5rem auto !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    .SfDialog .e-dialog-header,
    .modal-header {
        padding: 0.75rem 1rem;
    }

    .SfDialog .e-dialog-content,
    .modal-body {
        padding: 1rem;
    }

    .SfDialog .e-dialog-footer,
    .modal-footer {
        padding: 0.75rem 1rem;
        flex-direction: column;
    }

    .SfDialog .e-dialog-footer .btn,
    .modal-footer .btn {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }

    .SfDialog .e-dialog-footer .btn:last-child,
    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }
}

@media (min-width: 1200px) {
    .SfDialog,
    .modal-dialog {
        max-width: 900px !important;
    }
}

/* ═══════════════════════════════════════════════════════
   Timer page - card header with multiple controls
   ═══════════════════════════════════════════════════════ */
@media (max-width: 640.98px) {
    .timer-entries-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.4rem;
    }

    .timer-entries-header > div.d-flex {
        flex-wrap: wrap;
        gap: 0.4rem;
        width: 100%;
    }

    /* Override full-width button rule inside card header controls */
    .timer-entries-header .btn {
        width: auto !important;
        margin-bottom: 0 !important;
    }

    /* Toggle switch row stays inline */
    .timer-entries-header .form-check {
        flex-shrink: 0;
    }
}

/* ═══════════════════════════════════════════════════════
   Navigation - mobile responsive
   ═══════════════════════════════════════════════════════ */
.mobile-header {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        background: var(--bs-body-bg);
        border-bottom: 1px solid var(--bs-border-color);
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .header-title {
        font-size: var(--font-lg);
        font-weight: 600;
    }

    .hamburger-icon {
        display: flex;
        flex-direction: column;
        gap: 5px;
        cursor: pointer;
        padding: 0.5rem;
        width: var(--min-touch-target);
        height: var(--min-touch-target);
    }

    .hamburger-icon span {
        width: 24px;
        height: 2px;
        background: var(--bs-body-color);
        transition: all 0.3s ease;
    }
}

/* ═══════════════════════════════════════════════════════
   Typography - responsive scaling
   ═══════════════════════════════════════════════════════ */
h1, .h1 { font-size: clamp(1.75rem, 4vw, 2.25rem); }
h2, .h2 { font-size: clamp(1.5rem, 3.5vw, 2rem); }
h3, .h3 { font-size: clamp(1.25rem, 3vw, 1.75rem); }
h4, .h4 { font-size: clamp(1.125rem, 2.5vw, 1.5rem); }
h5, .h5 { font-size: clamp(1rem, 2vw, 1.25rem); }
h6, .h6 { font-size: clamp(0.875rem, 1.5vw, 1rem); }

body {
    font-size: var(--font-md);
    line-height: 1.6;
}

@media (max-width: 768px) {
    body {
        font-size: var(--font-md); /* Keep readable */
        line-height: 1.7; /* Better readability */
    }

    p {
        margin-bottom: 0.75rem;
    }
}

/* ═══════════════════════════════════════════════════════
   Utilities - responsive helpers
   ═══════════════════════════════════════════════════════ */
/* Hide/show elements based on viewport */
.hide-mobile {
    display: inherit !important;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

.hide-desktop {
    display: none !important;
}

@media (max-width: 768px) {
    .hide-desktop {
        display: inherit !important;
    }
}

/* Responsive spacing utilities */
.sm-mb-0 { margin-bottom: 0 !important; }
.sm-mb-1 { margin-bottom: 0.5rem !important; }
.sm-mb-2 { margin-bottom: 1rem !important; }
.sm-mb-3 { margin-bottom: 1.5rem !important; }
.sm-mb-4 { margin-bottom: 2rem !important; }

@media (max-width: 768px) {
    .sm-mb-0 { margin-bottom: 0 !important; }
    .sm-mb-1 { margin-bottom: 0.5rem !important; }
    .sm-mb-2 { margin-bottom: 1rem !important; }
    .sm-mb-3 { margin-bottom: 1.5rem !important; }
    .sm-mb-4 { margin-bottom: 2rem !important; }
}

/* Text truncation with tooltip on hover */
.truncate-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: help;
}

@media (max-width: 768px) {
    .truncate-text {
        white-space: normal; /* Allow wrapping on mobile */
        cursor: auto;
    }
}

/* ═══════════════════════════════════════════════════════
   Syncfusion Components - responsive overrides
   ═══════════════════════════════════════════════════════ */
/* Grid component responsive */
.e-grid .e-table {
    font-size: var(--font-sm);
}

@media (max-width: 640.98px) {
    .e-grid .e-table {
        font-size: var(--font-xs);
    }

    .e-grid .e-header-cells,
    .e-grid .e-row-cells {
        padding: 0.5rem 0.25rem !important;
    }

    /* Secondary grid columns hidden on mobile via CustomAttributes class */
    .e-grid th.col-mobile-hidden,
    .e-grid td.col-mobile-hidden {
        display: none !important;
    }

    /* Auto-resize the remaining visible columns to fill the available width.
       Overrides Syncfusion's fixed-layout table with explicit pixel widths. */
    .grid-container .e-grid .e-table,
    .timer-layout .card-body .e-grid .e-table {
        width: 100% !important;
        table-layout: auto !important;
    }
}

/* Chip component - adaptive sizing */
.e-chip {
    font-size: var(--font-sm);
    padding: 0.35rem 0.65rem;
    min-height: 32px;
}

@media (max-width: 768px) {
    .e-chip {
        font-size: var(--font-sm);
        padding: 0.4rem 0.75rem;
        min-height: 36px;
    }
}

/* ═══════════════════════════════════════════════════════
   Invoice-specific optimizations
   ═══════════════════════════════════════════════════════ */
/* Invoice totals section - prominent display */
.invoice-totals {
    background: var(--bs-light);
    border-radius: var(--card-border-radius);
    padding: var(--spacing-lg);
    margin-top: var(--spacing-xl);
}

@media (max-width: 768px) {
    .invoice-totals {
        padding: var(--spacing-md);
        margin-top: var(--spacing-lg);
    }
}

/* Item listing - better spacing */
.invoice-item-row {
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--bs-border-color);
}

.invoice-item-row:last-child {
    border-bottom: none;
}

@media (max-width: 768px) {
    .invoice-item-row {
        padding: var(--spacing-sm);
        display: block;
    }

    .invoice-item-row .col {
        margin-bottom: 0.25rem;
    }

    .invoice-item-row .col:last-child {
        text-align: left !important;
        margin-bottom: 0;
    }
}

/* ═══════════════════════════════════════════════════════
   Dashboard - responsive cards
   ═══════════════════════════════════════════════════════ */
.dashboard-card {
    background: var(--evoi-surface);
    border-radius: var(--card-border-radius);
    padding: var(--spacing-lg);
    box-shadow: var(--card-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--card-hover-shadow);
}

@media (max-width: 768px) {
    .dashboard-card {
        padding: var(--spacing-md);
        border-radius: 8px;
        margin-bottom: var(--spacing-sm);
    }

    .dashboard-card h3 {
        font-size: var(--font-md);
    }

    .dashboard-card .display-4 {
        font-size: 1.75rem;
    }
}

/* ═══════════════════════════════════════════════════════
   Dashboard page - KPI grid + charts
   ═══════════════════════════════════════════════════════ */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.kpi-card {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
}

/* Clickable KPI cards (drill-down to a filtered invoice list) */
.kpi-card-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.kpi-card-link:hover,
.kpi-card-link:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--evoi-shadow);
    color: inherit;
    text-decoration: none;
}

.invoice-filter-banner {
    padding: var(--spacing-sm) var(--spacing-md);
    margin-bottom: var(--spacing-md);
    background-color: rgba(13, 110, 253, 0.08);
    border: 1px solid rgba(13, 110, 253, 0.2);
    border-radius: var(--radius-md, 6px);
    font-size: var(--font-sm);
}

.kpi-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-lg);
    color: white;
}

.kpi-icon-open { background-color: #28a745; }
.kpi-icon-overdue { background-color: #dc3545; }
.kpi-icon-outstanding { background-color: #fd7e14; }
.kpi-icon-revenue { background-color: #0d6efd; }
.kpi-icon-paid { background-color: #17a2b8; }
.kpi-icon-draft { background-color: #ffc107; color: #212529; }
.kpi-icon-days { background-color: #6c757d; }

.kpi-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kpi-value {
    font-size: var(--font-2xl);
    font-weight: 700;
    line-height: 1.2;
}

.kpi-label {
    font-size: var(--font-sm);
}

.kpi-sub {
    font-size: var(--font-xs);
}

.dashboard-charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--spacing-md);
}

.dashboard-chart-card h3 {
    font-size: var(--font-lg);
    margin-bottom: var(--spacing-sm);
}

@media (max-width: 640.98px) {
    .dashboard-grid,
    .dashboard-charts-row {
        grid-template-columns: 1fr;
    }

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

/* ═══════════════════════════════════════════════════════
   Customer/Project/Invoice lists - responsive tables
   ═══════════════════════════════════════════════════════ */
.list-card {
    background: var(--evoi-surface);
    border-radius: var(--card-border-radius);
    padding: var(--spacing-md);
    box-shadow: var(--card-shadow);
}

@media (max-width: 768px) {
    .list-card {
        padding: var(--spacing-sm);
        border-radius: 8px;
    }

    /* Convert tables to cards on mobile */
    .table-responsive .table {
        display: block;
    }

    .table-responsive thead {
        display: none;
    }

    .table-responsive tbody tr {
        display: block;
        margin-bottom: var(--spacing-md);
        border: 1px solid var(--bs-border-color);
        border-radius: 8px;
        padding: var(--spacing-sm);
    }

    .table-responsive tbody td {
        display: flex;
        justify-content: space-between;
        text-align: right;
        padding: 0.5rem 0;
        border: none;
    }

    .table-responsive tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        margin-right: auto;
    }
}

/* ═══════════════════════════════════════════════════════
   Print styles - ensure proper printing
   ═══════════════════════════════════════════════════════ */
@media print {
    .mobile-header,
    .sidebar,
    .navbar-toggler,
    .btn,
    .no-print {
        display: none !important;
    }

    main .content {
        padding: 0;
    }

    .section, .dashboard-card, .list-card {
        box-shadow: none;
        border: 1px solid var(--evoi-border);
    }
}

/* ═══════════════════════════════════════════════════════
   Dark mode responsive adjustments (if applicable)
   ═══════════════════════════════════════════════════════ */
[data-theme="dark"] .section,
[data-theme="dark"] .dashboard-card,
[data-theme="dark"] .list-card {
    box-shadow: 0 2px 8px var(--evoi-shadow-strong);
}

[data-theme="dark"] .time-entry-group {
    background: var(--bs-body-bg);
    border-color: var(--bs-border-color);
}

/* ═══════════════════════════════════════════════════════
   Animation for smooth transitions
   ═══════════════════════════════════════════════════════ */
* {
    transition: none !important; /* Disable global transitions */
}

/* Enable transitions only on specific elements */
.section,
.dashboard-card,
.list-card,
.time-entry-group,
.btn,
.SfButton,
.modal-dialog,
.e-chip {
    transition: box-shadow 0.2s ease,
                transform 0.2s ease,
                background-color 0.2s ease,
                border-color 0.2s ease;
}

/* Focus styles for accessibility */
*:focus {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
