/* ================================================================
 * tracker-compra — Premium Redesign
 * 100% custom CSS, no framework. Mobile-first.
 * ================================================================ */

/* ─────────────────────────────────────────────
 * 0. Design Tokens
 * ───────────────────────────────────────────── */

:root {
    /* — Palette — */
    --color-primary:       #1a7a4c;
    --color-primary-dark:  #145e3a;
    --color-primary-light: #e6f4ed;
    --color-primary-rgb:   26, 122, 76;

    --color-accent:        #f0a500;
    --color-accent-light:  #fef3d5;

    --color-danger:        #d93025;
    --color-danger-light:  #fde8e6;
    --color-danger-bg:     #fef2f2;

    --color-success:       #16a34a;
    --color-success-light: #dcfce7;

    --color-bg:            #f4f5f8;
    --color-surface:       #ffffff;
    --color-surface-hover: #f9fafb;
    --color-surface-raised:#ffffff;

    --color-text:          #1a1d23;
    --color-text-secondary:#5f6577;
    --color-text-tertiary: #9398a8;
    --color-text-inverse:  #ffffff;

    --color-border:        #e5e7ec;
    --color-border-light:  #eff0f4;

    /* — Shadows — */
    --shadow-xs:  0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.03);
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
    --shadow-lg:  0 12px 32px rgba(0,0,0,0.1), 0 4px 8px rgba(0,0,0,0.06);
    --shadow-xl:  0 20px 48px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.08);
    --shadow-glow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);

    /* — Radius — */
    --radius-sm:   8px;
    --radius-md:   12px;
    --radius-lg:   16px;
    --radius-xl:   24px;
    --radius-pill: 9999px;

    /* — Spacing — */
    --space-1:  4px;
    --space-2:  8px;
    --space-3:  12px;
    --space-4:  16px;
    --space-5:  20px;
    --space-6:  24px;
    --space-8:  32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* — Typography — */
    --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;

    --text-xs:   0.75rem;    /* 12px */
    --text-sm:   0.8125rem;  /* 13px */
    --text-base: 0.9375rem;  /* 15px */
    --text-md:   1rem;       /* 16px */
    --text-lg:   1.125rem;   /* 18px */
    --text-xl:   1.25rem;    /* 20px */
    --text-2xl:  1.5rem;     /* 24px */

    --leading-tight: 1.2;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    --weight-regular: 400;
    --weight-medium:   500;
    --weight-semibold: 600;
    --weight-bold:     700;

    /* — Motion — */
    --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out:   cubic-bezier(0.45, 0, 0.55, 1);
    --duration-fast:   150ms;
    --duration-normal: 250ms;
    --duration-slow:   400ms;

    /* — Layout — */
    --header-height: 56px;
    --max-width: 560px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─────────────────────────────────────────────
 * 1. Reset & Base
 * ───────────────────────────────────────────── */

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

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    line-height: var(--leading-normal);
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ─────────────────────────────────────────────
 * 2. App Shell
 * ───────────────────────────────────────────── */

.tc-app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--color-bg);
}

.tc-main {
    flex: 1;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-4) var(--space-4) calc(var(--space-8) + var(--safe-bottom));
}

/* ─────────────────────────────────────────────
 * 3. Decorative Background
 * ───────────────────────────────────────────── */

.tc-bg-decor {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.tc-bg-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.35;
    will-change: transform;
}

.tc-bg-blob--1 {
    width: 300px;
    height: 300px;
    background: rgba(var(--color-primary-rgb), 0.15);
    top: -80px;
    right: -60px;
    animation: tc-blob-drift 20s var(--ease-in-out) infinite alternate;
}

.tc-bg-blob--2 {
    width: 250px;
    height: 250px;
    background: rgba(240, 165, 0, 0.1);
    bottom: 10%;
    left: -50px;
    animation: tc-blob-drift 25s var(--ease-in-out) infinite alternate-reverse;
}

.tc-bg-blob--3 {
    width: 200px;
    height: 200px;
    background: rgba(100, 140, 255, 0.08);
    top: 40%;
    right: 10%;
    animation: tc-blob-drift 18s var(--ease-in-out) infinite alternate;
}

@keyframes tc-blob-drift {
    0%   { transform: translate(0, 0) scale(1); }
    50%  { transform: translate(20px, -15px) scale(1.05); }
    100% { transform: translate(-10px, 20px) scale(0.95); }
}

/* ─────────────────────────────────────────────
 * 4. Header
 * ───────────────────────────────────────────── */

.tc-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    height: var(--header-height);
}

.tc-header__inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--space-4);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tc-header__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.tc-header__logo {
    color: var(--color-primary);
    flex-shrink: 0;
}

.tc-header__title {
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    letter-spacing: -0.02em;
    color: var(--color-text);
}

