:root {
  --bg: #0b0f17;
  --surface: #121824;
  --surface-soft: #0f1521;
  --ink: #ecf2ff;
  --muted: #9cabc4;
  --brand: #4f8cff;
  --brand-strong: #3a75e8;
  --danger: #ef4444;
  --border: #263043;
  --sidebar-bg: #0d131f;
  --sidebar-ink: #e2ebfc;
  --sidebar-border: #1f293c;
  --shadow-soft: none;
  --shadow-strong: none;
  --sidebar-width: 264px;
}

body.theme-dark {
  --bg: #0b0f17;
  --surface: #121824;
  --surface-soft: #0f1521;
  --ink: #ecf2ff;
  --muted: #9cabc4;
  --brand: #4f8cff;
  --brand-strong: #3a75e8;
  --danger: #ef4444;
  --border: #263043;
  --sidebar-bg: #0d131f;
  --sidebar-ink: #e2ebfc;
  --sidebar-border: #1f293c;
}

body:not(.theme-dark) {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --ink: #111827;
  --muted: #64748b;
  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --border: #d9e2ef;
  --sidebar-bg: #ffffff;
  --sidebar-ink: #111827;
  --sidebar-border: #d9e2ef;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 14px;
  padding: 14px;
  min-height: 100vh;
  transition: grid-template-columns 0.25s ease, background-color 0.2s ease, color 0.2s ease;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  border: 1px solid var(--sidebar-border);
  border-radius: 18px;
  box-shadow: none;
  width: var(--sidebar-width);
  min-height: calc(100vh - 32px);
  padding: 16px 10px;
  position: sticky;
  top: 16px;
  overflow: hidden;
  transition: width 0.25s ease, padding 0.25s ease;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.sidebar-head h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.01em;
}

