:root {
    color-scheme: dark;
    --bg: #08110f;
    --panel: #101b18;
    --panel-soft: #14231f;
    --panel-raised: #182b26;
    --text: #eef7f4;
    --muted: #8ea09a;
    --line: #263a34;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: #123c37;
    --bad: #f87171;
    --bad-soft: #3f171b;
    --ok-soft: #12351f;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.48);
    --app-width: 430px;
}

* {
    box-sizing: border-box;
}

* {
    scrollbar-width: none;
}

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

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

@media (min-width: 520px) {
    body {
        background: #030806;
    }

    .app {
        background: var(--bg);
        box-shadow: 0 0 0 1px rgba(94, 234, 212, 0.08);
    }
}

body.drawer-open {
    overflow: hidden;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app {
    width: min(var(--app-width), 100%);
    max-width: 100%;
    min-height: 100vh;
    margin: 0 auto;
    padding: 14px 12px 96px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -14px -12px 0;
    padding: 18px 12px 12px;
    border-bottom: 1px solid rgba(38, 58, 52, 0.72);
    background: rgba(8, 17, 15, 0.92);
    backdrop-filter: blur(14px);
}

.app-header > div:first-child {
    min-width: 0;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: 23px;
    line-height: 1.1;
}

h2 {
    font-size: 17px;
}

h3 {
    font-size: 15px;
}

.eyebrow,
.muted,
.panel-head p,
.card-top p,
.mini-row span,
label span,
.section-label {
    color: var(--muted);
    font-size: 12px;
}

.eyebrow,
.muted {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    font-size: 20px;
}

.icon-btn.primary,
.primary-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: #04110f;
}

.icon-btn.is-loading {
    pointer-events: none;
}

.icon-btn.is-loading .icon-spin {
    display: inline-block;
    animation: spin 800ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: grid;
    gap: 14px;
    min-width: 0;
    max-width: 100%;
    padding-top: 10px;
}

.tab-panel > * {
    min-width: 0;
    max-width: 100%;
}

.kpi-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.metric,
.panel,
.service-card,
.session-card {
    min-width: 0;
    max-width: 100%;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
}

.metric {
    display: grid;
    gap: 8px;
    min-height: 82px;
    padding: 12px;
}

.metric.wide {
    grid-column: span 2;
}

.metric span {
    color: var(--muted);
    font-size: 12px;
}

.metric strong {
    font-size: 21px;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.metric.wide strong {
    font-size: 26px;
}

.panel {
    padding: 12px;
}

.panel-head,
.tab-toolbar,
.mini-row,
.timeline article {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.card-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 10px;
}

.card-top > div {
    min-width: 0;
}

.card-top h3,
.card-top p {
    overflow-wrap: anywhere;
}

.panel-head {
    margin-bottom: 12px;
}

.panel-head > span {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.scroll-chart {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 54px;
    align-items: end;
    gap: 8px;
    min-height: 178px;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 2px 4px;
    overscroll-behavior-x: contain;
}

.chart-item {
    display: grid;
    grid-template-rows: 28px 116px 20px;
    justify-items: center;
    align-items: end;
    gap: 6px;
}

.chart-value {
    max-width: 56px;
    color: var(--muted);
    font-size: 10px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-bar {
    width: 28px;
    min-height: 8px;
    border-radius: 8px 8px 3px 3px;
    background: var(--accent);
}

.chart-label {
    color: var(--muted);
    font-size: 11px;
}

.stack-list,
.card-list,
.detail-body {
    display: grid;
    gap: 10px;
}

.mini-row {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    background: var(--panel-soft);
}

.mini-row div {
    display: grid;
    gap: 3px;
}

.mini-row b {
    white-space: nowrap;
}

.audit-pills {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.audit-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 50px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-soft);
    color: var(--text);
    padding: 10px;
    text-align: left;
}

.audit-pill span {
    color: var(--muted);
    font-size: 12px;
}

.tab-toolbar {
    position: sticky;
    top: 72px;
    z-index: 7;
    align-items: center;
    padding: 8px 0;
    background: var(--bg);
}

.tab-toolbar > span {
    font-size: 17px;
    font-weight: 750;
}

.sort-chips {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    gap: 8px;
    max-width: 100%;
    overflow-x: auto;
    padding: 0 0 2px;
    overscroll-behavior-x: contain;
}

.sort-chips button {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    color: var(--muted);
    padding: 0 12px;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 700;
}

.sort-chips button.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-strong);
}

select,
input {
    width: 100%;
    max-width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    padding: 0 12px;
}

select:focus,
input:focus,
button:focus-visible {
    outline: 2px solid rgba(45, 212, 191, 0.55);
    outline-offset: 2px;
}

.session-card,
.service-card {
    display: grid;
    gap: 10px;
    width: 100%;
    padding: 14px;
    text-align: left;
}

.session-card {
    color: var(--text);
}

.session-card strong,
.service-card strong {
    white-space: nowrap;
    font-size: 14px;
}

.session-money,
.card-stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.card-stats span {
    display: inline-flex;
    gap: 4px;
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    background: #1e2d29;
    color: #c6d8d2;
    padding: 3px 8px;
    font-size: 12px;
}

.badge.bad {
    background: var(--bad-soft);
    color: var(--bad);
}

.badge.ok {
    background: var(--ok-soft);
    color: #86efac;
}

.negative {
    color: var(--bad);
}

