:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --bg-app: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --input-bg: #f1f5f9;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Prevent body scroll, handle in main */
}

/* Authentication Overlay */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: var(--bg-app);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    background: var(--bg-card);
    padding: 32px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    text-align: center;
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    margin-bottom: 12px;
    font-size: 24px;
}

.auth-card p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* Main App Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 100px);
}

.app-header {
    background: var(--bg-card);
    padding: 16px 20px;
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
    z-index: 10;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
}

.connection-pill {
    font-size: 11px;
    background: #e2e8f0;
    padding: 4px 8px;
    border-radius: 12px;
    display: inline-block;
    margin-top: 4px;
    font-weight: 500;
}

.connection-pill.connected {
    background: #dcfce7;
    color: #166534;
}

.connection-pill.disconnected {
    background: #fee2e2;
    color: #991b1b;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
}

/* Content Area */
.app-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.view {
    display: none;
    animation: fadeIn 0.2s ease-out;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

/* Forms & Inputs */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

input {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    font-size: 16px;
    font-family: inherit;
    transition: all 0.2s;
    outline: none;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    font-size: 16px;
    font-family: inherit;
    transition: all 0.2s;
    outline: none;
    resize: vertical;
}

.card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* Specific Component Styles */
.type-selector {
    background: var(--input-bg);
    padding: 4px;
    border-radius: 14px;
    display: flex;
    margin-bottom: 20px;
}

.type-selector input {
    display: none;
}

.type-option {
    flex: 1;
    text-align: center;
    padding: 10px;
    border-radius: 10px;
    font-weight: 500;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.type-selector input:checked+.type-option {
    background: #fff;
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.mileage-card {
    border-left: 4px solid var(--primary);
}

.mileage-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
}

.mileage-info {
    display: flex;
    flex-direction: column;
}

.distance-result {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.distance-result .value {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}

/* Buttons */
.btn {
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.1s;
}

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

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

.btn-secondary {
    background: #e2e8f0;
    color: var(--text-main);
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-block {
    width: 100%;
}

.drive-buttons {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.drive-buttons .btn {
    flex: 1;
}

/* History List */
.drives-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.drive-item {
    background: var(--bg-card);
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drive-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.drive-route {
    font-weight: 600;
    font-size: 15px;
}

.drive-meta {
    font-size: 13px;
    color: var(--text-muted);
}

.drive-distance {
    font-weight: 700;
    color: var(--primary);
}

.drive-desc {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 2px;
}

.drive-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.edit-icon {
    font-size: 14px;
    color: var(--text-muted);
    opacity: 0.5;
}

.drive-item:active {
    background: #f1f5f9;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}

.nav-item.active {
    color: var(--primary);
}

.hidden {
    display: none !important;
}