:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #687269;
  --line: #dce4da;
  --green: #1f7a4d;
  --green-dark: #145637;
  --amber: #b66a16;
  --red: #b83a35;
  --blue: #2f67b1;
  --shadow: 0 18px 48px rgba(23, 32, 27, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  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;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #17201b;
  color: #fff;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand span,
.eyebrow,
.metric span,
.settings label,
.small-muted {
  color: var(--muted);
  font-size: 12px;
}

.sidebar .brand span {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.6);
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 34px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
}

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

.nav-item svg,
.button svg,
.search-field svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.04;
}

h2 {
  font-size: 20px;
}

.actions,
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button,
.icon-check {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
}

.button:disabled,
.icon-check:disabled {
  cursor: wait;
  opacity: 0.65;
}

.button.primary {
  color: #fff;
  background: var(--green);
}

.button.primary:hover {
  background: var(--green-dark);
}

.button.secondary,
.button.ghost {
  color: var(--ink);
  background: var(--panel);
  border-color: var(--line);
}

.button.ghost {
  background: transparent;
}

.status-panel,
.rank-sync,
.metrics,
.toolbar,
.settings,
.table-shell,
.instagram-panel,
.history {
  margin-top: 18px;
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border: 1px solid #edc47f;
  border-radius: 8px;
  background: #fff8e9;
}

.status-panel p {
  margin: 4px 0 0;
  color: #6f5225;
}

.rank-sync {
  display: flex;
  justify-content: flex-end;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
  line-height: 1;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) repeat(4, minmax(130px, 180px));
  gap: 10px;
}

.search-field,
.settings label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.search-field {
  padding: 0 12px;
}

input,
select {
  min-width: 0;
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--panel);
}

.search-field input {
  border: 0;
  padding: 0;
  outline: 0;
}

.settings {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
}

.settings label {
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding: 8px 10px 10px;
}

.settings input {
  height: 28px;
  border: 0;
  padding: 0;
  outline: 0;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f9faf7;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td {
  font-size: 14px;
}

.query-cell strong,
.url-cell a {
  display: block;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.query-cell span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.rank-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rank {
  display: inline-flex;
  min-width: 58px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 800;
  background: #eef3ed;
}

.rank.top {
  color: var(--green-dark);
  background: #dff2e6;
}

.rank.mid {
  color: #69420f;
  background: #ffefcb;
}

.rank.miss {
  color: var(--red);
  background: #ffe4e1;
}

.icon-check {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-color: var(--line);
  background: #fff;
}

.icon-check:hover {
  border-color: rgba(31, 122, 77, 0.35);
  color: var(--green);
}

.icon-check.danger:hover {
  border-color: rgba(184, 58, 53, 0.35);
  color: var(--red);
}

.history {
  padding-bottom: 40px;
}

.instagram-panel {
  scroll-margin-top: 20px;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title.compact {
  align-items: flex-end;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.sync-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.sync-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.sync-pill {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--green-dark);
  background: #dff2e6;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.account-card,
.ig-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.account-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  padding: 18px;
}

.account-card h3,
.ig-block h3 {
  margin: 0;
  letter-spacing: 0;
}

.account-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.account-role {
  display: inline-flex;
  margin-bottom: 7px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.account-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, 1fr));
  gap: 10px;
  margin: 0;
}

.account-card .button {
  align-self: flex-start;
}

.account-card dt {
  color: var(--muted);
  font-size: 12px;
}

.account-card dd {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 800;
}

.instagram-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 14px;
  margin-top: 14px;
}

.ig-block {
  padding: 16px;
}

.instagram-panel > .ig-block {
  margin-top: 14px;
}

.ig-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.ig-form fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ig-form legend {
  padding: 0 5px;
  font-weight: 800;
}

.ig-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.ig-form input,
.table-shell.mini input,
.table-shell.mini select {
  height: 34px;
  font-size: 13px;
}

.audit-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.audit-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border-radius: 8px;
  background: #f7f8f5;
}

.audit-item svg {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.audit-item.ok svg {
  color: var(--green);
}

.audit-item.warn svg {
  color: var(--amber);
}

.audit-item span,
.row-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.table-shell.mini {
  margin-top: 12px;
  box-shadow: none;
}

.table-shell.mini table {
  min-width: 1040px;
}

.table-shell.mini td {
  padding: 8px 10px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 90px;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.history-item span {
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #17201b;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  body {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 18px;
  }

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

  .metrics,
  .toolbar,
  .settings,
  .sync-panel,
  .account-grid,
  .instagram-grid {
    grid-template-columns: 1fr 1fr;
  }

  .account-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .main {
    padding: 18px;
  }

  .actions,
  .metrics,
  .toolbar,
  .settings,
  .sync-panel,
  .account-grid,
  .instagram-grid,
  .ig-form,
  .ig-form fieldset,
  .history-item {
    grid-template-columns: 1fr;
  }

  .actions {
    display: grid;
  }

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