:root {
  --teal: #13544C;
  --teal-deep: #0D3B35;
  --mint: #33C9A8;
  --mint-pale: #E4F7F5;
  --mint-lightest: #F1FEFB;
  --orange: #FF9C4E;
  --ink: #1A1A1A;
  --gray: #6E7674;
  --gray-soft: #9AA3A1;
  --line: #E7EAE9;
  --surface: #FFFFFF;
  --canvas: #F7FAF9;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --radius: 20px;
  --radius-sm: 12px;
  --shell: 1360px;
  --shadow: 0 1px 2px rgba(16, 40, 36, .04), 0 8px 24px rgba(16, 40, 36, .05);
}

* { box-sizing: border-box; }

/* Class selectors below set display, which would otherwise beat the UA [hidden] rule. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Mona Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.022em; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 18px; line-height: 1.3; }
h3 { font-size: 15px; line-height: 1.3; }
p { margin: 0; }

.muted { color: var(--gray); font-size: 14px; line-height: 1.5; }
.error { color: #B3261E; font-size: 14px; line-height: 1.5; }
.info { color: var(--teal); font-size: 14px; line-height: 1.5; }

.shell {
  width: 100%;
  max-width: var(--shell);
  margin: 0 auto;
  padding-left: var(--s6);
  padding-right: var(--s6);
}

.stack { display: flex; flex-direction: column; gap: var(--s4); }
.row { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: center; }

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: inset -9px -9px 0 0 var(--mint);
  flex: 0 0 auto;
}

/* ---------------------------------------------------------------- controls */
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 18px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn.primary { background: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-deep); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--gray-soft); }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(51, 201, 168, .22);
}
select { appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%236E7674' stroke-width='1.8' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 13px center;
}

.segmented {
  display: inline-flex;
  gap: var(--s1);
  background: var(--mint-pale);
  border-radius: 999px;
  padding: var(--s1);
}
.segmented button {
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  border: 0;
  background: transparent;
  color: var(--teal);
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button.is-active { background: var(--surface); box-shadow: 0 1px 2px rgba(16, 40, 36, .08); }

.field { display: flex; flex-direction: column; gap: var(--s2); font-size: 13px; font-weight: 700; }
.field-inline { display: flex; align-items: center; gap: var(--s2); font-size: 14px; color: var(--gray); }
.field-inline select { width: auto; min-width: 168px; }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--s5); background: var(--mint-lightest); }
.login-card {
  width: 100%;
  max-width: 384px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.login-card h1 { margin-top: var(--s4); }
.login-card form { display: flex; flex-direction: column; gap: var(--s3); margin-top: var(--s5); }
.login-card label { font-size: 13px; font-weight: 700; }

/* ---------------------------------------------------------------- shell */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s5);
  min-height: 72px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: var(--s3); }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 16px; font-weight: 800; letter-spacing: -0.02em; }
.brand-text .muted { font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.user { font-size: 14px; color: var(--gray); padding: 0 var(--s2); }

.platform-nav { border-top: 1px solid var(--line); }
.platform-tabs { display: flex; gap: var(--s6); }
.platform-tabs button {
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--gray);
  padding: var(--s4) 0;
  margin-bottom: -1px;
  cursor: pointer;
}
.platform-tabs button:hover { color: var(--ink); }
.platform-tabs button.is-active { color: var(--ink); border-bottom-color: var(--mint); }

main { padding-top: var(--s6); padding-bottom: var(--s7); display: flex; flex-direction: column; gap: var(--s5); }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  min-height: 44px;
}
.toolbar-right { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s5);
}
.card-head { display: flex; flex-direction: column; gap: var(--s1); margin-bottom: var(--s5); }

.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: var(--s5); align-items: stretch; }
.account-card { display: flex; flex-direction: column; }
.account-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s5); min-height: 24px; }
.account-head .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.platform-icon { width: 19px; height: 19px; flex: 0 0 auto; display: block; }
.account-head h2 { font-size: 16px; }
.account-head .tag {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--gray);
  background: var(--canvas);
  border-radius: 999px;
  padding: 5px 11px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s4);
  /* A platform with one account gets a full-width card; without this the three
     numbers drift apart across 1300px and stop reading as a group. */
  max-width: 860px;
  padding-bottom: var(--s5);
  margin-bottom: var(--s5);
  border-bottom: 1px solid var(--line);
}
.metric { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.metric-label { font-size: 12px; font-weight: 700; color: var(--gray); text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.metric-foot { font-size: 12px; font-weight: 700; color: var(--gray-soft); min-height: 18px; }
.metric-foot.up { color: var(--teal); }
.metric-foot.down { color: #B3261E; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--teal);
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--mint-pale); border-color: var(--mint); }

.upload-context {
  align-self: flex-start;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal);
  background: var(--mint-pale);
  border-radius: 999px;
  padding: 6px 13px;
}

