/* ============================================================================
   TRACKIT - CSS Styles
   Modern dark-first design system for time & mileage tracking
   ============================================================================ */

/* ============================================================================
   CSS Custom Properties (Design Tokens)
   ============================================================================ */

:root {
    /* Colors - Dark Theme (default) */
    --color-bg-primary: #0f0f17;
    --color-bg-secondary: #1a1a2e;
    --color-bg-tertiary: #252540;
    --color-bg-elevated: #2d2d4a;

    --color-text-primary: #ffffff;
    --color-text-secondary: #a0a0b8;
    --color-text-muted: #6b6b80;

    --color-border: #3a3a55;
    --color-border-light: #4a4a65;

    --color-accent-primary: #6366f1;
    --color-accent-primary-hover: #818cf8;
    --color-accent-secondary: #22c55e;
    --color-accent-danger: #ef4444;
    --color-accent-warning: #f59e0b;

    --color-success: #22c55e;
    --color-error: #ef4444;
    --color-warning: #f59e0b;
    --color-info: #3b82f6;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-md: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    --font-size-2xl: 32px;

    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* Z-index layers */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal-backdrop: 300;
    --z-modal: 400;
    --z-toast: 500;
}

/* Light Theme */
[data-theme="light"] {
    --color-bg-primary: #f8fafc;
    --color-bg-secondary: #ffffff;
    --color-bg-tertiary: #f1f5f9;
    --color-bg-elevated: #ffffff;

    --color-text-primary: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;

    --color-border: #e2e8f0;
    --color-border-light: #cbd5e1;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.15);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

/* ============================================================================
   Reset & Base Styles
   ============================================================================ */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: var(--line-height-normal);
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--color-accent-primary);
    text-decoration: none;
}

a:hover {
    color: var(--color-accent-primary-hover);
}

button {
    font-family: inherit;
    cursor: pointer;
}

input, select, textarea, button {
    font-size: var(--font-size-md);
}

:focus-visible {
    outline: 2px solid var(--color-accent-primary);
    outline-offset: 2px;
}

/* ============================================================================
   Layout
   ============================================================================ */

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-md);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 800px;
    margin: 0 auto;
}

.logo {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.main-content {
    flex: 1;
    padding: var(--space-md);
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* ============================================================================
   Components - Icons
   ============================================================================ */

.icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
}

/* Theme toggle icons */
[data-theme="dark"] .sun-icon,
.moon-icon {
    display: none;
}

[data-theme="dark"] .moon-icon,
.sun-icon {
    display: block;
}

[data-theme="light"] .sun-icon {
    display: block;
}

[data-theme="light"] .moon-icon {
    display: none;
}

/* ============================================================================
   Components - Status Indicator
   ============================================================================ */

.status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--color-error);
}

.status-indicator.online .status-dot {
    background: var(--color-success);
}

.status-indicator.offline .status-dot {
    background: var(--color-error);
    animation: pulse-offline 2s infinite;
}

