:root {
    --primary-color: #60a5fa;
    /* Blue 400 */
    --primary-hover: #3b82f6;
    /* Blue 500 */
    --background-color: #0f172a;
    /* Slate 900 */
    --card-bg: #1e293b;
    /* Slate 800 */
    --text-main: #f8fafc;
    /* Slate 50 */
    --text-muted: #94a3b8;
    /* Slate 400 */
    --border-color: #334155;
    /* Slate 700 */
    --danger-color: #f87171;
    /* Red 400 */
    --danger-hover: #ef4444;
    /* Red 500 */

    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    --transition-fast: 0.2s ease;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--background-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-icon {
    color: var(--primary-color);
}

h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Layout Grid */
.app-main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 350px 1fr;
        align-items: start;
    }
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.card-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.card-body {
    padding: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    background-color: #0f172a;
    /* Slate 900 */
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color var(--transition-fast), transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    margin-top: 1rem;
}

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

.btn-text {
    background: none;
    border: none;
    color: var(--danger-color);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
}

.btn-text:hover {
    color: var(--danger-hover);
    text-decoration: underline;
}

/* Filter Section */
.filter-section {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter-label {
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.95rem;
}

.filter-select {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Summary Cards (Top right) */
.overview-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.summary-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.summary-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.time-icon {
    background-color: rgba(96, 165, 250, 0.15);
    /* Primary with opacity */
    color: var(--primary-color);
}

.km-icon {
    background-color: rgba(34, 197, 94, 0.15);
    /* Green with opacity */
    color: #4ade80;
    /* Green 400 */
}

.summary-content h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

/* History Table */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-responsive {
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.history-table th {
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.history-table td {
    padding: 1rem;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.history-table tbody tr:last-child td {
    border-bottom: none;
}

.history-table tbody tr:hover {
    background-color: #334155;
    /* Slate 700 */
}

.empty-state td {
    text-align: center;
    padding: 3rem !important;
    color: var(--text-muted);
    font-style: italic;
}

.action-btn {
    background: none;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.action-btn:hover {
    background-color: rgba(248, 113, 113, 0.15);
}

/* Badge for Hours/KM in table */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 500;
    background-color: var(--border-color);
}

.badge.primary {
    background-color: rgba(96, 165, 250, 0.15);
    color: var(--primary-color);
}

.badge.success {
    background-color: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

/* ===== Login Overlay ===== */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 40%, #0f172a 100%);
    animation: loginFadeIn 0.5s ease;
}

@keyframes loginFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.login-card {
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 400px;
    margin: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 80px rgba(96, 165, 250, 0.06);
    text-align: center;
    animation: loginSlideIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes loginSlideIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.15), rgba(96, 165, 250, 0.05));
    border-radius: 50%;
    color: var(--primary-color);
}

.login-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 2rem;
}

.login-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.login-input-group input[type="password"] {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-main);
    background-color: rgba(15, 23, 42, 0.6);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    text-align: center;
    letter-spacing: 0.15em;
}

.login-input-group input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.login-input-group input[type="password"]::placeholder {
    letter-spacing: normal;
    color: var(--text-muted);
}

.login-btn {
    margin-top: 0.5rem;
    padding: 0.875rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

.login-error {
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-top: 1rem;
    animation: shake 0.4s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-6px);
    }

    50% {
        transform: translateX(6px);
    }

    75% {
        transform: translateX(-4px);
    }
}

/* Fade-in for app content after login */
#app-content {
    animation: appFadeIn 0.4s ease;
}

@keyframes appFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================= */
/* ===== Responsive Design: iPad & iPhone  ===== */
/* ============================================= */

