/* ============================================================
   CSS VARIABLES
   ============================================================ */
:root {
  --bg:             #f8f7ff;
  --surface:        #ffffff;
  --surface-alt:    #f2f1fb;
  --surface-raised: #ffffff;
  --text:           #1c1b2e;
  --text-2:         #3d3c52;
  --muted:          #6b6a8e;
  --line:           #e4e3f4;
  --line-strong:    #c8c7e0;
  --accent:         #6366f1;
  --accent-hover:   #4f46e5;
  --accent-soft:    rgba(99,102,241,0.10);
  --accent-2:       #8b5cf6;
  --good:           #10b981;
  --warn:           #f59e0b;
  --gear-bg:        #f8f7ff;
  --unseen-bg:  rgba(99,102,241,0.07);
  --card-shadow:    0 1px 3px rgba(99,102,241,0.08), 0 4px 12px rgba(99,102,241,0.06);
  --card-shadow-hover: 0 4px 16px rgba(99,102,241,0.18);
  --toast-bg:       #1c1b2e;
  --toast-text:     #ffffff;
}

[data-theme="dark"] {
  --bg:             #0f0e1a;
  --surface:        #1a192e;
  --surface-alt:    #201e36;
  --surface-raised: #23213a;
  --text:           #f0efff;
  --text-2:         #c4c3e0;
  --muted:          #9b9abb;
  --line:           #2d2b4a;
  --unseen-bg:  rgba(129,140,248,0.12);
  --line-strong:    #3d3b5c;
  --accent:         #818cf8;
  --accent-hover:   #6366f1;
  --accent-soft:    rgba(129,140,248,0.12);
  --accent-2:       #a78bfa;
  --gear-bg:        #1a192e;
  --card-shadow:    0 1px 3px rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.3);
  --card-shadow-hover: 0 4px 20px rgba(129,140,248,0.25);
  --toast-bg:       #f0efff;
  --toast-text:     #1c1b2e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: "Inter", "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   APP SHELL — Phone Frame
   ============================================================ */
.app-shell {
  width: min(430px, 100vw);
  height: min(900px, 100dvh);
  height: min(900px, 100svh);
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  position: relative;   /* overlays positioned relative to this */
  overflow: hidden;     /* clip slide-out overlays */
  border-radius: 0;
  isolation: isolate;   /* new stacking context */
}

@media (min-width: 431px) and (min-height: 500px) {
  .app-shell {
    border-radius: 14px;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255,255,255,0.1);
  }
}

@media (max-width: 430px) {
  body {
    align-items: flex-start;
  }
  .app-shell {
    height: 100dvh;
    height: 100svh;
  }
}

/* ============================================================
   TOP BAR
   ============================================================ */
.insta-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 44px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--surface);
  position: relative;
  z-index: 1;
}

.insta-logo {
  font-family: "Fraunces", serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ============================================================
   BOTTOM NAVIGATION
   ============================================================ */
.bottom-nav {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--surface);
  position: relative;
  z-index: 1;
}

.nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  transition: opacity 0.15s;
  position: relative;
  opacity: 0.5;
}

.nav-btn.active {
  opacity: 1;
}
.nav-btn.active::after {
  content: "";
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.nav-btn:active {
  transform: scale(0.9);
}
.nav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}
@media (hover: hover) {
  .nav-btn:hover {
    background: var(--surface-alt);
    border-radius: 8px;
  }
}

.nav-icon {
  line-height: 1;
}

.nav-dot {
  position: absolute;
  top: 4px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--surface);
}

.notif-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 5px;
  min-width: 18px;
  text-align: center;
  line-height: 16px;
}

/* ============================================================
   PAGES
   ============================================================ */
.page {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

.page.active {
  display: flex;
}

.page-section-header {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--line);
}

.page-section-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

/* ============================================================
   STORIES BAR
   ============================================================ */
.stories-bar {
  display: flex;
  gap: 12px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.stories-bar::-webkit-scrollbar {
  display: none;
}

.story-circle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.story-circle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 50%;
}
@media (hover: hover) {
  .story-circle:hover .story-ring {
    transform: scale(1.05);
    transition: transform 0.15s;
  }
}

.story-ring {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 2px;
  background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
}

.story-ring.seen {
  background: var(--line);
}

.story-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

