/* Dashboard home – mobile-first */
.dash-page {
    position: relative;
    min-height: calc(100dvh - var(--header-height) - 2rem);
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

.dash-page::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(900px 420px at 8% -10%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 60%),
        radial-gradient(700px 360px at 110% 8%, color-mix(in srgb, var(--primary) 14%, transparent), transparent 55%);
}

.dash-page > * {
    position: relative;
    z-index: 1;
}

.dash-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.dash-hello {
    min-width: 0;
}

.dash-hello h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.dash-hello p {
    margin: 0.15rem 0 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.dash-icon-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface-card) 82%, transparent);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, background 0.15s;
}

.dash-icon-btn:hover,
.dash-icon-btn.is-on {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.dash-icon-btn svg {
    width: 20px;
    height: 20px;
}

.dash-icon-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.dash-export-wrap {
    position: relative;
}

.dash-export-menu {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0;
    z-index: 30;
    min-width: 168px;
    display: flex;
    flex-direction: column;
    padding: 0.35rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-card);
    box-shadow: var(--shadow-lg);
}

.dash-export-menu button {
    border: none;
    background: transparent;
    text-align: left;
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
    cursor: pointer;
    min-height: 44px;
}

.dash-export-menu button:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.dash-search-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.85rem;
    padding: 0.15rem 0.75rem;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.dash-search-wrap svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.dash-search {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text);
    outline: none;
}

.dash-search::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.dash-search-clear {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.25rem;
    line-height: 1;
    width: 32px;
    height: 32px;
    cursor: pointer;
    border-radius: 8px;
}

.dash-catalog-empty {
    margin: 0.5rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    grid-column: 1 / -1;
}

.dash-page.is-exporting .dash-fab,
.dash-page.is-exporting .dash-toolbar-actions,
.dash-page.is-exporting .dash-export-menu,
.dash-page.is-exporting .dash-widget-handle,
.dash-page.is-exporting .dash-widget-tools {
    display: none !important;
}

.dash-empty {
    margin-top: 1.5rem;
    padding: 2.25rem 1.25rem 2rem;
    text-align: center;
    border-radius: 22px;
    background: color-mix(in srgb, var(--surface-card) 78%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--border));
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(16px);
}

