/* ============================
   Design System & Variables
   ============================ */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: rgba(20, 20, 30, 0.7);
    --bg-card-hover: rgba(25, 25, 38, 0.85);
    --bg-input: rgba(255, 255, 255, 0.04);
    --bg-input-focus: rgba(255, 255, 255, 0.07);

    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;

    --accent: #a78bfa;
    --accent-dim: rgba(167, 139, 250, 0.15);
    --accent-glow: rgba(167, 139, 250, 0.25);

    --green: #34d399;
    --green-dim: rgba(52, 211, 153, 0.12);
    --green-glow: rgba(52, 211, 153, 0.2);

    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.12);

    --purple: #c084fc;
    --purple-dim: rgba(192, 132, 252, 0.12);

    --yellow: #fbbf24;
    --yellow-dim: rgba(251, 191, 36, 0.12);

    --blue: #60a5fa;
    --blue-dim: rgba(96, 165, 250, 0.12);

    --border: rgba(255, 255, 255, 0.06);
    --border-focus: rgba(167, 139, 250, 0.4);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 24px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px var(--accent-glow);

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================
   Reset & Base
   ============================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* ============================
   Animated Background
   ============================ */
.app-bg {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    overflow: hidden;
}

.app-bg::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-glow), transparent 70%);
    top: -150px;
    right: -100px;
    animation: floatGlow 12s ease-in-out infinite;
}

.app-bg::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--green-glow), transparent 70%);
    bottom: -100px;
    left: -100px;
    animation: floatGlow 15s ease-in-out infinite reverse;
}

@keyframes floatGlow {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -20px) scale(1.1); }
    66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* ============================
   Container & Layout
   ============================ */
.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 16px 60px;
    position: relative;
}

/* ============================
   Header
   ============================ */
.app-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 28px 0 32px;
    animation: fadeSlideIn 0.6s ease-out;
}

.logo-icon {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border-radius: var(--radius-md);
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 20px rgba(167, 139, 250, 0.35);
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 2px;
}

/* ============================
   Cards
   ============================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: all var(--transition-normal);
    animation: fadeSlideIn 0.5s ease-out backwards;
}

.card:nth-child(1) { animation-delay: 0.05s; }
.card:nth-child(2) { animation-delay: 0.1s; }
.card:nth-child(3) { animation-delay: 0.15s; }
.card:nth-child(4) { animation-delay: 0.2s; }
.card:nth-child(5) { animation-delay: 0.25s; }
.card:nth-child(6) { animation-delay: 0.3s; }

.card:hover {
    border-color: rgba(255, 255, 255, 0.1);
    background: var(--bg-card-hover);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px 0;
}

.card-header h2 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    flex: 1;
}

.section-number {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent-dim);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.section-number-time {
    background: var(--blue-dim);
    color: var(--blue);
}

.card-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.badge-red {
    background: var(--red-dim);
    color: var(--red);
}

.badge-green {
    background: var(--green-dim);
    color: var(--green);
}

.badge-purple {
    background: var(--purple-dim);
    color: var(--purple);
}

.card-body {
    padding: 20px 24px 24px;
}

/* ============================
   Time Range (New Section)
   ============================ */
.time-range {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.time-field {
    flex: 1;
}

.time-field label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.time-field input[type="date"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 0.88rem;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: border-color var(--transition-fast);
    color-scheme: dark;
}

.time-field input[type="date"]:focus {
    border-color: var(--border-focus);
    background: var(--bg-input-focus);
}

.time-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    padding-bottom: 8px;
    flex-shrink: 0;
}

/* ============================
   Stats Grid (Section 1)
   ============================ */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.stat-card {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    text-align: center;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
    transition: opacity var(--transition-normal);
    opacity: 0.6;
}

.stat-inbox::before {
    background: linear-gradient(90deg, var(--blue), var(--accent));
}

.stat-tattoo::before {
    background: linear-gradient(90deg, var(--green), #22d3ee);
}

.stat-card:hover {
    border-color: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-icon {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.stat-inbox .stat-icon { color: var(--blue); }
.stat-tattoo .stat-icon { color: var(--green); }

.stat-card label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 10px;
    letter-spacing: 0.02em;
}

.stat-card input[type="number"] {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    text-align: center;
    font-family: 'Inter', sans-serif;
    -moz-appearance: textfield;
}

.stat-card input[type="number"]::-webkit-inner-spin-button,
.stat-card input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.stat-card input::placeholder {
    color: var(--text-muted);
}

/* Conversion Bar */
.conversion-bar {
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: fadeIn 0.3s ease-out;
}

.conversion-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

.conversion-track {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.conversion-fill {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent), var(--green));
    transition: width 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.conversion-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
    min-width: 42px;
    text-align: right;
}

/* ============================
   Dynamic List Items (Sections 2, 3, 4)
   ============================ */
.dynamic-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dynamic-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    transition: all var(--transition-normal);
    animation: fadeSlideIn 0.3s ease-out;
    position: relative;
}