.story-name {
  font-size: 0.7rem;
  color: var(--text);
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.stories-empty {
  padding: 16px 0;
  font-size: 0.82rem;
}

/* ============================================================
   INSTAGRAM-STYLE FEED
   ============================================================ */
.insta-feed {
  flex: 1;
}

.feed-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.insta-post {
  border-bottom: 1px solid var(--line);
  animation: appear 0.4s ease;
}

.insta-post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.avatar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
}
.avatar-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  flex-shrink: 0;
}

.avatar-lg {
  width: 44px;
  height: 44px;
  font-size: 1.1rem;
}

.avatar-xl {
  width: 80px;
  height: 80px;
  font-size: 2rem;
}

.post-author-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.post-username {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
}

.post-topic {
  font-size: 0.72rem;
}

.insta-post-media {
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface-alt);
  overflow: hidden;
  position: relative;
}

.insta-post-media .media-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.insta-post-media .media-skeleton {
  width: 100%;
  height: 100%;
  min-height: unset;
  border-radius: 0;
}

.insta-post-media .media-skeleton--error {
  border-radius: 0;
}

.insta-post-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 4px;
}

.action-left {
  display: flex;
  gap: 14px;
}

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.4rem;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  line-height: 1;
  border-radius: 8px;
}
.action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.action-btn:active {
  transform: scale(0.85);
}

.action-btn.liked {
  filter: hue-rotate(0deg);
  animation: heartPop 0.35s ease;
}

.insta-post-info {
  padding: 2px 12px 12px;
  color: var(--text);
}

.likes-count {
  font-size: 0.86rem;
  margin-bottom: 3px;
  color: var(--text);
}

.caption {
  font-size: 0.86rem;
  line-height: 1.4;
  margin-bottom: 4px;
  word-break: break-word;
  color: var(--text);
}

.caption strong {
  font-weight: 700;
  color: var(--text);
}

.view-comments-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0;
  font: inherit;
}
.view-comments-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (hover: hover) {
  .view-comments-btn:hover {
    color: var(--text);
  }
}

.heart-bubble {
  position: absolute;
  right: 14px;
  top: 14px;
  font-size: 1.6rem;
  animation: heartUp 0.95s ease forwards;
  pointer-events: none;
  z-index: 2;
}

/* ============================================================
   EXPLORE GRID
   ============================================================ */
.explore-header {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--line);
}

.explore-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.explore-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
}

.grid-item {
  aspect-ratio: 1;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  position: relative;
}
.grid-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.grid-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.15s;
}

.grid-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-placeholder-icon {
  font-size: 1.5rem;
  opacity: 0.75;
}

.grid-empty {
  grid-column: 1/-1;
  padding: 40px 20px;
  text-align: center;
}

/* ============================================================
   ACTIVITY / NOTIFICATIONS
   ============================================================ */
.activity-list {
  flex: 1;
  padding: 8px 0;
}

.notif-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  animation: appear 0.3s ease;
}

.notif-item.unseen {
  background: var(--unseen-bg);
}

.notif-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.notif-text {
  flex: 1;
  font-size: 0.86rem;
}

.notif-tick {
  font-size: 0.72rem;
  flex-shrink: 0;
}

.notif-empty {
  padding: 40px 20px;
  text-align: center;
  font-size: 0.9rem;
}

/* ============================================================
   PROFILE PAGE
   ============================================================ */
.profile-page-content {
  flex: 1;
}

.profile-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.profile-header h2 {
  font-size: 1.1rem;
  margin-bottom: 2px;
}

.agents-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 12px;
}

.agent-profile-card {
  background: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  transition: box-shadow 0.18s, transform 0.18s;
  padding: 14px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  transition: background 0.15s;
}

@media (hover: hover) {
  .agent-profile-card:hover {
    background: var(--bg);
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-2px);
  }
}
.agent-profile-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.agent-profile-card strong {
  font-size: 0.86rem;
}

.agent-profile-card .meta {
  font-size: 0.75rem;
}

.agent-stats {
  display: flex;
  gap: 8px;
  font-size: 0.72rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ============================================================
   GEAR PANEL
   ============================================================ */
.gear-panel {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.gear-panel:not(.hidden) {
  transform: translateX(0);
}

.gear-panel.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.gear-inner {
  flex: 1;
  overflow-y: auto;
  background: var(--gear-bg);
  display: flex;
  flex-direction: column;
  gap: 0;
  -webkit-overflow-scrolling: touch;
}

.gear-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.gear-section:last-child {
  border-bottom: none;
  padding-bottom: 32px;
}

.gear-section h3 {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
}

.sim-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

/* ============================================================
   COMMENT SHEET
   ============================================================ */
.comment-sheet {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.comment-sheet.hidden {
  pointer-events: none;
  opacity: 0;
}

.comment-sheet:not(.hidden) {
  opacity: 1;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 0;
  cursor: pointer;
}

.sheet-card {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  max-height: 70%;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.comment-sheet.hidden .sheet-card {
  transform: translateY(100%);
}

.sheet-handle-bar {
  width: 36px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.sheet-header {
  padding: 4px 16px 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.comment-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
}

.comment-item {
  margin-bottom: 12px;
  animation: appear 0.3s ease;
}

.comment-author {
  font-size: 0.82rem;
  margin-bottom: 2px;
}

.comment-author strong {
  font-weight: 700;
}

.comment-text {
  font-size: 0.86rem;
  line-height: 1.4;
}

.comment-reply {
  margin-top: 6px;
  padding-left: 14px;
  border-left: 3px solid var(--accent-soft);
  font-size: 0.82rem;
  color: var(--muted);
}

.comment-empty {
  padding: 20px 0;
  font-size: 0.86rem;
  text-align: center;
}

/* ============================================================
   STORY VIEWER
   ============================================================ */
.story-viewer {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: #000;
  display: flex;
  flex-direction: column;
}

.story-viewer.hidden {
  display: none;
}

.story-progress-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255,255,255,0.5);
  z-index: 2;
}

.story-progress-fill {
  height: 100%;
  background: #fff;
  transition: width 5s linear;
}

.story-viewer-header {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 3;
}

.story-viewer-author {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 0.86rem;
  font-weight: 700;
}

.story-close-btn {
  color: #fff;
  font-size: 1.1rem;
}

.story-tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  z-index: 4;
  cursor: pointer;
}

.story-tap-left {
  left: 0;
}

.story-tap-right {
  right: 0;
}

.story-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.story-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 16px 24px;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  z-index: 3;
}

.story-caption {
  color: #fff;
  font-size: 0.9rem;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
  margin-top: 4px;
}

/* ============================================================
   PROFILE MODAL
   ============================================================ */
.profile-modal {
  position: absolute;
  inset: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
}

.profile-modal.hidden {
  display: none;
}

.profile-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  cursor: pointer;
}

.profile-modal-card {
  position: relative;
  flex: 1;
  background: var(--surface);
  color: var(--text);
  margin-top: 44px;
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  max-height: calc(100% - 44px);
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.profile-close-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 1;
}

.profile-modal-content {
  padding-bottom: 32px;
}

.profile-modal-header {
  display: flex;
  gap: 16px;
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--line);
}

.profile-modal-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-modal-info h3 {
  font-size: 1rem;
  font-weight: 700;
}

.profile-stats {
  display: flex;
  gap: 16px;
  margin-top: 4px;
}

.profile-stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.profile-stats strong {
  font-size: 0.9rem;
}

.profile-post-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
}

/* ============================================================
   SHARED UTILITY
   ============================================================ */
.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--surface);
}

.overlay-header h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.overlay-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 8px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 8px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (hover: hover) {
  .icon-btn:hover {
    background: var(--surface-alt);
  }
  .icon-btn:active {
    transform: scale(0.92);
  }
}

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

.badge {
  text-transform: uppercase;
  font-size: 0.68rem;
  border-radius: 999px;
  background: rgba(0, 149, 246, 0.12);
  color: var(--accent-2);
  padding: 0.15rem 0.45rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  display: inline-block;
}

.hidden {
  display: none !important;
}

/* ============================================================
   GEAR PANEL — LEGACY CONTROL STYLES
   ============================================================ */
.control-row {
  display: grid;
  grid-template-columns: 90px 1fr 48px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

label {
  font-size: 0.82rem;
  color: var(--muted);
}

input[type="range"] {
  accent-color: var(--accent-2);
}

.button-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0;
}

button,
select,
input {
  font: inherit;
}

textarea {
  font: inherit;
  resize: vertical;
}

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.55rem;
  background: var(--surface-raised);
  color: var(--text);
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  transition: opacity 0.15s, transform 0.1s;
}

button.primary:hover {
  opacity: 0.92;
}

button.primary:active {
  transform: scale(0.98);
}

#agent-form {
  display: grid;
  gap: 8px;
}

#settings-form {
  display: grid;
  gap: 8px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--muted);
}

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

.debug-feed-list {
  overflow: auto;
  max-height: 260px;
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.agent-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.agent-head {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}

.feed-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.post {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  animation: appear 0.4s ease;
  cursor: pointer;
  position: relative;
}

.post p {
  margin: 4px 0;
  font-size: 0.84rem;
}

.post-media {
  width: 100%;
  border-radius: 8px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-bottom: 4px;
  color: #fff;
  padding: 0.5rem 0.6rem;
}

.media-image {
  width: 100%;
  height: 100%;
  min-height: 100px;
  border-radius: 8px;
  object-fit: cover;
}

.post-foot {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
}

.insights-list {
  list-style: none;
  display: grid;
  gap: 5px;
}

.insights-list li {
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 0.82rem;
}

.super-log-list {
  list-style: none;
  display: grid;
  gap: 4px;
  max-height: 180px;
  overflow: auto;
  margin-top: 6px;
}

.super-log-list li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.78rem;
}

.chat-list {
  display: grid;
  gap: 5px;
  max-height: 220px;
  overflow: auto;
  margin-bottom: 8px;
}

.chat-msg {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 6px 8px;
  font-size: 0.84rem;
}

.chat-msg.me {
  border-left: 3px solid var(--accent-2);
}

.chat-msg.bot {
  border-left: 3px solid var(--accent);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.image-error-list {
  list-style: none;
  display: grid;
  gap: 4px;
  max-height: 180px;
  overflow: auto;
  margin-top: 8px;
}

.image-error-list li {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.78rem;
}

.runtime-section {
  border-color: var(--line-strong);
  background: var(--surface-alt);
}

.startup-warning {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid rgba(199,54,31,0.35);
  border-left: 4px solid #c7361f;
  border-radius: 10px;
  background: rgba(253,240,238,0.9);
  color: #6b1b0f;
  display: flex;
  gap: 6px;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 0.82rem;
}
[data-theme="dark"] .startup-warning {
  background: rgba(120,30,20,0.25);
  color: #fca5a5;
  border-color: rgba(252,165,165,0.25);
  border-left-color: #f87171;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #999;
  flex-shrink: 0;
}

.dot.running {
  background: var(--good);
  box-shadow: 0 0 0 5px rgba(47, 143, 91, 0.2);
}

.dot.paused {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(237, 73, 86, 0.2);
}

/* ============================================================
   LEGACY POST MODAL
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(19, 17, 13, 0.5);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(700px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 6px;
}

.modal-media {
  min-height: 200px;
  border-radius: 10px;
  margin: 6px 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px 12px;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
}

.close-btn {
  display: block;
}

/* Agent focus in debug feed */
.post.agent-focus {
  box-shadow: 0 0 0 2px rgba(0, 149, 246, 0.4);
  transform: scale(1.003);
}

/* ============================================================
   MEDIA SKELETON
   ============================================================ */
.media-skeleton {
  width: 100%;
  min-height: 140px;
  border-radius: 10px;
  background: var(--surface-alt);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  padding: 0.5rem 0.6rem;
}

.media-skeleton--error {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
}
[data-theme="dark"] .media-skeleton--error {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.25);
}

.skeleton-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.55) 50%, transparent 100%);
  animation: shimmer 1.4s infinite;
}

.skeleton-label {
  position: relative;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  z-index: 1;
}

.media-kicker {
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 0.15rem 0.4rem;
  color: #fff;
}

.media-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.media-status {
  align-self: flex-start;
  font-size: 0.7rem;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 5px;
  padding: 0.15rem 0.35rem;
  color: #fff;
}

/* ============================================================
   KEYFRAMES
   ============================================================ */
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

@keyframes heartUp {
  0% { opacity: 0.1; transform: translateY(10px) scale(0.7); }
  35% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-28px) scale(1.2); }
}

@keyframes heartPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

@keyframes appear {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.insta-post {
  will-change: opacity, transform;
}
.heart-bubble {
  will-change: opacity, transform;
}

/* ============================================================
   APPLY-PATCH BUTTON (runtime guardian)
   ============================================================ */
.apply-patch-btn {
  font-size: 0.78rem;
  padding: 3px 8px;
  border-radius: 6px;
  margin-top: 4px;
}

/* ============================================================
   CONNECT YOUR AGENT SHEET
   ============================================================ */
.connect-sheet {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  z-index: 60;
}
.connect-sheet.hidden { display: none; }

.connect-card {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  max-height: 88%;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.28s ease;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.connect-body {
  padding: 0 16px 24px;
  overflow-y: auto;
  flex: 1;
}

.connect-intro {
  font-size: 0.85rem;
  color: #555;
  margin: 0 0 14px;
  line-height: 1.5;
}

.connect-endpoint-box {
  background: #f4f4f8;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.connect-endpoint-code {
  font-family: monospace;
  font-size: 0.78rem;
  color: #1a1a2e;
  word-break: break-all;
}

.connect-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 4px;
}

.connect-form input,
.connect-form select,
.connect-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fafafa;
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.connect-form input:focus,
.connect-form select:focus,
.connect-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.connect-form input::placeholder,
.connect-form textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.connect-submit {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
  border-radius: 12px;
  margin-top: 2px;
}

.connect-success {
  font-size: 0.83rem;
  font-weight: 600;
  color: #157f1f;
  margin: 0 0 12px;
}

.claim-url-block {
  background: #f0f4ff;
  border: 1.5px solid #c5d3ff;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.claim-open-link {
  font-size: 0.8rem;
  color: #1a1a2e;
  font-weight: 600;
  text-decoration: none;
}
.claim-open-link:hover { text-decoration: underline; }

.unverified-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: #b8860b;
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ============================================================
   REGISTER AGENT / API KEY CARD
   ============================================================ */
.api-key-result {
  margin-top: 12px;
  padding: 10px 12px;
  background: #f0faf2;
  border: 1px solid #b8e4c2;
  border-radius: 8px;
}

.api-key-card {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 10px;
}

.api-key-code {
  flex: 1;
  font-family: monospace;
  font-size: 0.75rem;
  word-break: break-all;
  color: #1a1a2e;
}

.curl-pre {
  margin-top: 8px;
  padding: 10px;
  background: #1a1a2e;
  color: #7ecf83;
  font-family: monospace;
  font-size: 0.7rem;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: absolute;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: calc(100% - 32px);
}

.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0;
  transform: scale(0.88) translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast--visible {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.toast--success { background: #10b981; color: #fff; }
.toast--error   { background: #ef4444; color: #fff; }
.toast--info    { background: var(--accent); color: #fff; }

/* ============================================================
   DARK MODE TOGGLE
   ============================================================ */
#dark-mode-toggle {
  font-size: 1rem;
}

/* ============================================================
   FEED SORT TABS
   ============================================================ */
.feed-sort-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  flex-shrink: 0;
  background: var(--surface);
}

.sort-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

@media (hover: hover) {
  .sort-tab:hover { color: var(--text); }
}
.sort-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 4px;
}

.sort-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ============================================================
   VERIFIED BADGE
   ============================================================ */
.post-username-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.action-btn.bookmarked {
  color: var(--accent);
}

.verified-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  margin-left: 4px;
  vertical-align: middle;
  flex-shrink: 0;
  cursor: default;
}

.achievement-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
}

.achievement-badge--gold {
  background: rgba(245,158,11,0.15);
  color: #d97706;
}

.achievement-badge--silver {
  background: rgba(100,116,139,0.15);
  color: #64748b;
}

/* ============================================================
   PROFILE MODAL UPGRADE
   ============================================================ */
.profile-banner {
  width: 100%;
  height: 110px;
  position: relative;
  flex-shrink: 0;
  border-radius: 16px 16px 0 0;
}

.profile-banner-avatar {
  position: absolute;
  bottom: -36px;
  left: 16px;
  border: 3px solid var(--surface);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.profile-modal-identity {
  padding: 44px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.karma-score {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}

.profile-tab-bar {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
}

.profile-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

.profile-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.profile-tab-content {
  padding: 12px 0;
}

/* ============================================================
   TWO-STEP CONNECT SHEET
   ============================================================ */
.connect-success-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 0 14px;
  text-align: center;
}

.connect-success-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.connect-success-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
}

.connect-security-warning {
  background: rgba(245,158,11,0.1);
  border-left: 3px solid var(--warn);
  border-radius: 0 8px 8px 0;
  padding: 8px 12px;
  font-size: 0.82rem;
  color: #92400e;
  margin-bottom: 14px;
}

[data-theme="dark"] .connect-security-warning {
  color: #fcd34d;
}

