/* Triply — Mobile-first styles */

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #1a73e8;
    --primary-light: #e8f0fe;
    --primary-dark: #1557b0;
    --grey-50: #f8f9fa;
    --grey-100: #f1f3f4;
    --grey-200: #e8eaed;
    --grey-300: #dadce0;
    --grey-400: #bdc1c6;
    --grey-500: #80868b;
    --grey-600: #5f6368;
    --grey-700: #3c4043;
    --grey-800: #202124;
    --white: #ffffff;
    --red: #d93025;
    --green: #188038;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --transition: 150ms ease;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--grey-50);
    color: var(--grey-800);
    line-height: 1.5;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* === Login === */
.login-body {
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    text-align: center;
    padding: 2rem 1.5rem;
    width: 100%;
    max-width: 320px;
}

.login-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

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

.pin-display {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 1rem;
}

.pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--grey-300);
    transition: all var(--transition);
}

.pin-dot.filled {
    background: var(--primary);
    border-color: var(--primary);
}

.pin-error {
    color: var(--red);
    font-size: 0.85rem;
    height: 1.5rem;
    margin-bottom: 0.5rem;
}

.pin-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 280px;
    margin: 0 auto;
}

.pin-key {
    width: 100%;
    aspect-ratio: 1.4;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--grey-100);
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--grey-800);
    cursor: pointer;
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.pin-key:active {
    background: var(--grey-200);
}

.pin-key-empty {
    background: transparent;
    cursor: default;
}

.pin-key-delete {
    font-size: 1.3rem;
    color: var(--grey-600);
}

/* === App Header === */
#app-header {
    background: var(--white);
    border-bottom: 1px solid var(--grey-200);
    padding: 0.75rem 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

#app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

#app-nav {
    display: flex;
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--grey-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.nav-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* === Pages === */
.page {
    display: none;
    padding: 1rem;
}

.page.active {
    display: block;
}

/* === Common Components === */
.hidden {
    display: none !important;
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary:active {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--grey-100);
    color: var(--grey-700);
}

.btn-secondary:active {
    background: var(--grey-200);
}

.btn-danger {
    background: var(--white);
    color: var(--red);
    border: 1px solid var(--grey-200);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

/* Form elements */
input, select, textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--grey-300);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--grey-800);
    background: var(--white);
    transition: border-color var(--transition);
}

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

textarea {
    resize: vertical;
    min-height: 60px;
}

label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--grey-600);
    margin-bottom: 0.25rem;
}

/* Form group */
.form-group {
    margin-bottom: 0.75rem;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: all var(--transition);
}

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

.badge-private {
    background: var(--grey-100);
    color: var(--grey-500);
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--grey-800);
    color: var(--white);
    padding: 0.6rem 1.25rem;
    border-radius: 100px;
    font-size: 0.85rem;
    z-index: 1000;
    opacity: 0;
    transition: opacity 300ms ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--grey-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--grey-500);
}

.empty-state p {
    font-size: 0.95rem;
}

/* === Trip-specific styles === */
.trip-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.trip-controls .form-group {
    margin-bottom: 0;
}

.trip-controls .btn {
    align-self: stretch;
}

/* Date preset chips */
.date-chips {
    display: flex;
    gap: 0.4rem;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}

.date-chip {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--grey-300);
    border-radius: 100px;
    background: var(--white);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--grey-600);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.date-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.date-chip:not(.active):active {
    background: var(--grey-100);
}

/* Custom date range inputs */
.custom-dates {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.custom-dates .form-group {
    flex: 1;
    margin-bottom: 0;
}

.trip-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-left: 4px solid var(--grey-300);
    transition: border-color var(--transition);
}

.trip-card.work {
    border-left-color: var(--primary);
}

.trip-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.trip-date {
    font-size: 0.8rem;
    color: var(--grey-500);
}

.trip-time {
    font-weight: 600;
    font-size: 0.95rem;
}

.trip-route {
    font-size: 0.85rem;
    color: var(--grey-600);
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.trip-route .arrow {
    color: var(--grey-400);
    margin: 0 0.25rem;
}

.trip-distance {
    font-size: 0.8rem;
    color: var(--grey-500);
    margin-bottom: 0.75rem;
}

/* Trip route map */
.trip-map-wrapper {
    position: relative;
    margin-bottom: 0.75rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: all 300ms ease;
    isolation: isolate;
    z-index: 0;
}

.trip-map {
    height: 150px;
    width: 100%;
    background: var(--grey-100);
}

.map-fullscreen-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 500;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 4px;
    background: var(--white);
    box-shadow: var(--shadow-md);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.map-fullscreen-btn:active {
    background: var(--grey-100);
}

.trip-map-wrapper.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    margin: 0;
    border-radius: 0;
}

.trip-map-wrapper.fullscreen .trip-map {
    height: 100%;
}

.trip-map-wrapper.fullscreen .map-fullscreen-btn {
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    z-index: 1001;
}

