@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

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

:root {
  --bg: #060611;
  --bg-gradient: linear-gradient(135deg, #060611 0%, #0d0d1a 50%, #0a0a18 100%);
  --surface: rgba(18, 18, 35, 0.8);
  --surface-solid: #12121f;
  --surface2: rgba(26, 26, 50, 0.9);
  --surface-glass: rgba(20, 20, 40, 0.6);
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --primary: #00E676;
  --primary-glow: rgba(0, 230, 118, 0.15);
  --primary-dark: #00c853;
  --primary-soft: rgba(0, 230, 118, 0.08);
  --accent: #7c4dff;
  --accent-glow: rgba(124, 77, 255, 0.15);
  --danger: #ff5252;
  --danger-soft: rgba(255, 82, 82, 0.12);
  --warning: #ffab40;
  --warning-soft: rgba(255, 171, 64, 0.12);
  --info: #40c4ff;
  --info-soft: rgba(64, 196, 255, 0.12);
  --text: #eaeaf5;
  --text-secondary: #b0b0cc;
  --text-muted: #6a6a8e;
  --success: #00E676;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 30px rgba(0, 230, 118, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* === LAYOUT === */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* === SIDEBAR === */
.sidebar {
  background: var(--surface-solid);
  border-right: 1px solid var(--border);
  padding: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(20px);
}

.sidebar-logo {
  padding: 28px 24px 24px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  line-height: 1.2;
  text-shadow: 0 0 30px rgba(0, 230, 118, 0.3);
}

.sidebar-logo span {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 500;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 3px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  margin: 2px 0;
  position: relative;
}

.nav-item:first-of-type { margin-top: 12px; }

.nav-item:hover {
  background: var(--primary-soft);
  color: var(--text);
  border-left-color: rgba(0, 230, 118, 0.3);
}

.nav-item.active {
  color: var(--primary);
  border-left-color: var(--primary);
  background: linear-gradient(90deg, rgba(0,230,118,0.1) 0%, transparent 100%);
  font-weight: 600;
}

.nav-item.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 12px var(--primary);
}

.connection-status {
  margin-top: auto;
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 10px var(--success), 0 0 20px rgba(0,230,118,0.3);
  animation: pulse-green 2s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(255,82,82,0.4);
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 10px var(--success), 0 0 20px rgba(0,230,118,0.3); }
  50% { box-shadow: 0 0 15px var(--success), 0 0 30px rgba(0,230,118,0.5); }
}

/* === MAIN === */
.main {
  padding: 36px 40px;
  overflow-y: auto;
  max-height: 100vh;
  background: var(--bg-gradient);
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.3s ease; }

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

.page-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 28px;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(12px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.stat-card:hover::before { opacity: 1; }

.stat-card .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.stat-card .value {
  font-size: 34px;
  font-weight: 800;
  margin-top: 10px;
  color: var(--primary);
  letter-spacing: -1px;
  line-height: 1;
}

.stat-card .value.danger { color: var(--danger); }
.stat-card .value.warning { color: var(--warning); }

/* === TABLE === */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.table-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

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

th {
  text-align: left;
  padding: 14px 24px;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1.2px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
}

td {
  padding: 16px 24px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

tr:last-child td { border-bottom: none; }

tr {
  transition: background 0.2s;
}

tr:hover {
  background: rgba(0, 230, 118, 0.03);
}

/* === BADGE === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge.pending { background: var(--warning-soft); color: var(--warning); }
.badge.sent { background: rgba(0,230,118,0.12); color: var(--success); }
.badge.error { background: var(--danger-soft); color: var(--danger); }
.badge.sending { background: var(--info-soft); color: var(--info); }
.badge.add, .badge.join { background: rgba(0,230,118,0.12); color: var(--success); }
.badge.remove, .badge.leave { background: var(--danger-soft); color: var(--danger); }
.badge.snapshot { background: var(--info-soft); color: var(--info); }

/* === BUTTONS === */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: 0.2px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #000;
  box-shadow: 0 4px 15px rgba(0, 230, 118, 0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 25px rgba(0, 230, 118, 0.35);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #d32f2f);
  color: #fff;
  box-shadow: 0 4px 15px rgba(255, 82, 82, 0.2);
}

.btn-danger:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(255, 82, 82, 0.3);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.btn-sm { padding: 7px 14px; font-size: 12px; border-radius: 8px; }

/* === FORM === */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input, select, textarea {
  width: 100%;
  padding: 12px 16px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.25s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 230, 118, 0.1);
  background: rgba(0,0,0,0.4);
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

textarea { resize: vertical; min-height: 100px; }

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236a6a8e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* === MODAL === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 520px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg), 0 0 60px rgba(0,0,0,0.5);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 24px;
  letter-spacing: -0.3px;
}

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

