/* ===== Aimargo Portal — Design System ===== */
:root {
  --bg: #0a0a0f;
  --bg-elevated: #12121a;
  --bg-card: #1a1a26;
  --bg-card-hover: #222233;
  --border: #2a2a3e;
  --border-light: rgba(255,255,255,0.06);
  --text: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;
  --accent: #ff5701;
  --accent-glow: rgba(255,87,1,0.3);
  --accent-gradient: linear-gradient(135deg, #ff5701, #ff7744);
  --success: #22c55e;
  --success-bg: rgba(34,197,94,0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245,158,11,0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239,68,68,0.12);
  --info: #3b82f6;
  --info-bg: rgba(59,130,246,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --sidebar-width: 240px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: #fff; }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed; left: 0; top: 0;
  width: var(--sidebar-width); height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo {
  width: 32px; height: 32px;
  background: var(--accent-gradient);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: #fff; font-size: 18px; flex-shrink: 0;
}
.sidebar-header h2 {
  font-size: 18px; font-weight: 800;
  letter-spacing: -0.3px;
}
.sidebar-header .subtitle {
  font-size: 10px; color: var(--text-muted);
  letter-spacing: 0.5px; text-transform: uppercase;
  display: block; margin-top: -2px;
}
.user-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.user-icon {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #fff; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-muted); }
.nav-links { list-style: none; padding: 8px 0; flex: 1; }
.nav-links li { padding: 0; }
.nav-divider { height: 1px; background: var(--border); margin: 8px 20px; }
.nav-links a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none; font-size: 14px; font-weight: 500;
  transition: all 0.2s;
  border-right: 2px solid transparent;
}
.nav-links a:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}
.nav-links a.active {
  color: var(--accent);
  background: rgba(255,87,1,0.08);
  border-right-color: var(--accent);
}
.external-link::after { content: ' ↗'; font-size: 11px; }
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}
.logout-btn {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted);
  text-decoration: none; font-size: 14px;
  transition: color 0.2s;
}
.logout-btn:hover { color: var(--danger); }

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: var(--sidebar-width);
  padding: 28px 32px;
  max-width: 1400px;
  min-height: 100vh;
}
.full-content {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}

/* ===== PAGE HEADER ===== */
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 28px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 {
  font-size: 24px; font-weight: 800;
  letter-spacing: -0.5px;
}
.timestamp, .live-badge {
  font-size: 13px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.live-badge::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--success); animation: live-pulse 2s infinite;
}
@keyframes live-pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ===== STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px; margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: all 0.3s;
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px; opacity: 0; transition: opacity 0.3s;
}
.stat-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.stat-card:hover::before { opacity: 1; }
.stat-card.leads::before { background: var(--info); }
.stat-card.new-leads::before { background: var(--success); }
.stat-card.comments::before { background: var(--warning); }
.stat-card.posts::before { background: var(--accent-gradient); }
.stat-card.cron::before { background: var(--accent-gradient); }
.stat-value {
  font-size: 34px; font-weight: 900;
  letter-spacing: -1px;
  margin-bottom: 2px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat-card.leads .stat-value { background: var(--info); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-card.new-leads .stat-value { background: var(--success); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-card.comments .stat-value { background: var(--warning); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 22px;
  transition: border-color 0.2s;
}
.card:hover { border-color: rgba(255,87,1,0.15); }
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 15px; font-weight: 700; }
.card-body { padding: 12px 22px 22px; }
.card-link {
  font-size: 13px; color: var(--accent); text-decoration: none;
  font-weight: 600; transition: opacity 0.2s;
}
.card-link:hover { opacity: 0.8; text-decoration: underline; }
.card-full { grid-column: 1 / -1; }

/* ===== DASHBOARD GRID ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
@media (max-width: 1024px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ===== TABLES ===== */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; padding: 10px 12px;
  font-weight: 600; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border-light); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,0.02); }
.clickable { cursor: pointer; }
.text-preview { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 100px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-source { background: var(--info-bg); color: var(--info); }
.badge-new { background: var(--success-bg); color: var(--success); }
.badge-contacted { background: var(--warning-bg); color: var(--warning); }
.badge-converted { background: var(--success-bg); color: var(--success); }
.badge-closed { background: rgba(136,136,160,0.12); color: var(--text-muted); }
.badge-admin { background: rgba(255,87,1,0.12); color: var(--accent); }
.badge-user { background: var(--info-bg); color: var(--info); }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 6px;
}
.form-input, .search-input, .filter-select {
  width: 100%; padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color 0.2s;
}
.form-input:focus, .search-input:focus, .filter-select:focus {
  border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 22px; border-radius: var(--radius-sm);
  border: none; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
  text-decoration: none; font-family: inherit;
}
.btn-primary { background: var(--accent-gradient); color: #fff; }
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-full { width: 100%; }

/* ===== LOGIN ===== */
.login-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  position: relative;
}
.login-bg-grid {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(255,87,1,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,87,1,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
}
.login-bg-glow {
  position: fixed; top: -30vh; left: 50%; transform: translateX(-50%);
  width: 80vw; height: 60vh;
  background: radial-gradient(ellipse at center, var(--accent-glow) 0%, transparent 70%);
  pointer-events: none; opacity: 0.3;
}
.login-card {
  position: relative; z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: 0 25px 60px -12px rgba(0,0,0,0.6);
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-logo {
  width: 48px; height: 48px;
  background: var(--accent-gradient);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 900; color: #fff;
  margin: 0 auto 14px;
  box-shadow: 0 8px 24px var(--accent-glow);
}
.login-header h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.login-header p { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

/* ===== FILTERS ===== */
.filters { margin-bottom: 20px; }
.filter-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-group label { font-size: 13px; color: var(--text-muted); margin-right: 4px; }
.filter-tag {
  display: inline-flex; padding: 4px 14px; border-radius: 100px;
  font-size: 13px; background: var(--bg-card);
  border: 1px solid var(--border); color: var(--text-secondary);
  text-decoration: none; transition: all 0.2s;
}
.filter-tag:hover { background: var(--bg-card-hover); color: var(--text); }
.filter-tag.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== SEARCH ===== */
.search-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; }

/* ===== PAGINATION ===== */
.pagination {
  display: flex; justify-content: center; align-items: center;
  gap: 15px; padding: 20px 0 0;
}
.page-btn {
  padding: 8px 16px; border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-size: 14px;
  transition: all 0.2s;
}
.page-btn:hover { background: var(--bg-card-hover); border-color: var(--accent); }
.page-info { font-size: 14px; color: var(--text-muted); }

/* ===== MEMORY GRID ===== */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.memory-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px; transition: all 0.2s;
}
.memory-card:hover { border-color: rgba(255,87,1,0.2); }
.memory-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.memory-time { font-size: 12px; color: var(--text-muted); }
.memory-content { font-size: 13px; line-height: 1.5; color: var(--text); margin-bottom: 8px; }
.memory-details summary { font-size: 12px; color: var(--accent); cursor: pointer; }
.memory-json {
  margin-top: 8px; padding: 10px;
  background: var(--bg-card); border-radius: var(--radius-sm);
  font-size: 11px; overflow-x: auto; max-height: 200px;
}

/* ===== POST LIST ===== */
.post-list { display: flex; flex-direction: column; gap: 8px; }
.post-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border-light);
}
.post-item:last-child { border-bottom: none; }
.post-title { color: var(--text); text-decoration: none; font-size: 14px; transition: color 0.2s; }
.post-title:hover { color: var(--accent); }
.post-date { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 20px; font-size: 14px;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }

