:root {
  --bg: #16131f;
  --surface: #211d2e;
  --surface-2: #2b2640;
  --line: #35304a;
  --text: #f2eff7;
  --muted: #a8a2bd;
  --accent: #ff4d6d;
  --accent-ink: #1a0a10;
  --violet: #6a58e0;
  --ok: #19d3b0;
  --bad: #ff8aa0;
  --display: "Bricolage Grotesque", "Arial Black", system-ui, sans-serif;
  --body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 860px; margin: 0 auto; padding: clamp(16px, 4vw, 40px) 20px 60px; }

h1, h2, h3 { font-family: var(--display); letter-spacing: -0.02em; line-height: 1.1; margin: 0; }
h1 { font-size: clamp(1.8rem, 5vw, 2.4rem); font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .92rem; }
.error { color: var(--bad); margin-top: 14px; }
.ok { color: var(--ok); margin-top: 14px; }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; border-radius: 6px; }

/* ----- Top bar and tabs ----- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 4px 0 18px; }
.brand { font-family: var(--display); font-size: 1.25rem; letter-spacing: -0.02em; }
.top-actions { display: flex; align-items: center; gap: 18px; }
.link { color: var(--muted); text-decoration: none; font-weight: 500; }
.link:hover { color: var(--text); }

.tabs { display: flex; gap: 8px; border-bottom: 1.5px solid var(--line); padding-bottom: 12px; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 600; color: var(--muted); background: transparent; cursor: pointer;
  border: 1.5px solid transparent; border-radius: 999px; padding: 8px 18px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); background: var(--surface); border-color: var(--line); }

.intro { margin: 28px 0 8px; }
.intro .muted { margin-top: 8px; max-width: 60ch; }
.intro .small { margin-top: 6px; }

/* ----- Cards and forms ----- */
.card {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 20px;
  padding: clamp(18px, 4vw, 28px); margin-top: 20px;
}
.card.narrow { max-width: 420px; margin: 12vh auto 0; }
.card h2 + .muted { margin-top: 6px; }
.card h1 { margin-bottom: 8px; }

label { display: block; margin: 16px 0 6px; font-weight: 500; font-size: .95rem; }
input, textarea {
  width: 100%; padding: 11px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 72px; }
input:focus-visible, textarea:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; border-color: transparent; }
input:invalid:not(:placeholder-shown) { border-color: var(--bad); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.field.wide { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: .88rem; margin-top: 6px; }
.group-title { margin-top: 26px; padding-top: 22px; border-top: 1.5px solid var(--line); }
.group-title + .muted { margin-top: 4px; }

.tile-row { padding-top: 6px; }
.tile-row + .tile-row { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 14px; }
.tile-row h3 { grid-column: 1 / -1; margin-top: 8px; }

/* ----- Country rows ----- */
.countries { display: grid; gap: 10px; margin-top: 14px; }
.country-row {
  display: grid; grid-template-columns: 1fr 96px 90px 40px; gap: 10px; align-items: center;
}
.country-row input { margin: 0; }
.mini-bar { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.mini-fill { display: block; height: 100%; width: 0; background: var(--violet); border-radius: 99px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--line);
  background: transparent; color: var(--muted); font: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.add-country { margin-top: 12px; }

/* ----- Buttons ----- */
.btn {
  margin-top: 22px; padding: 13px 24px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.small { padding: 9px 18px; font-size: .95rem; margin-top: 0; }
.btn.ghost { margin-top: 0; background: transparent; color: var(--text); border: 1.5px solid var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: var(--muted); filter: none; }
.btn:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; }
.add-country.btn { margin-top: 12px; }

/* ----- Sticky save bar ----- */
.savebar {
  position: sticky; bottom: 0; z-index: 5; margin-top: 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 14px 18px; border: 1.5px solid var(--line); border-radius: 18px;
  background: rgba(33, 29, 46, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.savebar p { margin: 0; font-size: .95rem; min-height: 1.4em; }
.savebar-actions { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.savebar .btn { margin-top: 0; padding: 11px 22px; }
.savebar .ok, .savebar .error { margin-top: 0; }
.dirty-dot { color: var(--accent); }

/* ----- Table ----- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.good { color: var(--ok); }
td.bad { color: var(--bad); }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .country-row { grid-template-columns: 1fr 84px 40px; }
  .country-row .mini-bar { display: none; }
}
