:root {
  --bg: #0f1410;
  --bg-2: #161d18;
  --panel: #1c2620;
  --panel-2: #243029;
  --border: #2e3d34;
  --text: #e8efe9;
  --muted: #9bab9f;
  --accent: #5dbb46;
  --accent-2: #78c552;
  --accent-dim: #2f5a25;
  --danger: #e05a4a;
  --warn: #e0a44a;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);

  --tier-1: #c14a3d;
  --tier-2: #3d6cc1;
  --tier-3: #6b7b73;
  --tier-gm: #8e4ec1;

  --grp-san-xuat-co-ban: #4a8c3a;
  --grp-san-xuat-cao-cap: #c89124;
  --grp-xay-dung-bds: #b0703a;
  --grp-ha-tang-dich-vu: #3a8eb0;
  --grp-tai-chinh-quan-ly: #b03a8e;
  --grp-quan-su-an-ninh: #b03a3a;
  --grp-xa-hoi-van-hoa: #6f51b9;
  --grp-kham-pha-phieu-luu: #3ab09a;
  --grp-dac-biet-sang-tao: #c1b03a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(93, 187, 70, .08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(93, 187, 70, .06), transparent 60%),
    var(--bg);
}

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.boot {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}

/* === Header === */
.header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(15, 20, 16, .85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header .me {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.header .me .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header .switch-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  min-height: 36px;
}
.header .switch-btn:hover { color: var(--text); border-color: var(--accent-dim); }

/* === Login screen === */
.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 16px;
  max-width: 720px;
  margin: 0 auto;
}
.login h1 {
  font-size: clamp(24px, 6vw, 34px);
  margin: 0 0 6px;
  letter-spacing: -.01em;
}
.login .sub {
  color: var(--muted);
  margin: 0 0 28px;
}
.login-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.user-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 140px;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.user-btn:hover, .user-btn:focus-visible {
  border-color: var(--accent);
  background: var(--panel-2);
  transform: translateY(-2px);
  outline: none;
}
.user-btn .av { width: 64px; height: 64px; }
.user-btn .nm { font-weight: 600; font-size: 15px; }

/* === Avatar === */
.av {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--panel-2);
  overflow: hidden;
  flex-shrink: 0;
  image-rendering: pixelated;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}
.av img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.av.sm { width: 24px; height: 24px; font-size: 11px; border-radius: 6px; }
.av.md { width: 40px; height: 40px; font-size: 16px; border-radius: 10px; }
.av.lg { width: 64px; height: 64px; font-size: 22px; border-radius: 12px; }

/* === Layout === */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 14px 80px;
}