@keyframes pulse-offline {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ============================================================================
   Components - Cards
   ============================================================================ */

.card {
    background: var(--color-bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    margin-bottom: var(--space-md);
    overflow: hidden;
}

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

.card-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.card-body {
    padding: var(--space-md);
}

.disabled-card {
    opacity: 0.6;
    pointer-events: none;
}

/* ============================================================================
   Components - Buttons
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius-md);
    font-weight: var(--font-weight-medium);
    text-align: center;
    white-space: nowrap;
    transition: all var(--transition-fast);
    min-height: 44px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--color-accent-primary-hover);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-light);
}

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}

.btn-lg {
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-lg);
    min-height: 52px;
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    min-height: 36px;
}

.btn-block {
    width: 100%;
}

/* ============================================================================
   Components - Forms
   ============================================================================ */

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

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
}

.form-control {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-primary);
    min-height: 44px;
    transition: all var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--color-accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-control::placeholder {
    color: var(--color-text-muted);
}

.form-control:disabled,
.form-control[readonly] {
    opacity: 0.7;
    cursor: not-allowed;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b6b80' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-sm) center;
    background-size: 20px;
    padding-right: 40px;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

@media (max-width: 480px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.flex-grow {
    flex: 1;
}

/* ============================================================================
   Components - Active Session Panel
   ============================================================================ */

.active-session {
    background: linear-gradient(135deg, var(--color-bg-secondary), var(--color-bg-tertiary));
    border: 2px solid var(--color-accent-primary);
    box-shadow: var(--shadow-glow);
}

.active-session .card-title {
    color: var(--color-accent-primary);
}

.pulse-dot {
    width: 12px;
    height: 12px;
    background: var(--color-accent-primary);
    border-radius: var(--radius-full);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(99, 102, 241, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}

.session-info {
    margin-bottom: var(--space-md);
}

.session-client {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-md);
}

.session-time-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.session-start,
.session-elapsed {
    background: var(--color-bg-tertiary);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    text-align: center;
}

.session-start .label,
.session-elapsed .label {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.session-start .value,
.session-elapsed .value {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.timer {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: var(--font-size-xl) !important;
    color: var(--color-accent-primary) !important;
}

/* ============================================================================
   Components - Entries List
   ============================================================================ */

.recent-entries {
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--color-border);
}

.entries-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-md);
}

.entries-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.entry-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.entry-item:hover {
    background: var(--color-bg-elevated);
}

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

.entry-client {
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
}

.entry-date {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.entry-details {
    display: flex;
    gap: var(--space-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.entry-time,
.entry-miles {
    font-weight: var(--font-weight-medium);
    color: var(--color-accent-primary);
}

.entry-comment {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.loading-placeholder,
.empty-placeholder {
    text-align: center;
    padding: var(--space-lg);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* ============================================================================
   Components - Mileage Form
   ============================================================================ */

.mileage-form {
    margin-bottom: var(--space-md);
}

/* ============================================================================
   Components - Export Panel
   ============================================================================ */

.export-filters {
    margin-bottom: var(--space-md);
}

.export-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

@media (max-width: 480px) {
    .export-buttons {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
   Components - Modal
   ============================================================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    z-index: var(--z-modal);
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-modal-backdrop);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-modal);
}

.modal-lg {
    max-width: 600px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 24px;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
}

.modal-body {
    padding: var(--space-md);
}

.modal-actions {
    display: flex;
    gap: var(--space-md);
    justify-content: flex-end;
    margin-top: var(--space-lg);
}

.session-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-md);
}

.summary-item .label {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.summary-item .value {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

/* ============================================================================
   Components - Clients List
   ============================================================================ */

.add-client-form {
    margin-bottom: var(--space-lg);
}

.add-client-form .form-row {
    display: flex;
    gap: var(--space-md);
    align-items: flex-end;
}

.add-client-form .form-group {
    margin-bottom: 0;
}

.clients-list-container {
    max-height: 400px;
    overflow-y: auto;
}

.list-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-sm);
    margin-top: var(--space-md);
}

.list-title:first-child {
    margin-top: 0;
}

.clients-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.client-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.client-item:hover {
    background: var(--color-bg-elevated);
}

.client-item.inactive {
    opacity: 0.6;
}

.client-name {
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
}

.client-actions {
    display: flex;
    gap: var(--space-xs);
}

.client-actions button {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
}

/* ============================================================================
   Components - Toast Notifications
   ============================================================================ */

.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    z-index: var(--z-toast);
    max-width: 360px;
    width: 100%;
}

@media (max-width: 480px) {
    .toast-container {
        left: var(--space-md);
        right: var(--space-md);
        max-width: none;
    }
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
}

@keyframes toast-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.toast-out {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.toast.success .toast-icon {
    color: var(--color-success);
}

.toast.error .toast-icon {
    color: var(--color-error);
}

.toast.warning .toast-icon {
    color: var(--color-warning);
}

.toast.info .toast-icon {
    color: var(--color-info);
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: 2px;
}

.toast-message {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.toast-close {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-close:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
}

/* ============================================================================
   Components - Badge
   ============================================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge.coming-soon {
    background: var(--color-bg-tertiary);
    color: var(--color-text-muted);
    margin-left: auto;
}

/* ============================================================================
   Components - Future Navigation
   ============================================================================ */

.future-nav {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-md);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.nav-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================================
   Components - Offline Sync Banner
   ============================================================================ */

.offline-sync-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-warning);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    z-index: var(--z-sticky);
}

.offline-sync-banner.hidden {
    display: none;
}

.sync-icon {
    animation: spin 2s linear infinite;
}

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

/* ============================================================================
   Components - Disabled Controls (Future Features)
   ============================================================================ */

.disabled-control {
    opacity: 0.5;
    position: relative;
}

.disabled-control::after {
    content: 'Coming Soon';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    background: var(--color-bg-tertiary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

/* ============================================================================
   Utilities
   ============================================================================ */

.hidden {
    display: none !important;
}

.placeholder-text {
    text-align: center;
    padding: var(--space-lg);
    color: var(--color-text-muted);
}

/* ============================================================================
   Responsive Adjustments
   ============================================================================ */

@media (max-width: 480px) {
    .main-content {
        padding: var(--space-sm);
    }

    .card-header,
    .card-body {
        padding: var(--space-sm) var(--space-md);
    }

    .session-time-container {
        grid-template-columns: 1fr;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

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

/* ============================================================================
   Print Styles
   ============================================================================ */

@media print {
    .app-header,
    .modal,
    .toast-container,
    .offline-sync-banner,
    .btn,
    .future-nav {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .card {
        border: 1px solid #ccc;
        page-break-inside: avoid;
    }
}
