:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
}

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

body {
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.6;
    color: var(--gray-900);
    background: var(--gray-50);
}

/* Header & Nav */
header {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.5rem;
    color: var(--primary);
}

#main-nav {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--gray-700);
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}

.nav-link:hover {
    background: var(--gray-100);
}

.nav-link.active {
    background: var(--primary);
    color: white;
}

/* Main Content */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Loading */
.loading {
    text-align: center;
    padding: 4rem;
    color: var(--gray-500);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-card h3 {
    font-size: 0.875rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 600;
    color: var(--primary);
}

.stat-card .value.positive {
    color: var(--success);
}

.stat-card .value.negative {
    color: var(--danger);
}

.stat-card .value.small {
    font-size: 1.25rem;
}

/* Forms */
.form-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.form-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.form-card h3 {
    margin-bottom: 1rem;
    color: var(--gray-700);
}

.entry-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.entry-form input,
.entry-form select,
.entry-form textarea {
    padding: 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}

.entry-form input:focus,
.entry-form select:focus,
.entry-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.form-row {
    display: flex;
    gap: 0.5rem;
}

.form-row input {
    flex: 1;
}

.entry-form button {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.entry-form button:hover {
    background: var(--primary-dark);
}

/* Tables */
.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.table-header h3 {
    color: var(--gray-700);
}

.table-filters {
    display: flex;
    gap: 0.5rem;
}

.table-filters input,
.table-filters select {
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 0.875rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
}

.data-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
}

.data-table tr:hover {
    background: var(--gray-50);
}

.data-table .actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    padding: 0.25rem 0.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-edit {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-delete {
    background: #fee2e2;
    color: var(--danger);
}

.btn-save {
    background: #dcfce7;
    color: var(--success);
}

.btn-cancel {
    background: var(--gray-200);
    color: var(--gray-700);
}

/* Charts */
.chart-section {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
}

.chart-section h3 {
    margin-bottom: 1rem;
    color: var(--gray-700);
}

/* Correlation table */
.correlation-table {
    overflow-x: auto;
}

.correlation-table td.positive {
    color: var(--success);
    font-weight: 600;
}

.correlation-table td.negative {
    color: var(--danger);
    font-weight: 600;
}

/* Quick Timer */
.quick-timer-section {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
    text-align: center;
}

.quick-timer-section h3 {
    margin-bottom: 1rem;
    color: var(--gray-700);
}

.timer-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.timer-btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
}

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

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

.timer-btn-stand:hover {
    background: var(--primary-dark);
}

.timer-btn-walk {
    background: var(--success);
    color: white;
}

.timer-btn-walk:hover {
    background: #15803d;
}

.timer-btn-end {
    background: var(--success);
    color: white;
    flex: 1;
    max-width: 200px;
}

.timer-btn-cancel {
    background: var(--gray-200);
    color: var(--gray-700);
}

.timer-btn-cancel:hover {
    background: var(--gray-300);
}

.timer-active {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.timer-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.timer-display span:first-child {
    font-size: 1rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.timer-elapsed {
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

/* Day View */
.day-view {
    max-width: 600px;
    margin: 0 auto;
}

.day-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 1rem;
}

.day-nav-btn {
    background: var(--gray-100);
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.2s;
}

.day-nav-btn:hover {
    background: var(--gray-200);
}

.day-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.day-title input[type="date"] {
    border: none;
    background: transparent;
    font-size: 1rem;
    color: var(--gray-500);
    text-align: center;
    cursor: pointer;
}

#day-label {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
}

/* Timeline */
.timeline {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 1rem;
    min-height: 100px;
}

.timeline-entry {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--gray-100);
}

.timeline-entry:last-child {
    border-bottom: none;
}

.timeline-time {
    width: 70px;
    padding: 1rem 0.75rem;
    font-size: 0.85rem;
    color: var(--gray-500);
    font-weight: 500;
    text-align: right;
    flex-shrink: 0;
    border-right: 2px solid var(--gray-200);
}

.timeline-exercise .timeline-time {
    border-right-color: var(--primary);
}

.timeline-tolerance .timeline-time {
    border-right-color: var(--success);
}

.timeline-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    flex: 1;
    min-width: 0;
}

.timeline-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.timeline-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.timeline-title {
    font-weight: 600;
    color: var(--gray-900);
}

.timeline-value {
    color: var(--gray-600);
    font-size: 0.9rem;
}

.timeline-meta {
    color: var(--gray-400);
    font-size: 0.8rem;
}

.timeline-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

/* Day Add Section */
.day-add-section {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.day-add-section h3 {
    margin-bottom: 0.75rem;
    color: var(--gray-700);
    font-size: 1rem;
}

.add-entry-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

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

.day-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.day-form .form-row {
    display: flex;
    gap: 0.5rem;
}

.day-form select,
.day-form input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 1rem;
}

