:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --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);
    --radius: 16px;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #94a3b8;
    --danger: #f87171;
    --success: #34d399;
    --warning: #fbbf24;
    --background: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
}

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

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
        sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    transition:
        background-color 0.3s,
        color 0.3s;
    font-size: 16px;
}

/* Header */
.app-header {
    background: var(--surface);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
    background: color-mix(in srgb, var(--surface) 90%, transparent);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}

.header-actions {
    display: flex;
    gap: 0.25rem;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background: var(--border);
}

/* Dashboard */
.dashboard {
    padding: 1.5rem;
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 7rem;
}

.projects-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.hidden {
    display: none !important;
}

/* Card - Responsive Flex Layout */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    position: relative;
    transition:
        transform 0.2s,
        box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
}

.card.running-highlight {
    border: 2px solid var(--accent-color);
    box-shadow: 0 0 0 4px
        color-mix(in srgb, var(--accent-color) 20%, transparent);
}

.card.menu-open {
    z-index: 40;
}

/* Icon */
.project-icon-wrapper {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--background);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 2rem;
    flex-shrink: 0;
    border: 1px solid var(--border);
}
.project-icon-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Content */
.list-content {
    flex: 1;
    min-width: 0; /* Enables truncation */
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.list-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.card-title {
    font-weight: 700;
    font-size: 1.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    margin-right: auto;
}

/* Badges */
.badge-container {
    position: relative;
    display: inline-flex;
}

.card-badge-btn {
    font-size: 0.7rem;
    padding: 0.15rem 0.6rem;
    border-radius: 99px;
    font-weight: 700;
    text-transform: uppercase;
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--background);
    color: var(--text-muted);
}

.state-main .card-badge-btn,
.state-active .card-badge-btn {
    background: color-mix(in srgb, var(--accent-color) 10%, transparent);
    color: var(--accent-color);
    border-color: transparent;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0; /* Align right on desktop usually better for badges */
    left: auto;
    margin-top: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    min-width: 180px;
    z-index: 100;
    overflow: hidden;
    padding: 0.5rem;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: 6px;
}
.dropdown-item:hover {
    background: var(--background);
}
.dropdown-item.danger {
    color: var(--danger);
}
.dropdown-item.danger:hover {
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}

/* Time & Progress */
.progress-container {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    width: 100%;
    margin: 0.25rem 0;
}
.progress-fill {
    height: 100%;
    background: var(--accent-color, var(--success));
    transition: width 0.3s ease;
}

.time-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.time-current {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    font-size: 1.1rem;
}

/* Actions */
.list-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
}

.btn-round {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    padding: 0;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: transform 0.1s;
}
.btn-round:active {
    transform: scale(0.95);
}

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

.btn-history {
    width: 2.75rem;
    height: 2.75rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    box-shadow: none;
}
.btn-history:hover {
    background: var(--background);
    color: var(--text);
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.modal:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 20px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform 0.2s;
}
.modal:not(.hidden) .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.close-icon {
    background: transparent;
    border: none;
    font-size: 1.75rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
}

.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 0.875rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    background: var(--background);
    color: var(--text);
    outline: none;
}
.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}

/* Styled File Input */
.file-upload-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.5rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    width: 100%;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.2s;
}
.file-upload-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--background);
}
input[type="file"].hidden-input {
    display: none;
}

/* Styled Color Input */
.color-picker-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.25rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 12px;
}

input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 48px;
    height: 48px;
    cursor: pointer;
    background: none;
    padding: 0;
    flex-shrink: 0;
}
input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}
input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}
#color-preview-text {
    font-family: monospace;
    font-weight: 600;
}

/* Radio Group */
.radio-group {
    display: flex;
    gap: 0.75rem;
}
.radio-card {
    flex: 1;
    position: relative;
}
.radio-card input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.radio-card span {
    display: block;
    padding: 0.75rem;
    background: var(--background);
    border: 2px solid var(--border);
    border-radius: 12px;
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s;
}
.radio-card input:checked + span {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    color: var(--primary);
}

/* Emoji Input */
.emoji-input-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.emoji-input {
    width: 100%;
    text-align: center;
    font-size: 2.5rem;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--background);
    color: var(--text);
}
.help-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
    background: var(--background);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.btn {
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
        filter 0.2s,
        transform 0.1s;
}
.btn:active {
    transform: scale(0.98);
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    filter: brightness(1.1);
}
.btn-lg {
    padding: 0.875rem 1.5rem;
    width: 100%;
}
.btn-secondary {
    background: var(--border);
    color: var(--text);
}

/* FAB */
.fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 3.5rem;
    height: 3.5rem;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    border: none;
    box-shadow: 0 4px 15px color-mix(in srgb, var(--primary) 40%, transparent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    transition: transform 0.2s;
}
.fab:hover {
    transform: scale(1.05);
}

/* Calendar */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin: 1rem 0;
}
.cal-day {
    aspect-ratio: 1;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    background: var(--background);
    color: var(--text-muted);
}
.cal-day.has-data {
    background: color-mix(in srgb, var(--danger) 15%, transparent);
    color: var(--danger);
    font-weight: bold;
}
.cal-day.goal-met {
    background: color-mix(in srgb, var(--success) 15%, transparent);
    color: var(--success);
    font-weight: bold;
}

/* --- Mobile Responsive Tweaks --- */
@media (max-width: 600px) {
    html {
        font-size: 14px; /* Scale down base size */
    }

    .dashboard {
        padding: 1rem;
        padding-bottom: 6rem;
    }

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

    .project-icon-wrapper {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
        border-radius: 12px;
    }

    .btn-round {
        width: 3rem;
        height: 3rem;
    }

    .btn-history {
        width: 2.5rem;
        height: 2.5rem;
    }

    .card-title {
        font-size: 1.1rem;
    }

    .time-current {
        font-size: 1rem;
    }

    .fab {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 3.25rem;
        height: 3.25rem;
    }

    .dropdown-menu {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        margin: 0;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
        padding: 1rem;
        animation: slideUp 0.2s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
}
