/* ==========================================================================
   Base styles
   ========================================================================== */

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

:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-error: #dc2626;
    --color-success: #16a34a;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-bg: #f9fafb;
    --color-white: #ffffff;
    --color-border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-full: 9999px;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--color-text);
    background-color: var(--color-bg);
    line-height: 1.5;
}

/* ==========================================================================
   Button component
   ========================================================================== */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease;
}

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

.button:active {
    transform: scale(0.98);
}

/* Primary button style */
.button--primary {
    background-color: var(--color-primary);
    color: var(--color-white);
}

.button--primary:hover {
    background-color: var(--color-primary-hover);
}

/* Text button style */
.button--text {
    padding: 0.5rem 1rem;
    background-color: transparent;
    color: var(--color-text-muted);
}

.button--text:hover {
    color: var(--color-text);
    background-color: var(--color-border);
}

/* Danger button style */
.button--danger {
    color: var(--color-error);
}

.button--danger:hover {
    background-color: rgb(220 38 38 / 0.1);
}

/* Small button */
.button--small {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

/* ==========================================================================
   Form field component
   ========================================================================== */

.form-field {
    margin-bottom: 1.5rem;
}

.form-field__label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
}

.form-field__input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    text-align: left;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background-color: var(--color-white);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field__input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

/* Error state */
.form-field__input--error {
    border-color: var(--color-error);
}

.form-field__input--error:focus {
    border-color: var(--color-error);
    box-shadow: 0 0 0 3px rgb(220 38 38 / 0.1);
}

.form-field__error {
    margin: 0.5rem 0 0;
    font-size: 0.875rem;
    color: var(--color-error);
}

/* ==========================================================================
   Login page
   ========================================================================== */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login {
    width: 100%;
    max-width: 24rem;
    padding: 2rem;
    background-color: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.login__title {
    margin: 0 0 2rem;
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
}

.login__form {
    margin: 0;
}

/* ==========================================================================
   Dashboard page
   ========================================================================== */

.dashboard-page {
    min-height: 100vh;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background-color: var(--color-white);
    border-bottom: 1px solid var(--color-border);
}

.header__left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.header__right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.header__logout {
    margin: 0;
}

.header__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.header__back:hover {
    background-color: var(--color-border);
    color: var(--color-text);
}

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

.header__back-icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* Tracker navigation */
.tracker-nav {
    display: flex;
    gap: 0.25rem;
}

.tracker-nav__link {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.tracker-nav__link:hover {
    background-color: var(--color-border);
    color: var(--color-text);
}

.tracker-nav__link--active {
    background-color: var(--color-primary);
    color: var(--color-white);
}

.tracker-nav__link--active:hover {
    background-color: var(--color-primary-hover);
    color: var(--color-white);
}

/* Dashboard main area */
.dashboard {
    max-width: 48rem;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ==========================================================================
   Track section
   ========================================================================== */

.track-section {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.track-section__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    background-color: var(--color-white);
    border-radius: var(--radius-lg);
    color: var(--color-text-muted);
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.track-section__back:hover {
    background-color: var(--color-border);
    color: var(--color-text);
}

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

.track-section__back-icon {
    width: 1.5rem;
    height: 1.5rem;
}

.track-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 10rem;
    height: 10rem;
    padding: 1.5rem;
    font-family: inherit;
    background-color: var(--color-primary);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    box-shadow: var(--shadow-lg);
}

.track-button:hover {
    background-color: var(--color-primary-hover);
    transform: scale(1.02);
}

.track-button:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 4px;
}

.track-button:active {
    transform: scale(0.98);
}

/* Visual feedback after tracking */
.track-button--success {
    background-color: var(--color-success);
}

.track-button__text {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-white);
}

/* Wide track button for dashboard */
.track-button-wide {
    flex: 1;
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: inherit;
    background-color: var(--color-primary);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease;
    box-shadow: var(--shadow-lg);
}

.track-button-wide:hover {
    background-color: var(--color-primary-hover);
}

.track-button-wide:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 4px;
}

.track-button-wide:active {
    transform: scale(0.98);
}

.track-button-wide--success {
    background-color: var(--color-success);
}

.track-button-wide__name {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-white);
}

/* Actions section (below track button) */
.actions-section {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

/* Historical section */
.historical-section {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

/* ==========================================================================
   Stats section
   ========================================================================== */

.stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

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

.stat-card__label {
    margin: 0 0 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.stat-card__value {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text);
}

/* Trend indicator styles */
.stat-card__value--trend-up {
    color: var(--color-success);
}

.stat-card__value--trend-down {
    color: var(--color-error);
}

/* ==========================================================================
   Chart section
   ========================================================================== */

.chart-section {
    background-color: var(--color-white);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}

.chart-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.chart-section__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.chart-section__range {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    color: var(--color-text);
    background-color: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.chart-section__range:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.chart-container {
    position: relative;
    height: 16rem;
}

/* ==========================================================================
   Entries section
   ========================================================================== */

.entries-section {
    background-color: var(--color-white);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.entries-section__title {
    margin: 0 0 1rem;
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.entries-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.entries-list__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
}

.entries-list__item:last-child {
    border-bottom: none;
}

.entries-list__date {
    font-size: 0.875rem;
    color: var(--color-text);
}

.entries-list__time {
    margin-left: 0.5rem;
    color: var(--color-text-muted);
}

.entries-list__delete {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.entries-list__delete:hover {
    color: var(--color-error);
    background-color: rgb(220 38 38 / 0.1);
}

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

.entries-list__empty {
    padding: 1rem 0;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* ==========================================================================
   Empty state
   ========================================================================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    flex: 1;
}

.empty-state__text {
    margin: 0 0 1.5rem;
    font-size: 1.125rem;
    color: var(--color-text-muted);
}

/* ==========================================================================
   Dialog component
   ========================================================================== */

.dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 2rem);
    max-width: 24rem;
    padding: 1.5rem;
    background-color: var(--color-white);
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
    background-color: rgb(0 0 0 / 0.5);
}

.dialog--wide {
    max-width: 32rem;
}

.dialog__title {
    margin: 0 0 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.dialog__form {
    margin: 0;
}

.dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* Color picker */
.color-picker {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.75rem;
}

.color-picker__option {
    aspect-ratio: 1;
    width: 100%;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.color-picker__option:hover {
    transform: scale(1.1);
}

.color-picker__option:focus-visible {
    outline: 2px solid var(--color-text);
    outline-offset: 2px;
}

.color-picker__option--selected {
    box-shadow: 0 0 0 3px var(--color-white), 0 0 0 5px currentColor;
}

/* Trackers list in dialog */
.trackers-list {
    list-style: none;
    margin: 0 0 1.5rem;
    padding: 0;
}

.trackers-list__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
}

.trackers-list__item:last-child {
    border-bottom: none;
}

.trackers-list__name {
    font-size: 0.9375rem;
    font-weight: 500;
}

.trackers-list__actions {
    display: flex;
    gap: 0.25rem;
}

/* Add tracker form */
.add-tracker-form {
    display: flex;
    gap: 0.5rem;
}

.add-tracker-form .form-field__input {
    flex: 1;
}

.add-tracker-form .button {
    flex-shrink: 0;
}

/* ==========================================================================
   Landing page
   ========================================================================== */

.landing-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 1rem;
}

.landing-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.landing-footer {
    display: flex;
    gap: 1rem;
}

.landing-footer__form {
    flex: 1;
    display: flex;
}

.landing-footer__button {
    flex: 1;
    padding: 0.625rem 1rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text-muted);
    background-color: var(--color-white);
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.landing-footer__button:hover {
    background-color: var(--color-border);
    color: var(--color-text);
}

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

/* Tracker grid - mobile first */
.tracker-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
}

/* Tracker card */
.tracker-card {
    position: relative;
    flex: 1;
    display: flex;
}

.tracker-card__button {
    position: relative;
    width: 100%;
    min-height: 6rem;
    padding: 1.5rem 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: inherit;
    background-color: var(--color-primary);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.tracker-card__button:hover {
    background-color: var(--color-primary-hover);
}

.tracker-card__button:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 4px;
}

.tracker-card__button:active {
    transform: scale(0.98);
}

.tracker-card__button--success,
.track-button-wide--success {
    animation: celebrate 3s ease-out;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(255,255,255,0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(255,255,255,0.2) 0%, transparent 40%);
}

@keyframes celebrate {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }
    5% {
        transform: scale(0.92);
        filter: brightness(0.9);
    }
    12% {
        transform: scale(1.08);
        filter: brightness(1.3);
    }
    20% {
        transform: scale(1);
        filter: brightness(1.2);
    }
    25% {
        transform: scale(1.03) rotate(-1deg);
        filter: brightness(1.15);
    }
    30% {
        transform: scale(0.98) rotate(1deg);
        filter: brightness(1.1);
    }
    35% {
        transform: scale(1.02) rotate(-0.5deg);
        filter: brightness(1.15);
    }
    40% {
        transform: scale(1) rotate(0.5deg);
        filter: brightness(1.1);
    }
    50% {
        transform: scale(1.01);
        filter: brightness(1.05);
    }
    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

.tracker-card__name {
    position: relative;
    z-index: 1;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-white);
    text-align: center;
}

.tracker-card__stats {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.375rem;
}

.tracker-card__count {
    position: relative;
    z-index: 1;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-white);
    line-height: 1;
}

