:root {
  --bg: #eef2f5;
  --bg-soft: rgba(255, 255, 255, 0.72);
  --panel: rgba(255, 255, 255, 0.94);
  --panel-alt: #f5f8fb;
  --panel-strong: #eaf1f5;
  --text: #122033;
  --muted: #6f7f92;
  --border: rgba(178, 191, 205, 0.55);
  --accent: #17c39b;
  --accent-strong: #0ea37f;
  --accent-secondary: #16324d;
  --danger: #d85a66;
  --success: #16956f;
  --shadow: 0 18px 44px rgba(23, 36, 51, 0.08);
}

body.theme-dark {
  --bg: #171d26;
  --bg-soft: rgba(24, 32, 42, 0.82);
  --panel: rgba(31, 40, 52, 0.96);
  --panel-alt: #25303d;
  --panel-strong: #202a36;
  --text: #f2f6fb;
  --muted: #97a7b7;
  --border: rgba(96, 113, 132, 0.42);
  --accent: #21d0a5;
  --accent-strong: #17b38d;
  --accent-secondary: #314458;
  --danger: #ff7f8d;
  --success: #56d3a6;
  --shadow: 0 24px 68px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(33, 208, 165, 0.12), transparent 24%),
    radial-gradient(circle at bottom right, rgba(22, 50, 77, 0.1), transparent 22%),
    linear-gradient(180deg, var(--bg) 0%, color-mix(in srgb, var(--bg), #000 3%) 100%);
}

input,
button,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 0.85rem 1.1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

button.secondary {
  background: var(--accent-secondary);
}

button.danger {
  background: var(--danger);
}

#logout-button {
  background: #d84d57;
}

#logout-button:hover {
  background: #bb3e47;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.82rem 0.92rem;
  background: color-mix(in srgb, var(--panel-alt), #fff 12%);
  color: var(--text);
}

select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.82rem 0.92rem;
  background: color-mix(in srgb, var(--panel-alt), #fff 12%);
  color: var(--text);
}