.chart-wrap { position: relative; height: 260px; margin-top: auto; }
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: var(--s4);
}
.chart-empty span {
  max-width: 240px;
  text-align: center;
  color: var(--gray-soft);
  font-size: 14px;
  line-height: 1.55;
}
.derived-note { font-size: 12px; color: var(--gray-soft); margin-top: var(--s3); }

/* ---------------------------------------------------------------- top posts */
.top-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: var(--s5); align-items: start; }
.top-col { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.top-col h3 { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s1); min-height: 30px; }
.top-col h3 .icon-btn { margin-left: var(--s1); }
.top-col h3 .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.top-col h3 .platform-icon { width: 17px; height: 17px; }

.post {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  grid-template-areas: "thumb body" "note note";
  gap: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--s4);
}
.post-thumb {
  grid-area: thumb;
  width: 96px;
  height: 96px;
  border-radius: 10px;
  background: var(--mint-pale);
  object-fit: cover;
  display: block;
}
.post-thumb.is-empty {
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 11px;
  color: var(--gray);
  padding: var(--s2);
  background: var(--canvas);
  border: 1px dashed var(--line);
}
.post-body { grid-area: body; min-width: 0; display: flex; flex-direction: column; gap: var(--s2); }
.post-rank {
  align-self: flex-start;
  background: var(--orange);
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  border-radius: 999px;
  padding: 3px 10px;
  line-height: 1.4;
}
.post-headline { font-weight: 700; font-size: 14px; line-height: 1.4; }
.post-stats { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: 12px; color: var(--gray); }
.post-stats span { display: flex; align-items: baseline; gap: var(--s1); }
.post-stats b { color: var(--ink); font-size: 13px; font-weight: 700; }
.post-meta { font-size: 12px; color: var(--gray-soft); }
.post-meta a { color: var(--teal); font-weight: 700; text-decoration: none; }
.post-meta a:hover { text-decoration: underline; }

.post-note { grid-area: note; display: flex; flex-direction: column; gap: var(--s2); }
.post-note-label { font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: var(--s2); }
.post-note textarea { min-height: 72px; resize: vertical; font-size: 13px; line-height: 1.5; }
.saved { font-size: 12px; font-weight: 700; color: var(--mint); }

.empty-note {
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: var(--s5);
  text-align: center;
  color: var(--gray-soft);
  font-size: 14px;
}

/* ---------------------------------------------------------------- modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(13, 59, 53, .45);
  display: grid;
  place-items: start center;
  padding: var(--s5);
  z-index: 30;
  overflow-y: auto;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s6);
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  margin: auto 0;
}
.modal-card.wide { max-width: 940px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); }

.review-post {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--s4);
}
.review-thumb { width: 84px; height: 84px; border-radius: 10px; background: var(--mint-pale); object-fit: cover; display: block; }
.review-thumb.is-empty {
  display: grid; place-items: center; text-align: center;
  font-size: 11px; color: var(--gray); background: var(--canvas); border: 1px dashed var(--line);
}
.review-post.has-clash { border-color: var(--orange); background: #FFF6EC; }
.review-body { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.check { display: flex; gap: var(--s2); align-items: center; font-size: 14px; font-weight: 700; }
.check input[type="checkbox"] { width: auto; }
.check .headline-input { flex: 1 1 auto; font-weight: 700; font-size: 14px; padding: 7px 11px; }
.candidates { display: flex; gap: var(--s2); flex-wrap: wrap; }
.cand {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--surface);
  cursor: pointer;
}
.cand.is-selected { border-color: var(--mint); background: var(--mint-pale); font-weight: 700; }
.review-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: var(--s2); }
.review-grid label { font-size: 11px; font-weight: 700; color: var(--gray); display: flex; flex-direction: column; gap: var(--s1); }
.review-grid input { padding: 8px 10px; font-size: 13px; }
.warn { background: #FFF6EC; border-radius: var(--radius-sm); padding: var(--s3) var(--s4); font-size: 13px; line-height: 1.5; }

@media (max-width: 900px) {
  .shell { padding-left: var(--s4); padding-right: var(--s4); }
  .account-grid, .top-grid { grid-template-columns: minmax(0, 1fr); }
  .platform-tabs { gap: var(--s5); }
}

@media (max-width: 560px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
  .post { grid-template-columns: minmax(0, 1fr); grid-template-areas: "thumb" "body" "note"; }
  .post-thumb { width: 100%; height: 168px; }
  .toolbar, .toolbar-right { flex-direction: column; align-items: stretch; }
}