/* === QR === */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 40px;
  text-align: center;
}

.qr-container img {
  width: 280px;
  height: 280px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: var(--shadow-md), 0 0 40px rgba(0, 230, 118, 0.1);
  border: 2px solid var(--border);
}

.qr-container p {
  color: var(--text-muted);
  font-size: 14px;
  max-width: 340px;
  line-height: 1.6;
}

/* === GROUP CARD === */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden;
}

.group-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(0,230,118,0.05) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.group-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md), var(--shadow-glow);
}

.group-card:hover::after { opacity: 1; }

.group-card.favorited {
  border-color: rgba(241, 196, 15, 0.4);
  box-shadow: 0 0 20px rgba(241, 196, 15, 0.05);
}

.fav-star-card {
  cursor: pointer;
  font-size: 20px;
  color: var(--text-muted);
  transition: all 0.25s;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.fav-star-card:hover { color: #f1c40f; transform: scale(1.2); }
.fav-star-card.active { color: #f1c40f; text-shadow: 0 0 12px rgba(241,196,15,0.5); }

.group-card h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.group-card .meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  font-weight: 500;
}

.group-card .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  position: relative;
  z-index: 1;
}

/* === EMPTY === */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* === FILTER BAR === */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-bar select, .filter-bar input {
  width: auto;
  min-width: 160px;
}

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* === TOAST === */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 22px;
  font-size: 13px;
  font-weight: 500;
  animation: toastIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 380px;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

@keyframes toastIn {
  from { transform: translateX(100%) scale(0.9); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

/* === SEARCH DROPDOWN === */
.search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface-solid);
  border: 1px solid var(--primary);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.search-dropdown.visible { display: block; }

.search-dropdown-item {
  padding: 11px 16px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  color: var(--text-secondary);
}

.search-dropdown-item:last-child { border-bottom: none; }

.search-dropdown-item:hover {
  background: var(--primary-soft);
  color: var(--text);
}

.search-dropdown-item .group-members {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
  padding-left: 12px;
  font-weight: 500;
}

.search-dropdown-empty {
  padding: 18px 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.fav-star {
  cursor: pointer;
  font-size: 15px;
  margin-right: 10px;
  color: var(--text-muted);
  transition: all 0.2s;
  flex-shrink: 0;
}

.fav-star:hover { color: #f1c40f; transform: scale(1.15); }
.fav-star.active { color: #f1c40f; }

.dropdown-section-label {
  padding: 10px 16px 6px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--primary);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: rgba(0,230,118,0.03);
}

/* === PERIOD BUTTONS === */
.period-btn {
  transition: all 0.2s !important;
}

.period-btn.active {
  background: var(--primary) !important;
  color: #000 !important;
  border-color: var(--primary) !important;
  font-weight: 700 !important;
  box-shadow: 0 2px 12px rgba(0,230,118,0.25);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    flex-direction: row;
    z-index: 500;
    overflow-x: auto;
    padding: 0;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  .sidebar-logo, .connection-status { display: none; }

  .nav-item {
    padding: 14px 16px;
    border-left: none;
    border-top: 2px solid transparent;
    font-size: 12px;
    white-space: nowrap;
  }

  .nav-item.active {
    border-left: none;
    border-top-color: var(--primary);
  }

  .nav-item.active::after { display: none; }

  .main {
    padding: 20px 16px 80px;
    max-height: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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

/* GIF & Sticker Grid */
.gif-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 4px;
}
.gif-grid .gif-item,
.gif-grid .sticker-item {
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.15s;
}
.gif-grid .gif-item:hover,
.gif-grid .sticker-item:hover {
  transform: scale(1.05);
  border-color: var(--primary);
}
.gif-grid .gif-item img,
.gif-grid .sticker-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
@media (max-width: 768px) {
  .gif-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}