.dash-empty-orb {
    width: 72px;
    height: 72px;
    margin: 0 auto 1rem;
    border-radius: 24px;
    display: grid;
    place-items: center;
    background: linear-gradient(160deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 12px 30px color-mix(in srgb, var(--primary) 35%, transparent);
}

.dash-empty h2 {
    margin: 0 0 0.4rem;
    font-size: 1.2rem;
}

.dash-empty p {
    margin: 0 auto 1.25rem;
    max-width: 28rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.dash-templates {
    display: flex;
    gap: 0.6rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.15rem 0.1rem 0.4rem;
    margin: 0 0 0.25rem;
}

.dash-template-card {
    flex: 0 0 auto;
    min-width: 148px;
    text-align: left;
    border: 1px solid var(--border);
    background: var(--surface-card);
    border-radius: 14px;
    padding: 0.85rem 0.95rem;
    cursor: pointer;
    color: inherit;
    font-family: inherit;
}

.dash-template-card strong {
    display: block;
    font-size: 0.9rem;
}

.dash-template-card span {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.dash-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 44px;
    padding: 0 1.1rem;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-weight: 650;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 28%, transparent);
}

.dash-btn-ghost {
    background: transparent;
    color: var(--primary);
    box-shadow: none;
    border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
}

.dash-fab {
    position: fixed;
    right: calc(1rem + env(safe-area-inset-right, 0px));
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 18px;
    background: linear-gradient(160deg, var(--primary-hover), var(--primary-dark));
    color: #fff;
    box-shadow: 0 14px 32px color-mix(in srgb, var(--primary) 40%, transparent);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.dash-fab svg {
    width: 26px;
    height: 26px;
}

.dash-stack {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.dash-widget {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 168px;
    border-radius: 18px;
    background: color-mix(in srgb, var(--surface-card) 86%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 14%, var(--border));
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    overflow: hidden;
}

.dash-widget::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary);
    opacity: 0.85;
}

.dash-widget.is-kpi {
    min-height: 132px;
}

.dash-widget-head {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    padding: 0.7rem 0.75rem 0.15rem 0.95rem;
}

.dash-widget-title {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 650;
    color: var(--text);
    letter-spacing: -0.01em;
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

.dash-widget-handle {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: none;
    place-items: center;
    cursor: grab;
    flex-shrink: 0;
}

.dash-page.is-editing .dash-widget-handle {
    display: grid;
}

.dash-widget-tools {
    display: flex;
    gap: 0.15rem;
}

.dash-mini {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 10px;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.dash-mini:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.dash-mini.danger:hover {
    background: #fee2e2;
    color: var(--danger);
}

.dash-widget-body {
    flex: 1;
    min-height: 0;
    padding: 0.15rem 0.7rem 0.7rem;
    overflow: hidden;
    position: relative;
}

.dash-chart {
    width: 100%;
    height: 210px;
}

.dash-widget.is-kpi .dash-chart {
    height: 42px;
}

.dash-kpi {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.15rem 0.2rem 0.35rem;
}

.dash-kpi-value {
    font-size: 1.7rem;
    font-weight: 750;
    letter-spacing: -0.04em;
    color: var(--text);
    line-height: 1.1;
}

.dash-kpi-delta {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
}

.dash-kpi-delta.up {
    background: #dcfce7;
    color: #166534;
}

.dash-kpi-delta.down {
    background: #fee2e2;
    color: #991b1b;
}

.dash-kpi-delta.flat {
    background: var(--surface);
    color: var(--text-muted);
}

.dash-empty-widget {
    height: 100%;
    min-height: 120px;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem;
}

.dash-skel {
    height: 100%;
    min-height: 110px;
    border-radius: 12px;
    background: linear-gradient(90deg, var(--surface) 0%, color-mix(in srgb, var(--primary) 8%, var(--surface)) 50%, var(--surface) 100%);
    background-size: 200% 100%;
    animation: dash-shimmer 1.2s ease infinite;
}

@keyframes dash-shimmer {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}

.dash-ranges {
    display: flex;
    gap: 0.25rem;
    padding: 0 0.75rem 0.65rem;
    overflow-x: auto;
}

.dash-range {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.28rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 650;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    min-height: 32px;
}

.dash-range.is-on {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.dash-widget-ghost {
    opacity: 0.45;
}

.grid-stack {
    min-height: 2rem;
}

.grid-stack-item-content {
    inset: 0 !important;
    overflow: hidden;
}

.grid-stack-item-content .dash-widget {
    height: 100%;
}

.dash-overlay {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(10, 20, 24, 0.42);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.dash-sheet {
    width: min(100%, 720px);
    max-height: min(88dvh, 820px);
    overflow: auto;
    background: var(--surface-card);
    border-radius: 22px 22px 0 0;
    padding: 0.85rem 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
    box-shadow: var(--shadow-lg);
}

.dash-sheet-grab {
    width: 42px;
    height: 4px;
    border-radius: 99px;
    background: var(--border);
    margin: 0.15rem auto 0.85rem;
}

.dash-sheet h2 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.dash-cats {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding-bottom: 0.75rem;
}

.dash-cat {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 650;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    min-height: 36px;
}

.dash-cat.is-on {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.dash-catalog-list {
    display: grid;
    gap: 0.55rem;
}

.dash-catalog-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.4rem 0.75rem;
    width: 100%;
    text-align: left;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 14px;
    padding: 0.8rem 0.9rem;
    cursor: pointer;
    font-family: inherit;
    color: inherit;
}

.dash-catalog-item strong {
    font-size: 0.92rem;
}

.dash-catalog-item span {
    grid-column: 1;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.dash-kind-pill {
    align-self: start;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--primary);
    background: var(--primary-light);
    border-radius: 999px;
    padding: 0.2rem 0.45rem;
}

.dash-expand {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 0.85rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
}

.dash-expand:focus {
    outline: none;
}

.dash-expand-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.dash-expand .dash-kpi {
    flex-shrink: 0;
}

.dash-expand .dash-chart {
    flex: 1;
    min-height: 0;
    height: 100%;
}

.dash-expand .dash-empty-widget {
    flex: 1;
}

.dash-tour {
    position: fixed;
    inset: 0;
    z-index: 200;
    pointer-events: auto;
}

.dash-tour-hole {
    display: none;
    position: fixed;
    box-sizing: border-box;
    pointer-events: none;
    box-shadow:
        0 0 0 4px color-mix(in srgb, var(--primary) 88%, #fff),
        0 0 0 9999px rgba(8, 16, 20, 0.62);
    transition: top 0.32s ease, left 0.32s ease, width 0.32s ease, height 0.32s ease, border-radius 0.32s ease;
}

.dash-tour-card {
    position: fixed;
    z-index: 201;
    top: 28%;
    left: 12px;
    padding: 0.85rem 0.95rem 0.95rem;
    border-radius: 16px;
    background: var(--surface-card);
    border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
    box-shadow: var(--shadow-lg);
    color: var(--text);
}

.dash-tour-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.45rem;
}

.dash-tour-dots {
    display: flex;
    gap: 0.3rem;
}

.dash-tour-dots span {
    width: 7px;
    height: 7px;
    border-radius: 99px;
    background: var(--border);
}

.dash-tour-dots span.is-on {
    width: 18px;
    background: var(--primary);
}

.dash-tour-skip {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-weight: 650;
    font-size: 0.8rem;
    min-height: 36px;
    cursor: pointer;
    padding: 0 0.2rem;
}

.dash-tour-timer {
    height: 3px;
    width: 100%;
    margin: 0 0 0.7rem;
    border-radius: 99px;
    background: color-mix(in srgb, var(--primary) 18%, var(--border));
    overflow: hidden;
}

.dash-tour-timer::after {
    content: "";
    display: block;
    height: 100%;
    width: 0;
    background: var(--primary);
    animation: dash-tour-timer 5s linear forwards;
}

.dash-tour-card strong {
    display: block;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
}

.dash-tour-card p {
    margin: 0.3rem 0 0.85rem;
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.4;
}

.dash-tour-next {
    width: 100%;
    min-height: 44px;
}

.dash-tour-ghost {
    text-align: left;
    border-radius: 18px;
    background: color-mix(in srgb, var(--surface-card) 92%, transparent);
    border: 1.5px dashed color-mix(in srgb, var(--primary) 50%, var(--border));
    box-shadow: var(--shadow);
    overflow: hidden;
}

.dash-tour-ghost .dash-widget-handle {
    display: grid;
    color: var(--primary);
    cursor: grab;
    animation: dash-tour-wiggle 1.1s ease-in-out infinite;
}

.dash-tour-ghost-body {
    padding: 0.35rem 0.9rem 1rem;
}

.dash-tour-ghost-body p {
    margin: 0.65rem 0 0;
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.dash-tour-ghost-bars {
    display: block;
    height: 72px;
    border-radius: 12px;
    background:
        linear-gradient(90deg,
            color-mix(in srgb, var(--primary) 55%, transparent) 18%,
            transparent 18% 22%,
            color-mix(in srgb, var(--primary) 35%, transparent) 22% 40%,
            transparent 40% 44%,
            color-mix(in srgb, var(--primary) 70%, transparent) 44% 58%,
            transparent 58% 62%,
            color-mix(in srgb, var(--primary) 28%, transparent) 62% 78%,
            transparent 78% 82%,
            color-mix(in srgb, var(--primary) 48%, transparent) 82% 94%,
            transparent 94%);
}

@keyframes dash-tour-timer {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes dash-tour-wiggle {
    0%, 100% { transform: translateX(0); }
    35% { transform: translateX(3px); }
    70% { transform: translateX(-2px); }
}

@media (min-width: 900px) {
    .dash-page {
        padding-bottom: 1.5rem;
    }

    .dash-hello h1 {
        font-size: 1.7rem;
    }

    .dash-fab {
        display: none !important;
    }

    .dash-widget {
        min-height: 0;
    }

    .grid-stack .dash-widget-body > .dash-chart {
        position: absolute;
        left: 0.7rem;
        right: 0.7rem;
        top: 0.15rem;
        bottom: 0.7rem;
        width: auto;
        height: auto;
        min-height: 0;
    }

    .dash-widget.is-kpi .dash-chart {
        position: relative;
        left: auto;
        right: auto;
        top: auto;
        bottom: auto;
        width: 100%;
        height: 42px;
    }

    .dash-overlay {
        align-items: center;
        padding: 2rem;
    }

    .dash-sheet {
        border-radius: 20px;
        max-height: 80vh;
    }

    .dash-catalog-list {
        grid-template-columns: 1fr 1fr;
    }

    .dash-widget:hover {
        border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
        box-shadow: var(--shadow-lg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .dash-skel { animation: none; }
    .dash-tour-hole { transition: none; }
    .dash-tour-timer::after { animation: none; width: 100%; }
    .dash-tour-ghost .dash-widget-handle { animation: none; }
}
