:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #e4e2dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7c77;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --track: #e9e7e1;
  --good: #0ca30c;
  --good-ink: #006300;
  --good-soft: #e5f5e5;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --warn-soft: #fff4dc;
  --bad: #d03b3b;
  --bad-ink: #b02a2a;
  --bad-soft: #fbe9e9;
  --idle: #b9b7b0;
  --idle-soft: #f0efec;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-soft: #1b2a3d;
    --track: #383835;
    --good-ink: #5fd35f;
    --good-soft: #17301a;
    --warn-ink: #fab219;
    --warn-soft: #3a2e12;
    --bad-ink: #f08a8a;
    --bad-soft: #3b1c1c;
    --idle: #5b5a55;
    --idle-soft: #262624;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2e2e2b;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-soft: #1b2a3d;
  --track: #383835;
  --good-ink: #5fd35f;
  --good-soft: #17301a;
  --warn-ink: #fab219;
  --warn-soft: #3a2e12;
  --bad-ink: #f08a8a;
  --bad-soft: #3b1c1c;
  --idle: #5b5a55;
  --idle-soft: #262624;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 10px 16px 4px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none !important; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect x='7' y='17' width='4' height='8' rx='1.5' fill='white'/%3E%3Crect x='14' y='12' width='4' height='13' rx='1.5' fill='white'/%3E%3Crect x='21' y='7' width='4' height='18' rx='1.5' fill='white'/%3E%3C/svg%3E") center/100% no-repeat;
}
.brand-name { display: block; font-weight: 700; font-size: 16px; }
.brand-sub { display: block; font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); flex: none; }
.tabs {
  max-width: 1200px; margin: 0 auto; padding: 0 12px;
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 12px; color: var(--text-2); font-weight: 550; font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent; text-decoration: none !important;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 16px; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: 13px; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head .hint { font-size: 12px; color: var(--muted); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.grid { display: grid; gap: 12px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
@media (max-width: 560px) {
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tiles > .tile:first-child:nth-last-child(odd) { grid-column: 1 / -1; }
  .tile { padding: 12px 14px; }
  .tile-value { font-size: 20px; }
}
.cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
@media (max-width: 420px) { .cards { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.loading, .empty { padding: 40px 16px; text-align: center; color: var(--text-2); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- stat tiles ---------- */
.tile { padding: 14px 16px; }
.tile-label { font-size: 12px; color: var(--text-2); font-weight: 550; text-transform: uppercase; letter-spacing: .04em; }
.tile-value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.tile-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-value small { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-top: 1px; }
.tile-foot { font-size: 12px; color: var(--text-2); margin-top: 8px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 8px; }
.tile-foot > * { white-space: nowrap; }
.tile .bar { margin-top: 10px; }

/* ---------- bars ---------- */
.bar { position: relative; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > span { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--accent); min-width: 0; }
.bar.thin { height: 6px; }
.bar.done > span { background: var(--good); }
.bar.none { background: repeating-linear-gradient(135deg, var(--track) 0 4px, transparent 4px 7px); }

/* ---------- ranking ---------- */
.rank-list { display: grid; gap: 2px; }
.rank {
  display: grid; grid-template-columns: 28px minmax(90px, 1.1fr) 3fr minmax(120px, auto);
  align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; cursor: pointer;
}
.rank:hover { background: var(--surface-2); }
.rank-no { font-weight: 700; color: var(--muted); text-align: center; }
.rank-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-val { text-align: right; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.rank-val b { color: var(--text); font-size: 14px; }
@media (max-width: 640px) {
  .rank { grid-template-columns: 24px 1fr auto; row-gap: 6px; }
  .rank .bar { grid-column: 2 / 4; grid-row: 2; }
}

/* ---------- member table (sales) ---------- */
.team-block { padding: 0; overflow: hidden; }
.team-block-head { padding: 14px 16px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px; border-bottom: 1px solid var(--border); }
.team-block-head .facis { font-size: 12px; color: var(--text-2); }
.mtable { width: 100%; }
.mrow {
  display: grid; grid-template-columns: minmax(130px, 1.3fr) repeat(3, minmax(90px, 1fr)) minmax(70px, .6fr) minmax(150px, 1.3fr);
  gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.mrow:last-child { border-bottom: 0; }
.mrow.head { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; padding-top: 8px; padding-bottom: 8px; background: var(--surface-2); }
.mrow.total { background: var(--surface-2); font-weight: 650; }
.mcell { min-width: 0; font-size: 13px; }
.mcell .v { white-space: nowrap; }
.mcell .v b { font-weight: 650; }
.mcell .bar { margin-top: 5px; }
.mcell .lbl { display: none; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.mname { font-weight: 600; display: flex; align-items: center; gap: 6px; min-width: 0; }
.mname a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) {
  .mrow { grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 12px 16px; }
  .mrow.head { display: none; }
  .mrow .mname { grid-column: 1 / -1; order: 0; font-size: 15px; }
  .mrow .mcell { order: 2; }
  .mrow .mcell.totalc { grid-column: 1 / -1; order: 1; padding-bottom: 4px; }
  .mcell .lbl { display: block; }
}

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 6px; border-radius: 999px; text-transform: uppercase; background: var(--accent-soft); color: var(--accent-ink); flex: none;
}
.badge.gray { background: var(--surface-2); color: var(--text-2); }
.badge.new { background: var(--warn-soft); color: var(--warn-ink); }

/* ---------- status pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 7px; border-radius: 999px;
  font-size: 12px; font-weight: 650; white-space: nowrap;
}
.pill i { font-style: normal; display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; font-size: 10px; color: #fff; }
.pill.ontrack { background: var(--good-soft); color: var(--good-ink); }
.pill.ontrack i { background: var(--good); }
.pill.behind { background: var(--bad-soft); color: var(--bad-ink); }
.pill.behind i { background: var(--bad); }
.pill.pending { background: var(--warn-soft); color: var(--warn-ink); }
.pill.pending i { background: var(--warn); color: #3a2a00; }
.pill.none, .pill.future, .pill.weekend { background: var(--idle-soft); color: var(--text-2); }
.pill.none i, .pill.future i, .pill.weekend i { background: var(--idle); }

/* ---------- chips (team / date pickers) ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); font-size: 13px; font-weight: 550; cursor: pointer; text-decoration: none !important; white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--idle); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.dim { opacity: .55; }
.chip .sub { display: block; font-size: 10.5px; font-weight: 500; opacity: .8; }
.chip.date { text-align: center; padding: 6px 12px; line-height: 1.2; }

/* ---------- member cards (team view) ---------- */
.mcard { display: flex; flex-direction: column; gap: 14px; }
.mcard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.mcard-head h3 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mcard-head h3 a { color: var(--text); }
.sub-h { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 10px; align-items: center; font-size: 13px; }
.kv .k { color: var(--text-2); }
.kv .val { text-align: right; white-space: nowrap; }
.goal { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 13px; margin-bottom: 8px; }
.goal .bar { grid-column: 1 / 3; }
.goal .gv { color: var(--text-2); white-space: nowrap; }
.goal .gv b { color: var(--text); }
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13.5px; }
.tasks li { display: flex; gap: 8px; align-items: flex-start; }
.tick {
  flex: none; width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; font-size: 11px; margin-top: 1px;
  border: 1.5px solid var(--idle); color: transparent;
}
.tick.on { background: var(--good); border-color: var(--good); color: #fff; }
.tick.off { border-color: var(--bad); color: var(--bad-ink); }
.tasks li.done span { color: var(--text-2); }

/* ---------- daily ---------- */
.daily-team { padding: 0; overflow: hidden; }
.drow { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 10px 16px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.drow:last-child { border-bottom: 0; }
.drow .who { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.drow .who a { color: var(--text); font-weight: 600; }
@media (max-width: 640px) { .drow { grid-template-columns: 1fr; } }

.history { overflow-x: auto; }
.htable { border-collapse: separate; border-spacing: 3px; font-size: 12px; min-width: 100%; }
.htable th { font-weight: 600; color: var(--muted); padding: 4px; white-space: nowrap; }
.htable th.name { text-align: left; color: var(--text); font-weight: 600; font-size: 13px; padding-right: 10px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.htable th.team { text-align: left; color: var(--text-2); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding-top: 12px; position: sticky; left: 0; background: var(--surface); }
.hcell {
  width: 34px; height: 28px; border-radius: 6px; text-align: center; font-weight: 700; cursor: pointer; font-size: 11px;
  border: 0; padding: 0; display: grid; place-items: center; margin: auto;
}
.hcell.ontrack { background: var(--good); color: #fff; }
.hcell.behind { background: var(--bad); color: #fff; }
.hcell.pending { background: var(--warn); color: #3a2a00; }
.hcell.none { background: var(--idle-soft); color: var(--muted); }
.hcell.future { background: transparent; color: var(--idle); border: 1px dashed var(--border); }
.hcell.sel { outline: 2px solid var(--text); outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-2); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 14px; height: 14px; border-radius: 4px; }

/* ---------- forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer;
  text-decoration: none !important;
}
.btn:hover { border-color: var(--idle); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad-ink); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.link { border: 0; background: none; color: var(--accent-ink); padding: 4px 6px; }
.btn[disabled] { opacity: .5; cursor: progress; }
.field { display: grid; gap: 4px; font-size: 13px; }
.field > span { color: var(--text-2); font-weight: 550; }
.input, select.input, textarea.input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); min-width: 0;
}
.input:focus, .btn:focus-visible, .chip:focus-visible, .hcell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.input { min-height: 220px; resize: vertical; font-size: 13px; line-height: 1.5; }
.input.num { text-align: right; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg label { padding: 8px 12px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-2); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--text); color: var(--bg); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }

/* ---------- editor (import preview / edit person) ---------- */
.editor { display: grid; gap: 14px; }
.editor-head { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
@media (max-width: 560px) { .editor-head { grid-template-columns: 1fr 1fr; } .editor-head .rm { grid-column: 1 / 3; justify-self: end; } }
.sales-edit { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px 8px; align-items: center; font-size: 13px; }
.sales-edit .h { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.sales-edit .note { grid-column: 2 / 4; font-size: 12px; color: var(--warn-ink); margin-top: -2px; }
.list-edit { display: grid; gap: 6px; }
.goal-edit { display: grid; grid-template-columns: 1fr 64px 64px 30px; gap: 6px; align-items: center; }
.task-edit { display: grid; grid-template-columns: 26px 1fr 30px; gap: 6px; align-items: center; }
.task-edit input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--good); }
.x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 4px; border-radius: 6px; }
.x:hover { color: var(--bad-ink); background: var(--bad-soft); }
.warns { margin: 0; padding: 10px 12px 10px 28px; background: var(--warn-soft); color: var(--warn-ink); border-radius: 10px; font-size: 12.5px; }
.warns li + li { margin-top: 3px; }
.note-box { padding: 10px 12px; background: var(--accent-soft); color: var(--accent-ink); border-radius: 10px; font-size: 13px; }
.sticky-actions {
  position: sticky; bottom: 0; margin-top: 16px; padding: 12px 0;
  background: linear-gradient(transparent, var(--bg) 30%); display: flex; justify-content: flex-end; gap: 8px;
}
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- admin ---------- */
.admin-row { display: grid; grid-template-columns: 1.4fr 1fr .9fr 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.admin-row:last-child { border-bottom: 0; }
@media (max-width: 760px) { .admin-row { grid-template-columns: 1fr 1fr; } .admin-row .actions { grid-column: 1 / 3; justify-content: flex-end; } }

/* ---------- toast & tooltip ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 550;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2); max-width: calc(100% - 32px);
}
.toast.err { background: var(--bad); color: #fff; }
.tip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 9px;
  border-radius: 8px; font-size: 12px; max-width: 260px; box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
