:root {
    color-scheme: dark;

    /* TaskMap palette — geo + tasks + money */
    --bg-deep: #070b14;
    --bg-mid: #0d1526;
    --accent-teal: #2dd4bf;
    --accent-cyan: #22d3ee;
    --accent-blue: #3b82f6;
    --accent-violet: #8b5cf6;
    --accent-gold: #fbbf24;
    --accent-rose: #fb7185;
    --text-primary: #f1f5f9;
    --text-muted: rgba(241, 245, 249, 0.62);
    --glass-fill: rgba(255, 255, 255, 0.06);
    --glass-fill-strong: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.14);
    --glass-highlight: rgba(255, 255, 255, 0.22);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --glass-blur: 20px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --nav-h: 72px;
}

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

html, body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--tg-theme-bg-color, var(--bg-deep));
    color: var(--tg-theme-text-color, var(--text-primary));
    overflow-x: hidden;
}

/* Ambient liquid background */
.ambient {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(45, 212, 191, 0.12), transparent 55%),
        radial-gradient(ellipse 60% 40% at 100% 50%, rgba(59, 130, 246, 0.1), transparent 50%),
        linear-gradient(165deg, var(--bg-deep) 0%, var(--bg-mid) 45%, #0a1220 100%);
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.55;
    animation: float 18s ease-in-out infinite;
}

.blob-a {
    width: 280px;
    height: 280px;
    top: -60px;
    left: -40px;
    background: radial-gradient(circle, rgba(45, 212, 191, 0.45), rgba(45, 212, 191, 0));
    animation-delay: 0s;
}

.blob-b {
    width: 320px;
    height: 320px;
    top: 35%;
    right: -100px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.4), rgba(59, 130, 246, 0));
    animation-delay: -6s;
}

.blob-c {
    width: 240px;
    height: 240px;
    bottom: 10%;
    left: 20%;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.35), rgba(139, 92, 246, 0));
    animation-delay: -12s;
}

.noise {
    position: absolute;
    inset: 0;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(24px, -16px) scale(1.05); }
    66% { transform: translate(-16px, 12px) scale(0.96); }
}

.app-shell {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    max-width: 520px;
    margin: 0 auto;
}

.hidden {
    display: none !important;
}

/* Glass panels */
.glass-panel {
    background: var(--glass-fill);
    backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-highlight);
}

.glass-chip {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    margin: 12px 12px 0;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    font-size: 20px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(45, 212, 191, 0.25), rgba(59, 130, 246, 0.2));
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.app-header h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 30%, var(--accent-teal) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-header p {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.app-main {
    padding: 12px 12px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

.view {
    display: none;
    animation: fadeIn 0.35s ease;
}

.view.active {
    display: block;
}

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

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 0 4px;
}

.section-head h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.section-tag {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-teal);
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(45, 212, 191, 0.12);
    border: 1px solid rgba(45, 212, 191, 0.25);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

/* Filters & forms */
.filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
    border-radius: var(--radius-lg);
    margin-bottom: 10px;
}

.filters select,
.filters input,
.field input,
.field textarea,
.field select {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    padding: 11px 12px;
    background: rgba(0, 0, 0, 0.22);
    color: inherit;
    font: inherit;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filters select:focus,
.filters input:focus,
.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: rgba(45, 212, 191, 0.5);
    box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.12);
}

.form-grid {
    display: grid;
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius-lg);
}

.field {
    display: grid;
    gap: 6px;
}

.field > span {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.coords-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Cards */
.card {
    border-radius: var(--radius-lg);
    padding: 16px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-interactive {
    cursor: pointer;
}

.card-interactive:active {
    transform: scale(0.985);
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}

.card h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.02em;
    flex: 1;
}

.price-pill {
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 700;
    padding: 6px 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.22), rgba(251, 191, 36, 0.08));
    border: 1px solid rgba(251, 191, 36, 0.35);
    color: #fde68a;
    white-space: nowrap;
}

.card-desc {
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-muted);
}

.meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 11px;
    margin-bottom: 8px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
}

.badge-cat {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: #93c5fd;
}

.badge-dist {
    background: rgba(45, 212, 191, 0.12);
    border-color: rgba(45, 212, 191, 0.28);
    color: #5eead4;
}

