:root {
  --bg-gradient: linear-gradient(180deg, #7b88f6 0%, #6a5fd4 35%, #5b45b8 65%, #4a38a8 100%);
  --surface: rgba(45, 35, 95, 0.55);
  --surface-light: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.78);
  --primary: #ffffff;
  --primary-text: #2d1f5c;
  --danger: #ff6b8a;
  --success: #5ee39f;
  --shadow: 0 8px 32px rgba(20, 10, 60, 0.25);
  --radius: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg-gradient);
  background-attachment: fixed;
  min-height: 100dvh;
}

a {
  color: inherit;
}

code {
  font-family: Consolas, Monaco, monospace;
  font-size: 0.88em;
}

/* Auth pages */
.auth-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.auth-brand span {
  font-size: 1.8rem;
}

.auth-brand h1,
.admin-topbar h1 {
  font-size: 1.45rem;
  font-weight: 800;
}

.auth-subtitle {
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}

.auth-back,
.topbar-link {
  display: inline-block;
  margin-top: 1rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.auth-note {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Admin layout */
.admin-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  background: rgba(20, 12, 55, 0.55);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 1.5rem;
}

.sidebar-brand span {
  font-size: 1.5rem;
}

.sidebar-brand strong {
  display: block;
  font-size: 1rem;
}

.sidebar-brand small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.sidebar-nav a {
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.sidebar-footer a {
  color: var(--text);
  text-decoration: none;
}

.admin-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.admin-content {
  padding: 1.25rem 1.5rem 2rem;
}

/* Components */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.panel-body {
  padding: 1.15rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.55rem;
  font-weight: 800;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-grid {
  gap: 1.1rem;
}

.form-narrow {
  max-width: 420px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.88rem;
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 0.72rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(255, 255, 255, 0.35);
  outline-offset: 1px;
}

small,
.form-help {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.78rem;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
}

.checkbox-label input {
  width: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.72rem 1rem;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
}

.btn-danger {
  background: rgba(255, 107, 138, 0.2);
  color: #ffd6de;
  border: 1px solid rgba(255, 107, 138, 0.45);
}

.btn-small {
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.alert-success {
  background: rgba(94, 227, 159, 0.15);
  border: 1px solid rgba(94, 227, 159, 0.35);
  color: #d7ffe9;
}

.alert-error {
  background: rgba(255, 107, 138, 0.15);
  border: 1px solid rgba(255, 107, 138, 0.35);
  color: #ffd6de;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 500px;
}

th,
td {
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-success {
  background: rgba(94, 227, 159, 0.18);
  color: #b8ffd8;
}

.badge-muted {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.inline-form {
  display: inline;
}

.copy-url {
  cursor: pointer;
  word-break: break-all;
  max-width: 220px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.copy-url.copied {
  color: var(--success);
}

.destinations-block {
  margin-top: 0.5rem;
}

.destinations-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.destinations-header h3 {
  font-size: 0.98rem;
}

.destination-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  border-radius: 12px;
  background: var(--surface-light);
  border: 1px solid var(--border);
  align-items: end;
}

.destination-row .remove-destination {
  grid-column: span 6;
  justify-self: start;
}

.destination-row .dest-message.hidden {
  display: none;
}

.filter-form select {
  min-width: 180px;
}

.filter-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.source-badge {
  display: inline-block;
  font-weight: 700;
}

.source-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  border-radius: 12px;
  background: var(--surface-light);
  border: 1px solid var(--border);
  align-items: end;
}

.source-url-preview {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
}

.source-url-preview span {
  color: var(--text-muted);
  font-weight: 600;
}

.source-url-preview code {
  word-break: break-all;
}

.source-url-preview.muted code {
  color: var(--text-muted);
}

.sources-block {
  margin-top: 0.5rem;
}

.source-row .remove-source {
  grid-column: 1 / -1;
  justify-self: start;
}

.info-list {
  list-style: none;
  display: grid;
  gap: 0.55rem;
  color: var(--text-muted);
}

.truncate {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* CSS Bar Chart */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  height: 160px;
  padding: 0.5rem 0;
}

.chart-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar-value {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}

.chart-bar {
  width: 100%;
  min-height: 4px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.12) 100%);
  transition: height 0.4s ease;
}

.chart-bar-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Device Stats */
.device-stats {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.device-row {
  display: grid;
  grid-template-columns: 90px 1fr 50px;
  align-items: center;
  gap: 0.75rem;
}

.device-label {
  font-size: 0.88rem;
  font-weight: 600;
}

.device-bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.device-bar {
  height: 100%;
  border-radius: 999px;
  min-width: 4px;
  transition: width 0.5s ease;
}

.device-bar-mobile {
  background: linear-gradient(90deg, #5ee39f, #3dd68c);
}

.device-bar-desktop {
  background: linear-gradient(90deg, #7b88f6, #6a75e8);
}

.device-bar-bot {
  background: linear-gradient(90deg, #ff6b8a, #e85d7c);
}

.device-count {
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
  color: var(--text-muted);
}

/* Bulk Action Bar */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  border-radius: 12px;
  background: rgba(94, 227, 159, 0.1);
  border: 1px solid rgba(94, 227, 159, 0.25);
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#bulk-count {
  font-weight: 700;
  font-size: 0.88rem;
  margin-right: auto;
}

.bulk-check {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

#select-all {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* User Dropdown */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-dropdown {
  position: relative;
}

.user-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-light);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.user-dropdown-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
}

.user-dropdown-toggle .dropdown-arrow {
  font-size: 0.65rem;
  transition: transform 0.2s ease;
}

.user-dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.user-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  padding: 0.5rem;
  border-radius: 12px;
  background: rgba(35, 25, 75, 0.95);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  box-shadow: 0 12px 40px rgba(10, 5, 30, 0.5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  z-index: 100;
}

.user-dropdown.open .user-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.1s ease, color 0.1s ease;
}

.user-dropdown-menu a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 0.35rem 0;
}

/* Mobile Sidebar Toggle */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-light);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Export / Data Management */
.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.data-actions form {
  display: inline;
}

.file-size-info {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Mobile card layout for tables */
.mobile-cards {
  display: none;
}

.mobile-card {
  background: var(--surface-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.65rem;
}

.mobile-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0;
  gap: 0.5rem;
}

.mobile-card-row + .mobile-card-row {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.mobile-card-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.mobile-card-value {
  font-size: 0.88rem;
  font-weight: 600;
  text-align: right;
  word-break: break-all;
  min-width: 0;
}

.mobile-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.mobile-card-title {
  font-size: 1rem;
  font-weight: 700;
}

/* Responsive */
@media (max-width: 960px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: -100%;
    width: 260px;
    height: 100dvh;
    z-index: 200;
    transition: left 0.25s ease;
    background: rgba(20, 12, 55, 0.98);
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
  }

  .sidebar.open + .sidebar-overlay {
    display: block;
  }

  .sidebar-toggle {
    display: flex;
  }

  .sidebar-nav {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .destination-row {
    grid-template-columns: 1fr;
  }

  .destination-row .remove-destination {
    grid-column: auto;
  }

  .source-row {
    grid-template-columns: 1fr;
  }

  .device-row {
    grid-template-columns: 80px 1fr 40px;
  }

  .copy-url {
    max-width: 140px;
    font-size: 0.78rem;
  }

  table {
    min-width: 450px;
  }

  .user-dropdown-toggle {
    padding: 0.35rem 0.55rem;
    font-size: 0.82rem;
  }

  .topbar-link {
    display: none;
  }
}

@media (max-width: 560px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-content,
  .admin-topbar {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .admin-content {
    padding-top: 0.75rem;
  }

  .chart-bars {
    height: 120px;
  }

  .bulk-bar {
    flex-wrap: wrap;
  }

  .data-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-header {
    padding: 0.75rem 0.85rem;
  }

  .panel-body {
    padding: 0.85rem;
  }

  .panel-header h2 {
    font-size: 0.95rem;
  }

  .stat-card {
    padding: 0.75rem 0.85rem;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .stat-label {
    font-size: 0.75rem;
  }

  table {
    font-size: 0.8rem;
    min-width: 400px;
  }

  th, td {
    padding: 0.55rem 0.4rem;
  }

  .copy-url {
    max-width: 110px;
    font-size: 0.72rem;
  }

  .filter-form select {
    min-width: 120px;
    font-size: 0.82rem;
  }

  .filter-form-row {
    gap: 0.35rem;
  }
}

