:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d26;
  --bg-tertiary: #232733;
  --bg-hover: #2b3040;
  --border-color: #2e3447;
  --text-main: #f0f2f8;
  --text-muted: #9ba3b8;
  --accent-primary: #00b4d8;
  --accent-hover: #0096c7;
  --accent-glow: rgba(0, 180, 216, 0.4);
  --color-success: #57f287;
  --color-warning: #fee75c;
  --color-danger: #ed4245;
  --color-purple: #9b59b6;
  --sidebar-width: 270px;
  --font-main: 'Kanit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-main);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.brand-logo-img {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid #00b4d8;
  box-shadow: 0 0 15px rgba(0, 180, 216, 0.5);
  object-fit: cover;
  flex-shrink: 0;
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent-primary), #845ef7);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 180, 216, 0.4);
}

.brand-title {
  display: block;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 1px;
  color: #fff;
}

.brand-subtitle {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.bot-status-card {
  margin: 16px;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border-color);
}

.bot-avatar-wrapper {
  position: relative;
  width: 42px;
  height: 42px;
}

.bot-avatar-wrapper img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-tertiary);
}

.status-dot.online { background-color: var(--color-success); }
.status-dot.offline { background-color: var(--color-danger); }

.bot-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.bot-port {
  font-size: 11px;
  color: var(--color-success);
  font-family: var(--font-mono);
}

.sidebar-nav {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  text-align: left;
}

.nav-btn i {
  font-size: 16px;
  width: 20px;
}

.nav-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-main);
}

.nav-btn.active {
  background: var(--accent-primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(88, 101, 242, 0.3);
}

.pulse-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  letter-spacing: 0.5px;
  animation: pulse-live 1.5s infinite;
}

@keyframes pulse-live {
  0% { opacity: 1; }
  50% { opacity: 0.4; }
  100% { opacity: 1; }
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

.system-tag {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Main Content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 30px;
  max-width: calc(100vw - var(--sidebar-width));
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.topbar-title h1 {
  font-size: 24px;
  font-weight: 700;
  color: #fff;
}

.topbar-title p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

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

.role-verified-badge {
  background: rgba(87, 242, 135, 0.1);
  color: var(--color-success);
  border: 1px solid rgba(87, 242, 135, 0.3);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-menu-dropdown {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-badge-header {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.user-badge-header img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.dynamic-badge {
  background: rgba(87, 242, 135, 0.1);
  color: var(--color-success);
  border: 1px solid rgba(87, 242, 135, 0.3);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-mono);
}

/* Tabs */
.tab-pane {
  display: none;
  animation: fadeIn 0.25s ease-in-out;
}

.tab-pane.active {
  display: block;
}

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

/* Stat Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-primary);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
}

.icon-blue { background: rgba(88, 101, 242, 0.2); color: #5865f2; }
.icon-green { background: rgba(87, 242, 135, 0.2); color: #57f287; }
.icon-purple { background: rgba(155, 89, 182, 0.2); color: #9b59b6; }
.icon-red { background: rgba(237, 66, 69, 0.2); color: #ed4245; }

.stat-number {
  display: block;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  color: #fff;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* Cards & Layout */
.dashboard-row {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-half {
  flex: 1;
  min-width: 320px;
}

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

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
}

.card-body {
  padding: 20px;
}

.p-0 { padding: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-4 { margin-bottom: 24px !important; }
.mt-3 { margin-top: 14px !important; }

/* Info List */
.info-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 14px;
}

.info-key {
  color: var(--text-muted);
}

.info-val {
  font-weight: 500;
  color: #fff;
}

.info-val a {
  color: var(--accent-primary);
  text-decoration: none;
}

.info-val a:hover {
  text-decoration: underline;
}

/* Badges */
.badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  display: inline-block;
}

.badge-success { background: rgba(87, 242, 135, 0.15); color: var(--color-success); }
.badge-blue { background: rgba(88, 101, 242, 0.15); color: var(--accent-primary); }
.badge-danger { background: rgba(237, 66, 69, 0.15); color: var(--color-danger); }
.badge-warning { background: rgba(254, 231, 92, 0.15); color: var(--color-warning); }

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.data-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.data-table .time-cell {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 12px;
}

.data-table .details-cell {
  max-width: 400px;
  word-break: break-word;
  color: #e0e4ef;
}

/* Logs Controls */
.logs-controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.search-group {
  position: relative;
  flex: 1;
  min-width: 250px;
}

.search-group i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-group input {
  padding-left: 36px !important;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: #d8deec;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-main);
  font-size: 14px;
  transition: border-color 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.form-control-sm {
  padding: 6px 10px;
  font-size: 13px;
}

.form-help {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Switches */
.switch-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.switch-meta strong {
  display: block;
  font-size: 14px;
  color: #fff;
}

.switch-meta p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--bg-tertiary);
  transition: .3s;
  border-radius: 26px;
  border: 1px solid var(--border-color);
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent-primary);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover {
  background: #c0392b;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background: var(--bg-tertiary);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-link {
  background: transparent;
  color: var(--accent-primary);
  padding: 0;
}

.btn-link:hover {
  text-decoration: underline;
}

.save-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
}

.save-status {
  font-size: 14px;
}

/* Responsive Recent Feed */
.recent-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recent-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.recent-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.recent-content {
  flex: 1;
}

.recent-action {
  font-weight: 600;
  color: #fff;
}

.recent-desc {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

.recent-time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.loading-state {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}

/* Mobile responsive */
@media (max-width: 900px) {
  .sidebar {
    width: 70px;
  }
  .brand-text, .bot-info-meta, .nav-btn span, .sidebar-footer, .nav-btn .pulse-badge {
    display: none;
  }
  .main-content {
    margin-left: 70px;
    padding: 16px;
    max-width: calc(100vw - 70px);
  }
  .card-half {
    min-width: 100%;
  }
}