.positive {
    color: var(--accent-strong);
}

.bottom-tabs {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    width: min(var(--app-width), 100%);
    max-width: 100%;
    margin: 0 auto;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(16, 27, 24, 0.94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.bottom-tabs button {
    display: grid;
    place-items: center;
    min-height: 42px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
}

.bottom-tabs button.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.bottom-tabs svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.58);
}

.drawer {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 12px;
    width: min(var(--app-width), 100%);
    max-width: 100%;
    height: min(560px, 64vh);
    max-height: 64vh;
    margin: 0 auto;
    padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
    overflow: hidden;
    background: var(--panel);
    border-radius: 22px 22px 0 0;
    box-shadow: var(--shadow);
    transform: translateY(110%);
    transition: transform 180ms ease;
}

.drawer[aria-hidden="false"] {
    transform: translateY(0);
}

.drawer-grip {
    width: 46px;
    height: 5px;
    margin: 0 auto;
    border-radius: 999px;
    background: #3b514a;
    touch-action: none;
}

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    touch-action: none;
}

.drawer-head button {
    touch-action: manipulation;
}

.drawer-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-section {
    display: grid;
    gap: 10px;
}

.drawer-body {
    display: grid;
    gap: 14px;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 1px;
}

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

.chip-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.status-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.chip,
.ghost-btn {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel-soft);
    color: var(--text);
    padding: 0 14px;
}

.ghost-btn {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.chip.active,
.status-chips button.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-strong);
}

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

label {
    display: grid;
    gap: 6px;
}

.drawer-actions {
    position: sticky;
    bottom: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    border-top: 1px solid var(--line);
    background: var(--panel);
    padding-top: 10px;
}

.primary-btn {
    border-radius: 14px;
    min-height: 46px;
    font-weight: 800;
}

.detail-drawer {
    height: min(620px, 72vh);
    max-height: 72vh;
    grid-template-rows: auto auto minmax(0, 1fr);
}

.detail-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel-soft);
    overflow: hidden;
    padding: 0;
}

.detail-line {
    display: grid;
    gap: 4px;
    min-height: 54px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: transparent;
    padding: 10px;
}

.detail-line:nth-child(2n) {
    border-right: 0;
}

.detail-line:nth-last-child(-n + 2) {
    border-bottom: 0;
}

.detail-summary span,
.timeline span,
.muted-id,
.service-meta,
.empty-subline,
.pause-head span,
.part-row span {
    color: var(--muted);
    font-size: 12px;
}

.detail-summary strong {
    font-size: 15px;
    line-height: 1.15;
    text-align: left;
    overflow-wrap: anywhere;
}

.detail-section {
    display: grid;
    gap: 8px;
}

.timeline {
    display: grid;
    gap: 8px;
}

.timeline article {
    align-items: stretch;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
}

.timeline article div {
    display: grid;
    gap: 3px;
}

.timeline b {
    color: var(--accent-strong);
    font-size: 12px;
    text-align: left;
}

.timeline article > div {
    display: grid;
    gap: 4px;
}

.timeline article > div strong {
    font-size: 18px;
}

.service-detail-list,
.pause-list,
.part-list {
    display: grid;
    gap: 8px;
}

.service-detail {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel-soft);
    padding: 10px;
}

.service-detail-head,
.pause-head,
.part-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.service-detail-head > div {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.service-detail-head span {
    color: var(--muted);
    font-size: 12px;
}

.service-detail-head b,
.pause-head b,
.part-row b {
    color: var(--accent-strong);
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
}

.service-meta {
    display: grid;
    gap: 3px;
    overflow-wrap: anywhere;
}

.pause-list {
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

.pause-list > strong {
    font-size: 13px;
}

.pause-card {
    display: grid;
    gap: 7px;
    border-radius: 12px;
    background: var(--panel-raised);
    padding: 8px;
}

.pause-card p {
    color: var(--muted);
    font-size: 12px;
}

.part-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid rgba(142, 160, 154, 0.2);
    padding-top: 6px;
}

.part-row:first-child {
    border-top: 0;
    padding-top: 0;
}

.part-row b {
    text-align: right;
}

.empty-subline {
    border-radius: 10px;
    background: var(--panel-raised);
    padding: 8px;
}

.empty-line {
    border: 1px dashed var(--line);
    border-radius: 12px;
    color: var(--muted);
    padding: 16px;
    text-align: center;
}

@media (min-width: 680px) {
    .app {
        padding-top: 24px;
    }

    .audit-pills {
        grid-template-columns: 1fr;
    }

    .date-grid {
        grid-template-columns: 1fr 1fr;
    }

    .card-stats {
        grid-template-columns: 1fr;
    }

    .timeline article {
        flex-direction: column;
        align-items: stretch;
    }

    .timeline b {
        text-align: left;
    }
}

@media (max-width: 380px) {
    .app {
        padding-right: 10px;
        padding-left: 10px;
    }

    h1 {
        font-size: 20px;
    }

    .icon-btn {
        width: 38px;
        height: 38px;
    }

    .metric strong {
        font-size: 19px;
    }

    .metric.wide strong {
        font-size: 23px;
    }

    .panel-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .card-top {
        grid-template-columns: 1fr;
    }

    .session-card strong,
    .service-card strong {
        white-space: normal;
    }

    .chip,
    .ghost-btn {
        padding-right: 10px;
        padding-left: 10px;
        font-size: 12px;
    }
}