label {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

code {
  background: var(--panel-alt);
  padding: 0.15rem 0.4rem;
  border-radius: 7px;
}

.auth-container {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.auth-page .auth-container {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.card {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.auth-page .card {
  width: min(320px, calc(100% - 1rem));
}

.login-card {
  max-width: 320px;
  padding: 1rem 0.95rem 0.95rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 0.9rem;
}

.login-logo {
  width: min(120px, 48%);
  height: auto;
  display: block;
  margin: 0 auto 0.35rem;
  filter: drop-shadow(0 16px 32px rgba(29, 205, 159, 0.2));
}

.login-brand h1 {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.18;
}

.auth-page label {
  font-size: 0.82rem;
}

.auth-page input {
  padding: 0.58rem 0.72rem;
  font-size: 0.92rem;
}

.auth-page button[type="submit"] {
  padding: 0.62rem 0.9rem;
  font-size: 0.95rem;
}

.auth-page .stack {
  gap: 0.75rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  position: relative;
}

.sidebar {
  background: rgba(19, 26, 35, 0.76);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.mobile-menu-button,
.sidebar-overlay {
  display: none;
}

.mobile-menu-button {
  position: fixed;
  top: 0.75rem;
  left: 0.85rem;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 14px;
  background: rgba(24, 31, 42, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 50;
}

.mobile-menu-button span {
  display: block;
  width: 22px;
  height: 3px;
  margin: 4px auto;
  border-radius: 999px;
  background: #35d7aa;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 18, 0.54);
  z-index: 35;
}

.mobile-topbar {
  display: none;
}

body:not(.theme-dark) .sidebar {
  background: rgba(243, 247, 250, 0.9);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.sidebar-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 16px;
}

.sidebar-brand strong,
.sidebar-brand span {
  display: block;
}

.sidebar-brand span {
  color: var(--muted);
  font-size: 0.92rem;
}

.sidebar-nav,
.sidebar-links {
  display: grid;
  gap: 0.6rem;
}

.sidebar-section {
  margin-top: 1.35rem;
}

.sidebar-main {
  display: grid;
  gap: 0.2rem;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
}

.sidebar-section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.7rem;
}

.sidebar-badge {
  min-width: 28px;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--panel-alt);
  text-align: center;
}

.sidebar-link {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.85rem 0.95rem;
  display: grid;
  gap: 0.25rem;
}

.sidebar-link:hover {
  background: color-mix(in srgb, var(--accent), transparent 90%);
  color: var(--text);
}

.sidebar-link.active {
  background: color-mix(in srgb, var(--accent), transparent 18%);
  color: #fff;
  border-color: transparent;
}

body:not(.theme-dark) .sidebar-link.active {
  color: #fff;
}

.sidebar-link-text {
  font-weight: 700;
}

.sidebar-link-meta {
  font-size: 0.82rem;
  opacity: 0.82;
}

.sidebar-empty {
  color: var(--muted);
  font-size: 0.92rem;
  padding: 0.5rem 0.15rem;
}

.content-area {
  padding: 1.6rem;
}

.topbar-dashboard {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.header-brand {
  display: block;
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.header-brand h1,
.header-brand p,
.hero-card h2,
.hero-card p,
.selected-link-header h2,
.section-header h3 {
  margin: 0;
}

.header-brand p,
.hint,
.group-stats,
.selected-link-url,
.eyebrow {
  color: var(--muted);
}

.selected-link-url-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.15rem;
}

.selected-link-url-row .selected-link-url {
  margin: 0;
}

.copy-link-button {
  padding: 0.55rem 0.9rem;
  font-size: 0.92rem;
  white-space: nowrap;
}

.hero-card,
.selected-link-card,
.groups-card,
.empty-dashboard-card {
  display: grid;
  gap: 1rem;
}

.hero-card {
  margin-bottom: 1rem;
}

html.has-link-selection #dashboard-home-panel {
  display: none;
}

.inline-form {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.inline-form input {
  flex: 1 1 280px;
}

.message {
  min-height: 1.5rem;
  color: var(--danger);
  font-weight: 700;
}

.message.success {
  color: var(--success);
}

.selected-link-panel,
.link-workspace,
.stack,
.groups-list {
  display: grid;
  gap: 1rem;
}

.users-workspace {
  display: grid;
  gap: 1rem;
}

.selected-link-header,
.group-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.selected-link-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-weight: 800;
  white-space: nowrap;
}

.grid-3,
.group-grid {
  display: grid;
  gap: 1rem;
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.group-grid {
  grid-template-columns: 2fr 1fr 1fr auto;
  align-items: end;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
}

.checkbox-field input {
  width: auto;
}

.group-item {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
}

.users-list {
  display: grid;
  gap: 0.9rem;
}

.user-grid {
  grid-template-columns: 1.5fr 1.3fr 1fr auto;
}

.button-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.empty-state,
.empty-dashboard-card {
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 16px;
  color: var(--muted);
  background: var(--bg-soft);
}

.theme-switch {
  position: relative;
  width: 58px;
  height: 30px;
  padding: 0;
  border-radius: 999px;
  background: #8ea0b3;
  box-shadow: 0 6px 18px rgba(10, 20, 30, 0.18);
  flex-shrink: 0;
}

.theme-switch:hover {
  transform: none;
  background: #8396aa;
}

.theme-switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
}

.theme-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #0f2c4a;
  display: grid;
  place-items: center;
  transform: translateX(0);
  transition: transform 0.2s ease;
  overflow: hidden;
}

body.theme-dark .theme-switch-thumb {
  transform: translateX(28px);
}

.theme-icon {
  position: absolute;
  font-size: 14px;
  line-height: 1;
  color: #ffffff;
  transition: opacity 0.2s ease;
}

.theme-icon-sun {
  opacity: 1;
}

.theme-icon-moon {
  opacity: 0;
}

body.theme-dark .theme-icon-sun {
  opacity: 0;
}

body.theme-dark .theme-icon-moon {
  opacity: 1;
}

.auth-page .theme-switch {
  position: fixed;
  top: 1.35rem;
  right: 1.35rem;
  left: auto;
  z-index: 60;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 72px;
    left: 0;
    width: min(310px, 82vw);
    height: calc(100dvh - 72px);
    max-height: calc(100dvh - 72px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 45;
  }

  .sidebar-brand {
    margin-bottom: 1rem;
  }

  .sidebar-section {
    margin-top: 1rem;
  }

  .mobile-menu-button {
    display: block;
  }

  .mobile-topbar {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 72px;
    background: rgba(24, 31, 42, 0.96);
    backdrop-filter: blur(10px);
    z-index: 40;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

    .toolbar {
      position: fixed;
      top: 0.7rem;
      right: 0.85rem;
      z-index: 52;
      width: auto;
      flex-direction: row;
      align-items: center;
      justify-content: flex-end;
      flex-wrap: nowrap;
      gap: 0.55rem;
    }

    .toolbar .theme-switch {
      position: relative;
      top: auto;
      right: auto;
      z-index: auto;
    }

    .toolbar .secondary {
      position: relative;
      top: auto;
      right: auto;
      z-index: auto;
      min-width: 58px;
      padding: 0.56rem 0.72rem;
      font-size: 0.92rem;
    }

  .content-area {
    padding-top: 5.9rem;
  }

  body.mobile-menu-open .sidebar {
    transform: translateX(0);
  }

  body.mobile-menu-open .sidebar-overlay {
    display: block;
  }
}

@media (max-width: 760px) {
  .topbar-dashboard,
  .header-brand,
  .selected-link-header,
  .group-actions,
  .selected-link-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .grid-3,
  .group-grid,
  .user-grid {
    grid-template-columns: 1fr;
  }

  .inline-form {
    flex-direction: column;
  }

  .inline-form input,
  .inline-form button,
  .selected-link-actions button,
  .selected-link-actions .badge {
    width: 100%;
  }

  .hero-card .inline-form input {
    min-height: 52px;
    padding: 0.72rem 0.85rem;
    flex: 0 1 auto;
  }

    .toolbar button:not(.theme-switch) {
      width: auto;
    }

  .sidebar-logo {
    width: 68px;
    height: 68px;
  }

  .sidebar-link {
    padding: 0.75rem 0.85rem;
  }

  .card {
    padding: 1rem;
    border-radius: 18px;
  }

  .button-row button {
    flex: 1 1 auto;
  }

  .content-area {
    padding: 1rem;
    padding-top: 6rem;
  }
}

@media (max-width: 480px) {
  .content-area,
  .sidebar {
    padding: 0.85rem;
  }

  .content-area {
    padding-top: 5.9rem;
  }

  .auth-page .theme-switch {
    top: 1rem;
    right: 1rem;
  }

  .header-brand h1 {
    font-size: 1.55rem;
  }

  .header-brand p,
  .hint,
  .eyebrow,
  .sidebar-brand span,
  .sidebar-link-meta {
    font-size: 0.9rem;
  }

  .selected-link-title,
  .hero-card h2,
  .section-header h3 {
    font-size: 1.1rem;
  }

  .group-item {
    padding: 0.85rem;
  }

    .toolbar {
      gap: 0.45rem;
      right: 0.65rem;
    }

  .theme-switch {
    width: 46px;
    height: 26px;
  }

  .toolbar .theme-switch {
    width: 46px;
    min-width: 46px;
  }

  .theme-switch-thumb {
    width: 22px;
    height: 22px;
  }

  body.theme-dark .theme-switch-thumb {
    transform: translateX(20px);
  }

    .toolbar .secondary {
      min-width: 54px;
      padding: 0.52rem 0.65rem;
      font-size: 0.88rem;
    }
}