/* --- iPad Portrait & small tablets (≤ 768px) --- */
@media (max-width: 768px) {
    .app-main {
        padding: 0 1rem;
        margin: 1.5rem auto;
    }

    .header-container {
        padding: 0 1rem;
    }

    .dashboard-grid {
        gap: 1.5rem;
    }

    .summary-cards {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    .summary-card {
        padding: 1.25rem;
    }

    .summary-value {
        font-size: 1.25rem;
    }

    .card-header {
        padding: 1.25rem 1.25rem 0.75rem;
    }

    .card-body {
        padding: 1.25rem;
    }

    .filter-section {
        padding: 0.85rem 1.25rem;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .filter-select {
        width: 100%;
    }

    .login-card {
        padding: 2.5rem 2rem;
        max-width: 380px;
    }
}

/* --- iPhone & small phones (≤ 480px) --- */
@media (max-width: 480px) {

    /* Safe area for notched iPhones */
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .app-header {
        padding: 0.75rem 0;
    }

    h1 {
        font-size: 1.05rem;
    }

    .app-main {
        padding: 0 0.75rem;
        margin: 1rem auto;
    }

    .dashboard-grid {
        gap: 1rem;
    }

    /* Form: stack all rows vertically */
    .form-row,
    .input-row-secondary {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    /* Larger touch targets for inputs */
    input[type="text"],
    input[type="date"],
    input[type="time"],
    input[type="number"] {
        padding: 0.85rem;
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    .btn {
        padding: 0.85rem 1rem;
        font-size: 1rem;
        min-height: 44px;
        /* Apple HIG minimum touch target */
    }

    .btn-primary {
        margin-top: 0.5rem;
    }

    /* Summary cards: 1 column on very small screens */
    .summary-cards {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .summary-card {
        padding: 1rem;
        gap: 0.75rem;
    }

    .summary-icon {
        width: 40px;
        height: 40px;
    }

    .summary-icon svg {
        width: 20px;
        height: 20px;
    }

    .summary-content h3 {
        font-size: 0.8rem;
    }

    .summary-value {
        font-size: 1.15rem;
    }

    .card-header {
        padding: 1rem 1rem 0.75rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header h2 {
        font-size: 1rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    /* History table: card-based layout on mobile */
    .history-table thead {
        display: none;
    }

    .history-table tbody tr {
        display: flex;
        flex-direction: column;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border-color);
        gap: 0.35rem;
    }

    .history-table tbody tr:hover {
        background-color: transparent;
    }

    .history-table td {
        padding: 0.15rem 0;
        border-bottom: none;
        font-size: 0.9rem;
    }

    /* Label the cells with pseudo-content */
    .history-table td:nth-child(1)::before {
        content: none;
        /* Date is already prominent */
    }

    .history-table td:nth-child(2)::before {
        content: "Kunde: ";
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.75rem;
    }

    .history-table td:nth-child(3)::before {
        content: "Zeit: ";
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.75rem;
    }

    .history-table td:nth-child(4),
    .history-table td:nth-child(5) {
        display: inline;
    }

    .history-table td:nth-child(6) {
        align-self: flex-end;
        margin-top: -2rem;
    }

    /* Make delete button larger for touch */
    .action-btn {
        padding: 0.5rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .action-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Filter section */
    .filter-section {
        padding: 0.75rem 1rem;
    }

    .filter-label {
        font-size: 0.85rem;
    }

    .filter-select {
        padding: 0.65rem 0.75rem;
        font-size: 16px;
        /* Prevent iOS zoom */
    }

    /* Login adjustments for small phones */
    .login-card {
        padding: 2rem 1.5rem;
        border-radius: 16px;
        margin: 0.75rem;
    }

    .login-icon {
        width: 64px;
        height: 64px;
        margin-bottom: 1.25rem;
    }

    .login-icon svg {
        width: 36px;
        height: 36px;
    }

    .login-card h2 {
        font-size: 1.25rem;
    }

    .login-subtitle {
        font-size: 0.85rem;
        margin-bottom: 1.5rem;
    }

    .login-input-group input[type="password"] {
        font-size: 16px;
        /* Prevent iOS zoom */
        padding: 0.75rem;
    }

    /* History header */
    .history-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .btn-text {
        font-size: 0.8rem;
    }

    /* Empty state */
    .empty-state td {
        padding: 2rem !important;
        font-size: 0.85rem;
    }
}

/* --- Touch device optimizations --- */
@media (hover: none) and (pointer: coarse) {

    /* Remove hover effects on touch devices */
    .history-table tbody tr:hover {
        background-color: transparent;
    }

    /* Use active state instead */
    .history-table tbody tr:active {
        background-color: rgba(51, 65, 85, 0.5);
    }

    .btn:active {
        transform: scale(0.97);
    }

    .action-btn:active {
        background-color: rgba(248, 113, 113, 0.2);
    }

    /* Prevent text selection on buttons */
    .btn,
    .action-btn,
    .btn-text {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        user-select: none;
    }
}

/* --- iPad landscape (769px – 1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 300px 1fr;
    }
}

/* --- Landscape mode on phones --- */
@media (max-height: 500px) and (orientation: landscape) {
    .login-card {
        padding: 1.5rem 2rem;
        max-width: 450px;
    }

    .login-icon {
        display: none;
    }

    .login-card h2 {
        margin-bottom: 0.25rem;
    }

    .login-subtitle {
        margin-bottom: 1rem;
    }
}