/* ===== MISC ===== */
.text-mono { font-family: 'JetBrains Mono', 'SF Mono', monospace; font-size: 13px; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--text-muted); }
.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); font-size: 14px; }

/* ===== MOBILE HEADER (HAMBURGER) ===== */
.mobile-header {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
}
/* Always show hamburger on auth pages — no media query dependency */
@media (max-width: 899px) {
  .mobile-header { display: flex; }
}
.mobile-header .mh-left {
  display: flex; align-items: center; gap: 10px;
}
.hamburger {
  width: 36px; height: 36px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px;
  background: none; border: none;
  cursor: pointer;
  padding: 0;
  position: relative;
}
.hamburger span {
  display: block;
  width: 20px; height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.3s;
}
.hamburger.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger.active span:nth-child(2) {
  opacity: 0;
}
.hamburger.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}
.mh-logo {
  width: 28px; height: 28px;
  background: var(--accent-gradient);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: #fff; font-size: 14px;
}
.mh-title {
  font-size: 16px; font-weight: 700;
}
.mh-right {
  display: flex; align-items: center; gap: 8px;
}
.mh-logout {
  font-size: 12px; color: var(--text-muted);
  text-decoration: none; padding: 4px 8px;
}

/* ===== MOBILE SIDEBAR OVERLAY ===== */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 150;
  opacity: 0;
  transition: opacity 0.3s;
}
.sidebar-overlay.show { opacity: 1; }

/* ===== MOBILE SIDEBAR (DRAWER) ===== */
@media (max-width: 899px) {
  html, body { overflow-x: hidden; }
  
  .mobile-header { display: flex; }
  
  body { padding-top: 52px; }
  
  .sidebar {
    position: fixed; left: -280px; top: 0;
    width: 260px; height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 300;
    overflow-y: auto;
    transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }
  
  .sidebar-header { padding: 18px 16px 14px; }
  .sidebar-header h2 { font-size: 16px; }
  .sidebar-logo { width: 28px; height: 28px; font-size: 15px; }
  .user-badge { padding: 10px 16px; }
  .nav-links a { padding: 10px 16px; font-size: 13px; }
  .sidebar-footer { padding: 10px 16px; }
  
  .main-content {
    margin-left: 0;
    padding: 16px 14px;
    max-width: 100%;
  }
  
  .sidebar-overlay { display: none; }
  .sidebar-overlay.show { display: block; }
  
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 11px; }
  .stat-sub { font-size: 11px; }
  
  .dashboard-grid { grid-template-columns: 1fr; gap: 14px; }
  .page-header { margin-bottom: 18px; }
  .page-header h1 { font-size: 18px; }
  
  .card-header { padding: 12px 16px; }
  .card-header h2 { font-size: 14px; }
  .card-body { padding: 8px 16px 16px; }
  
  /* Tables → Cards */
  .table, .table thead, .table tbody, .table th, .table td, .table tr { display: block; }
  .table thead { display: none; }
  .table tr {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
  }
  .table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid var(--border-light);
    gap: 6px;
    font-size: 13px;
  }
  .table td:last-child { border-bottom: none; }
  .table td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
  }
  .table td:first-child { padding-top: 0; }
  .table td:last-child { padding-bottom: 0; }
  .text-preview { max-width: none; white-space: normal; }
  .clickable tr { cursor: pointer; }
  
  .login-card { padding: 28px 20px; max-width: 100%; margin: 0 8px; }
  .filter-group { flex-direction: column; align-items: stretch; }
  .search-form { flex-direction: column; }
  .search-input { min-width: auto; width: 100%; }
  .pagination { flex-wrap: wrap; gap: 8px; }
  .memory-grid { grid-template-columns: 1fr; }
  .post-item { flex-direction: column; align-items: flex-start; gap: 4px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }
  .main-content { padding: 12px 10px; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .table tr { padding: 8px 10px; }
  .table td { font-size: 12px; }
  .table td::before { font-size: 9px; }
}
