:root {
  color-scheme: light;
  --bg: #f6f8f6;
  --surface: #fff;
  --ink: #202b24;
  --muted: #6b786f;
  --line: #dfe6df;
  --accent: #176a50;
  --accent-dark: #11523e;
  --soft: #edf6ef;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.container { max-width: 1180px; margin: 0 auto; padding: 0 24px; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner { min-height: 64px; display: flex; align-items: center; gap: 36px; }
.brand, .login-brand { display: inline-flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 750; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 16px; font-weight: 750; }
.main-nav { display: flex; align-self: stretch; align-items: center; gap: 28px; margin-right: auto; }
.main-nav a { display: flex; align-items: center; height: 100%; border-bottom: 2px solid transparent; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
.main-nav a:hover, .main-nav a.active { color: var(--accent); }
.main-nav a.active { border-bottom-color: var(--accent); }
.header-user { display: flex; align-items: center; gap: 17px; }
.user-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }
.logout-button { border: 0; background: none; padding: 6px 0; color: var(--accent); font-size: 12px; font-weight: 650; }

.dashboard-main, .inner-main { padding-top: 26px; padding-bottom: 50px; }
.page-heading { margin-bottom: 20px; }
.page-heading h1 { font-size: 27px; line-height: 1.2; letter-spacing: -.035em; font-weight: 750; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.panel-heading { padding: 18px 20px 13px; }
.panel-heading h2, .leaderboard-top h2 { font-size: 17px; line-height: 1.25; letter-spacing: -.02em; font-weight: 750; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,1.65fr) minmax(290px,.9fr); gap: 16px; align-items: start; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 17px; border: 1px solid transparent; border-radius: 8px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: var(--soft); color: var(--accent); }
.button.secondary:hover { background: #dff0e4; }
.button.full { width: 100%; }
.alert { padding: 10px 13px; margin-bottom: 16px; border: 1px solid; border-radius: 8px; font-size: 13px; }
.alert.error { background: #fff3f1; border-color: #f2d4ce; color: #9a4539; }
.alert.success { background: #eef8f0; border-color: #d5e9d9; color: #236b45; }

.date-navigation { display: flex; gap: 8px; align-items: center; padding: 0 20px 16px; }
.date-arrow { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 8px; font-size: 18px; color: var(--accent); }
.date-arrow:hover { background: var(--soft); }
.date-arrow.disabled { color: #b1bbb2; background: #f8faf8; }
.date-form { min-width: 0; flex: 1; display: flex; align-items: center; gap: 8px; }
.date-form input { min-width: 0; flex: 1; height: 38px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.date-form button { height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--accent); font-size: 12px; font-weight: 700; }
.date-form button:hover { background: var(--soft); }
.metric-list { border-top: 1px solid var(--line); }
.metric-row { display: grid; grid-template-columns: minmax(150px,.9fr) minmax(0,1.55fr); align-items: center; gap: 18px; padding: 15px 20px; border-bottom: 1px solid var(--line); }
.metric-row:last-child { border-bottom: 0; }
.metric-row h3 { font-size: 13px; font-weight: 700; line-height: 1.3; }
.counter-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.counter-field { min-width: 0; }
.counter-field label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 600; }
.counter-control { display: flex; align-items: stretch; height: 40px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; }
.counter-control button { flex: none; width: 37px; border: 0; background: #f4f7f4; color: var(--accent); font-size: 19px; }
.counter-control button:hover { background: #e3efe5; }
.counter-control input { flex: 1; min-width: 0; width: 100%; border: 0; padding: 0 2px; text-align: center; appearance: textfield; -moz-appearance: textfield; font-size: 15px; font-weight: 750; color: var(--ink); }
.counter-control input::-webkit-outer-spin-button, .counter-control input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.counter-control input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.save-bar { position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; justify-content: flex-end; gap: 16px; min-height: 64px; padding: 11px 20px; border-top: 1px solid var(--line); border-radius: 0 0 12px 12px; background: rgba(255,255,255,.97); }
.save-bar span { min-width: 0; color: #98642e; font-size: 12px; font-weight: 650; }
.save-bar .button { min-width: 130px; }

.personal-panel { padding-bottom: 5px; }
.summary-card { margin: 0 20px; padding: 15px 0; border-top: 1px solid var(--line); }
.summary-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 11px; }
.summary-top span { font-size: 13px; font-weight: 700; }
.summary-top strong { color: var(--accent); font-size: 13px; white-space: nowrap; }
.summary-metrics { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px 15px; }
.summary-metrics span { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); font-size: 11px; }
.summary-metrics b { color: var(--ink); font-size: 12px; }
.admin-actions { margin-bottom: 16px; }

.leaderboard-panel { margin-top: 16px; overflow: hidden; }
.leaderboard-top { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; }
.leaderboard-top p { margin-top: 3px; color: var(--muted); font-size: 12px; }
.period-tabs { display: flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #f5f7f5; }
.period-tabs a { min-width: 73px; padding: 6px 10px; border-radius: 5px; text-align: center; color: var(--muted); font-size: 12px; font-weight: 650; }
.period-tabs a.active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px #d8e2d8; }
.ranking-table-wrap { overflow-x: auto; }
.ranking-table { width: 100%; min-width: 620px; border-collapse: collapse; }
.ranking-table th { padding: 10px 13px; background: #f8faf8; color: var(--muted); font-size: 11px; font-weight: 650; text-align: left; white-space: nowrap; }
.ranking-table td { padding: 11px 13px; border-top: 1px solid var(--line); font-size: 13px; }
.ranking-table th:first-child, .ranking-table td:first-child { width: 70px; padding-left: 20px; }
.ranking-table th:nth-child(2) { width: 32%; }
.ranking-table .my-row { background: #f4faf5; }
.rank-number { color: var(--muted); font-weight: 750; }
.person-cell { font-weight: 700; }
.person-cell small { margin-left: 6px; color: var(--accent); font-size: 11px; font-weight: 650; }
.ranking-table td:last-child strong { color: var(--accent); font-weight: 800; }
.empty-state { padding: 22px 20px; color: var(--muted); font-size: 13px; }
.score-note { border-top: 1px solid var(--line); padding: 12px 20px; color: var(--muted); font-size: 12px; }
.score-note summary { cursor: pointer; width: max-content; color: var(--accent); font-weight: 650; }
.score-note p { max-width: 610px; padding-top: 9px; }

.admin-grid { display: grid; grid-template-columns: minmax(280px,.78fr) minmax(0,1.22fr); gap: 16px; align-items: start; }
.stack-form { display: flex; flex-direction: column; gap: 7px; }
.add-user-panel .stack-form, .password-panel .stack-form { padding: 0 20px 20px; }
.stack-form label { margin-top: 7px; font-size: 12px; font-weight: 700; }
.stack-form input, .reset-form input { width: 100%; height: 40px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); outline: none; }
.stack-form input:focus, .reset-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px #dceee0; }
.stack-form .button { margin-top: 13px; }
.count-badge { display: inline-block; min-width: 23px; padding: 2px 6px; border-radius: 6px; background: var(--soft); color: var(--accent); font-size: 11px; text-align: center; vertical-align: middle; }
.user-list { padding: 0 20px 20px; }
.user-card { padding: 13px 0; border-top: 1px solid var(--line); }
.user-card-main { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.user-card-main > div { min-width: 0; }
.user-card-main strong, .user-card-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card-main strong { font-size: 13px; }
.user-card-main small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.role-badge { display: inline-block; flex: none; padding: 4px 8px; border-radius: 6px; background: var(--soft); color: var(--accent); font-size: 11px; font-weight: 650; }
.role-badge.off { background: #f1f2f1; color: var(--muted); }
.user-actions { display: flex; align-items: flex-start; gap: 20px; margin-top: 10px; }
.text-button, .user-actions summary { border: 0; padding: 0; background: none; color: var(--accent); font-size: 12px; font-weight: 650; cursor: pointer; }
.reset-form { display: flex; gap: 8px; margin-top: 10px; }
.reset-form input { min-width: 0; }
.settings-grid { display: grid; grid-template-columns: minmax(230px,.7fr) minmax(0,1.3fr); gap: 16px; align-items: start; max-width: 800px; }
.profile-details { display: flex; align-items: center; flex-wrap: wrap; gap: 5px 10px; padding: 0 20px 20px; }
.profile-details strong { width: 100%; font-size: 15px; }
.profile-details > span:nth-child(2) { color: var(--muted); font-size: 12px; }
.profile-details .role-badge { margin-left: auto; }

.login-layout { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(390px,100%); padding: 30px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.login-brand { margin-bottom: 30px; }
.login-card h1 { margin-bottom: 18px; font-size: 25px; letter-spacing: -.03em; }
.login-card .stack-form .button { margin-top: 16px; }

@media (max-width: 950px) {
  .dashboard-grid { grid-template-columns: minmax(0,1fr); }
  .personal-panel { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); padding: 0 12px 12px; }
  .personal-panel .panel-heading { grid-column: 1/-1; padding-left: 8px; }
  .summary-card { margin: 0 8px; }
  .admin-grid { grid-template-columns: minmax(0,1fr) minmax(0,1.2fr); }
}
@media (max-width: 700px) {
  .container { padding: 0 16px; }
  .header-inner { flex-wrap: wrap; gap: 0; padding-top: 10px; }
  .brand { margin-right: auto; }
  .header-user { order: 2; }
  .user-name { display: none; }
  .main-nav { order: 3; width: 100%; height: 42px; gap: 22px; margin: 0; }
  .main-nav a { font-size: 12px; }
  .dashboard-main, .inner-main { padding-top: 20px; padding-bottom: 32px; }
  .page-heading { margin-bottom: 16px; }
  .page-heading h1 { font-size: 24px; }
  .panel-heading { padding: 16px 16px 12px; }
  .date-navigation { padding: 0 16px 14px; gap: 6px; }
  .date-arrow { width: 36px; height: 38px; }
  .date-form { gap: 6px; }
  .date-form button { padding: 0 7px; }
  .metric-row { display: block; padding: 13px 16px; }
  .metric-row h3 { margin-bottom: 10px; }
  .counter-grid { gap: 8px; }
  .counter-control button { width: 36px; }
  .save-bar { padding: 10px 16px; justify-content: space-between; }
  .save-bar .button { min-width: 128px; }
  .personal-panel { display: block; padding: 0 0 4px; }
  .personal-panel .panel-heading { padding: 16px 16px 10px; }
  .summary-card { margin: 0 16px; padding: 12px 0; }
  .leaderboard-top { align-items: stretch; flex-direction: column; gap: 12px; padding: 16px; }
  .period-tabs { width: 100%; }
  .period-tabs a { flex: 1; min-width: 0; }
  .ranking-table-wrap { overflow: visible; }
  .ranking-table { min-width: 0; display: block; }
  .ranking-table thead { display: none; }
  .ranking-table tbody { display: grid; gap: 8px; padding: 0 12px 12px; }
  .ranking-table tr { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px 4px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; }
  .ranking-table td { display: flex; flex-direction: column; min-width: 0; padding: 0; border: 0; font-size: 14px; }
  .ranking-table td:first-child { grid-column: 1; grid-row: 1; width: auto; padding: 0; }
  .ranking-table td:nth-child(2) { grid-column: 2/4; grid-row: 1; display: flex; flex-direction: row; align-items: center; overflow: hidden; }
  .ranking-table td:nth-child(2) span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ranking-table td:nth-child(7) { grid-column: 4; grid-row: 1; align-items: flex-end; }
  .ranking-table td:nth-child(3), .ranking-table td:nth-child(4), .ranking-table td:nth-child(5), .ranking-table td:nth-child(6) { grid-row: 2; padding-top: 8px; border-top: 1px solid var(--line); }
  .ranking-table td:nth-child(3) { grid-column: 1; }
  .ranking-table td:nth-child(4) { grid-column: 2; }
  .ranking-table td:nth-child(5) { grid-column: 3; }
  .ranking-table td:nth-child(6) { grid-column: 4; }
  .ranking-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 10px; font-weight: 500; }
  .score-note { padding: 12px 16px; }
  .admin-grid, .settings-grid { grid-template-columns: 1fr; }
  .login-card { padding: 24px; }
}
@media (max-width: 370px) {
  .counter-control button { width: 30px; }
  .counter-grid { gap: 6px; }
  .user-actions { gap: 12px; }
  .reset-form { flex-direction: column; }
}
