:root {
  --bg: #0f1117;
  --bg2: #161b22;
  --bg3: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --accent: #e1306c;
  --accent2: #833ab4;
  --accent-blue: #58a6ff;
  --green: #3fb950;
  --yellow: #d29922;
  --radius: 10px;
  --sidebar-w: 220px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}

.ig-logo { width: 28px; height: 28px; flex-shrink: 0; }

nav { padding: 12px 0; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text2);
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 8px;
  transition: all .15s;
  font-size: 14px;
}

.nav-item svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(225,48,108,.15); color: var(--accent); }

.badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}

/* MAIN */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
}

.section { display: none; }
.section.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 { font-size: 22px; font-weight: 700; }

/* BUTTONS */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
}
.btn-primary:hover { opacity: .9; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg3); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { background: #da3633; color: #fff; }
.btn-danger:hover { background: #c93030; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 4px 10px;
  font-size: 12px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text2); }

/* STATS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; fill: #fff; }
.dm-icon { background: linear-gradient(135deg, #405de6, #5851db); }
.replied-icon { background: linear-gradient(135deg, var(--green), #2ea043); }
.comment-icon { background: linear-gradient(135deg, var(--accent2), var(--accent)); }
.account-icon { background: linear-gradient(135deg, #fd5949, #d6249f); }

.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* RECENT */
.recent-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.recent-list { display: flex; flex-direction: column; gap: 2px; }

.recent-item {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--bg3);
  margin-bottom: 4px;
}
.recent-item-user { font-weight: 600; font-size: 13px; color: var(--accent-blue); }
.recent-item-text { font-size: 13px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.recent-item-time { font-size: 11px; color: var(--text2); margin-top: 3px; }

/* CARD */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 15px; font-weight: 600; }

.link { color: var(--accent-blue); text-decoration: none; font-size: 13px; }
.link:hover { text-decoration: underline; }

/* TABLE */
.table-toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search-input {
  width: 100%;
  max-width: 380px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: var(--bg3);
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg3); }
tbody td { padding: 10px 14px; font-size: 13px; vertical-align: middle; }

.cell-msg {
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.status-received { background: rgba(210,153,34,.15); color: var(--yellow); }
.status-replied { background: rgba(63,185,80,.15); color: var(--green); }

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text2);
  font-size: 14px;
}

/* PAGINATION */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.pagination button {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 11px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.pagination button:hover { border-color: var(--accent); }
.pagination button.active { background: var(--accent); border-color: var(--accent); }
.pagination button:disabled { opacity: .4; cursor: default; }
.pagination-info { color: var(--text2); font-size: 12px; }

/* ACCOUNTS TABLE */
.token-preview {
  font-family: monospace;
  font-size: 11px;
  color: var(--text2);
  background: var(--bg3);
  padding: 2px 6px;
  border-radius: 4px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

/* WEBHOOK INFO */
.webhook-info { padding: 16px 20px; }
.info-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.info-label { color: var(--text2); font-size: 13px; min-width: 120px; }
code {
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-family: monospace;
  color: var(--accent-blue);
}
.btn-copy {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.btn-copy:hover { border-color: var(--accent-blue); }
.info-note { font-size: 12px; color: var(--text2); margin-top: 8px; line-height: 1.6; }

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 100;
}

.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(520px, 95vw);
  z-index: 101;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg3); color: var(--text); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.hidden { display: none !important; }

/* FORMS */
.form-vertical {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text2);
  font-weight: 500;
}

input[type="text"], textarea, select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
  resize: vertical;
}
input[type="text"]:focus, textarea:focus, select:focus { border-color: var(--accent); }
select option { background: var(--bg3); }

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

/* SIMULATE */
.sim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* REPLY CONTEXT */
.reply-context {
  margin: 16px 20px 0;
  background: var(--bg3);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  color: var(--text2);
  border-left: 3px solid var(--accent);
}
.reply-context strong { color: var(--text); }

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 14px;
  z-index: 200;
  transition: opacity .3s;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: #da3633; color: #ff7b7b; }

@media (max-width: 900px) {
  .recent-grid, .sim-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; padding: 16px; }
}