.sidebar nav {
  display: grid;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-user {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  background: transparent;
  color: var(--sidebar-ink);
  padding: 8px 10px;
}

.avatar-chip {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(79, 140, 255, 0.2);
  color: var(--brand);
}

.sidebar-user-meta {
  display: grid;
  text-align: left;
}

.sidebar-user-meta small {
  color: var(--muted);
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-group-toggle {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--sidebar-ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.nav-group-toggle .caret {
  font-size: 0.78rem;
  opacity: 0.8;
  transition: transform 0.2s ease;
}

.nav-group-toggle.collapsed .caret {
  transform: rotate(-90deg);
}

.nav-sub {
  display: grid;
  gap: 6px;
  padding-left: 8px;
}

.nav-sub.collapsed {
  display: none;
}

.nav-btn {
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--sidebar-ink);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.nav-btn:hover {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(59, 130, 246, 0.2);
  transform: translateX(2px);
}

.nav-btn.active {
  background: rgba(37, 99, 235, 0.26);
  border-color: rgba(96, 165, 250, 0.34);
}

.nav-link {
  display: block;
  text-decoration: none;
  color: var(--sidebar-ink);
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
}

.nav-ico {
  width: 16px;
  text-align: center;
}

.nav-text {
  white-space: nowrap;
}

.nav-link:hover {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(59, 130, 246, 0.2);
}

body.sidebar-collapsed {
  grid-template-columns: 70px 1fr;
}

body.sidebar-collapsed .sidebar {
  width: 70px;
  padding: 16px 8px;
}

body.sidebar-collapsed .sidebar-head h1 {
  display: none;
}

body.sidebar-collapsed .nav-btn {
  text-align: center;
  padding-inline: 6px;
}

body.sidebar-collapsed .nav-btn span {
  display: inline;
}

body.sidebar-collapsed .nav-btn .nav-text {
  display: none;
}

body.sidebar-collapsed .nav-group-toggle span:first-child,
body.sidebar-collapsed .nav-link {
  display: none;
}

body.sidebar-collapsed .sidebar-footer {
  display: none;
}

body.sidebar-collapsed .nav-group-toggle {
  justify-content: center;
}

body.sidebar-collapsed .nav-sub {
  padding-left: 0;
}

.content {
  min-width: 0;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: none;
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.topbar-left h1 {
  margin: 0 0 4px;
  font-size: 1.36rem;
}

.breadcrumbs {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.notif-wrap {
  position: relative;
}

.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  line-height: 18px;
  text-align: center;
  padding: 0 4px;
}

.notif-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(380px, 85vw);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  z-index: 4500;
  overflow: hidden;
}

.notif-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.notif-list {
  max-height: 320px;
  overflow: auto;
  padding: 6px;
}

.notif-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--surface-soft);
}

.notif-item:last-child {
  margin-bottom: 0;
}

.notif-item p {
  margin: 0 0 4px;
  font-size: 0.9rem;
}

.notif-item small {
  color: var(--muted);
}

.user-menu-anchor {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

/* Clerk user button avatar wrapper */
.user-menu-anchor .cl-userButtonRoot {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  overflow: hidden;
}

.user-menu-anchor .cl-userButtonTrigger {
  width: 40px;
  height: 40px;
  border-radius: 999px;
}

.user-menu-anchor .cl-avatarBox {
  width: 40px;
  height: 40px;
  border-radius: 999px;
}

.icon-btn {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  line-height: 1;
  box-shadow: none;
}

.page { display: none; }
.page.active { display: block; }

h2 {
  margin-top: 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: none;
}

.card p { margin: 0 0 8px; color: var(--muted); }
.card h3 { margin: 0; font-size: 1.45rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  margin-top: 18px;
  box-shadow: none;
}

.action-area .row,
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.inline-check input {
  width: auto;
}

button {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 12px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

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

button.secondary {
  background: var(--surface);
  color: var(--brand);
  border-color: var(--border);
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 10px;
  width: 100%;
  background: var(--surface);
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 72px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85rem;
  line-height: 1.45;
}

.grid-2 {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid-3 {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

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

th, td {
  border-bottom: 1px solid var(--border);
  padding: 9px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.changes-table-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: auto;
  max-height: 68vh;
  background: var(--surface);
}

.changes-table {
  min-width: 980px;
}

.changes-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
}

.changes-table tbody tr:nth-child(odd) {
  background: var(--surface-soft);
}

.changes-table tbody tr:hover {
  background: rgba(37, 99, 235, 0.08);
}

.status-text {
  margin-top: 12px;
  color: var(--brand);
  font-weight: 600;
}

.importance-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.importance-critical {
  background: rgba(220, 38, 38, 0.18);
  color: #ef4444;
  border: 1px solid rgba(220, 38, 38, 0.35);
}

.importance-high {
  background: rgba(245, 158, 11, 0.18);
  color: #d97706;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.importance-medium {
  background: rgba(59, 130, 246, 0.18);
  color: #2563eb;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.importance-low {
  background: rgba(148, 163, 184, 0.2);
  color: var(--muted);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-scroll {
  max-height: 58vh;
  overflow: auto;
  padding-right: 4px;
}

.timeline-controls {
  margin-bottom: 8px;
}

.timeline-group {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--surface-soft);
}

.timeline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 8px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(0, 0, 0, 0.56);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  color: var(--ink);
  width: min(700px, 100%);
  max-height: min(86vh, 900px);
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--border);
  padding: 14px;
  box-shadow: var(--shadow-strong);
}

.why-grid {
  display: grid;
  gap: 10px;
}

.why-block {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.why-block h4 {
  margin: 0 0 6px;
  font-size: 0.92rem;
}

.why-list {
  margin: 0;
  padding-left: 18px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head button {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
}

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

.members-tabs {
  margin-top: 0;
}

.active-tab {
  background: rgba(37, 99, 235, 0.18) !important;
  border-color: rgba(96, 165, 250, 0.42) !important;
  color: #93c5fd !important;
}

.invite-box {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
  padding: 14px;
}

.invite-layout {
  display: grid;
  gap: 16px;
}

.invite-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 92%, #000 8%);
  padding: 18px;
}

.invite-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.invite-title-row h3 {
  margin: 0;
}

.invite-section {
  margin-top: 16px;
}

.invite-section h4 {
  margin: 0 0 8px;
  font-size: 1.16rem;
}

.invite-divider {
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

.invite-code-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
}

.invite-code-row input {
  min-width: 0;
}

.invite-pill-btn {
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
}

.icon-round-btn {
  border-radius: 999px !important;
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.invite-status-line {
  margin: 12px 0 8px;
}

.invite-duration-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 180px) auto;
  gap: 10px;
  align-items: end;
}

.invite-duration-input,
.invite-duration-unit {
  display: grid;
  gap: 6px;
}

.invite-duration-input label,
.invite-duration-unit label {
  font-weight: 600;
}

.invite-filter-row {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.invite-filter-row select {
  width: auto;
  min-width: 130px;
}

.invite-empty-state {
  margin-top: 26px;
  color: var(--muted);
  min-height: 56px;
  display: flex;
  align-items: center;
}

.members-headline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.members-tabs-panel {
  padding: 10px;
}

.members-segment {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}

.segment-btn {
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.segment-btn.active-tab {
  background: rgba(37, 99, 235, 0.2) !important;
  color: #bfdbfe !important;
  border-color: rgba(96, 165, 250, 0.45) !important;
}

.members-table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.member-table td {
  vertical-align: middle;
}

.member-actions-cell {
  position: relative;
}

.member-actions-btn {
  min-width: 34px;
  height: 34px;
  border-radius: 10px;
  padding: 0 8px;
  line-height: 1;
  font-size: 1rem;
}

.member-quick-overview {
  position: fixed;
  z-index: 4000;
  min-width: 240px;
  max-width: 320px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.35);
}

.member-quick-overview h4 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.member-quick-overview p {
  margin: 4px 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 6000;
  display: grid;
  gap: 8px;
}

.toast {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 220px;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.16s ease;
}

.toast.success {
  border-color: rgba(34, 197, 94, 0.45);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.45);
}

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

.member-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.member-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-soft);
}

