:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --secbg: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #7d8b99);
  --link: var(--tg-theme-link-color, #5ea9dd);
  --btn: var(--tg-theme-button-color, #5288c1);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: var(--tg-theme-accent-text-color, #6ab3f3);
  --green: #2ea043;
  --yellow: #d29922;
  --red: #d64545;
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

.hdr {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 12px 14px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.hdr-row { display: flex; align-items: flex-start; justify-content: space-between; }
.hdr-title { font-size: 17px; font-weight: 700; }
.hdr-sub { font-size: 13px; color: var(--hint); margin-top: 2px; }
.icon-btn {
  background: var(--secbg); color: var(--text); border: none;
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { opacity: .6; }
.icon-btn.primary-btn { background: var(--btn); color: var(--btn-text); }
.icon-btn svg { width: 19px; height: 19px; }

.cal-btn {
  background: none; border: none; color: var(--hint); cursor: pointer;
  width: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px;
}
.cal-btn svg { width: 18px; height: 18px; }
.cal-btn.active { background: var(--btn); color: var(--btn-text); }
.cal-input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }

.search { display: flex; gap: 8px; margin-top: 10px; align-items: center; position: relative; }
.search-ic {
  position: absolute; left: 11px; color: var(--hint); display: inline-flex; pointer-events: none;
}
.search-ic svg { width: 17px; height: 17px; }
.search input { padding-left: 36px !important; }

.hdr-actions { display: flex; gap: 6px; }

.day-switch {
  display: flex; gap: 4px; margin-top: 10px;
  background: var(--secbg); padding: 3px; border-radius: 10px;
}
.day-switch button {
  flex: 1; background: none; border: none; color: var(--hint);
  padding: 7px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.day-switch button.active { background: var(--btn); color: var(--btn-text); }

.progress {
  height: 8px; background: var(--secbg); border-radius: 6px; overflow: hidden; margin-top: 10px;
}
.progress-bar { height: 100%; width: 0; background: var(--green); transition: width .3s; }
.progress-label { font-size: 12px; color: var(--hint); margin-top: 4px; }

.search { display: flex; gap: 8px; margin-top: 10px; }
.search input {
  flex: 1; background: var(--secbg); border: none; border-radius: 10px;
  color: var(--text); padding: 10px 12px; font-size: 15px; outline: none;
}
.search button {
  background: var(--btn); color: var(--btn-text); border: none; border-radius: 10px;
  padding: 0 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}

main { padding: 8px 12px 40px; }
.loader { text-align: center; color: var(--hint); padding: 40px 0; }

.section { margin-top: 14px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 700; color: var(--hint);
  text-transform: uppercase; letter-spacing: .03em;
  padding: 4px 2px; cursor: pointer;
}
.section-head .chev { transition: transform .2s; }
.section.collapsed .chev { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.section-count {
  background: var(--secbg); color: var(--hint);
  border-radius: 10px; padding: 1px 8px; font-size: 12px; margin-left: 6px;
}

.card {
  background: var(--secbg); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px;
}
.card-top { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.type-icon { width: 18px; height: 18px; margin-top: 2px; flex: none; border-radius: 3px; }
.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex: none; }
.dot.new { background: var(--hint); }
.dot.indeterminate { background: var(--yellow); }
.dot.done { background: var(--green); }
.card-main { flex: 1; min-width: 0; }
.card-key { font-weight: 700; color: var(--accent); font-size: 14px; }
.card-key a { color: var(--accent); text-decoration: none; }
.card-summary { font-size: 14px; margin-top: 1px; line-height: 1.3; }
.card-meta { font-size: 12px; color: var(--hint); margin-top: 3px; }
.badge {
  display: inline-block; background: rgba(255,255,255,.08); color: var(--hint);
  border-radius: 6px; padding: 1px 6px; font-size: 11px; margin-right: 4px;
}
.logged-amount { color: var(--green); font-weight: 700; font-size: 14px; white-space: nowrap; }

.wl-list { margin-top: 8px; }
.wl-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 6px 0; border-top: 1px solid rgba(255,255,255,.06);
}
.wl-item .wl-min { font-weight: 700; color: var(--green); }
.wl-item .wl-comment { flex: 1; color: var(--hint); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-item .mini { font-size: 16px; background: none; border: none; color: var(--hint); cursor: pointer; padding: 2px 4px; }

.editor { margin-top: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--bg); color: var(--text); border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px; padding: 7px 12px; font-size: 14px; cursor: pointer; flex: 1; text-align: center;
}
.chip:active { background: var(--btn); color: var(--btn-text); }
.editor-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.editor-row input[type=text] {
  flex: 1; background: var(--bg); border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px; color: var(--text); padding: 9px 11px; font-size: 14px; outline: none;
}
.amount-pill {
  font-weight: 700; font-size: 15px; min-width: 64px; text-align: center;
  background: var(--bg); border-radius: 10px; padding: 9px 6px;
}
.save-btn {
  width: 100%; margin-top: 10px; background: var(--btn); color: var(--btn-text);
  border: none; border-radius: 10px; padding: 12px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.save-btn:disabled { opacity: .4; }
.editor-actions { display: flex; gap: 8px; }
.ghost-btn {
  margin-top: 10px; background: var(--secbg); color: var(--hint);
  border: 1px solid rgba(255,255,255,.12); border-radius: 10px; padding: 12px; font-size: 14px; cursor: pointer;
}

.empty { text-align: center; color: var(--hint); padding: 30px 10px; font-size: 14px; }

.load-more {
  width: 100%; margin: 6px 0 4px; background: var(--secbg); color: var(--text);
  border: 1px solid rgba(255,255,255,.1); border-radius: 10px; padding: 12px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.load-more:disabled { opacity: .5; }
.list-meta { font-size: 12px; color: var(--hint); padding: 2px 2px 8px; }

.overlay {
  position: fixed; inset: 0; background: #000a; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.overlay.hidden { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 520px;
  border-radius: 16px 16px 0 0; padding: 18px 16px 24px;
  max-height: 86vh; overflow-y: auto;
}
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-hint { font-size: 13px; color: var(--hint); margin: 4px 0 14px; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; font-size: 15px;
}
.toggle-row input { width: 20px; height: 20px; }
.times-label { font-size: 13px; color: var(--hint); text-transform: uppercase; margin: 12px 0 6px; }
.times-list { display: flex; flex-direction: column; gap: 8px; }
.time-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--secbg); border-radius: 10px; padding: 10px 14px; font-size: 16px; font-weight: 600;
}
.time-item .del-x { background: none; border: none; color: var(--red); font-size: 18px; cursor: pointer; }
.mini-switch { display: flex; gap: 3px; background: var(--bg); border-radius: 8px; padding: 2px; }
.mini-switch button {
  background: none; border: none; color: var(--hint); font-size: 12px;
  padding: 5px 9px; border-radius: 6px; cursor: pointer;
}
.mini-switch button.active { background: var(--btn); color: var(--btn-text); }
.add-time-row { display: flex; gap: 8px; margin-top: 10px; }
.add-time-row input {
  flex: 1; background: var(--secbg); border: none; border-radius: 10px;
  color: var(--text); padding: 10px 12px; font-size: 15px;
}
.add-time-row button {
  background: var(--secbg); color: var(--text); border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px; padding: 0 14px; font-size: 14px; cursor: pointer;
}

.field { margin-bottom: 12px; }
.field.hidden { display: none; }
.field label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 5px; text-transform: uppercase; }
.field select, .field input[type=text] {
  width: 100%; background: var(--secbg); border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; color: var(--text); padding: 11px 12px; font-size: 15px; outline: none;
}
.divider { height: 1px; background: rgba(255,255,255,.08); margin: 16px 0; }

.chips-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: var(--secbg); color: var(--hint); border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px; padding: 6px 12px; font-size: 13px; cursor: pointer; user-select: none;
}
.tag.on { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.sub-item {
  background: var(--secbg); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.sub-item .s-main { flex: 1; font-size: 13px; }
.sub-item .s-proj { font-weight: 700; color: var(--accent); }
.sub-item .del-x { background: none; border: none; color: var(--red); font-size: 18px; cursor: pointer; }

.user-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--secbg); border-radius: 10px; padding: 10px 14px; font-size: 14px;
}
.user-row input { width: 20px; height: 20px; }

.report-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-top: 1px solid rgba(255,255,255,.06);
}
.report-row .r-name { flex: 1; font-size: 14px; }
.report-row .r-min { font-weight: 700; font-size: 14px; }
.report-row .r-ping {
  background: var(--btn); color: var(--btn-text); border: none; border-radius: 8px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.r-min.g { color: var(--green); } .r-min.y { color: var(--yellow); } .r-min.r { color: var(--red); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #000a; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }
