:root {
  --bg: #080b14;
  --bg-elevated: #101624;
  --bg-card: #151d30;
  --border: #243049;
  --text: #f0f3fa;
  --text-muted: #8b95ad;
  --accent: #6c5ce7;
  --accent-bright: #8b7bff;
  --success: #2ecc71;
  --warning: #f5b942;
  --danger: #ff5b6a;
  --info: #4fb0ff;
  --radius: 14px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: radial-gradient(ellipse at 20% 0%, #1a2140 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.modal-open {
  overflow: hidden;
}

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
  animation: fadeInUp 0.45s ease;
}

.login-heading {
  margin: 0 0 4px;
  font-size: 24px;
  background: linear-gradient(90deg, var(--accent-bright), #ff8bd6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.login-subheading {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 14px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
  margin: 0;
}

/* Form controls */
.input, .textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.25);
}

.textarea {
  resize: vertical;
  font-family: inherit;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, color 0.2s ease;
  position: relative;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-bright));
  color: white;
  box-shadow: 0 6px 16px rgba(108, 92, 231, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 8px 22px rgba(108, 92, 231, 0.5);
}

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

.btn-ghost:hover {
  border-color: var(--accent-bright);
  color: var(--accent-bright);
}

.btn-danger {
  background: linear-gradient(135deg, #e63950, var(--danger));
  color: white;
}

.btn-copy {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-copy-success {
  background: var(--success);
  color: #06210f;
  border-color: var(--success);
}

.btn-block {
  width: 100%;
}

.btn-loading {
  opacity: 0.7;
  pointer-events: none;
}

/* App shell + header */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 22, 36, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent-bright), #ff8bd6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Hamburger */
.menu-toggle {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 0;
  border-radius: 10px;
  transition: background 0.15s ease;
}

.menu-toggle:hover {
  background: rgba(108, 92, 231, 0.12);
}

.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Drawer */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  z-index: 90;
}

.drawer-overlay.drawer-open {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(300px, 86vw);
  height: 100%;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  transform: translateX(-105%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
}

.drawer.drawer-open {
  transform: translateX(0);
}

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

.drawer-title {
  font-weight: 600;
  font-size: 15px;
}

.drawer-close {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
}

.drawer-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: rgba(108, 92, 231, 0.12);
  color: var(--text);
}

.nav-link-active {
  background: rgba(108, 92, 231, 0.22);
  color: var(--accent-bright);
  font-weight: 600;
}

.nav-logout {
  margin-top: auto;
}

/* Main content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.page-content {
  padding: 22px 18px 40px;
  animation: fadeIn 0.3s ease;
  flex: 1;
}

.page-heading {
  margin: 0 0 6px;
  font-size: 22px;
}

.page-description {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 14px;
}

.page-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}

.section-heading {
  margin: 28px 0 12px;
  font-size: 16px;
  font-weight: 600;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px;
  animation: fadeInUp 0.4s ease;
}

.stat-success { border-left-color: var(--success); }
.stat-warning { border-left-color: var(--warning); }
.stat-danger { border-left-color: var(--danger); }
.stat-info { border-left-color: var(--info); }

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

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

/* Manage bot */
.manage-section {
  margin-top: 8px;
}

.manage-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.manage-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.manage-status-label {
  font-weight: 600;
  font-size: 14px;
}

.manage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Cards & lists */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  animation: fadeInUp 0.3s ease;
}

.list-card-info {
  flex: 1;
  min-width: 160px;
}

.list-card-title {
  font-weight: 600;
  font-size: 15px;
}

.list-card-meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

.list-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-success { background: rgba(46, 204, 113, 0.15); color: var(--success); }
.badge-warning { background: rgba(245, 185, 66, 0.15); color: var(--warning); }
.badge-danger { background: rgba(255, 91, 106, 0.15); color: var(--danger); }

.empty-state, .loading-block {
  color: var(--text-muted);
  font-size: 14px;
  padding: 30px 0;
  text-align: center;
}

/* Spinner */
.spinner-wrap {
  display: flex;
  justify-content: center;
  padding: 40px 0;
  grid-column: 1 / -1;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-bright);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.card-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 560px;
}

.inline-form {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  max-width: none;
}

.tab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tab {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}

.tab-active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.table-wrapper {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

.data-table th, .data-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 1000;
  padding: 16px;
}

.modal-visible {
  opacity: 1;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 420px;
  transform: translateY(16px) scale(0.98);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-visible .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.modal-title {
  margin: 0;
  font-size: 17px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.modal-message {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 18px;
  line-height: 1.45;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.pairing-modal .pairing-code {
  font-size: 28px;
  letter-spacing: 5px;
  font-weight: 700;
  text-align: center;
  padding: 18px;
  background: var(--bg-elevated);
  border-radius: 10px;
  margin-bottom: 16px;
  color: var(--accent-bright);
  font-variant-numeric: tabular-nums;
}

.pairing-status {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: 14px 0 0;
}

.pairing-success {
  color: var(--success);
  font-weight: 600;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

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

.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@media (max-width: 640px) {
  .page-content {
    padding: 16px 14px 32px;
  }

  .stat-value {
    font-size: 22px;
  }

  .list-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .manage-actions {
    flex-direction: column;
  }

  .manage-actions .btn {
    width: 100%;
  }
}