.tc-header__stats {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.tc-stat {
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    background: var(--color-bg);
    transition: background var(--duration-fast) ease;
}

.tc-stat--done {
    background: var(--color-success-light);
}

.tc-stat__num {
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
    color: var(--color-text);
    line-height: 1;
}

.tc-stat--done .tc-stat__num {
    color: var(--color-success);
}

.tc-stat__label {
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
    font-weight: var(--weight-medium);
}

.tc-stat--done .tc-stat__label {
    color: var(--color-success);
    opacity: 0.7;
}

/* ─────────────────────────────────────────────
 * 5. Add Form
 * ───────────────────────────────────────────── */

.tc-add {
    margin-bottom: var(--space-4);
    position: relative;
    z-index: 1;
}

.tc-add__form {
    display: flex;
    align-items: stretch;
    gap: var(--space-2);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-2);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border-light);
    transition: box-shadow var(--duration-normal) ease;
}

.tc-add__form:focus-within {
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.tc-add__row {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.tc-field {
    flex: 1;
    position: relative;
    min-width: 0;
}

.tc-field--qty {
    flex: 0 0 72px;
}

.tc-field__input {
    width: 100%;
    height: 40px;
    padding: 0 var(--space-3);
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    color: var(--color-text);
    outline: none;
}

.tc-field__input::placeholder {
    color: var(--color-text-tertiary);
    transition: color var(--duration-fast) ease;
}

.tc-field__input:focus::placeholder {
    color: var(--color-text-secondary);
}

.tc-field--qty .tc-field__input {
    text-align: center;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
}

/* Add Button */
.tc-add__btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    cursor: pointer;
    transition: background var(--duration-fast) ease,
                transform var(--duration-fast) var(--ease-out-back),
                box-shadow var(--duration-fast) ease;
    position: relative;
    overflow: hidden;
}

.tc-add__btn:hover {
    background: var(--color-primary-dark);
    box-shadow: var(--shadow-sm);
}

.tc-add__btn:active {
    transform: scale(0.92);
}

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

.tc-add__btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.tc-add__icon {
    display: block;
}

.tc-add__text {
    display: none;
}

/* ─────────────────────────────────────────────
 * 6. Toolbar (Filters + Sort)
 * ───────────────────────────────────────────── */

.tc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
    position: relative;
    z-index: 1;
    gap: var(--space-2);
}

/* Segmented Control */
.tc-segmented {
    display: inline-flex;
    background: var(--color-surface);
    border-radius: var(--radius-pill);
    padding: 3px;
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--color-border-light);
    position: relative;
}

.tc-segmented__btn {
    position: relative;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius-pill);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: color var(--duration-fast) ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.tc-segmented__btn.active {
    color: var(--color-primary);
    font-weight: var(--weight-semibold);
}

.tc-segmented__btn:hover:not(.active) {
    color: var(--color-text);
}

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

/* Pill badge inside segmented */
.tc-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: rgba(0, 0, 0, 0.06);
    font-size: 10px;
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-tertiary);
    transition: all var(--duration-fast) ease;
    line-height: 1;
}

.tc-segmented__btn.active .tc-pill {
    background: rgba(var(--color-primary-rgb), 0.12);
    color: var(--color-primary);
}

/* Sort Button */
.tc-sort {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-text-tertiary);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.tc-sort:hover {
    color: var(--color-text-secondary);
    background: rgba(0, 0, 0, 0.04);
}

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

.tc-sort__icon {
    transition: transform var(--duration-normal) var(--ease-out-expo);
}

.tc-sort[data-order="name"] .tc-sort__icon {
    transform: rotate(90deg);
}

/* ─────────────────────────────────────────────
 * 7. Item List
 * ───────────────────────────────────────────── */

.tc-list-section {
    position: relative;
    z-index: 1;
}

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

/* ── Single Item ── */

.tc-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-2);
    background: var(--color-surface-raised);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--color-border-light);
    transition: all var(--duration-normal) var(--ease-out-expo);
    animation: tc-item-in var(--duration-slow) var(--ease-out-expo) both;
    position: relative;
    overflow: hidden;
}

.tc-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: transparent;
    border-radius: 0 2px 2px 0;
    transition: background var(--duration-fast) ease;
}

.tc-item:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--color-border);
    transform: translateY(-1px);
}

.tc-item:active {
    transform: translateY(0);
}

/* Bought state */
.tc-item--bought {
    background: var(--color-surface-hover);
    border-color: transparent;
    opacity: 0.7;
}

.tc-item--bought::before {
    background: var(--color-success);
}

.tc-item--bought:hover {
    opacity: 0.85;
}

/* ── Checkbox ── */

.tc-check {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out-back);
    background: var(--color-surface);
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.tc-check:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.tc-check:active {
    transform: scale(0.85);
}

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

.tc-check--done {
    background: var(--color-success);
    border-color: var(--color-success);
    animation: tc-check-pop var(--duration-normal) var(--ease-out-back);
}

@keyframes tc-check-pop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.tc-check__icon {
    width: 14px;
    height: 14px;
    opacity: 0;
    transform: scale(0.5);
    transition: all var(--duration-fast) var(--ease-out-back);
}

