:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #657168;
  --line: #dfe6dd;
  --blue: #2866d8;
  --green: #1f8a5b;
  --red: #c44135;
  --amber: #b46a16;
  --teal: #127b7f;
  --purple: #6d4fc2;
  --shadow: 0 14px 40px rgba(31, 40, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: #1a1033;
  color: #f7f6fb;
}

.brand,
.sync-panel {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #9b73f5;
  color: #1a1033;
  font-weight: 850;
}

.brand strong,
.sync-panel strong {
  display: block;
}

.brand span:last-child,
.sync-panel span:last-child {
  display: block;
  color: #b4aed8;
  font-size: 0.86rem;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-list a {
  color: #d8d3f0;
  padding: 12px 14px;
  border-radius: 8px;
  text-decoration: none;
}

.nav-list a:hover,
.nav-list a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sync-panel {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.sync-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #44d07b;
  box-shadow: 0 0 0 6px rgba(68, 208, 123, 0.14);
  flex-shrink: 0;
}

.main {
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--purple);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 3.2rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.05rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

select,
.icon-button,
.segmented button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

select {
  padding: 0 34px 0 12px;
}

.icon-button {
  width: 42px;
  font-size: 1.1rem;
  cursor: pointer;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.metric-tile,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-tile {
  padding: 16px;
}

.metric-tile span,
.metric-tile small {
  display: block;
  color: var(--muted);
}

.metric-tile strong {
  display: block;
  margin: 8px 0 2px;
  font-size: 2rem;
  letter-spacing: 0;
}

.new-comments-tile {
  border-color: rgba(109, 79, 194, 0.36);
  background: #f8f5ff;
}

.new-comments-tile.has-comments {
  border-color: rgba(109, 79, 194, 0.7);
  background: #f0eaff;
}

.new-comments-tile strong {
  color: var(--purple);
}

.content-grid {
  display: grid;
  align-items: stretch;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.72fr);
  gap: 14px;
  grid-auto-rows: auto;
}

.panel {
  min-width: 0;
  min-height: 0;
  padding: 18px;
}

.panel.full-span {
  grid-column: 1 / -1;
}

.chart-panel {
  grid-column: 1;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf6;
  font-size: 0.85rem;
}

.segmented button {
  min-height: 32px;
  border: 0;
  padding: 0 10px;
  background: transparent;
  cursor: pointer;
}

.segmented button.active {
  background: var(--panel);
  box-shadow: 0 2px 9px rgba(31, 40, 34, 0.08);
}

.chart-grid {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.chart-card {
  position: relative;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.trend-card {
  contain: inline-size;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.chart-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-title strong {
  font-size: 0.95rem;
}

.chart-title span {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.chart-tooltip {
  position: fixed;
  z-index: 20;
  max-width: 220px;
  padding: 8px 10px;
  border: 1px solid rgba(23, 32, 27, 0.16);
  border-radius: 8px;
  background: rgba(23, 32, 27, 0.94);
  color: #ffffff;
  box-shadow: 0 10px 28px rgba(23, 32, 27, 0.22);
  font-size: 0.82rem;
  pointer-events: none;
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
}

.chart-tooltip span {
  color: #dbe5dd;
}

.chart-card canvas {
  height: clamp(210px, 26vw, 250px);
}

#alerts {
  display: flex;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
}

#alerts .panel-header {
  flex: 0 0 auto;
}

.alert-list {
  display: grid;
  flex: 1 1 0;
  align-content: start;
  gap: 10px;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow-y: scroll;
  padding-right: 4px;
}

.alert-item {
  display: grid;
  gap: 4px;
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  background: #fbfcfa;
}

.alert-item.critical {
  border-left-color: var(--red);
  background: #fff8f6;
}

.alert-item strong {
  font-size: 0.95rem;
}

.alert-item .alert-account {
  color: var(--purple);
  font-size: 0.82rem;
  font-weight: 700;
}

.alert-item span {
  color: #3f4a43;
  font-size: 0.92rem;
  line-height: 1.45;
}

/* Posts & comments tables */
.table-wrap {
  max-height: 480px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

th,
td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fbfcfa;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  text-transform: inherit;
  cursor: pointer;
}

.sort-button::after {
  content: "";
  width: 0;
  height: 0;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  opacity: 0;
}

.sort-button.active {
  color: #17201b;
}

.sort-button.active[data-direction="asc"]::after {
  border-bottom: 6px solid currentColor;
  opacity: 0.9;
}

.sort-button.active[data-direction="desc"]::after {
  border-top: 6px solid currentColor;
  opacity: 0.9;
}

.post-caption {
  max-width: 340px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-caption a {
  color: inherit;
  text-decoration: none;
}

.post-caption a:hover {
  text-decoration: underline;
}

.platform-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.platform-pill.facebook {
  background: #e7eeff;
  color: #1a4db0;
}

.platform-pill.instagram {
  background: #fde8f3;
  color: #9d1b6e;
}

.media-type-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #eef2ec;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

/* Comment list */
.comment-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 4px;
}

.comment-card {
  display: grid;
  gap: 6px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.comment-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.comment-author {
  font-weight: 700;
  font-size: 0.9rem;
}

.comment-time {
  color: var(--muted);
  font-size: 0.82rem;
}

.comment-body {
  color: #3f4a43;
  font-size: 0.95rem;
  line-height: 1.5;
}

.comment-post-ref {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}

/* Account table status */
.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #edf7ef;
  color: #1d6a41;
  font-size: 0.82rem;
  font-weight: 700;
}

.status-pill.down {
  background: #fff3df;
  color: #8b4e08;
}

.status-pill.growth {
  background: #e7f5ed;
  color: #197145;
}

.status-pill.surge {
  background: #ede8ff;
  color: #4d2fa0;
}

.delta-up {
  color: var(--green);
  font-weight: 750;
}

.delta-down {
  color: var(--red);
  font-weight: 750;
}

.neutral {
  color: var(--muted);
}

/* Settings panel */
.data-panel {
  margin-top: 14px;
}

.integration-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr);
  gap: 12px;
}

.integration-grid > div {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.integration-grid span {
  color: var(--muted);
  line-height: 1.45;
}

.token-expiry {
  padding: 6px 10px;
  border-radius: 6px;
  background: #fff3df;
  color: #8b4e08;
  font-size: 0.88rem;
}

.data-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 12px;
}

.integration-grid .data-action {
  display: grid;
  align-content: space-between;
  gap: 14px;
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.data-action strong,
.data-action span {
  display: block;
}

.data-action span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-manager {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.site-manager-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.site-manager-header strong,
.site-manager-header span {
  display: block;
}

.site-manager-header span {
  color: var(--muted);
  font-size: 0.9rem;
}

.site-manager-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.site-toggle {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.site-toggle input {
  margin-top: 3px;
}

.site-toggle span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.site-toggle strong,
.site-toggle small {
  overflow-wrap: anywhere;
}

.site-toggle small {
  color: var(--muted);
}

.connect-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 750;
  text-decoration: none;
}

button.connect-link {
  border: 0;
  cursor: pointer;
}

button.connect-link:disabled {
  cursor: wait;
  opacity: 0.72;
}

.hidden {
  display: none !important;
}

code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #eef2ec;
}

@media (max-width: 1160px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    grid-column: 1;
  }

  .integration-grid {
    grid-template-columns: 1fr;
  }

  .data-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    gap: 12px;
    padding: 14px;
  }

  .nav-list {
    display: flex;
    gap: 8px;
    margin-inline: -2px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav-list a {
    flex: 0 0 auto;
    min-width: 118px;
    padding: 10px 12px;
    text-align: center;
    white-space: nowrap;
  }

  .sync-panel {
    margin-top: 0;
    padding: 12px;
  }

  .main {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    padding: 14px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar .icon-button {
    width: 100%;
  }

  .toolbar select {
    width: 100%;
    min-width: 0;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .metric-tile {
    padding: 14px;
  }

  .metric-tile strong {
    font-size: 1.75rem;
  }

  .panel {
    padding: 14px;
  }

  .chart-card {
    padding: 10px;
  }

  .trend-card {
    max-width: 100%;
    overflow-x: auto;
  }

  .chart-card canvas {
    height: 220px;
  }

  .trend-card canvas {
    width: 680px;
    max-width: none;
    min-width: 680px;
  }

  table {
    min-width: 680px;
  }

  .alert-list {
    height: auto;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .comment-list {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}
