/* Colours come from Telegram's theme so the app matches the user's client
   in both light and dark mode. Fallbacks are for opening outside Telegram. */
:root {
  --bg:        var(--tg-theme-bg-color, #ffffff);
  --sec-bg:    var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text:      var(--tg-theme-text-color, #000000);
  --hint:      var(--tg-theme-hint-color, #8b8b90);
  --link:      var(--tg-theme-link-color, #2481cc);
  --btn:       var(--tg-theme-button-color, #2481cc);
  --btn-text:  var(--tg-theme-button-text-color, #ffffff);
  --ok:    #2e9e5b;
  --warn:  #d99100;
  --danger:#d64545;
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 0 96px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Noto Sans Khmer", "Khmer OS", sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--hint); }
.km { display: block; font-size: 12px; color: var(--hint); font-weight: 400; }

.centered { padding: 48px 24px; text-align: center; color: var(--hint); }

/* ---- KPI header ---- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 8px;
  padding: 12px;
  background: var(--sec-bg);
}
.kpi { text-align: center; }
.kpi b { display: block; font-size: 20px; }
.kpi span { font-size: 11px; color: var(--hint); }

/* ---- controls ---- */
.controls { padding: 12px; display: grid; gap: 8px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.controls input, .controls select {
  width: 100%; padding: 9px 11px; font-size: 14px;
  color: var(--text); background: var(--sec-bg);
  border: 1px solid var(--line); border-radius: 9px;
}
/* Flex, not grid: the project select is hidden for requesters and a grid would
   leave an empty column behind it. */
.filters { display: flex; gap: 8px; }
.filters select { flex: 1; min-width: 0; }

/* ---- list ---- */
.group-title {
  padding: 14px 12px 6px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--hint);
}

.item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 12px; border-bottom: 1px solid var(--line);
}
.item.selected { background: color-mix(in srgb, var(--link) 12%, transparent); }
.item input[type=checkbox] { margin-top: 3px; width: 20px; height: 20px; flex: none; accent-color: var(--btn); }
.item-body { flex: 1; min-width: 0; }
.item-desc { font-weight: 600; overflow-wrap: anywhere; }
.item-meta { font-size: 12px; color: var(--hint); margin-top: 2px; overflow-wrap: anywhere; }

.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; align-items: center; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 20px; background: var(--sec-bg); color: var(--hint); }
.age-0 { background: color-mix(in srgb, var(--ok) 18%, transparent);     color: var(--ok); }
.age-1 { background: color-mix(in srgb, var(--warn) 20%, transparent);   color: var(--warn); }
.age-2 { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.photo-flag { text-decoration: none; }

/* ---- action bar ---- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--sec-bg); border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.actionbar .actions { display: flex; gap: 6px; }

.btn {
  padding: 9px 13px; font-size: 14px; font-weight: 600;
  border: 0; border-radius: 9px; cursor: pointer;
  background: var(--btn); color: var(--btn-text);
}
.btn.ok     { background: var(--ok);     color: #fff; }
.btn.warn   { background: var(--warn);   color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost  { background: var(--sec-bg); color: var(--text); border: 1px solid var(--line); }
.btn:disabled { opacity: .55; }

/* ---- confirm sheet ---- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end;
}
.sheet {
  width: 100%; background: var(--bg);
  border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet h2 { margin: 0 0 4px; font-size: 17px; }
.photo-picker {
  display: block; margin: 14px 0; padding: 14px; text-align: center;
  border: 1px dashed var(--line); border-radius: 11px; color: var(--link); cursor: pointer;
}
#photo-preview { width: 100%; max-height: 200px; object-fit: contain; border-radius: 11px; margin-bottom: 12px; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