.tc-check--done .tc-check__icon {
    opacity: 1;
    transform: scale(1);
}

/* ── Item Content ── */

.tc-item__content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tc-item__name {
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all var(--duration-normal) ease;
    line-height: var(--leading-tight);
}

.tc-item--bought .tc-item__name {
    text-decoration: line-through;
    text-decoration-color: var(--color-text-tertiary);
    color: var(--color-text-tertiary);
}

.tc-item__meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.tc-item__qty {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--color-bg);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    transition: all var(--duration-fast) ease;
}

.tc-item--bought .tc-item__qty {
    background: transparent;
    opacity: 0.5;
}

.tc-item__date {
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
    font-variant-numeric: tabular-nums;
}

/* ── Delete Button ── */

.tc-delete {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text-tertiary);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    opacity: 0;
    -webkit-tap-highlight-color: transparent;
}

.tc-item:hover .tc-delete,
.tc-item:focus-within .tc-delete {
    opacity: 1;
}

.tc-delete:hover {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.tc-delete:active {
    transform: scale(0.85);
}

.tc-delete:focus-visible {
    outline: 2px solid var(--color-danger);
    outline-offset: 2px;
    opacity: 1;
}

.tc-delete__icon {
    width: 16px;
    height: 16px;
}

/* ── Animations ── */

@keyframes tc-item-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.tc-item.removing {
    animation: tc-item-out var(--duration-normal) var(--ease-in-out) both;
}

@keyframes tc-item-out {
    to {
        opacity: 0;
        transform: translateX(30px) scale(0.95);
        max-height: 0;
        margin-bottom: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
}

/* ─────────────────────────────────────────────
 * 8. Empty State
 * ───────────────────────────────────────────── */

.tc-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) var(--space-4);
    text-align: center;
    animation: tc-fade-in var(--duration-slow) var(--ease-out-expo) both;
}

.tc-empty__illustration {
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-6);
    animation: tc-float 4s var(--ease-in-out) infinite;
}

.tc-empty__title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-1);
}

.tc-empty__hint {
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
}

@keyframes tc-float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-8px); }
}

@keyframes tc-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─────────────────────────────────────────────
 * 9. Progress Bar
 * ───────────────────────────────────────────── */

.tc-progress {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--color-border-light);
    z-index: 200;
    padding-bottom: var(--safe-bottom);
}

.tc-progress__bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), #22c55e);
    border-radius: 0 2px 2px 0;
    transition: width var(--duration-slow) var(--ease-out-expo);
    position: relative;
}

.tc-progress__bar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: tc-shimmer 2s ease-in-out infinite;
}

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

/* ─────────────────────────────────────────────
 * 10. Responsive
 * ───────────────────────────────────────────── */

@media (min-width: 576px) {
    .tc-add__btn {
        width: auto;
        padding: 0 var(--space-5);
    }

    .tc-add__icon {
        display: none;
    }

    .tc-add__text {
        display: inline;
        font-weight: var(--weight-semibold);
        font-size: var(--text-sm);
    }

    .tc-field--qty {
        flex: 0 0 90px;
    }

    .tc-delete {
        opacity: 0.6;
    }

    .tc-delete:hover {
        opacity: 1;
    }
}

@media (min-width: 768px) {
    :root {
        --header-height: 60px;
    }

    .tc-header__title {
        font-size: var(--text-xl);
    }

    .tc-add__form {
        padding: var(--space-3);
    }

    .tc-field__input {
        height: 44px;
    }

    .tc-add__btn {
        height: 44px;
        border-radius: var(--radius-md);
    }

    .tc-item {
        padding: var(--space-3) var(--space-5);
    }

    .tc-item__name {
        font-size: var(--text-md);
    }
}

@media (min-width: 1024px) {
    :root {
        --max-width: 600px;
    }

    .tc-main {
        padding-top: var(--space-6);
    }
}

/* ─────────────────────────────────────────────
 * 11. Accessibility
 * ───────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .tc-bg-blob {
        animation: none !important;
    }
}

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

/* Screen reader only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ─────────────────────────────────────────────
 * 12. Scrollbar (Webkit)
 * ───────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* ─────────────────────────────────────────────
 * 13. Selection
 * ───────────────────────────────────────────── */

::selection {
    background: rgba(var(--color-primary-rgb), 0.15);
    color: var(--color-primary-dark);
}

/* ─────────────────────────────────────────────
 * 14. Form Input States
 * ───────────────────────────────────────────── */

.tc-field__input.is-invalid {
    color: var(--color-danger);
}

.tc-field__input.is-invalid::placeholder {
    color: var(--color-danger);
    opacity: 0.6;
}

/* ─────────────────────────────────────────────
 * 15. Loading Spinner (for button state)
 * ───────────────────────────────────────────── */

.tc-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tc-spin 0.6s linear infinite;
}

@keyframes tc-spin {
    to { transform: rotate(360deg); }
}