.tracker-card__label {
    font-size: 0.75rem;
    color: rgb(255 255 255 / 0.7);
    text-transform: lowercase;
}

/* Month day boxes */
.tracker-card__month {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 2px;
    padding: 0.5rem;
    pointer-events: none;
}

.tracker-card__day {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background-color: rgb(0 0 0 / 0.15);
    border-radius: 4px;
}

.tracker-card__day--tracked {
    background-color: transparent;
}

.tracker-card__instance {
    flex: 1;
    background-color: rgb(255 255 255 / 0.4);
    border-radius: 2px;
}

/* Undo button - styled same as dashboard link */
.tracker-card__undo {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgb(255 255 255 / 0.2);
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-white);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease;
    animation: fadeIn 0.2s ease-out;
}

.tracker-card__undo:hover {
    background-color: rgb(255 255 255 / 0.3);
}

.tracker-card__undo:focus-visible {
    outline: 2px solid var(--color-white);
    outline-offset: 2px;
}

.tracker-card__undo svg {
    width: 1.25rem;
    height: 1.25rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Dragging state */
.tracker-card--dragging {
    opacity: 0.5;
}

.tracker-card--dragging-clone {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    opacity: 0.9;
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
}

/* Dashboard link in corner */
.tracker-card__dashboard {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgb(255 255 255 / 0.2);
    border-radius: var(--radius-md);
    color: var(--color-white);
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.tracker-card__dashboard:hover {
    background-color: rgb(255 255 255 / 0.3);
}

.tracker-card__dashboard:focus-visible {
    outline: 2px solid var(--color-white);
    outline-offset: 2px;
}

.tracker-card__icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 2rem 1rem;
}

/* ==========================================================================
   Responsive adjustments
   ========================================================================== */

@media (min-width: 640px) {
    .track-button {
        width: 12rem;
        height: 12rem;
    }

}

@media (min-width: 640px) {
    .track-button__text {
        font-size: 1.75rem;
    }

    .stat-card__value {
        font-size: 2.5rem;
    }

    .chart-container {
        height: 20rem;
    }
}

@media (max-width: 640px) {
    .header {
        flex-wrap: wrap;
    }

    .header__left {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .tracker-nav {
        flex-wrap: wrap;
    }
}
