@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    width: 100%;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
}

/* Анимация бегущей строки для длинных названий */
@keyframes scroll-text {
    0% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(0);
    }
    80% {
        transform: translateX(calc(-100% + var(--container-width, 150px)));
    }
    100% {
        transform: translateX(0);
    }
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    min-height: 100vh;
    color: #0f172a;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    width: 100%;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
}

/* Header - Clean and Compact */
.header {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo {
    width: 3rem;
    height: 3rem;
    border-radius: 0.5rem;
}

.header-icon {
    width: 2rem;
    height: 2rem;
    background: #0ea5e9;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.header-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: #0f172a;
}

.header-date {
    color: #64748b;
    font-size: 0.875rem;
    font-weight: 500;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #f1f5f9;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: #475569;
}

.status-dot {
    width: 0.5rem;
    height: 0.5rem;
    background: #06b6d4;
    border-radius: 50%;
}

/* Main Layout */
.main-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    display: grid;
    gap: 1.5rem;
    grid-template-columns: 1fr;
    box-sizing: border-box;
}

/* Cards */
.card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.card-header {
    padding: 1.25rem 1.25rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1.125rem;
    font-weight: 600;
    color: #0f172a;
}

.completion-badge {
    background: #f1f5f9;
    color: #475569;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Habits Section */
.habits-card {
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.habits-content {
    padding: 0 1.25rem 1.25rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.add-habit {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.add-habit input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    min-width: 0;
    box-sizing: border-box;
}

.add-habit input:focus {
    border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.add-habit button {
    width: 2.75rem;
    height: 2.75rem;
    background: #14b8a6;
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    flex-shrink: 0;
    box-sizing: border-box;
}

.add-habit button:hover {
    background: #0d9488;
}

.habit-list-container {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
}

.habit-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.habit-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.habit-item:hover {
    border-color: #cbd5e1;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.habit-item.completed {
    background: #ecfdf5;
    border-color: #a7f3d0;
}

.habit-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.habit-checkbox {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid #cbd5e1;
    border-radius: 0.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.habit-checkbox:hover {
    border-color: #059669;
}

.habit-checkbox.checked {
    background: #059669;
    border-color: #059669;
    color: white;
}

.habit-icon {
    width: 1.75rem;
    height: 1.75rem;
    background: #dbeafe;
    border: 1px solid #bfdbfe;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.habit-name {
    font-weight: 500;
    color: #0f172a;
    flex: 1;
    font-size: 0.875rem;
    word-break: break-word;
}

.habit-name.completed {
    text-decoration: line-through;
    color: #64748b;
}

.habit-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.streak-badge {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: #fef3c7;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: #f59e0b;
}

.edit-button,
.delete-button {
    width: 1.75rem;
    height: 1.75rem;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.edit-button:hover {
    background: #f1f5f9;
    color: #64748b;
}

.delete-button:hover {
    background: #fef2f2;
    color: #ef4444;
}

/* Calendar */
.calendar-card {
    min-height: 400px;
}

.calendar-content {
    padding: 0 1.25rem 1.25rem;
}

.calendar-header-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.calendar-title-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.calendar-icon {
    width: 1.75rem;
    height: 1.75rem;
    background: #0ea5e9;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
}

.calendar-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: #0f172a;
}

.intensity-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #f8fafc;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    border: 1px solid #e2e8f0;
    font-size: 0.75rem;
    color: #64748b;
}

.intensity-scale {
    display: flex;
    gap: 0.25rem;
}

.intensity-dot {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 0.25rem;
    border: 1px solid;
}

.intensity-dot.level-0 {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

.intensity-dot.level-1 {
    background: #dbeafe;
    border-color: #93c5fd;
}

.intensity-dot.level-2 {
    background: #93c5fd;
    border-color: #3b82f6;
}

.intensity-dot.level-3 {
    background: #3b82f6;
    border-color: #2563eb;
}

.intensity-dot.level-4 {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.weekday-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.weekday-label {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    padding: 0.25rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.25rem;
}

.calendar-day {
    aspect-ratio: 1;
    border: 1px solid #e2e8f0;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.calendar-day:hover {
    border-color: #0ea5e9;
    transform: scale(1.05);
}

.calendar-day.intensity-1 {
    background: #dbeafe;
    border-color: #93c5fd;
}

.calendar-day.intensity-2 {
    background: #93c5fd;
    border-color: #3b82f6;
    color: white;
}

.calendar-day.intensity-3 {
    background: #3b82f6;
    border-color: #2563eb;
    color: white;
}

.calendar-day.intensity-4 {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: white;
}

.calendar-day.today {
    border-color: #0ea5e9;
    border-width: 2px;
}

.calendar-footer {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.active-days {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.active-dot {
    width: 0.375rem;
    height: 0.375rem;
    background: #06b6d4;
    border-radius: 50%;
}

.active-text {
    font-size: 0.875rem;
    color: #64748b;
}

.active-count {
    font-weight: 700;
    color: #06b6d4;
}

.motivation-text {
    font-size: 0.875rem;
    color: #64748b;
}

/* Analytics */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin: 0;
    width: 100%;
    padding: 0;
}

.analytics-item {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.analytics-item:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.analytics-icon-wrapper {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.analytics-icon-wrapper.emerald {
    background: #ecfdf5;
}

.analytics-icon-wrapper.blue {
    background: #eff6ff;
}

.analytics-icon-wrapper.purple {
    background: #faf5ff;
}

.analytics-circle {
    position: relative;
    width: 3rem;
    height: 3rem;
}

.analytics-circle .analytics-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.875rem;
    font-weight: 700;
    color: #334155;
}

.analytics-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #475569;
}

/* Quick Stats - ВСЕГДА 3 в ряд, никогда не адаптируется */
.quick-stats-grid {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin: 0;
    width: 100%;
    padding: 0;
}

.stat-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    flex: 1;
}

.stat-card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.stat-value-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-icon {
    font-size: 2rem;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
}

.stat-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #334155;
    order: -1;
}

.stat-unit {
    font-size: 0.75rem;
    color: #64748b;
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: #94a3b8;
}

.empty-icon {
    width: 3rem;
    height: 3rem;
    margin: 0 auto 1rem;
    border-radius: 0.75rem;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.empty-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #475569;
}

.empty-description {
    max-width: 20rem;
    margin: 0 auto;
    line-height: 1.5;
    font-size: 0.875rem;
}

/* Scrollbar */
.habit-list-container::-webkit-scrollbar {
    width: 4px;
}

.habit-list-container::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 2px;
}

.habit-list-container::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 2px;
}

.habit-list-container::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Progress Chart */
.progress-chart-card {
    grid-column: 1 / -1;
    margin-top: 1rem;
}

.progress-chart-container {
    padding: 1rem 1.5rem;
    overflow-x: auto;
}

/* На мобильных устройствах убираем боковые отступы для прокрутки */
@media (max-width: 767px) {
    .progress-chart-container {
        padding: 1rem 0;
        overflow-x: auto;
    }
}

.chart-grid {
    display: flex;
    align-items: end;
    height: 200px;
    padding: 0 0.5rem;
    margin-bottom: 0.5rem;
    gap: 4px;
    width: 100%;
    justify-content: space-between;
}

.chart-bar {
    background: linear-gradient(135deg, #10b981, #059669);
    border-radius: 4px 4px 0 0;
    min-width: 16px;
    width: 16px;
    flex: 1;
    max-width: 30px;
    transition: all 0.3s ease;
    position: relative;
    cursor: pointer;
    min-height: 4px; /* Минимальная высота чтобы столбец всегда был виден */
}

/* На мобильных устройствах делаем график прокручиваемым */
@media (max-width: 767px) {
    .chart-grid {
        justify-content: flex-start;
        overflow-x: auto;
        overflow-y: hidden;
        width: 100%;
        max-width: 100%;
        gap: 8px;
        padding-right: 1rem;
    }
    
    .chart-bar {
        min-width: 20px;
        width: 20px;
        flex: none;
        max-width: none;
        min-height: 4px; /* Сохраняем минимальную высоту на мобильных */
    }
}

.chart-bar:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.chart-bar.low {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.chart-bar.medium {
    background: linear-gradient(135deg, #10b981, #059669);
}

.chart-bar.high {
    background: linear-gradient(135deg, #10b981, #059669);
}

.chart-bar::after {
    content: attr(data-percentage);
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chart-bar:hover::after {
    opacity: 1;
}

.chart-labels {
    display: flex;
    padding: 0 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    gap: 4px;
    width: 100%;
    justify-content: space-between;
}

.chart-label {
    text-align: center;
    min-width: 16px;
    width: 16px;
    flex: 1;
    max-width: 30px;
}

/* На мобильных устройствах синхронизируем с графиком */
@media (max-width: 767px) {
    .chart-labels {
        justify-content: flex-start;
        overflow-x: auto;
        overflow-y: hidden;
        width: 100%;
        max-width: 100%;
        gap: 8px;
    }
    
    .chart-label {
        min-width: 20px;
        width: 20px;
        flex: none;
        max-width: none;
    }
}

.chart-period {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Mobile Responsive */
/* Очень маленькие экраны */
@media (max-width: 400px) {
    * {
        box-sizing: border-box !important;
    }
    
    html, body {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow-x: hidden !important;
    }
    
    .header-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.25rem !important;
        margin: 0 !important;
    }
    
    .main-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.25rem !important;
        margin: 0 !important;
        gap: 0.5rem !important;
    }
    
    .card {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }
    
    .card-header {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.5rem !important;
        margin: 0 !important;
    }
    
    .habits-content {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.5rem !important;
        margin: 0 !important;
    }
    
    .calendar-content {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.5rem !important;
        margin: 0 !important;
    }
    
    .add-habit {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 0 1rem 0 !important;
        padding: 0 !important;
        gap: 0.5rem !important;
        flex-direction: column !important;
    }
    
    .add-habit input {
        width: 100% !important;
        min-width: 0 !important;
        font-size: 16px !important;
        padding: 0.75rem !important;
    }
    
    .add-habit button {
        width: 100% !important;
        height: 2.5rem !important;
        padding: 0.75rem !important;
        flex-shrink: 0 !important;
    }
    
    .analytics-grid {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        gap: 0.25rem !important;
    }
    
    .quick-stats-grid {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        gap: 0.25rem !important;
    }
    
    .chart-grid {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .habit-name-container {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        position: relative;
    }

    .habit-name {
        white-space: nowrap;
        position: relative;
        display: inline-block;
        width: max-content;
    }

    .habit-name.scrolling {
        animation: scroll-text 8s linear infinite;
        animation-delay: var(--animation-delay, 0s);
    }
}

@media (max-width: 768px) {
    .header-container {
        padding: 0.5rem;
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .header-left {
        width: 100%;
    }

    .header-title {
        font-size: 1.125rem;
    }

    .header-status {
        display: none;
    }

    .main-container {
        padding: 0.5rem;
        gap: 1rem;
    }

    .card-header {
        padding: 1rem 1rem 0;
        /* flex-direction: column; */
        align-items: flex-start;
        gap: 0.5rem;
    }

    .habits-content {
        padding: 0 1rem 1rem;
    }

    .calendar-content {
        padding: 0 1rem 1rem;
    }

    .add-habit {
        flex-direction: column;
    }

    .add-habit button {
        width: 100%;
        height: 2.5rem;
    }

    .habit-item {
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        min-height: 3.5rem;
    }

    .habit-left {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        flex: 1;
        min-width: 0;
    }

    .habit-name-container {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        position: relative;
    }

    .habit-name {
        white-space: nowrap;
        position: relative;
        display: inline-block;
        width: max-content;
    }

    .habit-name.scrolling {
        animation: scroll-text 8s linear infinite;
        animation-delay: var(--animation-delay, 0s);
    }
    
    .calendar-chart-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .habit-right {
        flex-shrink: 0;
        justify-content: flex-end;
    }

    .calendar-header-section {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .intensity-legend {
        width: 100%;
        justify-content: center;
    }

    .calendar-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .analytics-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-list {
        gap: 0.75rem;
    }

    .stat-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
}

/* Tablet */
@media (min-width: 768px) {
    .main-container {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto;
        max-width: calc(100% - 2rem);
        width: 100%;
    }

    .habits-card {
        grid-row: 1;
    }

    .calendar-card {
        grid-row: 1;
    }

    .analytics-grid {
        grid-column: 1 / -1;
        grid-template-columns: repeat(4, 1fr);
    }

    .quick-stats-grid {
        grid-column: 1 / -1;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    .header-container {
        padding: 1rem;
        flex-direction: row;
    }

    .main-container {
        padding: 1.5rem;
        gap: 1.5rem;
        width: 100%;
        max-width: 1200px;
        margin: 0 auto;
    }

    .card-header {
        flex-direction: row;
        align-items: center;
    }

    .habits-content {
        padding: 0 1.25rem 1.25rem;
    }

    .calendar-content {
        padding: 0 1.25rem 1.25rem;
    }

    .add-habit {
        flex-direction: row;
    }

    .add-habit button {
        width: 2.75rem;
    }

    .habit-item {
        flex-direction: row;
        align-items: center;
    }

    .habit-left {
        width: auto;
    }

    .habit-right {
        width: auto;
    }

    .calendar-header-section {
        flex-direction: row;
        align-items: center;
    }

    .intensity-legend {
        width: auto;
    }

    .calendar-footer {
        flex-direction: row;
        align-items: center;
    }
}