:root {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.72);
    --bg-glass-hover: rgba(255, 255, 255, 0.85);
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #aeaeb2;
    --accent: #007aff;
    --accent-light: rgba(0, 122, 255, 0.12);
    --success: #34c759;
    --success-light: rgba(52, 199, 89, 0.15);
    --warning: #ff9f0a;
    --danger: #ff3b30;
    --border: rgba(0, 0, 0, 0.08);
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --blur: 20px;
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    
    --priority-high: #af52de;
    --priority-high-bg: rgba(175, 82, 222, 0.15);
    --priority-medium: #5ac8fa;
    --priority-medium-bg: rgba(90, 200, 250, 0.15);
    --priority-low-bg: rgba(142, 142, 147, 0.1);
    --priority-low-border: rgba(142, 142, 147, 0.3);
    
    --calendar-empty: rgba(142, 142, 147, 0.1);
    --calendar-full: rgba(40, 205, 65, 0.35);
    
    --tg-header-offset: 0px;
}

[data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-glass: rgba(28, 28, 30, 0.78);
    --bg-glass-hover: rgba(44, 44, 46, 0.85);
    --text-primary: #ffffff;
    --text-secondary: #98989d;
    --text-tertiary: #636366;
    --accent: #0a84ff;
    --accent-light: rgba(10, 132, 255, 0.18);
    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    
    --priority-high-bg: rgba(175, 82, 222, 0.25);
    --priority-medium-bg: rgba(90, 200, 250, 0.2);
    --priority-low-bg: rgba(142, 142, 147, 0.15);
    --priority-low-border: rgba(142, 142, 147, 0.4);
    
    --calendar-empty: rgba(142, 142, 147, 0.15);
    --calendar-full: rgba(52, 199, 89, 0.45);
}

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

html {
    font-size: 16px;
    scroll-padding-top: 80px;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    padding-top: 0 !important;
    margin-top: 0 !important;
    overflow-x: hidden;
    overflow-y: auto;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#app {
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.glass {
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
}

.glass-accent {
    background: var(--accent);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
}

/* Header */
.header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: 12px;
    position: fixed !important;
    /* Combined offset: device safe area (notch) + Telegram UI (header buttons) */
    top: var(--tg-header-offset, 0px) !important;
    left: calc(8px + var(--tg-content-safe-area-inset-left, 0px));
    right: calc(8px + var(--tg-content-safe-area-inset-right, 0px));
    z-index: 100 !important;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    min-height: 56px;
}

.header-title {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.header-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.header-btn:active {
    background: var(--accent-light);
    transform: scale(0.95);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 8px 16px 100px;
    /* Header height (56px) + padding (16px) + Telegram safe areas */
    padding-top: calc(72px + var(--tg-header-offset, 0px));
}

.view {
    animation: fadeIn 0.25s ease;
}

.view.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Calendar */
.calendar-container {
    border-radius: var(--radius-xl);
    padding: 20px;
    margin-bottom: 16px;
}

.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.calendar-title {
    font-size: 18px;
    font-weight: 600;
    text-transform: capitalize;
}

.nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-light);
    border: none;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.nav-btn:active {
    transform: scale(0.92);
    background: var(--accent);
    color: white;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
    background: var(--calendar-empty);
}

.calendar-day:active {
    transform: scale(0.92);
}

.calendar-day.empty {
    background: transparent;
    cursor: default;
}

.calendar-day.today {
    border: 2px solid var(--accent);
}

.calendar-day.selected {
    background: var(--accent) !important;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
}