/* === Filter bar === */
.filters {
  position: sticky;
  top: 56px;
  z-index: 20;
  background: rgba(15, 20, 16, .9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 10px 0;
  margin: 0 0 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.filters select, .filters .toggle {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  min-height: 40px;
  font-size: 14px;
}
.filters select:focus, .filters .toggle:focus { outline: 2px solid var(--accent-dim); }
.filters .toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.filters .toggle input { accent-color: var(--accent); width: 18px; height: 18px; }
.filters .count {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

/* === Cards === */
.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 600px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 980px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
  min-height: 44px;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}
.card:hover, .card:focus-visible {
  border-color: var(--accent-dim);
  transform: translateY(-2px);
  outline: none;
}
.card .stt {
  font-size: 12px;
  color: var(--muted);
}
.card .card-top {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-edit {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.card-edit:hover { color: var(--accent-2); border-color: var(--accent-dim); }
.card-edit svg { width: 14px; height: 14px; }
.card h3 { padding-right: 70px; }
.card h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -.005em;
  padding-right: 28px;
}
.card .desc {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card .claimants { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.claim-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--border);
  white-space: nowrap;
  line-height: 1.2;
}
.claim-name .role-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 800;
}
.claim-name.p .role-mark { background: var(--accent); color: #0c1408; }
.claim-name.s .role-mark { background: var(--warn); color: #1c1100; }
.card .empty { color: var(--muted); font-size: 13px; }
.card .rating { color: var(--muted); font-size: 13px; }
.card .rating .stars { color: var(--warn); }

/* === Badges === */
.chip {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip.tier-1 { background: var(--tier-1); border-color: transparent; }
.chip.tier-2 { background: var(--tier-2); border-color: transparent; }
.chip.tier-3 { background: var(--tier-3); border-color: transparent; }
.chip.tier-gm { background: var(--tier-gm); border-color: transparent; }
.chip.grp { color: #fff; border-color: transparent; }

.claim-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 9px;
  font-weight: 800;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
  color: #fff;
}
.claim-badge.p { background: var(--accent); }
.claim-badge.s { background: var(--warn); color: #1c1100; }
.av-wrap { position: relative; display: inline-flex; }

/* === Modal === */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .15s ease;
}
@media (min-width: 720px) { .modal-back { align-items: center; padding: 24px; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 720px;
  max-height: 92dvh;
  overflow: auto;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px 32px;
  box-shadow: var(--shadow);
}
@media (min-width: 720px) { .modal { border-radius: 18px; border: 1px solid var(--border); padding: 22px; } }
.modal .close {
  background: var(--panel);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}
.modal-actions {
  position: sticky;
  top: 0;
  float: right;
  display: flex;
  gap: 8px;
  margin-left: 8px;
  z-index: 2;
}
.modal-edit {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.modal-edit:hover { color: var(--accent-2); border-color: var(--accent-dim); }
.modal-edit svg { width: 16px; height: 16px; }
.modal h2 { margin: 4px 0 6px; font-size: 22px; padding-right: 40px; }
.modal .sub-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.modal .desc { color: var(--muted); margin-bottom: 14px; }

.kv {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px 14px;
  margin: 12px 0 16px;
}
@media (min-width: 520px) { .kv { grid-template-columns: max-content 1fr; } }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-size: 14px; }

.section { margin: 18px 0; }
.section h3 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 700;
}

.claim-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:hover { border-color: var(--accent-dim); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #0c1408; border-color: transparent; }
.btn.primary:hover { background: var(--accent-2); }
.btn.secondary { background: var(--warn); color: #1c1100; border-color: transparent; }
.btn.secondary:hover { filter: brightness(1.05); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: rgba(224, 90, 74, .12); }
.btn.sm { padding: 6px 10px; min-height: 32px; font-size: 13px; border-radius: 8px; }

.claimants-list { display: flex; flex-direction: column; gap: 8px; }
.claimants-list .row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.claimants-list .row .nm { font-weight: 600; }
.claimants-list .row .tag {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}
.claimants-list .row .tag.p { background: var(--accent); color: #0c1408; }
.claimants-list .row .tag.s { background: var(--warn); color: #1c1100; }

.rating-widget {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.stars-input {
  display: inline-flex;
  gap: 2px;
  font-size: 28px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 8px;
}
.stars-input span {
  color: #4a5750;
  padding: 2px 4px;
  min-width: 32px;
  text-align: center;
  transition: transform .08s;
}
.stars-input span.on, .stars-input span.hover { color: var(--warn); }
.stars-input span:active { transform: scale(.92); }
textarea.comment {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  resize: vertical;
  min-height: 70px;
  font-size: 14px;
}
textarea.comment:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent-dim); }

.ratings-list { display: flex; flex-direction: column; gap: 10px; }
.rating-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.rating-row.no-avatar { grid-template-columns: 1fr; }
.rating-row.mine { border-color: var(--accent-dim); background: rgba(93,187,70,.05); }
.rating-row .row-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 4px;
}
.rating-row .row-actions .pencil {
  width: 26px;
  height: 26px;
  font-size: 13px;
}
.rating-row .row-actions .pencil.danger-icon {
  color: var(--danger);
}
.rating-row .row-actions .pencil.danger-icon:hover {
  border-color: var(--danger);
  color: var(--danger);
}
.rating-row .who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rating-row .who .nm { font-weight: 600; }
.rating-row .who .stars { color: var(--warn); }
.rating-row .ts { color: var(--muted); font-size: 12px; margin-left: auto; }
.rating-row .cmt { margin: 6px 0 0; font-size: 14px; color: var(--text); white-space: pre-wrap; word-break: break-word; }

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

/* === Toasts === */
.toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: min(420px, calc(100% - 24px));
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  pointer-events: auto;
  animation: rise .18s ease;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--accent); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 380px) {
  .filters { gap: 6px; }
  .filters select, .filters .toggle { padding: 8px 10px; font-size: 13px; }
}

/* === Tier sections === */
.tier-section { margin: 8px 0 28px; }
.tier-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin: 18px 0 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.tier-header.t1 { border-bottom-color: var(--accent); }
.tier-header h2 {
  margin: 0;
  font-size: clamp(20px, 4vw, 26px);
  letter-spacing: -.01em;
}
.tier-header h2 .accent { color: var(--accent); }
.tier-header.t1 h2 .accent { color: var(--accent-2); }
.tier-header .blurb {
  color: var(--muted);
  font-size: 14px;
  flex: 1 1 200px;
}

.group-section { margin: 16px 0 22px; }
.group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
}
.group-header .swatch {
  width: 12px;
  height: 24px;
  border-radius: 4px;
}
.group-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text);
}
.group-header .gcount {
  color: var(--muted);
  font-size: 13px;
}

/* Featured tier 1 cards: larger emphasis */
.tier-1-cards .card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border-color: var(--accent-dim);
}
.tier-1-cards .card h3 { font-size: 18px; }

/* === Minister note on card === */
.note-block {
  background: rgba(93, 187, 70, .06);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin: 0;
  font-size: 13px;
  color: var(--text);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-block.empty {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  font-style: italic;
}
.note-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: start;
}
.note-row .who {
  font-weight: 600;
  font-size: 12px;
  color: var(--accent-2);
  white-space: nowrap;
  align-self: center;
}
.note-row .body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}
.note-row .body.placeholder { color: var(--muted); font-style: italic; }
.pencil {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.pencil:hover { color: var(--accent-2); border-color: var(--accent-dim); }
.pencil svg { width: 14px; height: 14px; }
.note-edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-edit textarea {
  background: var(--bg-2);
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  resize: vertical;
  min-height: 60px;
  width: 100%;
  font: inherit;
}
.note-edit .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* === Admin spreadsheet view === */
.admin-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 8px 0 14px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.admin-bar .left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; flex: 1; }
.admin-bar .pending {
  background: var(--warn);
  color: #1c1100;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
}
.admin-bar .ok {
  color: var(--accent-2);
  font-size: 13px;
}

