:root {
  --bg: var(--tg-theme-bg-color, #f4f6f5);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #17201c);
  --muted: var(--tg-theme-hint-color, #748079);
  --accent: var(--tg-theme-button-color, #23845b);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--muted) 20%, transparent);
  --green: #168b59;
  --red: #c94f4f;
  --amber: #b77a16;
  --radius: 16px;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4; }
button, input, select { min-width: 0; font: inherit; }
button { color: inherit; }
.shell { width: min(760px, 100%); max-width: 100%; margin: 0 auto; padding: max(10px, env(safe-area-inset-top)) 10px max(24px, env(safe-area-inset-bottom)); }
.shell > *, .tab-page, .card, .ranking-content, .data-row > *, .section-title > * { min-width: 0; }

.hero { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 2px 12px; }
.hero h1 { margin: 0 0 2px; font-size: 24px; line-height: 1.08; letter-spacing: -.7px; }
.muted, .footnote { color: var(--muted); }
.muted { margin: 0; font-size: 12px; overflow-wrap: anywhere; }
.eyebrow { margin: 0 0 2px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 1.1px; }
.icon-button { width: 38px; height: 38px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 22px; cursor: pointer; }

.card { width: 100%; margin-bottom: 10px; padding: 14px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 3px 14px rgba(12, 28, 20, .035); }
.filter-heading, .section-title, .ranking-head, .prime-hour-head, .detail-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-title { margin-bottom: 11px; }
.section-title h2 { margin: 0; font-size: 18px; line-height: 1.2; letter-spacing: -.25px; }
.section-title > small, .filter-status { color: var(--muted); font-size: 10px; text-align: right; }
.select-grid, .date-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.select-grid { margin-top: 10px; }
.date-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0 8px; }
label { min-width: 0; color: var(--muted); font-size: 11px; }
input[type="date"], input[type="search"], select { width: 100%; max-width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; outline: none; background: var(--bg); color: var(--text); }
input:focus, select:focus { border-color: var(--accent); }
.primary { padding: 9px 12px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 750; cursor: pointer; }
.primary.small { padding: 7px 10px; font-size: 12px; }
.primary.wide { width: 100%; margin-top: 12px; }
.quick-periods, .chips { display: flex; max-width: 100%; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.quick-periods { margin-bottom: 8px; }
.quick-periods button { flex: 0 0 auto; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: transparent; font-size: 11px; white-space: nowrap; }
.quick-periods button.active { border-color: var(--text); background: var(--text); color: var(--bg); }
.chip { position: relative; flex: 0 0 auto; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: block; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; font-weight: 650; white-space: nowrap; }
.chip input:checked + span { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }

.tabs { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; width: 100%; margin-bottom: 10px; padding: 4px; border: 1px solid var(--line); border-radius: 13px; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); }
.tabs button { min-width: 0; padding: 8px 2px; overflow: hidden; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.tabs button.active { background: var(--bg); color: var(--text); }

.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.summary-card { min-width: 0; min-height: 84px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.summary-card strong { display: block; margin-top: 11px; overflow-wrap: anywhere; font-size: clamp(17px, 5vw, 21px); line-height: 1.1; letter-spacing: -.35px; }
.summary-card span { color: var(--muted); font-size: 11px; }

.chart { width: 100%; max-width: 100%; min-height: 230px; overflow: hidden; }
.chart-frame { display: grid; grid-template-columns: 44px minmax(0, 1fr); width: 100%; height: 230px; }
.chart-axis { position: relative; z-index: 2; display: block; width: 44px; height: 230px; background: var(--surface); }
.chart-viewport { min-width: 0; height: 230px; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: thin; }
.chart-plot { display: block; width: auto; min-width: 500px; height: 230px; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 9px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 11px; margin-top: 6px; color: var(--muted); font-size: 10px; }
.legend i { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 50%; }

.ranking-row { display: grid; grid-template-columns: 27px minmax(0, 1fr); gap: 8px; align-items: start; width: 100%; padding: 12px 0; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.ranking-row:first-child, .data-row:first-child { border-top: 0; }
.rank { padding-top: 1px; font-size: 16px; font-weight: 800; }
.ranking-head strong:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-head .score { flex: 0 0 auto; font-size: 15px; text-align: right; white-space: nowrap; }
.ranking-head .score small { display: block; color: var(--muted); font-size: 8px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; }
.ranking-meta { display: flex; flex-wrap: wrap; gap: 3px 9px; margin-top: 5px; color: var(--muted); font-size: 10px; }
.ranking-meta span { min-width: 0; overflow-wrap: anywhere; }

.bar-chart { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 14px; }
.bar-row { display: block; width: 100%; padding: 0; border: 0; background: transparent; text-align: left; cursor: pointer; }
.bar-header { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: 12px; }
.bar-header span { flex: 0 0 auto; }
.bar-track, .prime-track { height: 7px; overflow: hidden; border-radius: 99px; background: color-mix(in srgb, var(--muted) 12%, transparent); }
.bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

.data-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; width: 100%; padding: 11px 0; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.data-row:active { opacity: .68; }
.data-row strong { display: block; overflow-wrap: anywhere; }
.data-row small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.data-meta { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 4px 0; }
.badge { display: inline-flex; padding: 3px 7px; border-radius: 99px; background: var(--bg); color: var(--muted); font-size: 10px; }
.money { min-width: 0; text-align: left; font-weight: 800; overflow-wrap: anywhere; }
.money small { margin-top: 2px; font-weight: 400; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral { color: var(--muted); }

.search { display: block; margin-bottom: 10px; }
.employee-note, .coverage-note { padding: 9px 10px; border-radius: 10px; background: var(--bg); color: var(--muted); font-size: 11px; line-height: 1.4; }
.employee-note { margin-bottom: 3px; }
.coverage-note { margin: 0 0 12px; }
.coverage-note.warning { color: var(--amber); }
.employee-card h2, .detail-card h2 { margin: 0 0 2px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 12px 0; }
.metric { min-width: 0; padding: 10px; border-radius: 11px; background: var(--bg); }
.metric small { display: block; margin-bottom: 5px; color: var(--muted); }
.metric strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.detail-heading { align-items: flex-start; margin-bottom: 10px; }
.back-button, .secondary { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--text); font-size: 11px; font-weight: 700; cursor: pointer; }
.explain-card { margin: 12px 0 16px; padding: 10px 11px; border-radius: 11px; background: color-mix(in srgb, var(--accent) 7%, var(--bg)); color: var(--muted); font-size: 10px; line-height: 1.45; }
.explain-card p { margin: 0 0 7px; }
.explain-card p:last-child { margin-bottom: 0; }
.shift-list { display: grid; }
.shift-row, .employee-shift-row { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 5px 8px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 11px; }
.shift-row small, .employee-shift-row small { display: block; color: var(--muted); font-weight: 400; }
.shift-money { grid-column: 2; text-align: left; }
.shift-money b { display: block; }

.hour-chart { display: grid; gap: 9px; min-height: 0; }
.prime-hour-row { min-width: 0; }
.prime-hour-head { margin-bottom: 4px; font-size: 11px; }
.prime-hour-head strong { flex: 0 0 auto; }
.prime-track i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.prime-track i.negative-bar { background: var(--red); }
.subsection-title { display: flex; align-items: end; justify-content: space-between; gap: 8px; margin: 17px 0 6px; font-size: 13px; }
.subsection-title small { color: var(--muted); font-size: 9px; font-weight: 400; text-align: right; }
.prime-locations { display: grid; gap: 0; }
.prime-location-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: center; width: 100%; padding: 9px 0; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left; font-size: 12px; cursor: pointer; }
.prime-location-row:first-child { border-top: 0; }
.prime-location-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prime-location-row span { grid-column: 1; color: var(--muted); font-size: 10px; }
.prime-location-row b { grid-column: 2; grid-row: 1 / span 2; color: var(--green); white-space: nowrap; }
.footnote { margin: 11px 0 0; font-size: 10px; line-height: 1.45; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); color: var(--text); font-size: 12px; }
.switch-row:first-child { border-top: 0; }
.switch-row span { min-width: 0; flex: 1; }
.switch-row small { display: block; margin-top: 3px; color: var(--muted); line-height: 1.35; }
.switch-row input { position: absolute; opacity: 0; }
.switch-row i { position: relative; width: 42px; height: 25px; flex: 0 0 auto; border-radius: 99px; background: color-mix(in srgb, var(--muted) 30%, transparent); transition: .2s; }
.switch-row i::after { position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .18); content: ""; transition: .2s; }
.switch-row input:checked + i { background: var(--accent); }
.switch-row input:checked + i::after { transform: translateX(17px); }
.status-text { min-height: 14px; color: var(--muted); font-size: 11px; text-align: center; }
.export-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.export-grid .secondary { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.state-card { padding: 38px 10px; color: var(--muted); text-align: center; }
.state-card.compact { padding: 18px 8px; }
.state-card.error { color: var(--red); white-space: pre-line; }
.toast { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%; z-index: 20; max-width: calc(100% - 28px); padding: 9px 13px; transform: translateX(-50%); border-radius: 11px; background: #17231d; color: #fff; box-shadow: 0 10px 26px rgba(0, 0, 0, .22); font-size: 12px; }
.hidden { display: none !important; }

@media (min-width: 560px) {
  .shell { padding-inline: 14px; }
  .data-row { grid-template-columns: minmax(0, 1fr) minmax(150px, auto); align-items: center; gap: 10px; }
  .money { text-align: right; }
  .shift-row, .employee-shift-row { grid-template-columns: 58px minmax(0, 1fr) auto; align-items: center; }
  .shift-money { grid-column: auto; text-align: right; }
}

@media (min-width: 700px) {
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filter-panel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 16px; }
  .filter-heading, .chips { grid-column: 1 / -1; }
  .tabs button { font-size: 11px; }
}