/* Custom map markers */
.map-marker {
    border-radius: 50%;
    border: 2px solid var(--white);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.map-marker-start {
    background: var(--green);
}

.map-marker-end {
    background: var(--red);
}

.trip-fields {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.trip-fields select, .trip-fields textarea {
    font-size: 0.85rem;
    padding: 0.45rem 0.6rem;
}

/* Saving indicator on trip card */
.trip-card .saving-indicator {
    font-size: 0.75rem;
    color: var(--grey-400);
    text-align: right;
    margin-top: 0.25rem;
}

/* === Export styles === */
.export-filters {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.export-preview {
    text-align: center;
    padding: 1rem;
    font-size: 0.95rem;
    color: var(--grey-600);
}

.export-preview strong {
    color: var(--grey-800);
}

/* === Clients list === */
.client-item {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.client-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.client-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.client-projects {
    padding: 0 1rem 0.75rem;
    border-top: 1px solid var(--grey-100);
}

.project-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.9rem;
}

.project-item + .project-item {
    border-top: 1px solid var(--grey-50);
}

/* === Settings === */
.settings-group {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.settings-group h3 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--grey-500);
    padding: 0.75rem 1rem 0.5rem;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--grey-50);
}

.setting-row label {
    font-size: 0.9rem;
    color: var(--grey-700);
    margin-bottom: 0;
}

.setting-row select {
    width: auto;
    min-width: 120px;
}

/* Logout */
.logout-btn {
    width: 100%;
    margin-top: 1rem;
}

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

/* Disabled button state */
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Offline banner */
.offline-banner {
    background: var(--red);
    color: var(--white);
    text-align: center;
    padding: 0.4rem;
    font-size: 0.8rem;
    font-weight: 500;
}

/* Fade in animation for cards */
.trip-card {
    animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Trim toolbar === */
.trim-toolbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1002;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--grey-200);
}

.trim-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--grey-600);
    margin-bottom: 0.25rem;
}

.trim-time-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--grey-500);
    margin-bottom: 0.25rem;
}

.trim-slider-wrap {
    position: relative;
    height: 32px;
    margin-bottom: 0.25rem;
    padding: 0 11px;
}

.trim-range {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    margin: 0;
    padding: 0;
    border: none;
    box-shadow: none;
}

.trim-range:focus {
    outline: none;
    box-shadow: none;
}

.trim-range::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--grey-200);
    border-radius: 2px;
}

.trim-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--white);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    margin-top: -9px;
    pointer-events: auto;
    cursor: grab;
}

.trim-range::-moz-range-track {
    height: 4px;
    background: var(--grey-200);
    border-radius: 2px;
    border: none;
}

.trim-range::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--white);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    cursor: grab;
}

.trim-range-start::-webkit-slider-thumb {
    background: var(--green);
}

.trim-range-start::-moz-range-thumb {
    background: var(--green);
}

.trim-info {
    font-size: 0.75rem;
    color: var(--grey-500);
    text-align: center;
    margin-bottom: 0.5rem;
}

.trim-btn-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.trim-indicator {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    background: #fff3e0;
    color: #e65100;
    margin-left: 0.5rem;
    vertical-align: middle;
}

/* === Merge mode === */
.trip-btn-row {
    display: flex;
    gap: 0.5rem;
}

.trip-btn-row .btn {
    flex: 1;
}

.merge-mode .trip-card {
    position: relative;
    padding-left: 2.75rem;
}

.merge-checkbox {
    position: absolute;
    left: 0.75rem;
    top: 1.1rem;
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.merge-selected {
    border-left-color: var(--primary) !important;
    background: var(--primary-light);
}

.merge-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid var(--grey-200);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: center;
}

.merge-toolbar .btn {
    min-width: 200px;
}

.merge-indicator {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.5rem;
    background: #e3f2fd;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--primary);
}

.unmerge-btn {
    margin-left: 0.5rem;
}

/* Safe area padding for notch phones */
@supports (padding-top: env(safe-area-inset-top)) {
    #app-header {
        padding-top: calc(0.75rem + env(safe-area-inset-top));
    }

    .page {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    .login-body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* === Stats === */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    text-align: center;
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--grey-800);
    line-height: 1.2;
}

.stat-card-label {
    font-size: 0.8rem;
    color: var(--grey-500);
    margin-top: 0.15rem;
}

.stat-card-breakdown {
    font-size: 0.7rem;
    color: var(--grey-400);
    margin-top: 0.35rem;
}

.stats-alltime {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.stats-alltime-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.stats-mini {
    text-align: center;
    flex: 1;
}

.stats-mini-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--grey-800);
}

.stats-mini-label {
    font-size: 0.7rem;
    color: var(--grey-500);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stats-section {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.stats-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--grey-500);
    margin-bottom: 0.5rem;
}

.stats-list-row {
    display: flex;
    align-items: center;
    padding: 0.45rem 0;
    gap: 0.5rem;
}

.stats-list-row + .stats-list-row {
    border-top: 1px solid var(--grey-50);
}

.stats-rank {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--grey-400);
    width: 1.5rem;
    flex-shrink: 0;
}

.stats-list-name {
    font-size: 0.9rem;
    color: var(--grey-700);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats-list-meta {
    font-size: 0.8rem;
    color: var(--grey-500);
    white-space: nowrap;
    flex-shrink: 0;
}

/* === Responsive === */
@media (min-width: 600px) {
    .page {
        max-width: 640px;
        margin: 0 auto;
    }

    .trip-controls {
        flex-wrap: nowrap;
    }

    .pin-pad {
        max-width: 240px;
    }
}
