:root {
  --bg: #f6f4ef;
  --panel: #fffdfa;
  --ink: #1c1b19;
  --muted: #716c64;
  --line: #ded8cc;
  --accent: #14786f;
  --accent-2: #b43f35;
  --shadow: 0 20px 50px rgba(34, 28, 18, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button, input, select { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
}
button.secondary { background: #ece6db; color: var(--ink); }
.profile-link {
  color: inherit;
  text-decoration: none;
}
.profile-link:hover,
.profile-link:focus {
  color: inherit;
  text-decoration: none;
}
.hidden { display: none !important; }
.error { color: var(--accent-2); min-height: 20px; }
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 0; }
.brand {
  display: flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}
.brand img {
  display: block;
  height: auto;
  object-fit: contain;
}
.brand-login img {
  width: min(230px, 72vw);
}
.brand-sidebar img {
  width: 154px;
}
.brand-sidebar {
  width: fit-content;
}
.brand-sidebar:hover,
.brand-sidebar:focus {
  color: inherit;
  text-decoration: none;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 18px;
}
.login-panel h1 { margin: 0; font-size: 36px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 14px; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 26px 18px;
  background:
    linear-gradient(180deg, rgba(5, 87, 43, 0.06), rgba(5, 87, 43, 0) 230px),
    #fffdfa;
  border-right: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-content: start;
  gap: 26px;
}
.sidebar h1 { margin: 0; font-size: 30px; }
.sidebar .eyebrow { color: var(--accent); }
nav {
  display: grid;
  align-content: start;
  gap: 6px;
}
.nav {
  text-align: left;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 700;
  padding: 11px 12px;
}
.nav.active {
  background: #07572b;
  border-color: #07572b;
  color: white;
  box-shadow: 0 10px 22px rgba(5, 87, 43, 0.14);
}
.nav:hover:not(.active) {
  background: rgba(5, 87, 43, 0.07);
  color: #07572b;
}
.sidebar #logout {
  justify-self: start;
}
.content { min-width: 0; padding: 28px; }
.standalone-report .app {
  display: block;
}
.standalone-report .sidebar {
  display: none;
}
.standalone-report .content {
  margin: 0 auto;
  max-width: 1680px;
  padding: 28px;
}
.standalone-report .topbar {
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  padding-bottom: 18px;
}
.standalone-brand-link {
  display: inline-flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}
.standalone-brand-link img {
  display: block;
  height: auto;
  width: min(180px, 48vw);
}
.standalone-layout {
  display: grid;
  gap: 14px;
}
.standalone-person-detail {
  padding: 18px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.topbar h2 { margin: 0 0 4px; font-size: 28px; }
.topbar p { margin: 0; color: var(--muted); }
.controls { display: flex; gap: 10px; align-items: center; }
.controls select { min-width: 160px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(34, 28, 18, 0.04);
}
.kpi span { color: var(--muted); font-size: 13px; }
.kpi strong { display: block; font-size: 26px; margin-top: 6px; }
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.panel h3 { margin: 0 0 12px; font-size: 16px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}
th { color: var(--muted); font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.people-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.person-picker {
  padding: 14px 16px;
}
.person-picker-row {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(360px, 630px) auto;
  justify-content: start;
}
.person-picker label {
  grid-template-columns: 110px minmax(260px, 520px);
  align-items: center;
}
.person-picker-row .secondary {
  min-width: 104px;
  white-space: nowrap;
}
.correction-panel {
  margin-bottom: 14px;
}
.correction-panel label {
  grid-template-columns: 110px minmax(260px, 520px);
  align-items: center;
}
.correction-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.correction-head h3,
.correction-head p {
  margin: 0;
}
.correction-head p,
.correction-head span,
.muted-line {
  color: var(--muted);
}
.empty-chart-note {
  margin: 52px 0 0;
}
.paste-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
}
.paste-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}
.paste-grid label {
  display: grid;
  gap: 8px;
}
.paste-panel textarea {
  min-height: 120px;
  resize: vertical;
}
.paste-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  min-height: 36px;
}
.excluded-panel {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
}
.excluded-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.edit-table-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}
.edit-table input {
  width: 112px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.edit-table button {
  white-space: nowrap;
}
.edit-table.transposed th:first-child {
  left: 0;
  min-width: 190px;
  position: sticky;
  z-index: 1;
}
.edit-table.transposed tbody th:first-child {
  background: var(--panel);
}
.edit-table.transposed thead th:first-child {
  background: var(--panel);
  z-index: 2;
}
.edit-table.transposed .month-col {
  min-width: 128px;
}
.edit-table.transposed .save-row td {
  border-bottom: 0;
  padding-top: 14px;
}
.edit-table.transposed .remove-row th,
.edit-table.transposed .remove-row td {
  border-bottom: 0;
  padding-top: 4px;
}
button.danger {
  color: #f97373;
}
.chart {
  height: 220px;
  display: flex;
  align-items: end;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-top: 12px;
}
.bar {
  flex: 1;
  min-width: 10px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  position: relative;
}
.bar span {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.post-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(326px, 1fr));
  gap: 14px;
  align-items: start;
}
.post-column {
  min-width: 0;
  display: grid;
  gap: 14px;
  align-content: start;
}
.post-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}
.post-item a { color: var(--accent); text-decoration: none; }
.embed-card {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 8px;
  width: 100%;
}
.embed-card .instagram-media {
  max-width: 540px !important;
  min-width: 326px !important;
  width: 100% !important;
  margin: 0 !important;
}
.post-meta {
  width: min(100%, 540px);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.report-profile {
  display: grid;
  grid-template-columns: 112px minmax(280px, 1.55fr) repeat(3, minmax(104px, 0.7fr)) repeat(3, minmax(210px, 1.05fr));
  gap: 10px;
  align-items: center;
  margin-bottom: 22px;
}
.avatar {
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 999px;
  background: #24211d;
  color: white;
  font-size: 42px;
  font-weight: 800;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hero-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-rows: 34px auto;
  min-height: 112px;
  padding: 14px 16px;
}
.hero-card span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hero-card strong {
  align-self: end;
  display: block;
  font-size: 30px;
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.identity-card strong {
  font-size: 28px;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.period-stats {
  display: contents;
}
.activity-stats {
  display: grid;
  grid-column: 2 / -1;
  grid-template-columns: minmax(220px, 1.35fr) minmax(210px, 1.15fr) minmax(210px, 1.15fr) minmax(180px, 1fr) repeat(2, minmax(150px, 0.95fr));
  gap: 10px;
}
.ai-summary {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  padding: 16px;
}
.overview-ai-summary {
  background:
    linear-gradient(135deg, rgba(5, 87, 43, 0.06), rgba(5, 87, 43, 0) 48%),
    white;
}
.ai-summary.empty {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}
.ai-summary h3,
.ai-summary h4,
.ai-summary p {
  margin: 0;
}
.ai-summary-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}
.ai-summary-head h3 {
  font-size: 18px;
}
.ai-summary-head span,
.ai-summary.empty p {
  color: var(--muted);
  font-size: 13px;
}
.ai-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ai-summary section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.ai-summary h4 {
  font-size: 14px;
  margin-bottom: 8px;
}
.ai-summary p {
  color: var(--muted);
  line-height: 1.5;
}
.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.report-chart {
  min-width: 0;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  padding: 16px;
}
.report-chart h3 {
  margin: 0 0 12px;
  text-align: center;
}
.bars {
  min-height: 178px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 26px 0 24px;
}
.bar-wrap {
  min-width: 0;
  flex: 1;
  display: grid;
  align-items: end;
  justify-items: center;
  gap: 5px;
}
.bar-value {
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}
.bar-wrap span {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.report-bar {
  width: 100%;
  min-width: 18px;
  max-width: 52px;
  border-radius: 4px 4px 0 0;
  position: relative;
}
.report-bar.negative {
  opacity: 0.85;
}
.report-lower {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.post-bars .report-bar {
  max-width: 90px;
}
.summary-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 12px;
  align-content: center;
}
.summary-metrics div {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}
.summary-metrics span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}
.summary-metrics strong {
  font-size: 28px;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 16px;
    padding: 18px;
  }
  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sidebar #logout {
    justify-self: stretch;
  }
  .topbar { align-items: stretch; flex-direction: column; }
  .kpis, .grid, .people-layout, .report-grid, .report-lower, .report-profile, .post-list, .ai-summary-grid { grid-template-columns: 1fr; }
  .period-stats {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }
  .activity-stats {
    grid-column: auto;
    grid-template-columns: 1fr;
  }
  .person-picker-row { grid-template-columns: 1fr; }
  .person-picker label { grid-template-columns: 1fr; }
  .ai-summary.empty {
    grid-template-columns: 1fr;
  }
  .report-chart {
    padding: 16px 12px;
  }
  .report-chart h3 {
    font-size: 22px;
  }
  .bars {
    gap: 10px;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 36px 2px 28px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .bars::-webkit-scrollbar {
    height: 4px;
  }
  .bars::-webkit-scrollbar-thumb {
    background: rgba(113, 108, 100, 0.35);
    border-radius: 999px;
  }
  .bar-wrap {
    flex: 0 0 58px;
    min-width: 58px;
    scroll-snap-align: start;
  }
  .bar-value {
    font-size: 12px;
  }
  .bar-wrap span {
    font-size: 13px;
  }
  .report-bar {
    max-width: 48px;
  }
  .post-bars .bar-wrap {
    flex-basis: 70px;
    min-width: 70px;
  }
}