.today-btn {
    display: block;
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.today-btn:active {
    transform: scale(0.98);
    background: var(--bg-glass-hover);
}

/* Tasks */
.tasks-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-item {
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
}

.task-item:active {
    transform: scale(0.99);
}

.task-item.priority-3 {
    background: var(--priority-high-bg);
    border-left-color: var(--priority-high);
}

.task-item.priority-2 {
    background: var(--priority-medium-bg);
    border-left-color: var(--priority-medium);
}

.task-item.priority-1 {
    background: var(--priority-low-bg);
    border: 1px solid var(--priority-low-border);
    border-left: 4px solid var(--text-tertiary);
}

.task-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.task-checkbox {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2.5px solid var(--text-tertiary);
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.task-checkbox:active {
    transform: scale(0.9);
}

.task-checkbox.checked {
    background: var(--success);
    border-color: var(--success);
    animation: checkPop 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes checkPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.task-checkbox svg {
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s ease;
}

.task-checkbox.checked svg {
    opacity: 1;
    transform: scale(1);
}

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

.task-title {
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
    word-wrap: break-word;
    transition: all 0.2s ease;
}

.task-item.completed .task-title {
    text-decoration: line-through;
    color: var(--text-tertiary);
}

.task-description {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.4;
}

.task-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.task-action-btn {
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.task-action-btn:active {
    background: var(--accent-light);
    color: var(--accent);
    transform: scale(0.9);
}

.task-action-btn.delete:active {
    background: rgba(255, 59, 48, 0.15);
    color: var(--danger);
}

/* Progress */
.task-progress {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #30d158);
    border-radius: 3px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 42px;
    text-align: right;
}

/* Subtasks */
.subtasks-container {
    margin-top: 12px;
    padding-left: 12px;
    border-left: 2px solid var(--border);
}

.subtasks-toggle {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.subtasks-toggle svg {
    transition: transform 0.25s ease;
}

.subtasks-toggle.expanded svg {
    transform: rotate(90deg);
}

.subtasks-list {
    display: none;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.subtasks-list.expanded {
    display: flex;
}

.subtask-item {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 12px;
    border: 1px solid var(--border);
}

.subtask-item .task-title {
    font-size: 15px;
}

.subtask-item .task-checkbox {
    width: 22px;
    height: 22px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 24px;
}

.empty-state.hidden {
    display: none !important;
}

.empty-icon {
    color: var(--text-tertiary);
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-hint {
    font-size: 15px;
    color: var(--text-tertiary);
}

/* FAB */
.fab {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 122, 255, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.fab:active {
    transform: scale(0.92);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.fab.hidden {
    transform: scale(0) rotate(45deg);
    opacity: 0;
}

/* Settings */
.settings-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-group {
    border-radius: var(--radius-xl);
    padding: 20px;
}

.settings-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

.theme-selector,
.language-selector {
    display: flex;
    gap: 10px;
}

.theme-btn,
.lang-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    border: 2px solid transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.theme-btn:active,
.lang-btn:active {
    transform: scale(0.96);
}

.theme-btn.selected,
.lang-btn.selected {
    border-color: var(--accent);
    background: var(--accent-light);
}

.theme-btn svg {
    color: var(--text-secondary);
}

.theme-btn.selected svg {
    color: var(--accent);
}

.flag {
    font-size: 28px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 12px 24px 32px;
    padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
    animation: slideUp 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-handle {
    width: 36px;
    height: 5px;
    background: var(--text-tertiary);
    border-radius: 3px;
    margin: 0 auto 20px;
    opacity: 0.4;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-family: inherit;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

textarea.form-input {
    resize: none;
    min-height: 80px;
}

/* Priority Selector */
.priority-selector {
    display: flex;
    gap: 10px;
}

.priority-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 2px solid transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.priority-btn:active {
    transform: scale(0.96);
}

.priority-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.priority-low .priority-dot { background: var(--text-tertiary); }
.priority-medium .priority-dot { background: var(--priority-medium); }
.priority-high .priority-dot { background: var(--priority-high); }

.priority-btn.selected {
    border-color: var(--accent);
}

.priority-low.selected { background: var(--priority-low-bg); }
.priority-medium.selected { background: var(--priority-medium-bg); }
.priority-high.selected { background: var(--priority-high-bg); }

/* Buttons */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 28px;
}

.btn {
    flex: 1;
    padding: 16px;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

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

/* Toast */
.toast {
    position: fixed;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 14px 24px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    font-weight: 500;
    z-index: 300;
    max-width: calc(100% - 48px);
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    animation: none !important;
}

.toast.with-action {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toast.with-action.hidden {
    display: none !important;
}

.toast-action {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.toast-action:active {
    transform: scale(0.95);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 0;
    height: 0;
}

/* Selection */
::selection {
    background: var(--accent-light);
    color: var(--accent);
}