.role-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid rgba(59, 130, 246, 0.3);
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
  text-transform: capitalize;
}

.status-online {
  color: #22c55e;
  font-weight: 600;
}

.settings-panel {
  width: 100%;
  max-width: none;
}

.settings-form {
  display: grid;
  gap: 10px;
}

.logo-row {
  display: flex;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  background: var(--surface-soft);
}

.logo-preview {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  object-fit: cover;
}

.logo-actions {
  display: grid;
  gap: 8px;
  flex: 1;
}

#modal-root {
  position: fixed;
  inset: 0;
  z-index: 5000;
  pointer-events: none;
}

#modal-root .modal-overlay {
  pointer-events: auto;
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  .sidebar {
    position: static;
    width: 100%;
    min-height: auto;
  }

  body.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  body.sidebar-collapsed .sidebar {
    width: 100%;
  }

  body.sidebar-collapsed .sidebar-head h1,
  body.sidebar-collapsed .nav-btn span {
    display: inline;
  }

  .invite-code-row {
    grid-template-columns: 1fr auto auto;
  }

  .invite-code-row #toggle-invite-code {
    grid-column: 2;
  }

  .invite-code-row #copy-invite-code {
    grid-column: 3;
  }

  .invite-code-row #refresh-org-info {
    grid-column: 2 / span 2;
    justify-self: start;
  }

  .invite-duration-row {
    grid-template-columns: 1fr;
  }
}

/* Onboarding pages */
body.onboarding-page {
  display: block;
  min-height: 100vh;
  padding: 0;
  background: var(--bg);
}

.onboard-shell {
  width: min(820px, calc(100% - 28px));
  margin: 36px auto;
}

.onboard-topbar {
  justify-content: space-between;
  margin-bottom: 12px;
}

.onboard-center {
  padding: 22px;
}

.onboard-center.compact {
  max-width: 520px;
  margin-inline: auto;
}

.onboard-sub {
  margin-top: -4px;
  margin-bottom: 16px;
  color: var(--muted);
}

#clerk-auth {
  width: 100%;
  max-width: 100%;
}

#clerk-auth .cl-rootBox {
  width: 100%;
}

#clerk-auth .cl-card {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  box-sizing: border-box;
}

@media (max-width: 560px) {
  #clerk-auth .cl-card {
    max-width: 100%;
  }
}

.onboard-grid {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.onboard-card {
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.onboard-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-strong);
}

.onboard-form {
  display: grid;
  gap: 10px;
}

.brand-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--brand);
  transform: skewX(-22deg);
}

.secondary-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