.day-form .btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
}

.day-form .btn-primary:hover {
    background: var(--primary-dark);
}

.chart-container {
    position: relative;
    height: 300px;
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 1000;
}

.toast {
    padding: 1rem 1.5rem;
    border-radius: 6px;
    margin-top: 0.5rem;
    animation: slideIn 0.3s ease;
    color: white;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

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

/* Page titles */
.page-title {
    margin-bottom: 1.5rem;
    color: var(--gray-900);
}

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

/* Inline edit */
.edit-input {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--primary);
    border-radius: 4px;
    font-size: inherit;
    width: 80px;
}

/* Responsive - Tablet */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        text-align: center;
        padding: 1rem;
    }

    #main-nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    main {
        padding: 1rem;
    }

    .table-header {
        flex-direction: column;
        gap: 1rem;
    }

    .table-filters {
        flex-wrap: wrap;
        width: 100%;
    }

    .table-filters input,
    .table-filters select {
        flex: 1;
        min-width: 120px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-section {
        grid-template-columns: 1fr;
    }

    .chart-container {
        height: 250px;
    }
}

/* Responsive - Mobile */
@media (max-width: 480px) {
    /* Safe area for iPhone notch */
    body {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }

    header {
        padding: 0.75rem;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    header h1 {
        font-size: 1.25rem;
    }

    #main-nav {
        gap: 0.25rem;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 0.25rem;
    }

    #main-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    main {
        padding: 0.75rem;
    }

    .page-title {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    /* Stats - 2 column on mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-card h3 {
        font-size: 0.7rem;
    }

    .stat-card .value {
        font-size: 1.5rem;
    }

    .stat-card .value.small {
        font-size: 1rem;
    }

    /* Forms - larger touch targets */
    .form-card {
        padding: 1rem;
    }

    .form-card h3 {
        font-size: 1rem;
    }

    .entry-form input,
    .entry-form select,
    .entry-form textarea {
        padding: 1rem;
        font-size: 16px; /* Prevents iOS zoom */
    }

    .entry-form button {
        padding: 1rem;
        font-size: 1rem;
    }

    /* Tables - horizontal scroll */
    .table-container {
        border-radius: 0;
        margin: 0 -0.75rem;
        width: calc(100% + 1.5rem);
    }

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

    .table-header h3 {
        font-size: 1rem;
    }

    .table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-table {
        min-width: 500px;
    }

    .data-table th,
    .data-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.875rem;
    }

    .btn-icon {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Charts */
    .chart-section {
        padding: 1rem;
        border-radius: 0;
        margin: 0 -0.75rem 1rem;
        width: calc(100% + 1.5rem);
    }

    .chart-section h3 {
        font-size: 1rem;
    }

    .chart-container {
        height: 200px;
    }

    /* Toast - bottom center on mobile */
    #toast-container {
        bottom: env(safe-area-inset-bottom, 1rem);
        right: 0.5rem;
        left: 0.5rem;
    }

    .toast {
        text-align: center;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    /* Edit inputs on mobile */
    .edit-input {
        width: 60px !important;
        padding: 0.5rem;
        font-size: 14px;
    }

    /* Quick Timer mobile */
    .quick-timer-section {
        padding: 1rem;
        border-radius: 0;
        margin: 0 -0.75rem 1rem;
        width: calc(100% + 1.5rem);
    }

    .timer-btn {
        padding: 1rem 1.5rem;
        font-size: 1rem;
        flex: 1;
    }

    .timer-elapsed {
        font-size: 2.5rem;
    }

    /* Day View mobile */
    .day-header {
        border-radius: 0;
        margin: 0 -0.75rem 0.5rem;
        width: calc(100% + 1.5rem);
    }

    .day-nav-btn {
        padding: 0.5rem 0.75rem;
    }

    #day-label {
        font-size: 1.1rem;
    }

    .timeline {
        border-radius: 0;
        margin: 0 -0.75rem 0.5rem;
        width: calc(100% + 1.5rem);
    }

    .timeline-time {
        width: 55px;
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
    }

    .timeline-content {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .timeline-icon {
        font-size: 1.25rem;
    }

    .timeline-title {
        font-size: 0.9rem;
    }

    .timeline-value {
        font-size: 0.85rem;
    }

    .day-add-section {
        border-radius: 0;
        margin: 0 -0.75rem;
        width: calc(100% + 1.5rem);
    }

    .day-form select,
    .day-form input {
        padding: 0.75rem;
        font-size: 16px;
    }

    /* Empty state */
    .empty-state {
        padding: 2rem 1rem;
        font-size: 0.9rem;
    }
}

/* Touch improvements */
@media (hover: none) and (pointer: coarse) {
    .btn-icon {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .entry-form button {
        min-height: 48px;
    }

    .table-filters input,
    .table-filters select,
    .table-filters button {
        min-height: 44px;
    }
}
