:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #eef2f7;
  --text: #172033;
  --muted: #667085;
  --border: #d9e0ea;
  --brand: #246bfe;
  --brand-strong: #174bb8;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.08);
  --radius: 8px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101318;
  --surface: #181d24;
  --surface-strong: #232a34;
  --text: #edf2f7;
  --muted: #aab4c3;
  --border: #303946;
  --brand: #78a6ff;
  --brand-strong: #a9c5ff;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

.shell {
  min-height: 100vh;
}

.brand,
.nav-link,
.app-card,
.button {
  text-decoration: none;
}

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

.topbar-brand {
  margin-right: 6px;
}

.brand-mark,
.avatar,
.app-card-icon,
.nav-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small,
.profile-copy strong,
.profile-copy small {
  display: block;
}

.brand small,
.profile-copy small,
.eyebrow,
.app-card em {
  color: var(--muted);
}

.nav-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--bg);
  font-weight: 700;
}

.content-frame {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 82px;
  padding: 16px 28px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.workspace-search {
  flex: 1 1 260px;
  max-width: 360px;
}

.workspace-search input {
  width: 100%;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.topbar h1,
.topbar p,
.section-heading h2,
.section-heading p,
.module-header h2,
.module-header p {
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.theme-toggle,
.icon-button,
.button {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.theme-toggle,
.button {
  padding: 10px 14px;
  font-weight: 700;
}

.icon-button {
  width: 42px;
  height: 42px;
}

.profile-menu {
  position: relative;
}

.profile-menu summary {
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
  cursor: pointer;
}

.profile-menu summary::-webkit-details-marker {
  display: none;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.profile-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 12px);
  width: 240px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.profile-panel p {
  margin: 0 0 8px;
}

.profile-panel a,
.profile-panel button {
  display: block;
  width: 100%;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--brand-strong);
  font: inherit;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
}

.auth-panel {
  width: min(460px, 100%);
  margin: 32px auto;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel h2,
.auth-panel p {
  margin: 0 0 8px;
}

.auth-panel p {
  color: var(--muted);
}

.form-stack {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.form-stack label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.form-stack input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  font-weight: 500;
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
}

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

.form-message,
.dev-reset-link {
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--radius);
}

.form-message.error {
  background: #fee4e2;
  color: #912018;
}

.form-message.success,
.dev-reset-link {
  background: #dcfae6;
  color: #085d3a;
}

.dev-reset-link a {
  display: block;
  overflow-wrap: anywhere;
}

.auth-link {
  margin-top: 16px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 18px;
}

.admin-tabs,
.admin-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.admin-tabs {
  align-self: start;
  display: grid;
  gap: 4px;
  padding: 10px;
}

.admin-tabs a {
  padding: 10px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--muted);
}

.admin-tabs a:hover,
.admin-tabs a.is-active {
  background: var(--surface-strong);
  color: var(--text);
}

.admin-content {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.admin-panel {
  padding: 18px;
}

.admin-panel h2,
.admin-panel h3 {
  margin: 0 0 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  align-items: end;
}

.form-grid label,
.permission-list {
  display: grid;
  gap: 6px;
}

.permission-list {
  margin-top: 18px;
}

.permission-list small {
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

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

th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

td form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.compact-checkbox {
  margin: 0;
}

@media (max-width: 860px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

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

.workspace-tabs {
  position: sticky;
  top: 82px;
  z-index: 9;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 28px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  backdrop-filter: blur(14px);
}

.workspace-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 110px;
  max-width: 210px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  background: var(--surface-strong);
  color: var(--muted);
}

.workspace-tab.is-active {
  background: var(--surface);
  color: var(--text);
}

.workspace-tab a {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}

.workspace-tab button {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.main-content {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.main-content.app-content {
  width: 100%;
  max-width: none;
  padding: 18px 24px 28px;
}

.hosted-app {
  min-height: calc(100vh - 150px);
  padding: 14px 18px 24px;
}

.hosted-app .page-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 0;
}

.hero-panel,
.module-header,
.notice-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: end;
  padding: 28px;
}

.hero-panel h2 {
  max-width: 680px;
  margin: 0 0 8px;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1.05;
}

.hero-panel p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(96px, 1fr));
  gap: 10px;
}

.hero-stats div {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.hero-stats strong,
.hero-stats span {
  display: block;
}

.hero-stats strong {
  font-size: 1.4rem;
}

.hero-stats span {
  color: var(--muted);
  font-size: 0.88rem;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  margin: 30px 0 14px;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
}

.app-card {
  position: relative;
  display: grid;
  min-height: 132px;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}

.app-card:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
}

.app-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 4px;
  background: var(--surface-strong);
  color: var(--brand-strong);
  font-size: 1.25rem;
  font-weight: 800;
}

.app-card-copy {
  display: grid;
  gap: 3px;
}

.app-card-copy strong {
  font-size: 0.92rem;
}

.app-card-copy span {
  display: none;
  color: var(--muted);
}

.app-card em {
  align-self: end;
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 600;
}

.app-card-menu {
  position: absolute;
  top: 8px;
  right: 9px;
  color: var(--muted);
  font-weight: 800;
}

.module-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 24px;
}

.module-header .app-card-icon {
  width: 64px;
  height: 64px;
}

.notice-panel {
  margin-top: 18px;
  padding: 22px;
}

.notice-panel h3,
.notice-panel h2 {
  margin: 0 0 8px;
}

.notice-panel p {
  margin: 0 0 14px;
  color: var(--muted);
}

.error-panel {
  max-width: 680px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 860px) {
  .topbar {
    padding: 12px 16px;
    flex-wrap: wrap;
  }

  .topbar-brand {
    flex: 1 1 100%;
  }

  .workspace-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .profile-copy {
    display: none;
  }

  .main-content {
    padding: 18px 16px;
  }

  .main-content.app-content {
    padding: 12px 10px 18px;
  }

  .hosted-app {
    padding: 10px;
  }

  .workspace-tabs {
    top: 128px;
    padding-inline: 16px;
  }

  .hero-panel {
    grid-template-columns: 1fr;
    padding: 20px;
  }

  .hero-stats {
    grid-template-columns: 1fr;
  }

  .module-header {
    align-items: flex-start;
  }
}