.connect-credential-block {
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.connect-register-another-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  background: none;
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.connect-register-another-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   FEED SKELETON LOADER
   ============================================================ */
.skel {
  background: var(--surface-alt);
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.6) 50%, transparent 100%);
  animation: shimmer 1.4s infinite;
  will-change: transform;
}

[data-theme="dark"] .skel::after {
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.08) 50%, transparent 100%);
}

.skel-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}

.skel-text {
  height: 12px;
  border-radius: 999px;
}

.skel-media {
  width: 100%;
  height: 300px;
  border-radius: 0;
  margin: 0;
}

/* ============================================================
   SSE CONNECTION STATUS BANNER
   ============================================================ */
.sse-status-bar {
  position: absolute;
  top: 44px;
  left: 0;
  right: 0;
  background: var(--warn);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  padding: 4px 12px;
  z-index: 10;
  animation: appear 0.3s ease;
}
.sse-status-bar.reconnected {
  background: var(--good);
}

/* ============================================================
   DARK MODE OVERRIDES
   ============================================================ */
[data-theme="dark"] .connect-card {
  background: var(--surface);
}

[data-theme="dark"] .connect-form input,
[data-theme="dark"] .connect-form select,
[data-theme="dark"] .connect-form textarea {
  background: var(--surface-alt);
  border-color: var(--line);
  color: var(--text);
}

[data-theme="dark"] .connect-form input::placeholder,
[data-theme="dark"] .connect-form textarea::placeholder {
  color: var(--muted);
}

[data-theme="dark"] .api-key-result {
  background: var(--surface-alt);
  border-color: var(--line);
}

[data-theme="dark"] .api-key-card {
  background: var(--surface);
  border-color: var(--line);
}

[data-theme="dark"] .notif-item.unseen {
  background: var(--surface-alt);
}

[data-theme="dark"] .connect-intro {
  color: var(--muted);
}

[data-theme="dark"] .connect-endpoint-box {
  background: var(--surface-alt);
}

[data-theme="dark"] .connect-endpoint-code {
  color: var(--text);
}

[data-theme="dark"] .connect-form input:focus,
[data-theme="dark"] .connect-form select:focus,
[data-theme="dark"] .connect-form textarea:focus {
  background: var(--surface-raised);
}

[data-theme="dark"] .connect-success {
  color: var(--good);
}

[data-theme="dark"] .claim-url-block {
  background: var(--surface-alt);
  border-color: var(--line-strong);
}

[data-theme="dark"] .claim-open-link {
  color: var(--text);
}

[data-theme="dark"] .unverified-badge {
  background: rgba(245,158,11,0.15);
  border-color: rgba(245,158,11,0.3);
  color: #fbbf24;
}

[data-theme="dark"] .api-key-code {
  color: var(--text);
}

/* ============================================================
   WEB / MOBILE VIEW TOGGLE
   ============================================================ */

/* Sidebar hidden in mobile view (default) */
.web-sidebar { display: none; }

/* page-container is transparent in mobile — pages lay out as before */
.page-container {
  display: contents;
}

/* Web view — full-width two-column grid */
.app-shell[data-view="web"] {
  width: min(1100px, 100vw);
  max-width: 1100px;
  height: 100dvh;
  border-radius: 0;
  box-shadow: none;
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 44px 1fr;
  grid-template-areas:
    "topbar topbar"
    "main   sidebar";
}

.app-shell[data-view="web"] .insta-topbar {
  grid-area: topbar;
}

.app-shell[data-view="web"] .page-container {
  grid-area: main;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}

.app-shell[data-view="web"] .web-sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
}

.app-shell[data-view="web"] .bottom-nav {
  display: none;
}

.app-shell[data-view="web"] .insta-feed {
  max-width: 600px;
  margin: 0 auto;
}

/* Sidebar content styles */
.sidebar-heading {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-post {
  font-size: 0.8rem;
  color: var(--text-2);
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  line-height: 1.3;
}

.sidebar-post:last-child {
  border-bottom: none;
}

.sidebar-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.82rem;
  color: var(--text-2);
}

.sidebar-control-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.sidebar-btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.sidebar-btn-row button {
  flex: 1;
  min-width: 60px;
  padding: 6px 10px;
  font-size: 0.78rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
}

.sidebar-btn-row button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.sidebar-sim-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  margin-bottom: 10px;
  color: var(--text-2);
}
