:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-hover: #243044;
    --border: #2d3a4f;
    --text: #e8edf4;
    --text-muted: #8b9cb3;
    --primary: #4ade80;
    --primary-dim: #22c55e;
    --accent: #60a5fa;
    --warning: #fbbf24;
    --orange: #fb923c;
    --danger: #f87171;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

.app {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

.header {
    text-align: center;
    margin-bottom: 32px;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.logout-btn {
    padding: 4px 12px !important;
    font-size: 0.8rem !important;
    background: transparent !important;
    border: 1px solid var(--border) !important;
    color: var(--text-muted) !important;
    text-decoration: none;
}

.logout-btn:hover {
    border-color: var(--danger) !important;
    color: var(--danger) !important;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.subtitle {
    color: var(--text-muted);
    margin-top: 4px;
}

.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px 32px;
    text-align: center;
    box-shadow: var(--shadow);
    max-width: 360px;
    width: 100%;
}

.login-card h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.login-card .subtitle {
    margin-bottom: 24px;
}

.login-error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-bottom: 16px;
    padding: 8px 12px;
    background: rgba(248, 113, 113, 0.1);
    border-radius: 6px;
}

.yandex-btn {
    display: inline-block;
    padding: 12px 24px;
    background: #fc3f1d;
    color: #fff;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    text-decoration: none;
    transition: background 0.2s;
}

.yandex-btn:hover {
    background: #e03514;
}

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: var(--surface);
    padding: 6px;
    border-radius: var(--radius);
}

.tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.tab.active {
    background: var(--primary-dim);
    color: var(--bg);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card h2, .card h3 {
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.form-grid .full-width {
    grid-column: 1 / -1;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

input, select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn.primary {
    background: var(--primary-dim);
    color: var(--bg);
}

.btn.primary:hover {
    background: var(--primary);
}

.btn.secondary {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.secondary:hover {
    border-color: var(--accent);
}

.btn.quick {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 16px;
}

.btn.quick:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.result-card {
    border-color: var(--primary-dim);
}

.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.result-item {
    text-align: center;
    padding: 16px;
    background: var(--bg);
    border-radius: 8px;
}

.result-item.highlight {
    border: 1px solid var(--primary-dim);
}

.result-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.result-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.result-unit {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.custom-calories-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.custom-calories-label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.custom-calories-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.custom-calories-input-row input {
    flex: 1;
    max-width: 180px;
}

.custom-calories-input-row .btn.secondary {
    padding: 8px 14px;
    font-size: 0.85rem;
}

.hidden {
    display: none !important;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 48px 24px;
}

.counter-card {
    text-align: center;
}

.counter-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.date-header {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0;
}

.weight-display {
    position: relative;
    cursor: help;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: right;
}

.weight-display .weight-value {
    font-size: 1.3rem;
}

.weight-display .weight-value.bmi-underweight { color: var(--danger); }
.weight-display .weight-value.bmi-normal { color: var(--primary); }
.weight-display .weight-value.bmi-overweight { color: var(--warning); }
.weight-display .weight-value.bmi-obesity1 { color: var(--orange); }
.weight-display .weight-value.bmi-obesity2 { color: var(--orange); }
.weight-display .weight-value.bmi-obesity3 { color: var(--danger); }

.bmi-indicator {
    font-size: 0.8rem;
    font-weight: 400;
    margin-top: 2px;
}

.bmi-tooltip {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    white-space: nowrap;
    z-index: 100;
    box-shadow: var(--shadow);
    font-weight: 400;
    font-size: 0.8rem;
    line-height: 1.7;
}

.weight-display:hover .bmi-tooltip {
    display: block;
}

.bmi-tooltip .range-normal { color: var(--primary); }
.bmi-tooltip .range-overweight { color: var(--warning); }
.bmi-tooltip .range-obesity1 { color: var(--orange); }
.bmi-tooltip .range-obesity2 { color: var(--orange); }
.bmi-tooltip .range-obesity3 { color: var(--danger); }
.bmi-tooltip .range-underweight { color: var(--danger); }
.bmi-tooltip .current-mark {
    font-weight: 700;
}

.bmi-tooltip .range-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.bmi-tooltip .range-row.current {
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
    padding: 0 4px;
}

.counter-display {
    display: flex;
    justify-content: center;
    margin: 24px 0;
}

.counter-ring {
    position: relative;
    width: 220px;
    height: 220px;
}

.counter-ring svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.ring-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 12;
}

.ring-progress {
    fill: none;
    stroke: var(--primary);
    stroke-width: 12;
    stroke-linecap: round;
    stroke-dasharray: 565.48;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.5s ease, stroke 0.3s;
}

.counter-inner {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.counter-number {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1;
    color: var(--primary);
}

.counter-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.counter-stats {
    display: flex;
    justify-content: center;
    gap: 48px;
    margin-top: 16px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.meal-form, .weight-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.meal-form input[type="time"] {
    width: 120px;
}

.meal-form input[type="text"] {
    flex: 1;
    min-width: 140px;
}

.meal-form input[type="number"], .weight-form input {
    width: 100px;
}

.quick-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.meals-list {
    list-style: none;
}

.meals-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    cursor: grab;
    transition: background 0.15s;
}

.meals-list li:last-child {
    border-bottom: none;
}

.meals-list li.dragging {
    opacity: 0.4;
}

.meals-list li.drag-over {
    border-top: 2px solid var(--primary);
}

.drag-handle {
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: grab;
    user-select: none;
    padding: 0 4px;
}

.meal-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 4px 6px;
    border-radius: 4px;
    transition: all 0.15s;
}

.btn-icon:hover {
    color: var(--danger);
    background: rgba(248, 113, 113, 0.1);
}

.meal-desc {
    font-weight: 500;
}

.meal-time {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.meal-kcal {
    font-weight: 600;
    color: var(--warning);
}

.chart-container {
    position: relative;
    height: 280px;
}

.timeline-chart-container {
    margin-top: 16px;
    height: 120px;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.history-table th, .history-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.history-table th {
    color: var(--text-muted);
    font-weight: 500;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--primary);
    color: var(--text);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 1000;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (max-width: 520px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-grid input,
    .form-grid select {
        width: 100%;
    }

    .form-grid select {
        font-size: 0.8rem;
    }

    .custom-calories-input-row {
        flex-wrap: wrap;
    }

    .custom-calories-input-row input {
        max-width: 100%;
        flex: 1 1 100%;
    }

    .result-grid {
        grid-template-columns: 1fr;
    }

    .counter-number {
        font-size: 2.5rem;
    }
}
