* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 32px;
    height: 56px;
    padding: 0 24px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.brand {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.main-nav {
    display: flex;
    gap: 4px;
    height: 100%;
}

.nav-tab {
    position: relative;
    height: 100%;
    padding: 0 14px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: color var(--speed) var(--ease);
}

.nav-tab:hover,
.nav-tab.active {
    color: var(--text);
}

.nav-tab.active::after {
    content: "";
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: -1px;
    height: 2px;
    background: var(--accent);
}

.page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 28px 24px 60px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.page-title {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
}

.page-note {
    margin: 0;
    color: var(--muted);
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.toast {
    display: none;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.panel-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.panel-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}

.panel-note {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.panel-body {
    padding: 18px;
}

.dropzone {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 22px;
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color var(--speed) var(--ease);
}

.dropzone:hover,
.dropzone.dragging {
    border-color: var(--accent);
}

.dropzone input {
    display: none;
}

.dropzone-title {
    font-weight: 600;
}

.dropzone-note {
    font-size: 13px;
    color: var(--muted);
}

.status {
    margin: 14px 0 0;
    font-weight: 600;
}

.status.good {
    color: var(--good);
}

.error-list {
    margin: 14px 0 0;
    padding-left: 18px;
    color: var(--bad);
}

.preview {
    margin-top: 18px;
}

.preview-file {
    margin: 0 0 12px;
    font-size: 13px;
    color: var(--muted);
}

.stat-list {
    display: flex;
    flex-wrap: wrap;
    gap: 28px;
    margin: 0 0 16px;
}

.stat dt {
    font-size: 12px;
    color: var(--muted);
}

.stat dd {
    margin: 2px 0 0;
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.simple-table {
    width: 100%;
    border-collapse: collapse;
}

.simple-table th,
.simple-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.simple-table th {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.simple-table tbody tr:hover {
    background: var(--surface-2);
}

.simple-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.btn,
.btn-quiet {
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--speed) var(--ease),
        border-color var(--speed) var(--ease),
        opacity var(--speed) var(--ease);
}

.btn {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

.btn:hover {
    opacity: 0.88;
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn-quiet {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
}

.btn-quiet:hover {
    border-color: var(--muted);
}

.month-select {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.month-select select {
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: border-color var(--speed) var(--ease);
}

.month-select select:hover,
.month-select select:focus {
    border-color: var(--accent);
    outline: none;
}

.month-select select:disabled {
    color: var(--muted);
    cursor: default;
}

.month-range {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.muted {
    color: var(--muted);
}

.overview-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    align-items: start;
    gap: 16px;
    margin-top: 20px;
}

.overview-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ranking-table .rank {
    width: 32px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.ranking-table .bar-cell {
    width: 28%;
}

.bar {
    display: block;
    height: 6px;
    border-radius: 3px;
    background: var(--accent);
}

.ranking-table tfoot td {
    border-bottom: 0;
    font-weight: 700;
}

.tag {
    margin-left: 6px;
    padding: 1px 6px;
    border: 1px solid var(--line);
    border-radius: var(--pill);
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
}

.rank-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.rank-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    border-left: 2px solid transparent;
}

.rank-row .rank {
    width: 24px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.rank-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-row .num {
    font-variant-numeric: tabular-nums;
}

.rank-row.you {
    border-left-color: var(--accent);
    background: var(--surface-2);
    font-weight: 700;
}

.rank-row.you .rank {
    color: var(--accent);
}

.rank-gap {
    padding: 4px 10px;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
}

.rank-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    font-size: 13px;
    color: var(--muted);
}

.rank-footer .num {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.big-number {
    margin: 0 0 8px;
    font-size: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.line-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.line-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

@media (max-width: 900px) {
    .overview-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.store-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
}

.store-select {
    position: relative;
}

.store-select-button {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 170px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: border-color var(--speed) var(--ease);
}

.store-select-button:hover,
.store-select.open .store-select-button {
    border-color: var(--accent);
}

.caret {
    margin-left: auto;
    color: var(--muted);
}

.store-select-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 20;
    display: none;
    min-width: 220px;
    max-height: 360px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.store-select.open .store-select-menu {
    display: block;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.check:hover {
    background: var(--surface-2);
}

.check input {
    accent-color: var(--accent);
}

.check-all {
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    margin-bottom: 4px;
    font-weight: 600;
}

.sub-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.sub-tab {
    padding: 7px 14px;
    border: 0;
    border-radius: var(--pill);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--speed) var(--ease),
        color var(--speed) var(--ease);
}

.sub-tab:hover {
    color: var(--text);
    background: var(--surface-2);
}

.sub-tab.active {
    background: var(--accent);
    color: var(--on-accent);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 0 20px;
    margin: 0 0 18px;
}

.stat-grid .stat {
    padding: 10px 0;
    border-top: 1px solid var(--line);
}

.stat-note {
    margin-left: 4px;
    font-size: 11px;
    color: var(--muted);
    opacity: 0.8;
}

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    position: sticky;
    top: 0;
    background: var(--surface);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    transition: color var(--speed) var(--ease);
}

.data-table th:hover,
.data-table th.sorted {
    color: var(--text);
}

.data-table th.sorted {
    border-bottom-color: var(--accent);
}

.data-table .num {
    text-align: right;
}

.data-table th:first-child,
.data-table td:first-child {
    position: sticky;
    left: 0;
    background: var(--surface);
    font-weight: 600;
}

.data-table tbody tr:hover td {
    background: var(--surface-2);
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.segmented {
    display: inline-flex;
    gap: 2px;
    margin-bottom: 12px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.segment {
    padding: 6px 12px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--speed) var(--ease),
        color var(--speed) var(--ease);
}

.segment:hover {
    color: var(--text);
}

.segment.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: inset 0 -2px 0 var(--accent);
}

body.signed-out .header-tools,
body.signed-out .main-nav {
    display: none;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 12px;
    border-left: 1px solid var(--line);
}

.user-name {
    font-weight: 600;
}

.btn-small {
    padding: 5px 10px;
    font-size: 13px;
}

.status.bad {
    color: var(--bad);
}

.login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 56px - 88px);
}

.login .panel {
    width: 100%;
    max-width: 380px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-inline {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.form-title {
    width: 100%;
    margin: 0;
    font-size: 14px;
}

.form-inline .actions,
.form-inline .status {
    width: 100%;
    margin-top: 0;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.field input,
.field select {
    min-width: 180px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-weight: 400;
    transition: border-color var(--speed) var(--ease);
}

.field input:focus,
.field select:focus {
    border-color: var(--accent);
    outline: none;
}

.field input[readonly] {
    color: var(--muted);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    z-index: 50;
    display: none;
    max-width: calc(100vw - 32px);
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    transform: translateX(-50%);
}

.toast.show {
    display: block;
}

.toast.busy {
    border-color: var(--warn);
}

.toast.good {
    border-color: var(--good);
    color: var(--good);
}

.toast.bad {
    border-color: var(--bad);
    color: var(--bad);
}

.segmented-bar {
    margin-bottom: 0;
}

.page {
    max-width: 1680px;
}

.kpi-strip .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    margin: 0;
    padding: 4px 18px 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.kpi-strip .stat {
    padding: 12px 0;
}

.stat dd.good {
    color: var(--good);
}

.stat dd.bad {
    color: var(--bad);
}

.stat dd.warn {
    color: var(--warn);
}

.stat-sub {
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
}

.panel-body {
    padding: 14px 16px;
}

.data-table {
    font-size: 13px;
}

.data-table th,
.data-table td {
    padding: 6px 10px;
}

.data-table tfoot td {
    border-top: 1px solid var(--line);
    border-bottom: 0;
    font-weight: 700;
    background: var(--surface-2);
}

.data-table td.pos {
    color: var(--good);
}

.data-table td.neg {
    color: var(--bad);
}

.data-table a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.data-table a:hover {
    text-decoration: underline;
}

.coming-soon {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 600;
    color: var(--accent);
}

/* ---------- Admin: users and targets ---------- */

.users-table td {
    vertical-align: middle;
}

.pin {
    display: inline-block;
    min-width: 64px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.08em;
}

.pin-hidden {
    color: var(--muted);
}

.actions-cell {
    white-space: nowrap;
}

.row-inactive td {
    color: var(--muted);
}

.badge {
    display: inline-block;
    padding: 1px 8px;
    border: 1px solid var(--line);
    border-radius: var(--pill);
    font-size: 12px;
}

.badge.good {
    color: var(--good);
    border-color: var(--good);
}

.badge.bad {
    color: var(--bad);
    border-color: var(--bad);
}

.field-wide {
    min-width: 280px;
}

/* ---------- Target grading ---------- */

.data-table td.grade-good {
    color: var(--good);
    background: rgba(61, 220, 151, 0.10);
}

.data-table td.grade-warn {
    color: var(--warn);
    background: rgba(245, 196, 81, 0.10);
}

.data-table td.grade-bad {
    color: var(--bad);
    background: rgba(255, 107, 107, 0.10);
}

.target-legend {
    display: flex;
    gap: 16px;
    margin: 0 0 12px;
    font-size: 12px;
}

.target-legend span::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 2px;
    background: currentColor;
}

.target-legend .grade-good { color: var(--good); }
.target-legend .grade-warn { color: var(--warn); }
.target-legend .grade-bad { color: var(--bad); }
