:root {
    /* Dark Theme Palette - Premium Slate/Blue */
    --bg-body: #0f172a;
    /* Very dark slate */
    --bg-card: #1e293b;
    /* Dark slate */
    --bg-card-hover: #334155;
    /* Lighter slate for hover */

    --text-main: #f8fafc;
    /* Almost white */
    --text-muted: #94a3b8;
    /* Muted blue-grey */

    --primary: #3b82f6;
    /* Vibrant Blue */
    --primary-glow: rgba(59, 130, 246, 0.5);

    --success: #10b981;
    /* Emerald */
    --success-glow: rgba(16, 185, 129, 0.5);

    --warning: #f59e0b;
    /* Amber */
    --error: #ef4444;
    /* Red */

    --border-color: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(30, 41, 59, 0.7);

    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-glow: 0 0 15px var(--primary-glow);
}

/* Global Reset & Typography */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    padding: 1rem;
    padding-bottom: 3rem;
    box-sizing: border-box;
    line-height: 1.6;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-body);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-card-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Layout Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 0 0.5rem;
}

.header h1 {
    color: var(--text-main);
    font-size: 1.8rem;
    margin: 0;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, var(--text-main) 0%, var(--text-muted) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Date Navigation */
.date-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-card);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

.date-nav .current-date {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
    min-width: 100px;
    text-align: center;
}

.date-nav .not-today {
    color: var(--warning);
}

/* Controls */
.controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Icon Buttons */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
    transform: translateY(-1px);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* "Today" Button */
.today-btn {
    background: linear-gradient(135deg, var(--primary), #2563eb);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.today-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

/* GridStack & Widgets */
.grid-stack-item-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    color: var(--text-main);
    overflow: hidden;
    /* Changed from auto to hidden for better rounded corners */
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.grid-stack-item-content:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

/* Widget Inner Content */
.widget {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.widget h2 {
    margin-top: 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 1rem;
    text-align: left;
    /* Align left for cleaner look */
}

/* Progress Widget (Special Styling) */
.progress-container {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glow);
    /* Subtle glow for the main widget */
    text-align: center;
}

.progress-container .total {
    font-size: 4rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.progress-container .glass-icon {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 48px;
    height: 48px;
    opacity: 0.2;
    filter: drop-shadow(0 0 10px var(--primary));
}

.progress-container .details {
    display: flex;
    justify-content: center;
    gap: 2rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.progress-container .details span strong {
    color: var(--text-main);
    font-weight: 600;
}

.progress-container .details .percentage {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 0.5rem;
}

/* Progress Bar */
.progress {
    position: relative;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 50px;
    height: 24px;
    width: 100%;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.progress-bar-fill {
    /* Renamed from .progress-bar to match JS if needed, or keep both */
    display: block;
    position: relative;
    height: 100%;
    border-radius: 50px;
    background: linear-gradient(90deg, var(--primary), #60a5fa);
    box-shadow: 0 0 20px var(--primary-glow);
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Animated Shine Effect */
.progress-bar-fill::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.2),
            transparent);
    transform: translateX(-100%);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    100% {
        transform: translateX(100%);
    }
}

/* Goal Exceeded State */
.progress-bar-fill.goal-exceeded {
    background: linear-gradient(90deg, var(--success), #34d399);
    box-shadow: 0 0 20px var(--success-glow);
}

/* Warning State */
.progress-bar-fill.warning {
    background: linear-gradient(90deg, var(--warning), #fbbf24);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.5);
}

.progress .ideal-marker {
    position: absolute;
    top: 0;
    width: 2px;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.5);
    z-index: 5;
}

/* Messages */
.progress-container .message {
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.95rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
}

.progress-container .message.success {
    background: rgba(16, 185, 129, 0.1);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.2);
}

.progress-container .message.info {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.2);
}

.progress-container .message.warning {
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.2);
}

/* History Widget */
.history-widget ul {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 250px;
    overflow-y: auto;
}

.history-widget li {
    background: rgba(255, 255, 255, 0.03);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

.history-widget li:hover {
    border-color: var(--border-color);
}

.history-widget li span:first-child {
    font-weight: 600;
    color: var(--text-main);
}

.history-widget .time {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Weekly Summary Widget */
.weekly-summary-widget .chart-container {
    display: flex;
    height: 200px;
    padding: 1rem 0;
    position: relative;
}

.weekly-summary-widget .y-axis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    padding-right: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
    border-right: 1px solid var(--border-color);
}

.weekly-summary-widget .chart {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
    height: 100%;
    gap: 0.5rem;
}

.weekly-summary-widget .bar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    height: 100%;
    position: relative;
}

.weekly-summary-widget .bar {
    width: 80%;
    max-width: 24px;
    background: var(--bg-card-hover);
    border-radius: 4px 4px 0 0;
    position: absolute;
    bottom: 24px;
    /* Space for day label */
    transition: height 0.5s ease;
    min-height: 4px;
}

.weekly-summary-widget .bar.over-goal {
    background: var(--success);
    box-shadow: 0 0 10px var(--success-glow);
}

.weekly-summary-widget .bar:not(.over-goal) {
    background: var(--primary);
}

.weekly-summary-widget .bar .value {
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: var(--text-main);
    opacity: 0;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.weekly-summary-widget .bar-container:hover .bar .value {
    opacity: 1;
}

.weekly-summary-widget .day {
    position: absolute;
    bottom: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    width: 100%;
    text-align: center;
}

.weekly-summary-widget .goal-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed rgba(255, 255, 255, 0.2);
    z-index: 0;
}

/* Timeline Widget */
.timeline-chart {
    height: 100%;
    width: 100%;
}

.timeline-chart .timeline-area {
    fill: rgba(59, 130, 246, 0.1);
}

.timeline-chart .timeline-line {
    stroke: var(--primary);
    stroke-width: 3;
}

.timeline-chart .timeline-point {
    fill: var(--bg-card);
    stroke: var(--primary);
    stroke-width: 2;
}

.timeline-chart .timeline-label {
    fill: var(--text-muted);
    font-size: 12px;
}

.timeline-chart .axis-label {
    fill: var(--text-muted);
    font-size: 12px;
    text-anchor: middle;
}

/* Modal */
.modal {
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-content h2 {
    color: var(--text-main);
}

#manual-entry-form input {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.75rem;
    border-radius: var(--radius-md);
}

#manual-entry-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

#manual-entry-form button {
    background: var(--primary);
    color: white;
    font-weight: 600;
    transition: filter 0.2s;
}

#manual-entry-form button:hover {
    filter: brightness(1.1);
}

.close-btn {
    color: var(--text-muted);
}

.close-btn:hover {
    color: var(--text-main);
}

/* Utilities */
.hidden {
    display: none;
}