.sheet-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}
table.sheet {
  border-collapse: collapse;
  min-width: 100%;
  font-size: 13px;
}
table.sheet th, table.sheet td {
  border: 1px solid var(--border);
  padding: 0;
  vertical-align: top;
  min-width: 90px;
}
table.sheet th {
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 5;
  text-align: left;
  padding: 8px 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 700;
}
table.sheet td.id-cell {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  padding: 8px 10px;
  position: sticky;
  left: 0;
  z-index: 4;
  min-width: 48px;
}
table.sheet td .cell {
  display: block;
  padding: 8px 10px;
  min-height: 34px;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
  min-width: 110px;
}
table.sheet td .cell:focus {
  background: var(--bg-2);
  box-shadow: inset 0 0 0 2px var(--accent-dim);
}
table.sheet td.dirty .cell {
  background: rgba(224, 164, 74, .12);
}
table.sheet tr:hover td:not(.id-cell) { background: rgba(255,255,255,.015); }
.sheet-help { color: var(--muted); font-size: 13px; margin: 10px 4px 0; }

/* === Edit form (card pencil modal) === */
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.edit-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.edit-field .lbl {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 700;
}
.edit-field input,
.edit-field textarea,
.edit-field select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  font-size: 14px;
  font: inherit;
  width: 100%;
}
.edit-field textarea { resize: vertical; min-height: 60px; }
.edit-field input:focus,
.edit-field textarea:focus,
.edit-field select:focus {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent-dim);
}
