:root {
    color-scheme: light;
    --bg: var(--tg-theme-bg-color, #f5f5f7);
    --text: var(--tg-theme-text-color, #111814);
    --hint: var(--tg-theme-hint-color, #6f7873);
    --panel: var(--tg-theme-secondary-bg-color, #ffffff);
    --button: var(--tg-theme-button-color, #111814);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --line: rgba(17, 24, 20, 0.1);
    --soft-line: rgba(17, 24, 20, 0.06);
    --accent: #1d3128;
    --yellow: #f5c84c;
    --cloud: #a5aaa8;
    --danger: #d54b45;
    --radius: 18px;
    --card-padding: 16px;
    --section-gap: 14px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    background: var(--bg);
    overflow-x: hidden;
}

body {
    margin: 0;
    overflow-x: hidden;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
    font-size: 16px;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    user-select: none;
}

.app-shell {
    width: min(100%, 680px);
    margin: 0 auto;
    overflow-x: hidden;
    padding: calc(12px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom));
}

.date-header {
    margin-bottom: 12px;
}

.current-date {
    color: var(--hint);
    font-size: 20px;
    font-weight: 650;
    line-height: 1.25;
}

.current-date,
.muted-label,
.hint,
.summary {
    margin: 0;
    color: var(--hint);
}

.tabs {
    position: sticky;
    top: max(8px, env(safe-area-inset-top));
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: var(--section-gap);
    padding: 4px;
    border: 1px solid var(--soft-line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(18px);
}

.tab-button,
.icon-button,
.primary-button,
.danger-button {
    border: 0;
    cursor: pointer;
    transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.tab-button {
    min-width: 0;
    min-height: 38px;
    border-radius: 999px;
    background: transparent;
    color: var(--hint);
    padding: 0 8px;
    font-size: 14px;
    font-weight: 650;
    white-space: nowrap;
}

.tab-button.is-active {
    background: var(--button);
    color: var(--button-text);
    box-shadow: 0 3px 10px rgba(17, 24, 20, 0.12);
}

.tab-button:active,
.icon-button:active,
.primary-button:active,
.danger-button:active {
    transform: scale(0.97);
}

.tab-view {
    display: none;
}

.tab-view.is-active {
    display: grid;
    gap: var(--section-gap);
}

.panel,
.chart-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    padding: var(--card-padding);
    box-shadow: 0 6px 18px rgba(18, 24, 20, 0.045);
}

.panel h2,
.chart-card h2 {
    margin: 0;
    font-size: 21px;
    line-height: 1.18;
    font-weight: 760;
    letter-spacing: 0;
}

.field-label,
.muted-label {
    display: block;
    margin-bottom: 8px;
    color: var(--hint);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.input,
.big-input,
.duration-field input {
    width: 100%;
    min-width: 0;
    color: var(--text);
    outline: none;
}

.input {
    display: block;
    min-height: 48px;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f7f8f7;
    padding: 12px 14px;
    font-size: 16px;
}

.input:focus,
.duration-field:focus-within {
    border-color: rgba(17, 24, 20, 0.22);
    background: #ffffff;
}

.date-panel {
    overflow: hidden;
    padding: 14px;
}

.date-input {
    appearance: none;
    -webkit-appearance: none;
    display: block;
    box-sizing: border-box;
    min-height: 52px;
    width: 100%;
    max-width: 100%;
    padding: 0 14px;
    font-size: 16px;
    line-height: 52px;
    white-space: nowrap;
}

.date-input::-webkit-date-and-time-value {
    min-height: 52px;
    text-align: left;
}

.date-input::-webkit-calendar-picker-indicator {
    margin-left: 8px;
}

.big-input {
    border: 0;
    background: transparent;
    padding: 0;
    font-size: 40px;
    line-height: 1.08;
    font-weight: 800;
    letter-spacing: 0;
}

.metric-panel {
    overflow: hidden;
}

.metric-input-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.metric-input-row span,
.duration-field span,
.hint {
    color: var(--hint);
}

.metric-input-row span {
    flex: 0 0 auto;
}

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

.duration-field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    min-height: 48px;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.72);
    padding: 8px 11px;
}

.duration-field input {
    border: 0;
    background: transparent;
    padding: 0;
    text-align: right;
    font-size: 17px;
}

.weather-panel {
    background: var(--panel);
}

.toggle-row,
.section-header,
.week-nav,
.month-nav,
.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.toggle-row {
    position: relative;
    min-height: 48px;
    cursor: pointer;
}

.toggle-label {
    font-weight: 700;
}

.weather-label {
    margin: 0;
}

#sunnyInput {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.checkbox-control {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border: 1.5px solid var(--line);
    border-radius: 10px;
    background: #ffffff;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.checkbox-control::after {
    width: 12px;
    height: 7px;
    border-bottom: 2px solid #ffffff;
    border-left: 2px solid #ffffff;
    content: "";
    opacity: 0;
    transform: rotate(-45deg) translate(1px, -1px);
}

#sunnyInput:checked + .checkbox-control {
    border-color: var(--accent);
    background: var(--accent);
}

#sunnyInput:checked + .checkbox-control::after {
    opacity: 1;
}

.toggle-row:active .checkbox-control {
    transform: scale(0.96);
}

.icon-button {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 50%;
    background: #f2f3f2;
    color: var(--text);
    font-size: 24px;
    line-height: 1;
}

.primary-button {
    min-height: 48px;
    border-radius: 14px;
    background: var(--button);
    color: var(--button-text);
    padding: 0 16px;
    font-weight: 720;
}

.danger-button {
    min-height: 36px;
    border-radius: 12px;
    background: rgba(213, 75, 69, 0.1);
    color: var(--danger);
    padding: 0 12px;
    font-size: 14px;
    font-weight: 700;
}

.event-form,
.category-form {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.event-form.is-hidden {
    display: none;
}

.palette,
.chips,
.category-color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
}

.swatch {
    width: 32px;
    height: 32px;
    border: 2px solid transparent;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.swatch.is-selected {
    border-color: var(--text);
    box-shadow: inset 0 0 0 2px #ffffff;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 10px;
    background: #f7f8f7;
}

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.list {
    display: grid;
    gap: 0;
    margin-top: 12px;
}

.list-row {
    min-height: 48px;
    border-bottom: 1px solid var(--soft-line);
    padding: 10px 0;
}

.list-row:last-child {
    border-bottom: 0;
}

.list-row-title {
    margin: 0;
    overflow-wrap: anywhere;
    font-weight: 700;
}

.list-row-note,
.category-row-meta {
    margin: 3px 0 0;
    color: var(--hint);
    font-size: 13px;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.week-nav,
.month-nav {
    margin-bottom: 0;
}

.week-nav > div {
    min-width: 0;
}

.week-nav h2,
.month-nav h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
    font-weight: 760;
}

.chart-card {
    display: grid;
    gap: 14px;
    overflow: hidden;
}

.bar-chart {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px;
    height: 270px;
    overflow: hidden;
}

.bar-item {
    display: grid;
    grid-template-rows: 176px 20px 52px;
    align-items: end;
    min-width: 0;
    gap: 6px;
    text-align: center;
}

.bar-track {
    display: flex;
    align-items: end;
    width: 100%;
    height: 176px;
    overflow: hidden;
}

.bar {
    width: 100%;
    max-height: 100%;
    border-radius: 9px 9px 4px 4px;
}

.bar-label,
.bar-value,
.weather-day,
.calendar-weekday {
    color: var(--hint);
}

.bar-label {
    overflow: hidden;
    font-size: 14px;
    font-weight: 720;
    line-height: 20px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-value {
    overflow: hidden;
    min-width: 0;
    font-size: 11px;
    line-height: 1.18;
    overflow-wrap: anywhere;
}

.summary {
    font-size: 15px;
    line-height: 1.35;
}

.weather-chart {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
}

.weather-item {
    display: grid;
    justify-items: center;
    gap: 7px;
    min-width: 0;
}

.weather-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    color: var(--accent);
}

.weather-icon.sunny {
    background: rgba(29, 49, 40, 0.06);
    color: var(--accent);
}

.weather-icon.cloudy {
    background: rgba(29, 49, 40, 0.05);
    color: var(--hint);
}

.weather-icon.empty {
    background: transparent;
}

.calendar-panel {
    padding: var(--card-padding);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
}

.calendar-weekday {
    text-align: center;
    font-size: 12px;
    font-weight: 760;
}

.calendar-day {
    display: grid;
    justify-items: center;
    align-content: start;
    gap: 4px;
    min-height: 54px;
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 0;
}

.calendar-day.outside {
    opacity: 0.32;
}

.day-number {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-weight: 800;
}

.calendar-day.selected .day-number {
    background: var(--button);
    color: var(--button-text);
}

.calendar-day.sunny .day-number {
    background: var(--yellow);
    color: #181812;
    box-shadow: 0 0 0 2px var(--yellow);
}

.calendar-day.selected.sunny .day-number {
    box-shadow: 0 0 0 2px var(--yellow), 0 0 0 5px var(--button);
}

.category-dots {
    display: flex;
    justify-content: center;
    gap: 3px;
    height: 7px;
}

.category-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
}

.line-icon {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-row {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
}

.icon-row .line-icon {
    flex: 0 0 22px;
    color: var(--accent);
}

.search-panel {
    display: grid;
    gap: 10px;
}

.search-field {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    min-height: 46px;
    gap: 9px;
    border-radius: 14px;
    background: #f1f2f1;
    padding: 0 13px;
}

.search-field input {
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    outline: 0;
    font-size: 16px;
}

.search-icon {
    position: relative;
    width: 17px;
    height: 17px;
    color: var(--hint);
}

.search-icon::before {
    position: absolute;
    inset: 0 3px 3px 0;
    border: 1.8px solid currentColor;
    border-radius: 50%;
    content: "";
}

.search-icon::after {
    position: absolute;
    right: 0;
    bottom: 1px;
    width: 7px;
    height: 1.8px;
    border-radius: 2px;
    background: currentColor;
    content: "";
    transform: rotate(45deg);
    transform-origin: center;
}

.search-results {
    display: grid;
    gap: 8px;
}

.search-result {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 50px;
    border: 1px solid var(--soft-line);
    border-radius: 14px;
    background: #ffffff;
    color: var(--text);
    padding: 9px 11px;
    text-align: left;
}

.search-result strong,
.search-result small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result small {
    margin-top: 2px;
    color: var(--hint);
    font-size: 13px;
}

.search-empty {
    padding: 2px 4px 0;
}

.day-card-empty {
    color: var(--hint);
    text-align: center;
    padding: 18px 0;
}

.category-list {
    display: grid;
    gap: 12px;
    margin-top: 14px;
}

.category-editor-panel {
    margin-top: 2px;
}

.category-form {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--soft-line);
}

.category-row {
    display: grid;
    gap: 10px;
    border: 1px solid var(--soft-line);
    border-radius: 16px;
    background: #f8f9f8;
    padding: 12px;
}

.category-row-main {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.category-color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.category-name-input {
    min-height: 42px;
    padding: 9px 11px;
}

@media (max-width: 420px) {
    :root {
        --card-padding: 15px;
        --section-gap: 12px;
    }

    .app-shell {
        padding-inline: 12px;
    }

    .tab-button {
        min-height: 36px;
        padding-inline: 4px;
        font-size: 13px;
    }

    .panel h2,
    .chart-card h2 {
        font-size: 20px;
    }

    .bar-chart {
        gap: 6px;
        height: 264px;
    }

    .bar-item {
        grid-template-rows: 170px 20px 50px;
        gap: 6px;
    }

    .bar-track {
        height: 170px;
    }

    .bar-value {
        font-size: 11px;
    }

    .weather-icon {
        width: 38px;
        height: 38px;
        font-size: 21px;
    }

    .calendar-grid {
        gap: 6px;
    }

    .category-row-main {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .danger-button {
        grid-column: 2;
        justify-self: start;
    }
}