.badge-open { background: rgba(34, 211, 238, 0.14); border-color: rgba(34, 211, 238, 0.3); color: #67e8f9; }
.badge-in_progress { background: rgba(59, 130, 246, 0.16); border-color: rgba(59, 130, 246, 0.32); color: #93c5fd; }
.badge-done_by_executor { background: rgba(139, 92, 246, 0.16); border-color: rgba(139, 92, 246, 0.32); color: #c4b5fd; }
.badge-approved { background: rgba(52, 211, 153, 0.14); border-color: rgba(52, 211, 153, 0.3); color: #6ee7b7; }
.badge-canceled { background: rgba(148, 163, 184, 0.12); border-color: rgba(148, 163, 184, 0.25); color: #cbd5e1; }
.badge-dispute { background: rgba(251, 113, 133, 0.14); border-color: rgba(251, 113, 133, 0.3); color: #fda4af; }

.location-line {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.location-line::before {
    content: "◎";
    color: var(--accent-teal);
    font-size: 10px;
}

.muted {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.45;
}

/* Buttons */
.btn {
    border: 0;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}

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

.btn-primary {
    width: 100%;
    color: #042f2e;
    background: linear-gradient(135deg, var(--accent-teal) 0%, var(--accent-cyan) 100%);
    box-shadow: 0 4px 20px rgba(45, 212, 191, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn-glass {
    width: 100%;
    color: var(--text-primary);
    background: var(--glass-fill-strong);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    margin-bottom: 10px;
}

.btn-glass.active,
.segment.active {
    background: rgba(45, 212, 191, 0.18);
    border-color: rgba(45, 212, 191, 0.4);
    color: #99f6e4;
}

.btn-danger {
    color: #fff;
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.btn-row .btn {
    flex: 1;
    min-width: 120px;
}

/* Segmented control */
.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    border-radius: var(--radius-md);
    margin-bottom: 4px;
}

.segment {
    border: 0;
    border-radius: var(--radius-sm);
    padding: 10px 6px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    color: var(--text-muted);
    background: transparent;
    transition: all 0.2s;
}

.segment.active {
    background: rgba(45, 212, 191, 0.18);
    color: #99f6e4;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Map */
.map-glass {
    height: 400px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 12px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

#map.leaflet-container {
    background: #0d1526;
    font-family: inherit;
}

/* Bottom nav — liquid glass dock */
.bottom-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 40;
    max-width: 496px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    padding: 8px 6px;
    border-radius: 22px;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    font-family: inherit;
    padding: 8px 4px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.nav-icon {
    font-size: 18px;
    line-height: 1;
    opacity: 0.75;
    transition: transform 0.25s;
}

.nav-item.active {
    color: var(--accent-teal);
    background: rgba(45, 212, 191, 0.1);
}

.nav-item.active .nav-icon {
    opacity: 1;
    transform: scale(1.1);
}

.nav-create .nav-icon {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    font-size: 20px;
    background: linear-gradient(135deg, rgba(45, 212, 191, 0.35), rgba(59, 130, 246, 0.3));
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 16px rgba(45, 212, 191, 0.25);
}

.nav-create.active .nav-icon {
    box-shadow: 0 4px 20px rgba(45, 212, 191, 0.45);
}

/* Profile */
.profile-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 14px;
}

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

.profile-row span:last-child {
    font-weight: 600;
    color: var(--accent-cyan);
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 24px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(139, 92, 246, 0.25));
    border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Timeline */
.timeline-item {
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 13px;
    color: var(--text-muted);
}

.timeline-item b {
    color: var(--accent-cyan);
    font-weight: 600;
}

/* Empty state */
.empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 14px;
    border-radius: var(--radius-lg);
    background: var(--glass-fill);
    border: 1px dashed rgba(255, 255, 255, 0.12);
}

/* Toast */
.toast {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
    max-width: 488px;
    margin: 0 auto;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    display: none;
    z-index: 50;
    animation: toastIn 0.3s ease;
}

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

.location-hint {
    width: 100%;
}

/* Task detail hero */
.task-hero {
    margin-bottom: 12px;
}

.task-hero .price-pill {
    font-size: 18px;
    padding: 8px 14px;
}

/* Light Telegram theme fallback */
@media (prefers-color-scheme: light) {
    body.tg-light-fallback {
        --text-primary: #0f172a;
        --text-muted: rgba(15, 23, 42, 0.65);
        --glass-fill: rgba(255, 255, 255, 0.65);
        --glass-border: rgba(255, 255, 255, 0.8);
    }
}