.dynamic-item:hover {
    border-color: rgba(255, 255, 255, 0.1);
    background: var(--bg-input-focus);
}

.item-rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

/* Color cycle for ranks */
.dynamic-item:nth-child(6n+1) .item-rank { background: var(--yellow-dim); color: var(--yellow); }
.dynamic-item:nth-child(6n+2) .item-rank { background: var(--blue-dim); color: var(--blue); }
.dynamic-item:nth-child(6n+3) .item-rank { background: var(--purple-dim); color: var(--purple); }
.dynamic-item:nth-child(6n+4) .item-rank { background: var(--green-dim); color: var(--green); }
.dynamic-item:nth-child(6n+5) .item-rank { background: var(--red-dim); color: var(--red); }
.dynamic-item:nth-child(6n+6) .item-rank { background: var(--accent-dim); color: var(--accent); }

.item-content {
    flex: 1;
    min-width: 0;
}

.item-text-input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    outline: none;
    font-size: 0.9rem;
    color: var(--text-primary);
    padding: 3px 0 7px;
    font-family: 'Inter', sans-serif;
    transition: border-color var(--transition-fast);
}

.item-text-input:focus {
    border-bottom-color: var(--accent);
}

.item-text-input::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.item-stats {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 10px;
}

.item-count {
    flex: 1;
}

.item-count label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.count-input {
    width: 80px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 6px 10px;
    font-family: 'Inter', sans-serif;
    transition: border-color var(--transition-fast);
    -moz-appearance: textfield;
}

.count-input::-webkit-inner-spin-button,
.count-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.count-input:focus {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.06);
}

.count-input::placeholder {
    color: var(--text-muted);
}

.item-percent {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 54px;
}

.percent-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
    transition: color var(--transition-fast);
}

.percent-label {
    font-size: 0.58rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 3px;
}

/* Delete button on item */
.item-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 50%;
    transition: all var(--transition-fast);
    opacity: 0;
    padding: 0;
}

.dynamic-item:hover .item-delete {
    opacity: 1;
}

.item-delete:hover {
    background: var(--red-dim);
    color: var(--red);
}

/* ============================
   Add Button
   ============================ */
.btn-add {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    margin-top: 12px;
    background: transparent;
    border: 1.5px dashed rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn-add:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

/* ============================
   Textarea (Section 5)
   ============================ */
textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-size: 0.9rem;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    resize: vertical;
    outline: none;
    line-height: 1.7;
    transition: all var(--transition-fast);
    min-height: 100px;
}

textarea::placeholder {
    color: var(--text-muted);
}

textarea:focus {
    border-color: var(--border-focus);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ============================
   Buttons
   ============================ */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    animation: fadeSlideIn 0.5s ease-out 0.35s backwards;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    transition: all var(--transition-normal);
    letter-spacing: -0.01em;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 100%);
    pointer-events: none;
}

.btn-primary {
    flex: 1;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
    box-shadow: 0 4px 20px rgba(167, 139, 250, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(167, 139, 250, 0.45);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-input-focus);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.12);
}

/* ============================
   Modal
   ============================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 36px 32px;
    max-width: 480px;
    width: 100%;
    text-align: center;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-slow);
    max-height: 85vh;
    overflow-y: auto;
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--green-dim);
    color: var(--green);
    animation: scaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s backwards;
}

.modal-content h3 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}

.modal-content > p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin-bottom: 20px;
}

.report-summary {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    text-align: left;
    font-size: 0.82rem;
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: 24px;
    max-height: 300px;
    overflow-y: auto;
}

.report-summary strong {
    color: var(--text-primary);
}

.report-summary .summary-section {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.report-summary .summary-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
    padding: 12px 20px;
}

/* ============================
   Animations
   ============================ */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* ============================
   Scrollbar
   ============================ */
::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* ============================
   Toast
   ============================ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    border: 1px solid var(--green-dim);
    color: var(--green);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 1001;
    opacity: 0;
    transition: all var(--transition-normal);
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-md);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================
   Spinner & Disabled
   ============================ */
.spin {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* ============================
   Responsive
   ============================ */
@media (max-width: 480px) {
    .container {
        padding: 16px 12px 48px;
    }

    .app-header h1 {
        font-size: 1.4rem;
    }

    .logo-icon {
        width: 44px;
        height: 44px;
    }

    .card-header {
        padding: 16px 18px 0;
    }

    .card-body {
        padding: 16px 18px 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px 10px;
    }

    .stat-card input[type="number"] {
        font-size: 1.6rem;
    }

    .item-stats {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .item-percent {
        flex-direction: row;
        gap: 6px;
        align-items: baseline;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

    .time-range {
        flex-direction: column;
        gap: 10px;
    }

    .time-separator {
        transform: rotate(90deg);
        padding: 0;
    }
}
